Skip to content

Commit

Permalink
hard-code the empty tree object
Browse files Browse the repository at this point in the history
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@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 13, 2008
1 parent 6c47d0e commit 346245a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 346245a

Please sign in to comment.