{"thread":{"id":"12101","subject":"[PATCH 1/2] hard-code the empty tree object","startedAt":"2008-02-14T10:32:56Z","lastAt":"2008-02-15T18:25:42Z","messageCount":7,"participants":["Jeff King","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"68727","messageId":"20080214103256.GA17951@coredump.intra.peff.net","threadId":"12101","inReplyTo":null,"subject":"[PATCH 1/2] hard-code the empty tree object","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-14T10:32:56Z","receivedAt":"2008-02-14T10:32:56Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This maps sha1 4b825dc642cb6eb9a060e54bf8d69288fbee4904 to\nthe empty tree object, whether such an object exists in the\nobject database or not. The empty tree is useful for showing\nsome specialized diffs, especially for initial commits.\n\nWe also hard-code the special ref '{}' as an alias for the\nempty tree. Users may refer to the empty tree by its\nsha1 or by '{}'.\n\nThanks to Johannes Schindelin for the '{}' syntax and\nimplementation.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis is a cleaned-up version of what's in pu, along with the magic ref\nsyntax from Johannes (2/2 will have the fixes to \"git add -i\").\n\n cache.h     |    5 +++++\n sha1_file.c |    9 +++++++++\n sha1_name.c |    5 +++++\n 3 files changed, 19 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 3867ba7..e3abbe1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -253,6 +253,11 @@ static inline enum object_type object_type(unsigned int mode)\n #define INFOATTRIBUTES_FILE \"info/attributes\"\n #define ATTRIBUTE_MACRO_PREFIX \"[attr]\"\n \n+/* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */\n+#define EMPTY_TREE_SHA1 \\\n+\t\"\\x4b\\x82\\x5d\\xc6\\x42\\xcb\\x6e\\xb9\\xa0\\x60\" \\\n+\t\"\\xe5\\x4b\\xf8\\xd6\\x92\\x88\\xfb\\xee\\x49\\x04\"\n+\n extern int is_bare_repository_cfg;\n extern int is_bare_repository(void);\n extern int is_inside_git_dir(void);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 66a4e00..8068a4b 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1845,6 +1845,13 @@ static struct cached_object {\n } *cached_objects;\n static int cached_object_nr, cached_object_alloc;\n \n+static struct cached_object empty_tree = {\n+\tEMPTY_TREE_SHA1,\n+\tOBJ_TREE,\n+\t\"\",\n+\t0\n+};\n+\n static struct cached_object *find_cached_object(const unsigned char *sha1)\n {\n \tint i;\n@@ -1854,6 +1861,8 @@ static struct cached_object *find_cached_object(const unsigned char *sha1)\n \t\tif (!hashcmp(co->sha1, sha1))\n \t\t\treturn co;\n \t}\n+\tif (!hashcmp(sha1, empty_tree.sha1))\n+\t\treturn &empty_tree;\n \treturn NULL;\n }\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex be8489e..165aa7d 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -716,5 +716,10 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode)\n \t\t\treturn get_tree_entry(tree_sha1, cp+1, sha1,\n \t\t\t\t\t      mode);\n \t}\n+\tif (ret && !strcmp(name, \"{}\")) {\n+\t\t*mode = 0755;\n+\t\thashcpy(sha1, (unsigned char *)EMPTY_TREE_SHA1);\n+\t\tret = 0;\n+\t}\n \treturn ret;\n }\n-- \n1.5.4.1.123.ge4e8d-dirty\n"},{"id":"68732","messageId":"alpine.LSU.1.00.0802141238140.30505@racer.site","threadId":"12101","inReplyTo":"20080214103256.GA17951@coredump.intra.peff.net","subject":"Re: [PATCH 1/2] hard-code the empty tree object","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-14T12:39:01Z","receivedAt":"2008-02-14T12:39:01Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 14 Feb 2008, Jeff King wrote:\n\n> We also hard-code the special ref '{}' as an alias for the empty tree. \n> Users may refer to the empty tree by its sha1 or by '{}'.\n\nAnother idea just hit me: why not use \"\" (i.e. the empty string)?  It is \nnot a valid ref name, and not a valid filename either...\n\nBut maybe that would be _too_ cute,\nDscho\n"},{"id":"68735","messageId":"20080214140329.GA3549@coredump.intra.peff.net","threadId":"12101","inReplyTo":"alpine.LSU.1.00.0802141238140.30505@racer.site","subject":"Re: [PATCH 1/2] hard-code the empty tree object","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-14T14:03:29Z","receivedAt":"2008-02-14T14:03:29Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 14, 2008 at 12:39:01PM +0000, Johannes Schindelin wrote:\n\n> > We also hard-code the special ref '{}' as an alias for the empty tree. \n> > Users may refer to the empty tree by its sha1 or by '{}'.\n> \n> Another idea just hit me: why not use \"\" (i.e. the empty string)?  It is \n> not a valid ref name, and not a valid filename either...\n> \n> But maybe that would be _too_ cute,\n\nIMHO, that is a bit too cute.\n\n-Peff\n"},{"id":"68819","messageId":"7vabm2i1pf.fsf@gitster.siamese.dyndns.org","threadId":"12101","inReplyTo":"20080214103256.GA17951@coredump.intra.peff.net","subject":"Re: [PATCH 1/2] hard-code the empty tree object","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-15T17:11:56Z","receivedAt":"2008-02-15T17:11:56Z","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> We also hard-code the special ref '{}' as an alias for the\n> empty tree. Users may refer to the empty tree by its\n> sha1 or by '{}'.\n\nI think the users of hard coded empty tree are oddballs.  Let's\nnot be too cute and instead leave it in the add -i patch.  {} is\nalready too cute.\n"},{"id":"68820","messageId":"20080215172043.GA24221@sigill.intra.peff.net","threadId":"12101","inReplyTo":"7vabm2i1pf.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 1/2] hard-code the empty tree object","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-15T17:20:44Z","receivedAt":"2008-02-15T17:20:44Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Feb 15, 2008 at 09:11:56AM -0800, Junio C Hamano wrote:\n\n> > We also hard-code the special ref '{}' as an alias for the\n> > empty tree. Users may refer to the empty tree by its\n> > sha1 or by '{}'.\n> \n> I think the users of hard coded empty tree are oddballs.  Let's\n> not be too cute and instead leave it in the add -i patch.  {} is\n> already too cute.\n\nBy \"it\" I assume you mean \"the sha1 of the empty tree\", meaning to not\ninclude the {} bit at all?\n\nI am fine with that, as I don't think anyone has even mentioned a\nworkflow where such a shorthand would be beneficial to users. The only\none I can think of is to represent some tree using diff tools (e.g., \"git\ndiff --stat {} HEAD\" instead of some variant on ls-files), but I have\nnever once actually wanted to do that.\n\nShould I re-send, or do you want to just markup the existing patches?\n\n-Peff\n"},{"id":"68823","messageId":"7vhcgaglq5.fsf@gitster.siamese.dyndns.org","threadId":"12101","inReplyTo":"20080215172043.GA24221@sigill.intra.peff.net","subject":"Re: [PATCH 1/2] hard-code the empty tree object","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-15T17:42:26Z","receivedAt":"2008-02-15T17:42:26Z","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> By \"it\" I assume you mean \"the sha1 of the empty tree\", meaning to not\n> include the {} bit at all?\n\nYes, that's what I meant.\n\n> I am fine with that, as I don't think anyone has even mentioned a\n> workflow where such a shorthand would be beneficial to users. The only\n> one I can think of is to represent some tree using diff tools (e.g., \"git\n> diff --stat {} HEAD\" instead of some variant on ls-files), but I have\n> never once actually wanted to do that.\n\nLikewise.\n\n> Should I re-send, or do you want to just markup the existing patches?\n\nShouldn't the previous one that uses the hardcoded empty tree\nobject name good enough that is already on 'pu'?\n"},{"id":"68828","messageId":"20080215182542.GA25167@sigill.intra.peff.net","threadId":"12101","inReplyTo":"7vhcgaglq5.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 1/2] hard-code the empty tree object","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-15T18:25:42Z","receivedAt":"2008-02-15T18:25:42Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Feb 15, 2008 at 09:42:26AM -0800, Junio C Hamano wrote:\n\n> > Should I re-send, or do you want to just markup the existing patches?\n> \n> Shouldn't the previous one that uses the hardcoded empty tree\n> object name good enough that is already on 'pu'?\n\nYes, they are fine (I hadn't looked at them that carefully before, but\nit looks like you cleaned up the ordering sensibly already).\n\nThe last paragraph in the commit message of the add--interactive patch\nshould be removed (the implementation is no longer \"hack-ish\").\n\n-Peff\n"}]}