On Wed, Feb 13, 2008 at 05:50:51AM -0500, Jeff King wrote: > And here it is. I think this is a more sane approach in general than the > last patch. The only ugly thing is the empty tree hack, but that can be > addressed with a patch to allow referencing the empty tree without it > existing in the object db. And this patch hard-codes the empty tree. I _think_ this shouldn't cause us any problems, as it just reuses the existing pretend_sha1_file infrastructure. However that infrastructure is very rarely used. This patch also contains the matching fix to git-add--interactive (on top of my last patch). They should probably just be squashed together, but I can submit a cleaned up 2-patch series if people agree that this is a good idea. -- >8 -- hard-code the empty tree object Now any commands may reference the empty tree object by its sha1 (4b825dc642cb6eb9a060e54bf8d69288fbee4904). This is useful for showing some diffs, especially for initial commits. Signed-off-by: Jeff King <peff@xxxxxxxx> --- git-add--interactive.perl | 13 ++----------- sha1_file.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index bae631e..a0a81f1 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -91,17 +91,8 @@ my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path'); } } -{ - my $sha1; - sub get_empty_tree { - if (!$sha1) { - local $ENV{GIT_INDEX_FILE} = "$GIT_DIR/empty_index"; - $sha1 = run_cmd_pipe(qw(git write-tree)); - chomp $sha1; - unlink($ENV{GIT_INDEX_FILE}); - } - return $sha1; - } +sub get_empty_tree { + return '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; } # Returns list of hashes, contents of each of which are: diff --git a/sha1_file.c b/sha1_file.c index 4179949..1a6c7c8 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1845,6 +1845,15 @@ static struct cached_object { } *cached_objects; static int cached_object_nr, cached_object_alloc; +static struct cached_object empty_tree = { + /* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */ + "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" + "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04", + OBJ_TREE, + "", + 0 +}; + static struct cached_object *find_cached_object(const unsigned char *sha1) { int i; @@ -1854,6 +1863,8 @@ static struct cached_object *find_cached_object(const unsigned char *sha1) if (!hashcmp(co->sha1, sha1)) return co; } + if (!hashcmp(sha1, empty_tree.sha1)) + return &empty_tree; return NULL; } -- 1.5.4.1.1297.g3482b-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html