This adds "--cacheinfo" option to update-cache.  It is needed to
manipulate dircache without actually having such a blob in the working
directory.  To pretend you have a file with mode-sha1 at path, say:

 $ update-cache --cacheinfo mode sha1 path


Signed-off-by: Junio C Hamano <[EMAIL PROTECTED]>

---

 update-cache.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletion(-)

Index: update-cache.c
===================================================================
--- 6767883b330882bc0e9a7c1e4fd999c0ee97ba3a/update-cache.c  (mode:100644 
sha1:6c1d608cff03d2126191c0891cf1d262d6ae7823)
+++ 21e5e9f7d7dfa81c6519f0204d5a467236c7fdd5/update-cache.c  (mode:100644 
sha1:8e82862ee66dc339967de558e7a5a9c52ba37259)
@@ -250,6 +250,8 @@
 {
        int i, newfd, entries;
        int allow_options = 1;
+       const char *sha1_force = NULL;
+       const char *mode_force = NULL;
 
        newfd = open(".git/index.lock", O_RDWR | O_CREAT | O_EXCL, 0600);
        if (newfd < 0)
@@ -282,14 +284,35 @@
                                refresh_cache();
                                continue;
                        }
+                       if (!strcmp(path, "--cacheinfo")) {
+                               mode_force = argv[++i];
+                               sha1_force = argv[++i];
+                               continue;
+                       }
                        die("unknown option %s", path);
                }
                if (!verify_path(path)) {
                        fprintf(stderr, "Ignoring path %s\n", argv[i]);
                        continue;
                }
-               if (add_file_to_cache(path))
+               if (sha1_force && mode_force) {
+                       struct cache_entry *ce;
+                       int namelen = strlen(path);
+                       int mode;
+                       int size = cache_entry_size(namelen);
+                       sscanf(mode_force, "%o", &mode);
+                       ce = malloc(size);
+                       memset(ce, 0, size);
+                       memcpy(ce->name, path, namelen);
+                       ce->namelen = namelen;
+                       ce->st_mode = mode;
+                       get_sha1_hex(sha1_force, ce->sha1);
+
+                       add_cache_entry(ce, 1);
+               }
+               else if (add_file_to_cache(path))
                        die("Unable to add %s to database", path);
+               mode_force = sha1_force = NULL;
        }
        if (write_cache(newfd, active_cache, active_nr) ||
            rename(".git/index.lock", ".git/index"))

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to