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

[PATCH] sha1_name(): accept ':directory/' to get at the cache_tree

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 9, 2007, 14:03 UTC
Message-ID
<Pine.LNX.4.63.0701091502030.22628@wbgn013.biozentrum.uni-wuerzburg.de>
If the cache tree is not up-to-date, it will be updated first. So, now
        $ git show :Documentation/

will in effect show what files/directories are in the index' version of the directory Documentation. The commands

        $ git show :/
        $ git show :
are equivalent and show the index' idea of the root directory.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	'tis a resend of an earlier patch, but without support for the
	bogus ":." as equivalent to ":/".
	I find this feature highly convenient when I just want to see
	what files the index contains.
 sha1_name.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 6d7cd78..6baa7a4 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -5,6 +5,7 @@
 #include "blob.h"
 #include "tree-walk.h"
 #include "refs.h"
+#include "cache-tree.h"
 
 static int find_short_object_filename(int len, const char *name, unsigned char *sha1)
 {
@@ -532,7 +533,7 @@ int get_sha1(const char *name, unsigned char *sha1)
 	 */
 	if (name[0] == ':') {
 		int stage = 0;
-		struct cache_entry *ce;
+		struct cache_entry *ce = NULL;
 		int pos;
 		if (namelen < 3 ||
 		    name[2] != ':' ||
@@ -561,6 +562,23 @@ int get_sha1(const char *name, unsigned char *sha1)
 			}
 			pos++;
 		}
+		if (namelen > 0 && cp[namelen - 1] == '/')
+			namelen--;
+		if (namelen == 0 || (ce && ce_namelen(ce) > namelen &&
+					ce->name[namelen] == '/' &&
+					!memcmp(ce->name, cp, namelen))) {
+			struct cache_tree *tree =
+				cache_tree_find(active_cache_tree, cp);
+			if (!cache_tree_fully_valid(tree)) {
+				ret = cache_tree_update(active_cache_tree,
+						active_cache, active_nr, 0, 0);
+				if (ret < 0)
+					return ret;
+				tree = cache_tree_find(active_cache_tree, cp);
+			}
+			hashcpy(sha1, tree->sha1);
+			return 0;
+		}
 		return -1;
 	}
 	for (cp = name, bracket_depth = 0; *cp; cp++) {
Next: Alex Riesen
Message 1 of 6 in “sha1_name(): accept ':directory/' to get at the cache_tree”
  1. sha1_name(): accept ':directory/' to get at the cache_treeJohannes Schindelin, Jan 9, 2007
  2. Alex RiesenJan 9, 2007
  3. Junio C HamanoJan 9, 2007
  4. Johannes SchindelinJan 10, 2007
  5. Junio C HamanoJan 10, 2007
  6. Johannes SchindelinJan 10, 2007

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.