[PATCH] Add --info-only option to git-update-cache.
authorBryan Larsen <bryan.larsen@gmail.com>
Fri, 8 Jul 2005 23:52:12 +0000 (16:52 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sat, 9 Jul 2005 00:07:37 +0000 (17:07 -0700)
Add --info-only option to git-update-cache.

[JC demangled whitespace from the posted patch himself because he
liked it so much. Also adjusted to the index_fd() interface
slightly done differently from the original one.]

Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Documentation/git-update-cache.txt
update-cache.c
index 947f2bded0317bab04598d2fb9755db0995c6c45..7340e89c1fe2d0f93d7ed7499e9d1536f05620ad 100644 (file)
@@ -14,6 +14,7 @@ SYNOPSIS
             [--ignore-missing]
             [--force-remove]
             [--cacheinfo <mode> <object> <file>]\*
+            [--info-only]
             [--] [<file>]\*
 
 DESCRIPTION
@@ -47,6 +48,11 @@ OPTIONS
 --cacheinfo <mode> <object> <path>::
        Directly insert the specified info into the cache.
        
+--info-only::
+       Do not create objects in the object database for all
+       <file> arguments that follow this flag; just insert
+       their object IDs into the cache.
+
 --force-remove::
        Remove the file from the index even when the working directory
        still has such a file. (Implies --remove.)
@@ -80,15 +86,27 @@ the stat entry is out of date.
 For example, you'd want to do this after doing a "git-read-tree", to link
 up the stat cache details with the proper files.
 
-Using --cacheinfo
------------------
-'--cacheinfo' is used to register a file that is not in the current
-working directory.  This is useful for minimum-checkout merging.
+Using --cacheinfo or --info-only
+--------------------------------
+'--cacheinfo' is used to register a file that is not in the
+current working directory.  This is useful for minimum-checkout
+merging.
+
+  To pretend you have a file with mode and sha1 at path, say:
 
-To pretend you have a file with mode and sha1 at path, say:
+   $ git-update-cache --cacheinfo mode sha1 path
 
- $ git-update-cache --cacheinfo mode sha1 path
+'--info-only' is used to register files without placing them in the object
+database.  This is useful for status-only repositories.
 
+Both '--cacheinfo' and '--info-only' behave similarly: the index is updated
+but the object database isn't.  '--cacheinfo' is useful when the object is
+in the database but the file isn't available locally.  '--info-only' is
+useful when the file is available, but you do not wish to update the
+object database.
+
+Examples
+--------
 To update and refresh only the files already checked out:
 
    git-checkout-cache -n -f -a && git-update-cache --ignore-missing --refresh
index d5225c37644086f9b3c0b911c6e283fb5ec50c8e..cc4298ac4fa501136cfec192c047bc92138d5285 100644 (file)
@@ -12,7 +12,7 @@
  * like "git-update-cache *" and suddenly having all the object
  * files be revision controlled.
  */
-static int allow_add = 0, allow_remove = 0, allow_replace = 0, not_new = 0, quiet = 0;
+static int allow_add = 0, allow_remove = 0, allow_replace = 0, not_new = 0, quiet = 0, info_only = 0;
 static int force_remove;
 
 /* Three functions to allow overloaded pointer return; see linux/err.h */
@@ -68,7 +68,7 @@ static int add_file_to_cache(char *path)
                fd = open(path, O_RDONLY);
                if (fd < 0)
                        return -1;
-               if (index_fd(ce->sha1, fd, &st, 1, NULL) < 0)
+               if (index_fd(ce->sha1, fd, &st, !info_only, NULL) < 0)
                        return -1;
                break;
        case S_IFLNK:
@@ -77,7 +77,12 @@ static int add_file_to_cache(char *path)
                        free(target);
                        return -1;
                }
-               if (write_sha1_file(target, st.st_size, "blob", ce->sha1))
+               if (info_only) {
+                       unsigned char hdr[50];
+                       int hdrlen;
+                       write_sha1_file_prepare(target, st.st_size, "blob",
+                                               ce->sha1, hdr, &hdrlen);
+               } else if (write_sha1_file(target, st.st_size, "blob", ce->sha1))
                        return -1;
                free(target);
                break;
@@ -382,6 +387,10 @@ int main(int argc, char **argv)
                                i += 3;
                                continue;
                        }
+                       if (!strcmp(path, "--info-only")) {
+                               info_only = 1;
+                               continue;
+                       }
                        if (!strcmp(path, "--force-remove")) {
                                force_remove = 1;
                                continue;