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

Re: Joining cg-*-id

From
Linus Torvalds <torvalds@osdl.org>
Date
Sep 19, 2005, 22:16 UTC
Message-ID
<Pine.LNX.4.58.0509191505470.2553@g5.osdl.org>
In-Reply-To
<20050919215608.GA13845@pasky.or.cz>
On Mon, 19 Sep 2005, Petr Baudis wrote:
> 
> There is git-rev-parse, but it is not as powerful (cannot take dates and
> sha1 completion does not work when listing parents)
Hmm.
That lack of sha1 completion is a bug. 

How does the date thing work? It sounds like something horribly ambiguous, but hey, maybe some useful semantics could be found.

The short sha1 problem is fixed thus,
		Linus

---- Fix extended short SHA1 name completion

get_sha1() would not do sha1 completion of short SHA1's when they were part of a more complex expression. So doing

	git-rev-parse 727132834e6be48a93c1bd6458a29d474ce7d5d5^

would work, and return 87c6aeb4efdd4355918d127a91bd0adc5a02f8ff. But using the shorthand version

	git-rev-list 72713^
wouldn't work.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/sha1_name.c b/sha1_name.c
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -84,19 +84,19 @@ static int find_short_packed_object(int 
 	return 0;
 }
 
-static int get_short_sha1(const char *name, unsigned char *sha1)
+static int get_short_sha1(const char *name, int len, unsigned char *sha1)
 {
 	int i;
 	char canonical[40];
 	unsigned char res[20];
 
+	if (len < 4)
+		return -1;
 	memset(res, 0, 20);
 	memset(canonical, 'x', 40);
-	for (i = 0;;i++) {
+	for (i = 0; i < len ;i++) {
 		unsigned char c = name[i];
 		unsigned char val;
-		if (!c || i > 40)
-			break;
 		if (c >= '0' && c <= '9')
 			val = c - '0';
 		else if (c >= 'a' && c <= 'f')
@@ -112,8 +112,6 @@ static int get_short_sha1(const char *na
 			val <<= 4;
 		res[i >> 1] |= val;
 	}
-	if (i < 4)
-		return -1;
 	if (find_short_object_filename(i, canonical, sha1))
 		return 0;
 	if (find_short_packed_object(i, res, sha1))
@@ -254,7 +252,7 @@ static int get_sha1_1(const char *name, 
 	ret = get_sha1_basic(name, len, sha1);
 	if (!ret)
 		return 0;
-	return get_short_sha1(name, sha1);
+	return get_short_sha1(name, len, sha1);
 }
 
 /*
Previous: Petr BaudisNext: Petr Baudis
Message 3 of 22 in “Joining cg-*-id”
  1. Pavel RoskinSep 19, 2005
  2. Petr BaudisSep 19, 2005
  3. Linus TorvaldsSep 19, 2005
  4. Petr BaudisSep 19, 2005
  5. Linus TorvaldsSep 20, 2005
  6. Petr BaudisSep 20, 2005
  7. Linus TorvaldsSep 20, 2005
  8. Petr BaudisSep 20, 2005
  9. Linus TorvaldsSep 20, 2005
  10. Linus TorvaldsSep 20, 2005
  11. Paul MackerrasSep 21, 2005
  12. Linus TorvaldsSep 21, 2005
  13. Paul MackerrasSep 21, 2005
  14. Petr BaudisSep 21, 2005
  15. Matthias UrlichsSep 20, 2005
  16. Junio C HamanoSep 20, 2005
  17. Matthias UrlichsSep 20, 2005
  18. Paul MackerrasSep 20, 2005
  19. Pavel RoskinSep 19, 2005
  20. Petr BaudisSep 19, 2005
  21. Pavel RoskinSep 20, 2005
  22. Petr BaudisSep 20, 2005

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.