{"thread":{"id":"23730","subject":"[PATCH/RFC] Add [] as an alias for a reference to the empty tree","startedAt":"2010-05-07T16:37:27Z","lastAt":"2010-05-10T11:00:17Z","messageCount":10,"participants":["Peter Kjellerstedt","Jeff King","Junio C Hamano","Jonathan Nieder","Sverre Rabbelier"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"141129","messageId":"1273250247-20762-1-git-send-email-pkj@axis.com","threadId":"23730","inReplyTo":null,"subject":"[PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Peter Kjellerstedt","fromEmail":"peter.kjellerstedt@axis.com","sentAt":"2010-05-07T16:37:27Z","receivedAt":"2010-05-07T16:37:27Z","isPatch":true,"sender":{"key":"peter.kjellerstedt@axis.com","avatar":"https://gravatar.com/avatar/6d5a0182283c8eccd7b134a54dbfd5f30038f3ad4d38b96f424884b614a61ca2?d=mp&s=160"},"body":"Instead of specifying the SHA1 for the empty tree (i.e.,\n4b825dc642cb6eb9a060e54bf8d69288fbee4904) one can now say [], e.g.,\n'git diff [] v1.7.1' would give all the changes between the empty tree\nand the tag v1.7.1.\n\nThe rationale for selecting [] as the alias for the empty tree was that\nit looks empty, the brackets are not used for anything related to\nreferences (AFAIK), they are not allowed in references according to\n'man git-check-ref-format', and the syntax can easily be extended to\nallow other types of references by adding information between the\nbrackets.\n\nSigned-off-by: Peter Kjellerstedt <pkj@axis.com>\n---\n sha1_name.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\nThis is in response to the discussion in [1]. I am not sure the use of\n'[]' as an alias for the empty tree will be accepted, but I think having\nan alias similar to this is much easier to implement than adding support\nfor a --root option to all commands which can take a <tree-ish>...\n\nSince this is mostly an RFC I have not included any new tests (though\nthe existsing once still pass after this change).\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/146468/focus=146484\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex bf92417..ba58eab 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -347,6 +347,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)\n \tint refs_found = 0;\n \tint at, reflog_len;\n \n+\tif (len == 2 && str[0] == '[' && str[1] == ']')\n+\t\treturn get_sha1_hex(EMPTY_TREE_SHA1_HEX, sha1);\n+\n \tif (len == 40 && !get_sha1_hex(str, sha1))\n \t\treturn 0;\n \n-- \n1.7.0.1\n"},{"id":"141224","messageId":"20100508045319.GD14998@coredump.intra.peff.net","threadId":"23730","inReplyTo":"1273250247-20762-1-git-send-email-pkj@axis.com","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-08T04:53:20Z","receivedAt":"2010-05-08T04:53:20Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, May 07, 2010 at 06:37:27PM +0200, Peter Kjellerstedt wrote:\n\n> Instead of specifying the SHA1 for the empty tree (i.e.,\n> 4b825dc642cb6eb9a060e54bf8d69288fbee4904) one can now say [], e.g.,\n> 'git diff [] v1.7.1' would give all the changes between the empty tree\n> and the tag v1.7.1.\n\nFWIW, I like the idea of a special namespace that indicates \"this is not\na regular ref, but you can resolve it to some object\". It seems to come\nup once in a while, but I don't recall anybody ever actually making a\npatch.\n\n> The rationale for selecting [] as the alias for the empty tree was that\n> it looks empty, the brackets are not used for anything related to\n> references (AFAIK), they are not allowed in references according to\n> 'man git-check-ref-format', and the syntax can easily be extended to\n> allow other types of references by adding information between the\n> brackets.\n\nI am a little iffy on brackets, as they can invoke shell wildcarding\nbehavior. But the fact that they don't cause a syntactic conflict does\nmake them appealing.\n\nBased on past discussions, I suspect other people would be interested\nin:\n\n  $ git diff [index] HEAD\n  $ git diff HEAD [index]\n  $ git diff [working-tree] [index]\n\netc. I don't think I would want to type those all the time, but they\nconceptually are quite clear about what is happening, so they may be\nnice for showing new users what is happening with each diff invocation\n(as opposed to, say, \"git diff --cached\" versus \"git diff\", which is\nsomewhat unintuitive, even though it is more handy in practice).\n\n-Peff\n"},{"id":"141228","messageId":"7vhbmjc6dy.fsf@alter.siamese.dyndns.org","threadId":"23730","inReplyTo":"20100508045319.GD14998@coredump.intra.peff.net","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-08T05:24:57Z","receivedAt":"2010-05-08T05:24:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Based on past discussions, I suspect other people would be interested\n> in:\n>\n>   $ git diff [index] HEAD\n>   $ git diff HEAD [index]\n>   $ git diff [working-tree] [index]\n>\n> etc. I don't think I would want to type those all the time,...\n\nIf you go that route, why not use INDEX and WORKTREE (all caps) to at\nleast avoid the brackets?  I am not personally interested in [] at all,\nbut as part of that repertoire of syntactic sugar tokens EMPTY might be\nable to sneak in [*1*]\n\n[Footnote]\n\n*1* Without that \"[]\" syntax, the feature is \"Meh\" for me, but with the\nsyntax, it becomes \"Yuck\".  The reason I am not interested in the feature\nis because I don't see much value in running \"git diff EMPTY <anything>\".\nPerhaps \"git archive\" might be what the user really wants to find.\n"},{"id":"141230","messageId":"20100508053405.GH14998@coredump.intra.peff.net","threadId":"23730","inReplyTo":"7vhbmjc6dy.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-08T05:34:05Z","receivedAt":"2010-05-08T05:34:05Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, May 07, 2010 at 10:24:57PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > Based on past discussions, I suspect other people would be interested\n> > in:\n> >\n> >   $ git diff [index] HEAD\n> >   $ git diff HEAD [index]\n> >   $ git diff [working-tree] [index]\n> >\n> > etc. I don't think I would want to type those all the time,...\n> \n> If you go that route, why not use INDEX and WORKTREE (all caps) to at\n> least avoid the brackets?  I am not personally interested in [] at all,\n> but as part of that repertoire of syntactic sugar tokens EMPTY might be\n> able to sneak in [*1*]\n\nYeah, I would be fine with that (and I think I even suggested it the\nlast time this came up). In theory we can be breaking somebody's repo by\nstealing from the valid ref namespace, but it really is not all that\nlikely (and I suppose we could prefer user refs).\n\n> *1* Without that \"[]\" syntax, the feature is \"Meh\" for me, but with the\n> syntax, it becomes \"Yuck\".  The reason I am not interested in the feature\n> is because I don't see much value in running \"git diff EMPTY <anything>\".\n> Perhaps \"git archive\" might be what the user really wants to find.\n\nSomehow it comes up for me every once in a while, and I go look up the\nempty tree sha1 in the source and use it, think \"it would be nice if\nthere was a handy syntax\", and then realize that it is the sort of thing\nthat only comes up infrequently, and even then only when you are trying\nto do something a little odd, so it probably isn't worth caring about. I\nwish I could remember the reason for the last time I needed it, but I\ncan't.\n\n-Peff\n"},{"id":"141251","messageId":"20100508160731.GA4638@progeny.tock","threadId":"23730","inReplyTo":"7vhbmjc6dy.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-05-08T16:07:31Z","receivedAt":"2010-05-08T16:07:31Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n> The reason I am not interested in the feature\n> is because I don't see much value in running \"git diff EMPTY <anything>\".\n> Perhaps \"git archive\" might be what the user really wants to find.\n\nI suspect the goal was to use a tool such as checkpatch, or\nget_maintainer without -f.  An implementation using git archive should\nstill work (with the help of a tar diff-ing program with the EMPTY\nfeature ;-)), but as UI that might be less discoverable than building\nit into git diff.\n\nPersonally, I liked both the\n\n  git diff $(</dev/null git hash-object -t tree --stdin) $rev\n\nand\n\n  git diff --root $rev\n\nsuggestions.  That may be from a warped sense of aesthetics.\n\nCheers,\nJonathan\n"},{"id":"141356","messageId":"A612847CFE53224C91B23E3A5B48BAC74482E511E7@xmail3.se.axis.com","threadId":"23730","inReplyTo":"7vhbmjc6dy.fsf@alter.siamese.dyndns.org","subject":"RE: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Peter Kjellerstedt","fromEmail":"peter.kjellerstedt@axis.com","sentAt":"2010-05-10T08:14:15Z","receivedAt":"2010-05-10T08:14:15Z","isPatch":true,"sender":{"key":"peter.kjellerstedt@axis.com","avatar":"https://gravatar.com/avatar/6d5a0182283c8eccd7b134a54dbfd5f30038f3ad4d38b96f424884b614a61ca2?d=mp&s=160"},"body":"> -----Original Message-----\n> From: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On\n> Behalf Of Junio C Hamano\n> Sent: den 8 maj 2010 07:25\n> To: Jeff King\n> Cc: Peter Kjellerstedt; git@vger.kernel.org\n> Subject: Re: [PATCH/RFC] Add [] as an alias for a reference to the\n> empty tree\n> \n> Jeff King <peff@peff.net> writes:\n> \n> > Based on past discussions, I suspect other people would be interested\n> > in:\n> >\n> >   $ git diff [index] HEAD\n> >   $ git diff HEAD [index]\n> >   $ git diff [working-tree] [index]\n\nInteresting. I had not thought of that, but I can see the use for it\nin some situations if nothing else but to clarify what is going on.\n\n> > etc. I don't think I would want to type those all the time,...\n\nWell, I have to agree on that, even though I guess they could be \nabbreviated like [i] and [wt].\n\n> If you go that route, why not use INDEX and WORKTREE (all caps) to at\n> least avoid the brackets?  I am not personally interested in [] at all,\n> but as part of that repertoire of syntactic sugar tokens EMPTY might be\n> able to sneak in [*1*]\n\nThe reason I choose to use some special characters like [] was that I \nexplicitly did not want to touch the normal namespace for references,\nsince these refs do not actually exist in the .git directory and things\ncould get a bit surprising if someone actually created a branch/tag\nnamed INDEX...\n\nHowever, if INDEX, WORKTREE and EMPTY are preferred as syntactic sugar\ntokes, then that is fine by me. Unfortunately, I do not have the time\nnor the knowledge needed to add support for the INDEX and WORKTREE \ntokens, so I am afraid I will have to leave this as a suggestion for \nthe future.\n\n> [Footnote]\n> \n> *1* Without that \"[]\" syntax, the feature is \"Meh\" for me, but with the\n> syntax, it becomes \"Yuck\".  The reason I am not interested in the\n> feature is because I don't see much value in running \"git diff EMPTY\n> <anything>\". Perhaps \"git archive\" might be what the user really wants \n> to find.\n\nAs I mentioned in [1] I am post-processing the generated diff, and then \nthe empty tree is just another starting point for the diff. Having to \nget the full content some other way (e.g., via git archive) would just\nmean a lot of unnecessary code and special casing in this case.\n\n//Peter\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/146468/focus=146518\n"},{"id":"141362","messageId":"20100510092054.GA2602@coredump.intra.peff.net","threadId":"23730","inReplyTo":"A612847CFE53224C91B23E3A5B48BAC74482E511E7@xmail3.se.axis.com","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-10T09:20:54Z","receivedAt":"2010-05-10T09:20:54Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, May 10, 2010 at 10:14:15AM +0200, Peter Kjellerstedt wrote:\n\n> However, if INDEX, WORKTREE and EMPTY are preferred as syntactic sugar\n> tokes, then that is fine by me. Unfortunately, I do not have the time\n> nor the knowledge needed to add support for the INDEX and WORKTREE \n> tokens, so I am afraid I will have to leave this as a suggestion for \n> the future.\n\nImplementing INDEX and WORKTREE would be quite challenging. EMPTY is\neasy because it is really just a fake ref for a particular sha1. The\nothers need special casing everywhere that might look at the result.\n\nSo certainly if you want to do EMPTY, I wouldn't let the lack of the\nother two hold you back. The only reason they are related at all is that\nthey would probably share a syntax, if the other two ever even get\nimplemented.\n\n-Peff\n"},{"id":"141366","messageId":"AANLkTinsofcjlVmnMtW7mONO8zGQd2eT9rMEynVNchsR@mail.gmail.com","threadId":"23730","inReplyTo":"20100510092054.GA2602@coredump.intra.peff.net","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-05-10T09:51:05Z","receivedAt":"2010-05-10T09:51:05Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, May 10, 2010 at 11:20, Jeff King <peff@peff.net> wrote:\n>> However, if INDEX, WORKTREE and EMPTY are preferred as syntactic sugar\n>> tokes, then that is fine by me.\n\nMust it be ALL CAPS? In Mercurial the fairly elegant 'nil' is used for\nthe empty commit, why can't we do the same?\n\n> So certainly if you want to do EMPTY, I wouldn't let the lack of the\n> other two hold you back. The only reason they are related at all is that\n> they would probably share a syntax, if the other two ever even get\n> implemented.\n\nI still don't see the point in having INDEX and WORKTREE, especially\nsince they're so CAPSY. Almost as if they're supposed to be\nenvironment variables.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"141374","messageId":"20100510100050.GB2098@coredump.intra.peff.net","threadId":"23730","inReplyTo":"AANLkTinsofcjlVmnMtW7mONO8zGQd2eT9rMEynVNchsR@mail.gmail.com","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-10T10:00:50Z","receivedAt":"2010-05-10T10:00:50Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, May 10, 2010 at 11:51:05AM +0200, Sverre Rabbelier wrote:\n\n> On Mon, May 10, 2010 at 11:20, Jeff King <peff@peff.net> wrote:\n> >> However, if INDEX, WORKTREE and EMPTY are preferred as syntactic sugar\n> >> tokes, then that is fine by me.\n> \n> Must it be ALL CAPS? In Mercurial the fairly elegant 'nil' is used for\n> the empty commit, why can't we do the same?\n\n[Please watch your quoting, which is a bit misleading there].\n\nI think the intent was that because they clash in the normal refs\nnamespace, we would set them apart with caps (and we have already\nsort-of claimed the all-caps namespace with things like HEAD,\nFETCH_HEAD, etc).\n\n> > So certainly if you want to do EMPTY, I wouldn't let the lack of the\n> > other two hold you back. The only reason they are related at all is that\n> > they would probably share a syntax, if the other two ever even get\n> > implemented.\n> \n> I still don't see the point in having INDEX and WORKTREE, especially\n> since they're so CAPSY. Almost as if they're supposed to be\n> environment variables.\n\nThe point was to make a more obvious and verbose alternative for people\nwho find \"git diff\" a little confusing. E.g.:\n\n  # diff index to working tree\n  # (now)\n  git diff\n  # (verbose)\n  git diff INDEX..WORKTREE\n\n  # diff HEAD to index\n  # (now)\n  git diff --cached\n  # (verbose)\n  git diff HEAD..INDEX\n\n  # diff HEAD to working tree\n  # (now)\n  git diff HEAD\n  # (verbose)\n  git diff HEAD..WORKTREE\n\nI think the original proposal is from this post-GitTogether 2008 thread:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/99376/focus=100729\n\n-Peff\n"},{"id":"141380","messageId":"AANLkTikrRJZu2I5BYU-UqtjYh0x6WMJ8Frh8DKPUM-yK@mail.gmail.com","threadId":"23730","inReplyTo":"20100510100050.GB2098@coredump.intra.peff.net","subject":"Re: [PATCH/RFC] Add [] as an alias for a reference to the empty tree","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-05-10T11:00:17Z","receivedAt":"2010-05-10T11:00:17Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, May 10, 2010 at 12:00, Jeff King <peff@peff.net> wrote:\n> On Mon, May 10, 2010 at 11:51:05AM +0200, Sverre Rabbelier wrote:\n>> Must it be ALL CAPS? In Mercurial the fairly elegant 'nil' is used for\n>> the empty commit, why can't we do the same?\n>\n> [Please watch your quoting, which is a bit misleading there].\n\nApologies, I accidentally removed Junio's attribution line. I fully\nintended to reply to both your and Junio's post at the same time :).\n\n> I think the intent was that because they clash in the normal refs\n> namespace, we would set them apart with caps (and we have already\n> sort-of claimed the all-caps namespace with things like HEAD,\n> FETCH_HEAD, etc).\n\nWhile I understand the rationale, (of already having two all-caps\nrefs), I don't think adding more of them is a good idea. Aesthetically\nI think 'nil' does make sense, but I agree that 'worktree' and 'index'\nas lower-case names do not.\n\n> The point was to make a more obvious and verbose alternative for people\n> who find \"git diff\" a little confusing. E.g.:\n\nI don't think that all caps names make for a good solution to that\nproblem though.\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}