{"thread":{"id":"6071","subject":"[PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","startedAt":"2006-12-22T02:19:21Z","lastAt":"2006-12-22T19:25:01Z","messageCount":10,"participants":["Johannes Schindelin","Junio C Hamano","Jakub Narebski","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"30000","messageId":"Pine.LNX.4.63.0612220318320.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6071","inReplyTo":null,"subject":"[PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-22T02:19:21Z","receivedAt":"2006-12-22T02:19:21Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nIf the cache tree is not up-to-date, it will be updated first. So, now\n\n\t$ git show :Documentation/\n\nwill in effect show what files/directories are in the index' version\nof the directory Documentation. The three commands\n\n\t$ git show :./\n\t$ git show :.\n\t$ git show :\n\nare all equivalent and show the index' idea of the root directory.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n sha1_name.c |   24 +++++++++++++++++++++++-\n 1 files changed, 23 insertions(+), 1 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 6d7cd78..e3758cc 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -5,6 +5,7 @@\n #include \"blob.h\"\n #include \"tree-walk.h\"\n #include \"refs.h\"\n+#include \"cache-tree.h\"\n \n static int find_short_object_filename(int len, const char *name, unsigned char *sha1)\n {\n@@ -532,7 +533,7 @@ int get_sha1(const char *name, unsigned char *sha1)\n \t */\n \tif (name[0] == ':') {\n \t\tint stage = 0;\n-\t\tstruct cache_entry *ce;\n+\t\tstruct cache_entry *ce = NULL;\n \t\tint pos;\n \t\tif (namelen < 3 ||\n \t\t    name[2] != ':' ||\n@@ -561,6 +562,27 @@ int get_sha1(const char *name, unsigned char *sha1)\n \t\t\t}\n \t\t\tpos++;\n \t\t}\n+\t\tif (namelen > 0 && cp[namelen - 1] == '/')\n+\t\t\tnamelen--;\n+\t\tif (namelen == 1 && cp[0] == '.') {\n+\t\t\tnamelen = 0;\n+\t\t\tcp = \"\";\n+\t\t}\n+\t\tif (namelen == 0 || (ce && ce_namelen(ce) > namelen &&\n+\t\t\t\t\tce->name[namelen] == '/' &&\n+\t\t\t\t\t!memcmp(ce->name, cp, namelen))) {\n+\t\t\tstruct cache_tree *tree =\n+\t\t\t\tcache_tree_find(active_cache_tree, cp);\n+\t\t\tif (!cache_tree_fully_valid(tree)) {\n+\t\t\t\tret = cache_tree_update(active_cache_tree,\n+\t\t\t\t\t\tactive_cache, active_nr, 0, 0);\n+\t\t\t\tif (ret < 0)\n+\t\t\t\t\treturn ret;\n+\t\t\t\ttree = cache_tree_find(active_cache_tree, cp);\n+\t\t\t}\n+\t\t\thashcpy(sha1, tree->sha1);\n+\t\t\treturn 0;\n+\t\t}\n \t\treturn -1;\n \t}\n \tfor (cp = name, bracket_depth = 0; *cp; cp++) {\n-- \n1.4.4.2.ga854-dirty\n"},{"id":"30009","messageId":"7vzm9g7duz.fsf@assigned-by-dhcp.cox.net","threadId":"6071","inReplyTo":"Pine.LNX.4.63.0612220318320.19693@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-22T04:29:08Z","receivedAt":"2006-12-22T04:29:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"(1) Why is this needed?\n\n(2) What does this do when the index is unmerged?\n"},{"id":"30026","messageId":"emg4qp$f8v$2@sea.gmane.org","threadId":"6071","inReplyTo":"7vzm9g7duz.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-22T08:28:43Z","receivedAt":"2006-12-22T08:28:43Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n\n> (1) Why is this needed?\n\nProbably for completeness.\n\n> (2) What does this do when the index is unmerged?\n\nI think it should show \"git ls-files --unmerged --abbrev\", perhaps...\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"30032","messageId":"20061222084425.GA4644@steel.home","threadId":"6071","inReplyTo":"Pine.LNX.4.63.0612220318320.19693@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Alex Riesen","fromEmail":"fork0@t-online.de","sentAt":"2006-12-22T08:44:25Z","receivedAt":"2006-12-22T08:44:25Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Johannes Schindelin, Fri, Dec 22, 2006 03:19:21 +0100:\n> \n> If the cache tree is not up-to-date, it will be updated first. So, now\n> \n> \t$ git show :Documentation/\n> \n> will in effect show what files/directories are in the index' version\n> of the directory Documentation. The three commands\n> \n> \t$ git show :./\n> \t$ git show :.\n> \t$ git show :\n> \n> are all equivalent and show the index' idea of the root directory.\n\nThat is a bit unexpected if you're not in the root directory of\nrepository, but in some subdir of the working directory.\nWhy root? Why not the current directory relative to root?\n"},{"id":"30047","messageId":"Pine.LNX.4.63.0612221312540.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6071","inReplyTo":"7vzm9g7duz.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-22T12:14:05Z","receivedAt":"2006-12-22T12:14:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 21 Dec 2006, Junio C Hamano wrote:\n\n> (1) Why is this needed?\n\nIt was asked recently. It also serves well when you want to show the \nindex.\n\n> (2) What does this do when the index is unmerged?\n\nI have no idea, and ATM no time to test. Will do later.\n\nCiao,\nDscho\n"},{"id":"30049","messageId":"Pine.LNX.4.63.0612221315370.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6071","inReplyTo":"emg4qp$f8v$2@sea.gmane.org","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-22T12:16:42Z","receivedAt":"2006-12-22T12:16:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 22 Dec 2006, Jakub Narebski wrote:\n\n> Junio C Hamano wrote:\n> \n> > (2) What does this do when the index is unmerged?\n> \n> I think it should show \"git ls-files --unmerged --abbrev\", perhaps...\n\nNah. I'd rather fail out, saying that because there are unmerged entries, \nthere is no valid tree in the index.\n\nCiao,\nDscho\n"},{"id":"30050","messageId":"Pine.LNX.4.63.0612221316550.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6071","inReplyTo":"20061222084425.GA4644@steel.home","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-22T12:18:55Z","receivedAt":"2006-12-22T12:18:55Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 22 Dec 2006, Alex Riesen wrote:\n\n> Johannes Schindelin, Fri, Dec 22, 2006 03:19:21 +0100:\n> > \n> > If the cache tree is not up-to-date, it will be updated first. So, now\n> > \n> > \t$ git show :Documentation/\n> > \n> > will in effect show what files/directories are in the index' version\n> > of the directory Documentation. The three commands\n> > \n> > \t$ git show :./\n> > \t$ git show :.\n> > \t$ git show :\n> > \n> > are all equivalent and show the index' idea of the root directory.\n> \n> That is a bit unexpected if you're not in the root directory of\n> repository, but in some subdir of the working directory.\n> Why root? Why not the current directory relative to root?\n\nWhy root? Because you are not asking for the working directory. Use \"ls\" \nfor that. You are asking for the index. If you git-show a commit, you \ndon't expect the output to be restricted by the subdirectory you're in, \neither, right?\n\nCIao,\nDscho\n"},{"id":"30066","messageId":"20061222160944.GA4651@steel.home","threadId":"6071","inReplyTo":"Pine.LNX.4.63.0612221316550.19693@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Alex Riesen","fromEmail":"fork0@t-online.de","sentAt":"2006-12-22T16:09:44Z","receivedAt":"2006-12-22T16:09:44Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Johannes Schindelin, Fri, Dec 22, 2006 13:18:55 +0100:\n> > > If the cache tree is not up-to-date, it will be updated first. So, now\n> > > \n> > > \t$ git show :Documentation/\n> > > \n> > > will in effect show what files/directories are in the index' version\n> > > of the directory Documentation. The three commands\n> > > \n> > > \t$ git show :./\n> > > \t$ git show :.\n> > > \t$ git show :\n> > > \n> > > are all equivalent and show the index' idea of the root directory.\n> > \n> > That is a bit unexpected if you're not in the root directory of\n> > repository, but in some subdir of the working directory.\n> > Why root? Why not the current directory relative to root?\n> \n> Why root? Because you are not asking for the working directory. Use \"ls\" \n> for that. You are asking for the index. If you git-show a commit, you \n> don't expect the output to be restricted by the subdirectory you're in, \n> either, right?\n\nOf course I do. You're breaking a very well-known and widely used\nidiom here: the \".\" means current or at least somehow related to the\ncurrent directory. Why would you expect \"git show :.\" to show\neverything from root on if your current directory is \"Documentation\"?\nYes, it is a commit which \"git show\" displays, but the patches/diffs\nare restricted by filenames, and that is where the old rules come into\nplay. And I would actually expect \":/\" to filter from the root on, and\n\":.\" to mean the current directory.\n"},{"id":"30073","messageId":"200612221905.02915.jnareb@gmail.com","threadId":"6071","inReplyTo":"Pine.LNX.4.63.0612221315370.19693@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-22T18:05:01Z","receivedAt":"2006-12-22T18:05:01Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Johannes Schindelin wrote:\n\n> On Fri, 22 Dec 2006, Jakub Narebski wrote:\n> \n>> Junio C Hamano wrote:\n>> \n>>> (2) What does this do when the index is unmerged?\n>> \n>> I think it should show \"git ls-files --unmerged --abbrev\", perhaps...\n> \n> Nah. I'd rather fail out, saying that because there are unmerged entries, \n> there is no valid tree in the index.\n\nWell, 'git diff' on unmerged IIRC does 'git diff -cc', so why not 'git show :'\ndo 'git ls-files --unmerged --abbrev'...\n-- \nJakub Narebski\nPoland\n"},{"id":"30080","messageId":"Pine.LNX.4.63.0612222023400.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6071","inReplyTo":"7vzm9g7duz.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] sha1_name(): accept ':directory/' to get at the cache_tree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-22T19:25:01Z","receivedAt":"2006-12-22T19:25:01Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 21 Dec 2006, Junio C Hamano wrote:\n\n> (2) What does this do when the index is unmerged?\n\n\t$ git show :\n\ta1: unmerged (f16f906ab60483c100d1241dfc39868de9ec9fcb)\n\ta1: unmerged (cf84443e49e1b366fac938711ddf4be2d4d1d9e9)\n\ta1: unmerged (fd7923529855d0b274795ae3349c5e0438333979)\n\tfatal: ambiguous argument ':': unknown revision or path not in the \n\tworking tree. Use '--' to separate paths from revisions\n\nWe could be a bit nicer, but I think the first three lines speak for \nthemselves. This is all stderr BTW.\n\nCiao,\nDscho\n"}]}