Skip to content

Commit b866533

Browse files
jonathantanmyttaylorr
authored andcommitted
fetch-pack: warn if in commit graph but not obj db
When fetching, there is a step in which sought objects are first checked against the local repository; only objects that are not in the local repository are then fetched. This check first looks up the commit graph file, and returns "present" if the object is in there. However, the action of first looking up the commit graph file is not done everywhere in Git, especially if the type of the object at the time of lookup is not known. This means that in a repo corruption situation, a user may encounter an "object missing" error, attempt to fetch it, and still encounter the same error later when they reattempt their original action, because the object is present in the commit graph file but not in the object DB. Therefore, detect when this occurs and print a warning. (Note that we cannot proceed to include this object in the list of objects to be fetched without changing at least the fetch negotiation code: what would happen is that the client will send "want X" and "have X" and when I tested at $DAYJOB with a work server that uses JGit, the server reasonably returned an empty packfile. And changing the fetch negotiation code to only use the object DB when deciding what to report as "have" would be an unnecessary slowdown, I think.) This was discovered when a lazy fetch of a missing commit completed with nothing actually fetched, and the writing of the commit graph file after every fetch then attempted to read said missing commit, triggering a lazy fetch of said missing commit, resulting in an infinite loop with no user-visible indication (until they check the list of processes running on their computer). With this fix, at least a warning message will be printed. Note that although the repo corruption we discovered was caused by a bug in GC in a partial clone, the behavior that this patch teaches Git to warn about applies to any repo with commit graph enabled and with a missing commit, whether it is a partial clone or not. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 55e09f3 commit b866533

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

fetch-pack.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
5757
#define ALTERNATE (1U << 1)
5858
#define COMMON (1U << 6)
5959
#define REACH_SCRATCH (1U << 7)
60+
#define COMPLETE_FROM_COMMIT_GRAPH (1U << 8)
6061

6162
/*
6263
* After sending this many "have"s if we do not get any new ACK , we
@@ -123,15 +124,18 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
123124
}
124125

125126
static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
126-
int mark_tags_complete)
127+
int mark_additional_complete_information)
127128
{
128129
enum object_type type;
129130
struct object_info info = { .typep = &type };
130131
struct commit *commit;
131132

132133
commit = lookup_commit_in_graph(the_repository, oid);
133-
if (commit)
134+
if (commit) {
135+
if (mark_additional_complete_information)
136+
commit->object.flags |= COMPLETE_FROM_COMMIT_GRAPH;
134137
return commit;
138+
}
135139

136140
while (1) {
137141
if (oid_object_info_extended(the_repository, oid, &info,
@@ -143,7 +147,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
143147

144148
if (!tag->tagged)
145149
return NULL;
146-
if (mark_tags_complete)
150+
if (mark_additional_complete_information)
147151
tag->object.flags |= COMPLETE;
148152
oid = &tag->tagged->oid;
149153
} else {
@@ -809,6 +813,14 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
809813
save_commit_buffer = old_save_commit_buffer;
810814
}
811815

816+
static void warn_in_commit_graph_only(const struct object_id *oid)
817+
{
818+
warning(_("You are attempting to fetch %s, which is in the commit graph file but not in the object database."),
819+
oid_to_hex(oid));
820+
warning(_("This is probably due to repo corruption."));
821+
warning(_("If you are attempting to repair this repo corruption by refetching the missing object, use 'git fetch --refetch' with the missing object."));
822+
}
823+
812824
/*
813825
* Returns 1 if every object pointed to by the given remote refs is available
814826
* locally and reachable from a local ref, and 0 otherwise.
@@ -830,6 +842,10 @@ static int everything_local(struct fetch_pack_args *args,
830842
ref->name);
831843
continue;
832844
}
845+
if (o->flags & COMPLETE_FROM_COMMIT_GRAPH) {
846+
if (!has_object(the_repository, remote, 0))
847+
warn_in_commit_graph_only(remote);
848+
}
833849
print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote),
834850
ref->name);
835851
}

object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void object_array_init(struct object_array *array);
6565
/*
6666
* object flag allocation:
6767
* revision.h: 0---------10 15 23------27
68-
* fetch-pack.c: 01 67
68+
* fetch-pack.c: 01 6-8
6969
* negotiator/default.c: 2--5
7070
* walker.c: 0-2
7171
* upload-pack.c: 4 11-----14 16-----19

0 commit comments

Comments
 (0)