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

[PATCH v3 8/9] sha1_name.c: teach get_short_sha1() a commit-only option

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 24, 2012, 00:11 UTC
Message-ID
<1340496691-12258-9-git-send-email-gitster@pobox.com>
In-Reply-To
<1340496691-12258-1-git-send-email-gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 sha1_name.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/sha1_name.c b/sha1_name.c
index 7cca7d9..58dbbe2 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -219,6 +219,13 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 }
 
 #define GET_SHORT_QUIETLY 01
+#define GET_SHORT_COMMIT_ONLY 02
+
+static int disambiguate_commit_only(const unsigned char *sha1, void *cb_data_unused)
+{
+	int kind = sha1_object_info(sha1, NULL);
+	return kind == OBJ_COMMIT;
+}
 
 static int get_short_sha1(const char *name, int len, unsigned char *sha1,
 			  unsigned flags)
@@ -255,6 +262,9 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
 	prepare_alt_odb();
 
 	memset(&ds, 0, sizeof(ds));
+	if (flags & GET_SHORT_COMMIT_ONLY)
+		ds.fn = disambiguate_commit_only;
+
 	find_short_object_filename(len, hex_pfx, &ds);
 	find_short_packed_object(len, bin_pfx, &ds);
 	status = finish_object_disambiguation(&ds, sha1);
-- 
1.7.11.1.29.gf71be5c
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 11 in “Extending the shelf-life of "git describe" output”
  1. 0/9 Extending the shelf-life of "git describe" outputJunio C Hamano, Jun 24, 2012
  2. 1/9 sha1_name.c: indentation fixJunio C Hamano, Jun 24, 2012
  3. 2/9 sha1_name.c: clarify what "fake" is for in find_short_object_filename()Junio C Hamano, Jun 24, 2012
  4. 3/9 sha1_name.c: rename "now" to "current"Junio C Hamano, Jun 24, 2012
  5. 4/9 sha1_name.c: refactor find_short_packed_object()Junio C Hamano, Jun 24, 2012
  6. 5/9 sha1_name.c: correct misnamed "canonical" and "res"Junio C Hamano, Jun 24, 2012
  7. 6/9 sha1_name.c: restructure disambiguation of short namesJunio C Hamano, Jun 24, 2012
  8. 7/9 sha1_name.c: allow get_short_sha1() to take other flagsJunio C Hamano, Jun 24, 2012
  9. 8/9 sha1_name.c: teach get_short_sha1() a commit-only optionJunio C Hamano, Jun 24, 2012
  10. 9/9 sha1_name.c: get_describe_name() by definition groks only commitsJunio C Hamano, Jun 24, 2012
  11. Junio C HamanoJun 24, 2012

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.