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

[PATCH v2 2/3] ls: remove redundant logic

From
Erik Faye-Lund <kusmabite@googlemail.com>
Date
Mar 20, 2010, 18:55 UTC
Message-ID
<1269111329-5896-3-git-send-email-kusmabite@gmail.com>
In-Reply-To
<1269111329-5896-1-git-send-email-kusmabite@gmail.com>

find_unique_abbrev() already returns the full SHA-1 if abbrev = 0, so we can remove the logic that avoids the call.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 builtin/ls-files.c |    7 ++-----
 builtin/ls-tree.c  |    6 ++----
 2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b065061..c0fbcdc 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -153,8 +153,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
 		printf("%s%06o %s %d\t",
 		       tag,
 		       ce->ce_mode,
-		       abbrev ? find_unique_abbrev(ce->sha1,abbrev)
-				: sha1_to_hex(ce->sha1),
+		       find_unique_abbrev(ce->sha1,abbrev),
 		       ce_stage(ce));
 	}
 	write_name_quoted(ce->name + offset, stdout, line_terminator);
@@ -176,9 +175,7 @@ static int show_one_ru(struct string_list_item *item, void *cbdata)
 		if (!ui->mode[i])
 			continue;
 		printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
-		       abbrev
-		       ? find_unique_abbrev(ui->sha1[i], abbrev)
-		       : sha1_to_hex(ui->sha1[i]),
+		       find_unique_abbrev(ui->sha1[i], abbrev),
 		       i + 1);
 		write_name_quoted(path + offset, stdout, line_terminator);
 	}
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 4484185..dc86b0d 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -103,13 +103,11 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
 			} else
 				strcpy(size_text, "-");
 			printf("%06o %s %s %7s\t", mode, type,
-			       abbrev ? find_unique_abbrev(sha1, abbrev)
-				      : sha1_to_hex(sha1),
+			       find_unique_abbrev(sha1, abbrev),
 			       size_text);
 		} else
 			printf("%06o %s %s\t", mode, type,
-			       abbrev ? find_unique_abbrev(sha1, abbrev)
-			              : sha1_to_hex(sha1));
+			       find_unique_abbrev(sha1, abbrev));
 	}
 	write_name_quotedpfx(base + chomp_prefix, baselen - chomp_prefix,
 			  pathname, stdout, line_termination);
-- 
1.7.0.2.456.g64f24
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 3 of 6 in “cherry-abbrev”
  1. 0/3 cherry-abbrevErik Faye-Lund, Mar 20, 2010
  2. 1/3 cherry: support --abbrev optionErik Faye-Lund, Mar 20, 2010
  3. 2/3 ls: remove redundant logicErik Faye-Lund, Mar 20, 2010
  4. 3/3 find_unique_abbrev: early out without a memcpyErik Faye-Lund, Mar 20, 2010
  5. Junio C HamanoMar 21, 2010
  6. Erik Faye-LundMar 21, 2010

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.