git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] make inline is_null_sha1 global
@ 2006-08-15 20:37 David Rientjes
  2006-08-15 21:58 ` Jonas Fonseca
  2006-08-16  6:40 ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: David Rientjes @ 2006-08-15 20:37 UTC (permalink / raw)
  To: git

Replace sha1 comparisons to null_sha1 with a global inline (which previously an 
unused static inline in builtin-apply.c)

		David

Signed-off-by: David Rientjes <rientjes@google.com>
---
 builtin-apply.c |    7 +------
 builtin-diff.c  |    3 +--
 cache.h         |    4 ++++
 combine-diff.c  |    4 ++--
 diff.c          |    2 +-
 fsck-objects.c  |    2 +-
 sha1_name.c     |    2 +-
 7 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index 4573c9a..1c1d16f 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1684,7 +1684,7 @@ static int apply_binary(struct buffer_de
 	}
 
 	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
 	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;
diff --git a/builtin-diff.c b/builtin-diff.c
index 82afce7..9003d55 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -68,8 +68,7 @@ static void stuff_change(struct diff_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;
 
diff --git a/cache.h b/cache.h
index af77402..c738299 100644
--- a/cache.h
+++ b/cache.h
@@ -210,6 +210,10 @@ extern char *sha1_pack_name(const unsign
 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);
 
diff --git a/combine-diff.c b/combine-diff.c
index 4c6bfed..ce063b4 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -94,7 +94,7 @@ static char *grab_blob(const unsigned ch
 {
 	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 combi
 	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;
 
diff --git a/diff.c b/diff.c
index 2327e60..6a8c0c9 100644
--- a/diff.c
+++ b/diff.c
@@ -1102,7 +1102,7 @@ void fill_filespec(struct diff_filespec 
 	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);
 	}
 }
 
diff --git a/fsck-objects.c b/fsck-objects.c
index 4ba3377..b0e882a 100644
--- a/fsck-objects.c
+++ b/fsck-objects.c
@@ -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;
 }
diff --git a/sha1_name.c b/sha1_name.c
index c5a05fa..f567454 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -191,7 +191,7 @@ const char *find_unique_abbrev(const uns
 	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;
-- 
1.4.2.g460c-dirty

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] make inline is_null_sha1 global
  2006-08-15 20:37 [PATCH] make inline is_null_sha1 global David Rientjes
@ 2006-08-15 21:58 ` Jonas Fonseca
  2006-08-15 22:11   ` David Rientjes
  2006-08-16  6:40 ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Jonas Fonseca @ 2006-08-15 21:58 UTC (permalink / raw)
  To: David Rientjes; +Cc: git

David Rientjes <rientjes@google.com> wrote Tue, Aug 15, 2006:
> diff --git a/builtin-diff.c b/builtin-diff.c
> index 82afce7..9003d55 100644
> --- a/builtin-diff.c
> +++ b/builtin-diff.c
> @@ -68,8 +68,7 @@ static void stuff_change(struct diff_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;
>  

Looks like this should be !is_null_sha1(...) in both cases.

-- 
Jonas Fonseca

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] make inline is_null_sha1 global
  2006-08-15 21:58 ` Jonas Fonseca
@ 2006-08-15 22:11   ` David Rientjes
  2006-08-15 22:28     ` Jonas Fonseca
  0 siblings, 1 reply; 5+ messages in thread
From: David Rientjes @ 2006-08-15 22:11 UTC (permalink / raw)
  To: Jonas Fonseca; +Cc: git

On Tue, 15 Aug 2006, Jonas Fonseca wrote:

> Looks like this should be !is_null_sha1(...) in both cases.
> 

Correct, thanks for pointing that out.  Please ack the following patch that 
fixes it.

		David

Signed-off-by: David Rientjes <rientjes@google.com>
---
 builtin-apply.c |    7 +------
 builtin-diff.c  |    3 +--
 cache.h         |    4 ++++
 combine-diff.c  |    4 ++--
 diff.c          |    2 +-
 fsck-objects.c  |    2 +-
 sha1_name.c     |    2 +-
 7 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index 4573c9a..1c1d16f 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1684,7 +1684,7 @@ static int apply_binary(struct buffer_de
 	}
 
 	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
 	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;
diff --git a/builtin-diff.c b/builtin-diff.c
index 82afce7..40e5c96 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -68,8 +68,7 @@ static void stuff_change(struct diff_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;
 
diff --git a/cache.h b/cache.h
index af77402..c738299 100644
--- a/cache.h
+++ b/cache.h
@@ -210,6 +210,10 @@ extern char *sha1_pack_name(const unsign
 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);
 
diff --git a/combine-diff.c b/combine-diff.c
index 4c6bfed..ce063b4 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -94,7 +94,7 @@ static char *grab_blob(const unsigned ch
 {
 	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 combi
 	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;
 
diff --git a/diff.c b/diff.c
index 2327e60..6a8c0c9 100644
--- a/diff.c
+++ b/diff.c
@@ -1102,7 +1102,7 @@ void fill_filespec(struct diff_filespec 
 	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);
 	}
 }
 
diff --git a/fsck-objects.c b/fsck-objects.c
index 4ba3377..b0e882a 100644
--- a/fsck-objects.c
+++ b/fsck-objects.c
@@ -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;
 }
diff --git a/sha1_name.c b/sha1_name.c
index c5a05fa..f567454 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -191,7 +191,7 @@ const char *find_unique_abbrev(const uns
 	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;
-- 
1.4.2.g460c-dirty

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] make inline is_null_sha1 global
  2006-08-15 22:11   ` David Rientjes
@ 2006-08-15 22:28     ` Jonas Fonseca
  0 siblings, 0 replies; 5+ messages in thread
From: Jonas Fonseca @ 2006-08-15 22:28 UTC (permalink / raw)
  To: David Rientjes; +Cc: git

David Rientjes <rientjes@google.com> wrote Tue, Aug 15, 2006:
> On Tue, 15 Aug 2006, Jonas Fonseca wrote:
> 
> > Looks like this should be !is_null_sha1(...) in both cases.
> > 
> 
> Correct, thanks for pointing that out.  Please ack the following patch that 
> fixes it.
> 
> 		David
> 
> Signed-off-by: David Rientjes <rientjes@google.com>

Acked-by: Jonas Fonseca <fonseca@diku.dk>

-- 
Jonas Fonseca

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] make inline is_null_sha1 global
  2006-08-15 20:37 [PATCH] make inline is_null_sha1 global David Rientjes
  2006-08-15 21:58 ` Jonas Fonseca
@ 2006-08-16  6:40 ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2006-08-16  6:40 UTC (permalink / raw)
  To: David Rientjes; +Cc: git, Jonas Fonseca

Makes sense, except the gotcha found by Jonas.
Thanks, both.

BTW, please drop the "\n\t\tDavid\n" from these messages and
fold lines to a reasonable length.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-08-16  6:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-15 20:37 [PATCH] make inline is_null_sha1 global David Rientjes
2006-08-15 21:58 ` Jonas Fonseca
2006-08-15 22:11   ` David Rientjes
2006-08-15 22:28     ` Jonas Fonseca
2006-08-16  6:40 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).