]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Fix lost-found to show commits only referenced by reflogs
authorShawn O. Pearce <spearce@spearce.org>
Wed, 4 Apr 2007 14:46:14 +0000 (10:46 -0400)
committerJunio C Hamano <junkio@cox.net>
Thu, 5 Apr 2007 22:00:03 +0000 (15:00 -0700)
Prior to 1.5.0 the git-lost-found utility was useful to locate
commits that were not referenced by any ref.  These were often
amends, or resets, or tips of branches that had been deleted.
Being able to locate a 'lost' commit and recover it by creating a
new branch was a useful feature in those days.

Unfortunately 1.5.0 added the reflogs to the reachability analysis
performed by git-fsck, which means that most commits users would
consider to be lost are still reachable through a reflog.  So most
(or all!) commits are reachable, and nothing gets output from
git-lost-found.

Now git-fsck can be told to ignore reflogs during its reachability
analysis, making git-lost-found useful again to locate commits
that are no longer referenced by a ref itself, but may still be
referenced by a reflog.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/git-fsck.txt
builtin-fsck.c
git-lost-found.sh

index 058009d2fab4c73edcbfefe7b48c5f9348459da3..8c68cf037259b3abc7ea16952d232b2fb2f07a25 100644 (file)
@@ -9,7 +9,7 @@ git-fsck - Verifies the connectivity and validity of the objects in the database
 SYNOPSIS
 --------
 [verse]
-'git-fsck' [--tags] [--root] [--unreachable] [--cache]
+'git-fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
                 [--full] [--strict] [<object>*]
 
 DESCRIPTION
@@ -38,6 +38,12 @@ index file and all SHA1 references in .git/refs/* as heads.
        Consider any object recorded in the index also as a head node for
        an unreachability trace.
 
+--no-reflogs::
+       Do not consider commits that are referenced only by an
+       entry in a reflog to be reachable.  This option is meant
+       only to search for commits that used to be in a ref, but
+       now aren't, but are still in that corresponding reflog.
+
 --full::
        Check not just objects in GIT_OBJECT_DIRECTORY
        ($GIT_DIR/objects), but also the ones found in alternate
index 4e5aa33dfb9921e4be98ea893cea34fc66e35735..4d8b66c344422dd60c72c72bbfbc5aa87be7907e 100644 (file)
@@ -14,6 +14,7 @@
 static int show_root;
 static int show_tags;
 static int show_unreachable;
+static int include_reflogs = 1;
 static int check_full;
 static int check_strict;
 static int keep_cache_objects;
@@ -517,7 +518,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
 static void get_default_heads(void)
 {
        for_each_ref(fsck_handle_ref, NULL);
-       for_each_reflog(fsck_handle_reflog, NULL);
+       if (include_reflogs)
+               for_each_reflog(fsck_handle_reflog, NULL);
 
        /*
         * Not having any default heads isn't really fatal, but
@@ -616,6 +618,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
                        keep_cache_objects = 1;
                        continue;
                }
+               if (!strcmp(arg, "--no-reflogs")) {
+                       include_reflogs = 0;
+                       continue;
+               }
                if (!strcmp(arg, "--full")) {
                        check_full = 1;
                        continue;
index 9360804711d6b81983e53df67c86ddc8082e2ab4..58570dff137adfdeb72ebf3f088af7379eded522 100755 (executable)
@@ -12,7 +12,7 @@ fi
 laf="$GIT_DIR/lost-found"
 rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
 
-git fsck --full |
+git fsck --full --no-reflogs |
 while read dangling type sha1
 do
        case "$dangling" in