Browse Source

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>
maint
David Rientjes 19 years ago committed by Junio C Hamano
parent
commit
0bef57ee44
  1. 7
      builtin-apply.c
  2. 3
      builtin-diff.c
  3. 4
      cache.h
  4. 4
      combine-diff.c
  5. 2
      diff.c
  6. 2
      fsck-objects.c
  7. 2
      sha1_name.c

7
builtin-apply.c

@ -1684,7 +1684,7 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch) @@ -1684,7 +1684,7 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch)
}

get_sha1_hex(patch->new_sha1_prefix, sha1);
if (!memcmp(sha1, null_sha1, 20)) {
if (is_null_sha1(sha1)) {
free(desc->buffer);
desc->alloc = desc->size = 0;
desc->buffer = NULL;
@ -1916,11 +1916,6 @@ static int check_patch_list(struct patch *patch) @@ -1916,11 +1916,6 @@ static int check_patch_list(struct patch *patch)
return error;
}

static inline int is_null_sha1(const unsigned char *sha1)
{
return !memcmp(sha1, null_sha1, 20);
}

static void show_index_list(struct patch *list)
{
struct patch *patch;

3
builtin-diff.c

@ -68,8 +68,7 @@ static void stuff_change(struct diff_options *opt, @@ -68,8 +68,7 @@ static void stuff_change(struct diff_options *opt,
{
struct diff_filespec *one, *two;

if (memcmp(null_sha1, old_sha1, 20) &&
memcmp(null_sha1, new_sha1, 20) &&
if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&
!memcmp(old_sha1, new_sha1, 20))
return;


4
cache.h

@ -210,6 +210,10 @@ extern char *sha1_pack_name(const unsigned char *sha1); @@ -210,6 +210,10 @@ extern char *sha1_pack_name(const unsigned char *sha1);
extern char *sha1_pack_index_name(const unsigned char *sha1);
extern const char *find_unique_abbrev(const unsigned char *sha1, int);
extern const unsigned char null_sha1[20];
static inline int is_null_sha1(const unsigned char *sha1)
{
return !memcmp(sha1, null_sha1, 20);
}

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


4
combine-diff.c

@ -94,7 +94,7 @@ static char *grab_blob(const unsigned char *sha1, unsigned long *size) @@ -94,7 +94,7 @@ static char *grab_blob(const unsigned char *sha1, unsigned long *size)
{
char *blob;
char type[20];
if (!memcmp(sha1, null_sha1, 20)) {
if (is_null_sha1(sha1)) {
/* deleted blob */
*size = 0;
return xcalloc(1, 1);
@ -611,7 +611,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, @@ -611,7 +611,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
struct sline *sline; /* survived lines */
int mode_differs = 0;
int i, show_hunks;
int working_tree_file = !memcmp(elem->sha1, null_sha1, 20);
int working_tree_file = is_null_sha1(elem->sha1);
int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;
mmfile_t result_file;


2
diff.c

@ -1102,7 +1102,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1, @@ -1102,7 +1102,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
if (mode) {
spec->mode = canon_mode(mode);
memcpy(spec->sha1, sha1, 20);
spec->sha1_valid = !!memcmp(sha1, null_sha1, 20);
spec->sha1_valid = !is_null_sha1(sha1);
}
}


2
fsck-objects.c

@ -452,7 +452,7 @@ static int fsck_head_link(void) @@ -452,7 +452,7 @@ static int fsck_head_link(void)
if (strncmp(git_refs_heads_master + pfxlen, "refs/heads/", 11))
return error("HEAD points to something strange (%s)",
git_refs_heads_master + pfxlen);
if (!memcmp(null_sha1, sha1, 20))
if (is_null_sha1(sha1))
return error("HEAD: not a valid git pointer");
return 0;
}

2
sha1_name.c

@ -191,7 +191,7 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len) @@ -191,7 +191,7 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
int status, is_null;
static char hex[41];

is_null = !memcmp(sha1, null_sha1, 20);
is_null = is_null_sha1(sha1);
memcpy(hex, sha1_to_hex(sha1), 40);
if (len == 40 || !len)
return hex;

Loading…
Cancel
Save