git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree
@ 2006-12-22  2:19 Johannes Schindelin
  2006-12-22  4:29 ` Junio C Hamano
  2006-12-22  8:44 ` Alex Riesen
  0 siblings, 2 replies; 16+ messages in thread
From: Johannes Schindelin @ 2006-12-22  2:19 UTC (permalink / raw)
  To: git, junkio


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 three commands

	$ git show :./
	$ git show :.
	$ git show :

are all equivalent and show the index' idea of the root directory.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 sha1_name.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 6d7cd78..e3758cc 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,27 @@ int get_sha1(const char *name, unsigned char *sha1)
 			}
 			pos++;
 		}
+		if (namelen > 0 && cp[namelen - 1] == '/')
+			namelen--;
+		if (namelen == 1 && cp[0] == '.') {
+			namelen = 0;
+			cp = "";
+		}
+		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++) {
-- 
1.4.4.2.ga854-dirty

^ permalink raw reply related	[flat|nested] 16+ messages in thread
* [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree
@ 2007-01-09 14:03 Johannes Schindelin
  2007-01-09 17:25 ` Alex Riesen
  2007-01-09 23:47 ` Junio C Hamano
  0 siblings, 2 replies; 16+ messages in thread
From: Johannes Schindelin @ 2007-01-09 14:03 UTC (permalink / raw)
  To: git, junkio


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++) {

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-01-10  0:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-22  2:19 [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree Johannes Schindelin
2006-12-22  4:29 ` Junio C Hamano
2006-12-22  8:28   ` Jakub Narebski
2006-12-22 12:16     ` Johannes Schindelin
2006-12-22 18:05       ` Jakub Narebski
2006-12-22 12:14   ` Johannes Schindelin
2006-12-22 19:25   ` Johannes Schindelin
2006-12-22  8:44 ` Alex Riesen
2006-12-22 12:18   ` Johannes Schindelin
2006-12-22 16:09     ` Alex Riesen
  -- strict thread matches above, loose matches on Subject: below --
2007-01-09 14:03 Johannes Schindelin
2007-01-09 17:25 ` Alex Riesen
2007-01-09 23:47 ` Junio C Hamano
2007-01-10  0:22   ` Johannes Schindelin
2007-01-10  0:36     ` Junio C Hamano
2007-01-10  0:54       ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).