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

[PATCH v7 13/16] fetch-pack: restore save_commit_buffer after use

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Dec 8, 2017, 15:58 UTC
Message-ID
<20171208155851.855-14-git@jeffhostetler.com>
In-Reply-To
<20171208155851.855-1-git@jeffhostetler.com>
From: Jonathan Tan <jonathantanmy@google.com>

In fetch-pack, the global variable save_commit_buffer is set to 0, but not restored to its original value after use.

In particular, if show_log() (in log-tree.c) is invoked after fetch_pack() in the same process, show_log() will return before printing out the commit message (because the invocation to get_cached_commit_buffer() returns NULL, because the commit buffer was not saved). I discovered this when attempting to run "git log -S" in a partial clone, triggering the case where revision walking lazily loads missing objects.

Therefore, restore save_commit_buffer to its original value after use.

An alternative to solve the problem I had is to replace get_cached_commit_buffer() with get_commit_buffer(). That invocation was introduced in commit a97934d ("use get_cached_commit_buffer where appropriate", 2014-06-13) to replace "commit->buffer" introduced in commit 3131b71 ("Add "--show-all" revision walker flag for debugging", 2008-02-13). In the latter commit, the commit author seems to be deciding between not showing an unparsed commit at all and showing an unparsed commit without the message (which is what the commit does), and did not mention parsing the unparsed commit, so I prefer to preserve the existing behavior.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 fetch-pack.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/fetch-pack.c b/fetch-pack.c
index 3c5f064..773453c 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -717,6 +717,7 @@ static int everything_local(struct fetch_pack_args *args,
 {
 	struct ref *ref;
 	int retval;
+	int old_save_commit_buffer = save_commit_buffer;
 	timestamp_t cutoff = 0;
 
 	save_commit_buffer = 0;
@@ -786,6 +787,9 @@ static int everything_local(struct fetch_pack_args *args,
 		print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote),
 			      ref->name);
 	}
+
+	save_commit_buffer = old_save_commit_buffer;
+
 	return retval;
 }
 
-- 
2.9.3
Previous: Jeff HostetlerNext: Jeff Hostetler
Message 6 of 24 in “Parial clone part 3: clone, fetch, fetch-pack, upload-pack, and tests”
  1. 00/16 Parial clone part 3: clone, fetch, fetch-pack, upload-pack, and testsJeff Hostetler, Dec 8, 2017
  2. 03/16 gc: do not repack promisor packfilesJeff Hostetler, Dec 8, 2017
  3. 09/16 fetch: support filtersJeff Hostetler, Dec 8, 2017
  4. Duy NguyenAug 19, 2018
  5. Jeff HostetlerAug 20, 2018
  6. 13/16 fetch-pack: restore save_commit_buffer after useJeff Hostetler, Dec 8, 2017
  7. 12/16 unpack-trees: batch fetching of missing blobsJeff Hostetler, Dec 8, 2017
  8. 11/16 clone: partial cloneJeff Hostetler, Dec 8, 2017
  9. 15/16 fetch: inherit filter-spec from partial cloneJeff Hostetler, Dec 8, 2017
  10. 16/16 t5616: test bulk prefetch after partial fetchJeff Hostetler, Dec 8, 2017
  11. 10/16 partial-clone: define partial clone settings in configJeff Hostetler, Dec 8, 2017
  12. 14/16 t5616: end-to-end tests for partial cloneJeff Hostetler, Dec 8, 2017
  13. 02/16 rev-list: support termination at promisor objectsJeff Hostetler, Dec 8, 2017
  14. 08/16 fetch: refactor calculation of remote listJeff Hostetler, Dec 8, 2017
  15. 07/16 fetch-pack: test support excluding large blobsJeff Hostetler, Dec 8, 2017
  16. 01/16 sha1_file: support lazily fetching missing objectsJeff Hostetler, Dec 8, 2017
  17. 05/16 fetch-pack, index-pack, transport: partial cloneJeff Hostetler, Dec 8, 2017
  18. 06/16 fetch-pack: add --no-filterJeff Hostetler, Dec 8, 2017
  19. 04/16 upload-pack: add object filtering for partial cloneJeff Hostetler, Dec 8, 2017
  20. Junio C HamanoDec 8, 2017
  21. Jeff HostetlerDec 8, 2017
  22. Junio C HamanoDec 8, 2017
  23. Brandon WilliamsDec 8, 2017
  24. Jonathan TanDec 11, 2017

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.