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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Feb 7, 2011 at 02:17 UTC
dab0d4108d7b45905a12ec6cea2cfc20ea8eabef
4 files changed
+6
-4
builtin/checkout.c
+1
-1
@@ -404,7 +404,7 @@ static int merge_working_tree(struct checkout_opts *opts,
404
topts.dir->exclude_per_dir = ".gitignore";
405
tree = parse_tree_indirect(old->commit ?
406
old->commit->object.sha1 :
407
- (unsigned char *)EMPTY_TREE_SHA1_BIN);
407
+ EMPTY_TREE_SHA1_BIN);
408
init_tree_desc(&trees[0], tree->buffer, tree->size);
409
tree = parse_tree_indirect(new->commit->object.sha1);
410
init_tree_desc(&trees[1], tree->buffer, tree->size);
cache.h
+3
-1
@@ -676,9 +676,11 @@ static inline void hashclr(unsigned char *hash)
676
677
#define EMPTY_TREE_SHA1_HEX \
678
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
679
-#define EMPTY_TREE_SHA1_BIN \
679
+#define EMPTY_TREE_SHA1_BIN_LITERAL \
680
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
681
"\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)
684
685
int git_mkstemp(char *path, size_t n, const char *template);
686
notes-merge.c
+1
-1
@@ -615,7 +615,7 @@ int notes_merge(struct notes_merge_options *o,
615
bases = get_merge_bases(local, remote, 1);
616
if (!bases) {
617
base_sha1 = null_sha1;
618
- base_tree_sha1 = (unsigned char *)EMPTY_TREE_SHA1_BIN;
618
+ base_tree_sha1 = EMPTY_TREE_SHA1_BIN;
619
OUTPUT(o, 4, "No merge base found; doing history-less merge");
620
} else if (!bases->next) {
621
base_sha1 = bases->item->object.sha1;
sha1_file.c
+1
-1
@@ -52,7 +52,7 @@ static struct cached_object {
52
static int cached_object_nr, cached_object_alloc;
53
54
static struct cached_object empty_tree = {
55
- EMPTY_TREE_SHA1_BIN,
55
+ EMPTY_TREE_SHA1_BIN_LITERAL,
56
OBJ_TREE,
57
"",
58
0