Skip to content

Commit dab0d41

Browse files
jrngitster
authored andcommitted
correct type of EMPTY_TREE_SHA1_BIN
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9971d6d commit dab0d41

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int merge_working_tree(struct checkout_opts *opts,
404404
topts.dir->exclude_per_dir = ".gitignore";
405405
tree = parse_tree_indirect(old->commit ?
406406
old->commit->object.sha1 :
407-
(unsigned char *)EMPTY_TREE_SHA1_BIN);
407+
EMPTY_TREE_SHA1_BIN);
408408
init_tree_desc(&trees[0], tree->buffer, tree->size);
409409
tree = parse_tree_indirect(new->commit->object.sha1);
410410
init_tree_desc(&trees[1], tree->buffer, tree->size);

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,11 @@ static inline void hashclr(unsigned char *hash)
676676

677677
#define EMPTY_TREE_SHA1_HEX \
678678
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
679-
#define EMPTY_TREE_SHA1_BIN \
679+
#define EMPTY_TREE_SHA1_BIN_LITERAL \
680680
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
681681
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
682+
#define EMPTY_TREE_SHA1_BIN \
683+
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)
682684

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

notes-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ int notes_merge(struct notes_merge_options *o,
615615
bases = get_merge_bases(local, remote, 1);
616616
if (!bases) {
617617
base_sha1 = null_sha1;
618-
base_tree_sha1 = (unsigned char *)EMPTY_TREE_SHA1_BIN;
618+
base_tree_sha1 = EMPTY_TREE_SHA1_BIN;
619619
OUTPUT(o, 4, "No merge base found; doing history-less merge");
620620
} else if (!bases->next) {
621621
base_sha1 = bases->item->object.sha1;

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static struct cached_object {
5252
static int cached_object_nr, cached_object_alloc;
5353

5454
static struct cached_object empty_tree = {
55-
EMPTY_TREE_SHA1_BIN,
55+
EMPTY_TREE_SHA1_BIN_LITERAL,
5656
OBJ_TREE,
5757
"",
5858
0

0 commit comments

Comments
 (0)