Skip to content

Commit

Permalink
correct type of EMPTY_TREE_SHA1_BIN
Browse files Browse the repository at this point in the history
Functions such as hashcmp that expect a binary SHA-1 value take
parameters of type "unsigned char *" to avoid accepting a textual
SHA-1 passed by mistake.  Unfortunately, this means passing the string
literal EMPTY_TREE_SHA1_BIN requires an ugly cast.  Tweak the
definition of EMPTY_TREE_SHA1_BIN to produce a value of more
convenient type.

In the future the definition might change to

	extern const unsigned char empty_tree_sha1_bin[20];
	#define EMPTY_TREE_SHA1_BIN empty_tree_sha1_bin

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
jrn authored and gitster committed Feb 14, 2011
1 parent 9971d6d commit dab0d41
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion builtin/checkout.c
Expand Up @@ -404,7 +404,7 @@ static int merge_working_tree(struct checkout_opts *opts,
topts.dir->exclude_per_dir = ".gitignore";
tree = parse_tree_indirect(old->commit ?
old->commit->object.sha1 :
(unsigned char *)EMPTY_TREE_SHA1_BIN);
EMPTY_TREE_SHA1_BIN);
init_tree_desc(&trees[0], tree->buffer, tree->size);
tree = parse_tree_indirect(new->commit->object.sha1);
init_tree_desc(&trees[1], tree->buffer, tree->size);
Expand Down
4 changes: 3 additions & 1 deletion cache.h
Expand Up @@ -676,9 +676,11 @@ static inline void hashclr(unsigned char *hash)

#define EMPTY_TREE_SHA1_HEX \
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
#define EMPTY_TREE_SHA1_BIN \
#define EMPTY_TREE_SHA1_BIN_LITERAL \
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
#define EMPTY_TREE_SHA1_BIN \
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)

int git_mkstemp(char *path, size_t n, const char *template);

Expand Down
2 changes: 1 addition & 1 deletion notes-merge.c
Expand Up @@ -615,7 +615,7 @@ int notes_merge(struct notes_merge_options *o,
bases = get_merge_bases(local, remote, 1);
if (!bases) {
base_sha1 = null_sha1;
base_tree_sha1 = (unsigned char *)EMPTY_TREE_SHA1_BIN;
base_tree_sha1 = EMPTY_TREE_SHA1_BIN;
OUTPUT(o, 4, "No merge base found; doing history-less merge");
} else if (!bases->next) {
base_sha1 = bases->item->object.sha1;
Expand Down
2 changes: 1 addition & 1 deletion sha1_file.c
Expand Up @@ -52,7 +52,7 @@ static struct cached_object {
static int cached_object_nr, cached_object_alloc;

static struct cached_object empty_tree = {
EMPTY_TREE_SHA1_BIN,
EMPTY_TREE_SHA1_BIN_LITERAL,
OBJ_TREE,
"",
0
Expand Down

0 comments on commit dab0d41

Please sign in to comment.