@matheusbsbs / matheus-bagliano / commits / 0bef57ee44
Fork 0

make inline is_null_sha1 global

Replace sha1 comparisons to null_sha1 with a global inline (which previously an unused static inline in builtin-apply.c) [jc: with a fix from Jonas Fonseca.] Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

David Rientjes committed Aug 15, 2006 at 13:37 UTC 0bef57ee44a2f924ad0066b751a3c87888633f56
7 files changed +11 -13
builtin-apply.c
+1 -6
@@ -1684,7 +1684,7 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch)
1684 }
1685
1686 get_sha1_hex(patch->new_sha1_prefix, sha1);
1687 - if (!memcmp(sha1, null_sha1, 20)) {
1687 + if (is_null_sha1(sha1)) {
1688 free(desc->buffer);
1689 desc->alloc = desc->size = 0;
1690 desc->buffer = NULL;
@@ -1916,11 +1916,6 @@ static int check_patch_list(struct patch *patch)
1916 return error;
1917 }
1918
1919 -static inline int is_null_sha1(const unsigned char *sha1)
1920 -{
1921 - return !memcmp(sha1, null_sha1, 20);
1922 -}
1923 -
1919 static void show_index_list(struct patch *list)
1920 {
1921 struct patch *patch;
builtin-diff.c
+1 -2
@@ -68,8 +68,7 @@ static void stuff_change(struct diff_options *opt,
68 {
69 struct diff_filespec *one, *two;
70
71 - if (memcmp(null_sha1, old_sha1, 20) &&
72 - memcmp(null_sha1, new_sha1, 20) &&
71 + if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&
72 !memcmp(old_sha1, new_sha1, 20))
73 return;
74
cache.h
+4
@@ -210,6 +210,10 @@ extern char *sha1_pack_name(const unsigned char *sha1);
210 extern char *sha1_pack_index_name(const unsigned char *sha1);
211 extern const char *find_unique_abbrev(const unsigned char *sha1, int);
212 extern const unsigned char null_sha1[20];
213 +static inline int is_null_sha1(const unsigned char *sha1)
214 +{
215 + return !memcmp(sha1, null_sha1, 20);
216 +}
217
218 int git_mkstemp(char *path, size_t n, const char *template);
219
combine-diff.c
+2 -2
@@ -94,7 +94,7 @@ static char *grab_blob(const unsigned char *sha1, unsigned long *size)
94 {
95 char *blob;
96 char type[20];
97 - if (!memcmp(sha1, null_sha1, 20)) {
97 + if (is_null_sha1(sha1)) {
98 /* deleted blob */
99 *size = 0;
100 return xcalloc(1, 1);
@@ -611,7 +611,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
611 struct sline *sline; /* survived lines */
612 int mode_differs = 0;
613 int i, show_hunks;
614 - int working_tree_file = !memcmp(elem->sha1, null_sha1, 20);
614 + int working_tree_file = is_null_sha1(elem->sha1);
615 int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;
616 mmfile_t result_file;
617
diff.c
+1 -1
@@ -1102,7 +1102,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
1102 if (mode) {
1103 spec->mode = canon_mode(mode);
1104 memcpy(spec->sha1, sha1, 20);
1105 - spec->sha1_valid = !!memcmp(sha1, null_sha1, 20);
1105 + spec->sha1_valid = !is_null_sha1(sha1);
1106 }
1107 }
1108
fsck-objects.c
+1 -1
@@ -452,7 +452,7 @@ static int fsck_head_link(void)
452 if (strncmp(git_refs_heads_master + pfxlen, "refs/heads/", 11))
453 return error("HEAD points to something strange (%s)",
454 git_refs_heads_master + pfxlen);
455 - if (!memcmp(null_sha1, sha1, 20))
455 + if (is_null_sha1(sha1))
456 return error("HEAD: not a valid git pointer");
457 return 0;
458 }
sha1_name.c
+1 -1
@@ -191,7 +191,7 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
191 int status, is_null;
192 static char hex[41];
193
194 - is_null = !memcmp(sha1, null_sha1, 20);
194 + is_null = is_null_sha1(sha1);
195 memcpy(hex, sha1_to_hex(sha1), 40);
196 if (len == 40 || !len)
197 return hex;