Skip to content

Commit 346245a

Browse files
peffgitster
authored andcommitted
hard-code the empty tree object
Now any commands may reference the empty tree object by its sha1 (4b825dc). 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>
1 parent 6c47d0e commit 346245a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sha1_file.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,15 @@ static struct cached_object {
18451845
} *cached_objects;
18461846
static int cached_object_nr, cached_object_alloc;
18471847

1848+
static struct cached_object empty_tree = {
1849+
/* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */
1850+
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60"
1851+
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04",
1852+
OBJ_TREE,
1853+
"",
1854+
0
1855+
};
1856+
18481857
static struct cached_object *find_cached_object(const unsigned char *sha1)
18491858
{
18501859
int i;
@@ -1854,6 +1863,8 @@ static struct cached_object *find_cached_object(const unsigned char *sha1)
18541863
if (!hashcmp(co->sha1, sha1))
18551864
return co;
18561865
}
1866+
if (!hashcmp(sha1, empty_tree.sha1))
1867+
return &empty_tree;
18571868
return NULL;
18581869
}
18591870

0 commit comments

Comments
 (0)