git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] fetch-pack: warn if in commit graph but not obj db

From
Josh Steadmon <steadmon@google.com>
Date
Oct 30, 2024, 21:22 UTC
Message-ID
<bzhg2a7mv2xrbahk6o5kpijx4dxmpkm4wrrjhatetowjdowout@hesucnp6cikf>
In-Reply-To
<1027ff2cb7d9af5cc9ce6b653d28150457db8703.1730235646.git.jonathantanmy@google.com>
On 2024.10.29 14:11, Jonathan Tan wrote:
Show 48 quoted lines
> 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 <jonathantanmy@google.com>
> ---
>  fetch-pack.c | 22 +++++++++++++++++++---
>  object.h     |  2 +-
>  2 files changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 6728a0d2f5..5a0020366b 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -57,6 +57,7 @@ static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
>  #define ALTERNATE	(1U << 1)
>  #define COMMON		(1U << 6)
>  #define REACH_SCRATCH	(1U << 7)
> +#define COMPLETE_FROM_COMMIT_GRAPH	(1U << 8)

We're defining a new flag, and we note it in object.h as well below, so looks good so far.

Show 8 quoted lines
>  /*
>   * 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,
>  }
>  
>  static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
> -					       int mark_tags_complete)
> +					       int mark_additional_complete_information)

We're already marking some completion flags here, so we're just making the parameter name more descriptive, OK.

Show 12 quoted lines
>  {
>  	enum object_type type;
>  	struct object_info info = { .typep = &type };
>  	struct commit *commit;
>  
>  	commit = lookup_commit_in_graph(the_repository, oid);
> -	if (commit)
> +	if (commit) {
> +		if (mark_additional_complete_information)
> +			commit->object.flags |= COMPLETE_FROM_COMMIT_GRAPH;
>  		return commit;
> +	}

We already have a case where we're checking the commit graph, so we can also mark the commit complete here... well, not the original "COMPLETE" flag since we don't want to change behavior, but our new COMPLETE_FROM_COMMIT_GRAPH flag. Sounds good.

Show 24 quoted lines
>  
>  	while (1) {
>  		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,
>  
>  			if (!tag->tagged)
>  				return NULL;
> -			if (mark_tags_complete)
> +			if (mark_additional_complete_information)
>  				tag->object.flags |= COMPLETE;
>  			oid = &tag->tagged->oid;
>  		} else {
> @@ -809,6 +813,14 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
>  	save_commit_buffer = old_save_commit_buffer;
>  }
>  
> +static void warn_in_commit_graph_only(const struct object_id *oid)
> +{
> +	warning(_("You are attempting to fetch %s, which is in the commit graph file but not in the object database."),
> +		oid_to_hex(oid));
> +	warning(_("This is probably due to repo corruption."));
> +	warning(_("If you are attempting to repair this repo corruption by refetching the missing object, use 'git fetch --refetch' with the missing object."));
> +}
> +

Here's the new warning. As mentioned in my reply to the cover letter, I feel like it makes more sense to die(), but I don't feel too strongly about it.

Show 11 quoted lines
>  /*
>   * Returns 1 if every object pointed to by the given remote refs is available
>   * locally and reachable from a local ref, and 0 otherwise.
> @@ -830,6 +842,10 @@ static int everything_local(struct fetch_pack_args *args,
>  				      ref->name);
>  			continue;
>  		}
> +		if (o->flags & COMPLETE_FROM_COMMIT_GRAPH) {
> +			if (!has_object(the_repository, remote, 0))
> +				warn_in_commit_graph_only(remote);
> +		}

And now that we're checking what's local, we issue our warning if we have an object missing from the DB but mentioned in the commit graph. Seems fine, although I wonder if it makes more sense to fail earlier. It looks like the only place we do the `mark_additional_complete_information` checks is in `mark_complete()`, so should we just check this condition there? No strong feelings either way, just curious.

Show 20 quoted lines
>  		print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote),
>  			      ref->name);
>  	}
> diff --git a/object.h b/object.h
> index 17f32f1103..196e489253 100644
> --- a/object.h
> +++ b/object.h
> @@ -65,7 +65,7 @@ void object_array_init(struct object_array *array);
>  /*
>   * object flag allocation:
>   * revision.h:               0---------10         15               23------27
> - * fetch-pack.c:             01    67
> + * fetch-pack.c:             01    6-8
>   * negotiator/default.c:       2--5
>   * walker.c:                 0-2
>   * upload-pack.c:                4       11-----14  16-----19
> -- 
> 2.47.0.163.g1226f6d8fa-goog
> 
> 
Previous: Jonathan TanNext: Jonathan Tan
Message 15 of 38 in “promisor-remote: always JIT fetch with --refetch”
  1. promisor-remote: always JIT fetch with --refetchEmily Shaffer, Oct 3, 2024
  2. Junio C HamanoOct 6, 2024
  3. Robert CoupOct 7, 2024
  4. Junio C HamanoOct 7, 2024
  5. Emily ShafferOct 11, 2024
  6. Junio C HamanoOct 11, 2024
  7. fetch-pack: don't mark COMPLETE unless we have the full objectEmily Shaffer, Oct 23, 2024
  8. Emily ShafferOct 23, 2024
  9. Taylor BlauOct 23, 2024
  10. Jonathan TanOct 28, 2024
  11. 0/2 When fetching, warn if in commit graph but not obj dbJonathan Tan, Oct 29, 2024
  12. 1/2 Revert "fetch-pack: add a deref_without_lazy_fetch_extended()"Jonathan Tan, Oct 29, 2024
  13. Josh SteadmonOct 30, 2024
  14. 2/2 fetch-pack: warn if in commit graph but not obj dbJonathan Tan, Oct 29, 2024
  15. Josh SteadmonOct 30, 2024
  16. Jonathan TanOct 31, 2024
  17. Taylor BlauOct 31, 2024
  18. Jonathan TanOct 31, 2024
  19. Taylor BlauNov 1, 2024
  20. Jonathan TanNov 1, 2024
  21. Josh SteadmonOct 30, 2024
  22. 0/2 When fetching, die if in commit graph but not obj dbJonathan Tan, Oct 31, 2024
  23. 1/2 Revert "fetch-pack: add a deref_without_lazy_fetch_extended()"Jonathan Tan, Oct 31, 2024
  24. 2/2 fetch-pack: warn if in commit graph but not obj dbJonathan Tan, Oct 31, 2024
  25. Junio C HamanoNov 1, 2024
  26. Junio C HamanoNov 1, 2024
  27. Han XinNov 1, 2024
  28. Jonathan TanNov 1, 2024
  29. Jonathan TanNov 1, 2024
  30. Junio C HamanoNov 2, 2024
  31. Jonathan TanNov 1, 2024
  32. Taylor BlauNov 1, 2024
  33. Jonathan TanNov 1, 2024
  34. Josh SteadmonOct 31, 2024
  35. 0/2 When fetching, die if in commit graph but not obj dbJonathan Tan, Nov 5, 2024
  36. 1/2 Revert "fetch-pack: add a deref_without_lazy_fetch_extended()"Jonathan Tan, Nov 5, 2024
  37. 2/2 fetch-pack: die if in commit graph but not obj dbJonathan Tan, Nov 5, 2024
  38. Junio C HamanoNov 6, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.