[PATCH] sha1_name(): accept ':directory/' to get at the cache_tree
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Dec 22, 2006, 02:19 UTC
- Message-ID
- <Pine.LNX.4.63.0612220318320.19693@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 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