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

[PATCH v2 5/5] get_sha1: drop object/refname ambiguity flag

From
Jeff King <peff@peff.net>
Date
Jan 8, 2014, 00:00 UTC
Message-ID
<20140108000009.GE10657@sigill.intra.peff.net>
In-Reply-To
<20140107235631.GA10503@sigill.intra.peff.net>

Now that our object/refname ambiguity test is much faster (thanks to the previous commit), there is no reason for code like "cat-file --batch-check" to turn it off. Here are before and after timings with this patch (on git.git):

  $ git rev-list --objects --all | cut -d' ' -f1 >objects
  [with flag]
  $ best-of-five -i objects ./git cat-file --batch-check
  real    0m0.392s
  user    0m0.368s
  sys     0m0.024s
  [without flag, without speedup; i.e., pre-25fba78]
  $ best-of-five -i objects ./git cat-file --batch-check
  real    0m1.652s
  user    0m0.904s
  sys     0m0.748s
  [without flag, with speedup]
  $ best-of-five -i objects ./git cat-file --batch-check
  real    0m0.388s
  user    0m0.356s
  sys     0m0.028s

So the new implementation does just as well as we did with the flag turning the whole thing off (better actually, but that is within the noise).

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/cat-file.c | 9 ---------
 cache.h            | 1 -
 environment.c      | 1 -
 sha1_name.c        | 2 +-
 4 files changed, 1 insertion(+), 12 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index ce79103..afba21f 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -285,15 +285,6 @@ static int batch_objects(struct batch_options *opt)
 	if (opt->print_contents)
 		data.info.typep = &data.type;
 
-	/*
-	 * We are going to call get_sha1 on a potentially very large number of
-	 * objects. In most large cases, these will be actual object sha1s. The
-	 * cost to double-check that each one is not also a ref (just so we can
-	 * warn) ends up dwarfing the actual cost of the object lookups
-	 * themselves. We can work around it by just turning off the warning.
-	 */
-	warn_on_object_refname_ambiguity = 0;
-
 	while (strbuf_getline(&buf, stdin, '\n') != EOF) {
 		if (data.split_on_whitespace) {
 			/*
diff --git a/cache.h b/cache.h
index ce377e1..73afc38 100644
--- a/cache.h
+++ b/cache.h
@@ -566,7 +566,6 @@ extern int assume_unchanged;
 extern int prefer_symlink_refs;
 extern int log_all_ref_updates;
 extern int warn_ambiguous_refs;
-extern int warn_on_object_refname_ambiguity;
 extern int shared_repository;
 extern const char *apply_default_whitespace;
 extern const char *apply_default_ignorewhitespace;
diff --git a/environment.c b/environment.c
index 3c76905..c59f6d4 100644
--- a/environment.c
+++ b/environment.c
@@ -22,7 +22,6 @@ int prefer_symlink_refs;
 int is_bare_repository_cfg = -1; /* unspecified */
 int log_all_ref_updates = -1; /* unspecified */
 int warn_ambiguous_refs = 1;
-int warn_on_object_refname_ambiguity = 1;
 int repository_format_version;
 const char *git_commit_encoding;
 const char *git_log_output_encoding;
diff --git a/sha1_name.c b/sha1_name.c
index f83ecb7..b9aaf74 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -451,7 +451,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 	int at, reflog_len, nth_prior = 0;
 
 	if (len == 40 && !get_sha1_hex(str, sha1)) {
-		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
+		if (warn_ambiguous_refs) {
 			if (sha1_is_ambiguous_with_ref(sha1)) {
 				warning(warn_msg, len, str);
 				if (advice_object_name_warning)
-- 
1.8.5.2.500.g8060133
Previous: Michael HaggertyNext: Michael Haggerty
Message 32 of 36 in “sha1_name: don't resolve refs when core.warnambiguousrefs is false”
  1. sha1_name: don't resolve refs when core.warnambiguousrefs is falseBrodie Rao, Jan 7, 2014
  2. Brodie RaoJan 7, 2014
  3. Jeff KingJan 7, 2014
  4. Junio C HamanoJan 7, 2014
  5. Jeff KingJan 7, 2014
  6. Junio C HamanoJan 7, 2014
  7. Jeff KingJan 7, 2014
  8. Junio C HamanoJan 7, 2014
  9. Jeff KingJan 7, 2014
  10. 1/4 cat-file: refactor error handling of batch_objectsJeff King, Jan 7, 2014
  11. 2/4 cat-file: fix a minor memory leak in batch_objectsJeff King, Jan 7, 2014
  12. 3/4 cat-file: restore ambiguity warning flag in batch_objectsJeff King, Jan 7, 2014
  13. 4/4 revision: turn off object/refname ambiguity check for --stdinJeff King, Jan 7, 2014
  14. speeding up 40-hex ambiguity checkJeff King, Jan 7, 2014
  15. 1/5 cat-file: refactor error handling of batch_objectsJeff King, Jan 7, 2014
  16. 2/5 cat-file: fix a minor memory leak in batch_objectsJeff King, Jan 7, 2014
  17. 3/5 refs: teach for_each_ref a flag to avoid recursionJeff King, Jan 7, 2014
  18. 3/5 refs: teach for_each_ref a flag to avoid recursionJeff King, Jan 8, 2014
  19. Jeff KingJan 8, 2014
  20. Michael HaggertyJan 8, 2014
  21. Jeff KingJan 9, 2014
  22. Michael HaggertyJan 10, 2014
  23. Jeff KingJan 10, 2014
  24. Junio C HamanoJan 9, 2014
  25. Jeff KingJan 9, 2014
  26. 4/5 get_sha1: speed up ambiguous 40-hex testJeff King, Jan 7, 2014
  27. Michael HaggertyJan 8, 2014
  28. Junio C HamanoJan 9, 2014
  29. Jeff KingJan 10, 2014
  30. Jeff KingJan 14, 2014
  31. Michael HaggertyJan 14, 2014
  32. 5/5 get_sha1: drop object/refname ambiguity flagJeff King, Jan 8, 2014
  33. Michael HaggertyJan 8, 2014
  34. Duy NguyenJan 7, 2014
  35. Junio C HamanoJan 7, 2014
  36. sha1_name: don't resolve refs when core.warnambiguousrefs is falseBrodie Rao, Jan 7, 2014

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.