{"thread":{"id":"5289","subject":"[PATCH] make inline is_null_sha1 global","startedAt":"2006-08-15T20:37:19Z","lastAt":"2006-08-16T06:40:50Z","messageCount":5,"participants":["David Rientjes","Jonas Fonseca","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"25380","messageId":"Pine.LNX.4.63.0608151335020.1475@chino.corp.google.com","threadId":"5289","inReplyTo":null,"subject":"[PATCH] make inline is_null_sha1 global","fromName":"David Rientjes","fromEmail":"rientjes@google.com","sentAt":"2006-08-15T20:37:19Z","receivedAt":"2006-08-15T20:37:19Z","isPatch":true,"sender":{"key":"rientjes@google.com","avatar":null},"body":"Replace sha1 comparisons to null_sha1 with a global inline (which previously an \nunused static inline in builtin-apply.c)\n\n\t\tDavid\n\nSigned-off-by: David Rientjes <rientjes@google.com>\n---\n builtin-apply.c |    7 +------\n builtin-diff.c  |    3 +--\n cache.h         |    4 ++++\n combine-diff.c  |    4 ++--\n diff.c          |    2 +-\n fsck-objects.c  |    2 +-\n sha1_name.c     |    2 +-\n 7 files changed, 11 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 4573c9a..1c1d16f 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -1684,7 +1684,7 @@ static int apply_binary(struct buffer_de\n \t}\n \n \tget_sha1_hex(patch->new_sha1_prefix, sha1);\n-\tif (!memcmp(sha1, null_sha1, 20)) {\n+\tif (is_null_sha1(sha1)) {\n \t\tfree(desc->buffer);\n \t\tdesc->alloc = desc->size = 0;\n \t\tdesc->buffer = NULL;\n@@ -1916,11 +1916,6 @@ static int check_patch_list(struct patch\n \treturn error;\n }\n \n-static inline int is_null_sha1(const unsigned char *sha1)\n-{\n-\treturn !memcmp(sha1, null_sha1, 20);\n-}\n-\n static void show_index_list(struct patch *list)\n {\n \tstruct patch *patch;\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 82afce7..9003d55 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -68,8 +68,7 @@ static void stuff_change(struct diff_opt\n {\n \tstruct diff_filespec *one, *two;\n \n-\tif (memcmp(null_sha1, old_sha1, 20) &&\n-\t    memcmp(null_sha1, new_sha1, 20) &&\n+\tif (is_null_sha1(old_sha1) && is_null_sha1(new_sha1) &&\n \t    !memcmp(old_sha1, new_sha1, 20))\n \t\treturn;\n \ndiff --git a/cache.h b/cache.h\nindex af77402..c738299 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -210,6 +210,10 @@ extern char *sha1_pack_name(const unsign\n extern char *sha1_pack_index_name(const unsigned char *sha1);\n extern const char *find_unique_abbrev(const unsigned char *sha1, int);\n extern const unsigned char null_sha1[20];\n+static inline int is_null_sha1(const unsigned char *sha1)\n+{\n+\treturn !memcmp(sha1, null_sha1, 20);\n+}\n \n int git_mkstemp(char *path, size_t n, const char *template);\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex 4c6bfed..ce063b4 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -94,7 +94,7 @@ static char *grab_blob(const unsigned ch\n {\n \tchar *blob;\n \tchar type[20];\n-\tif (!memcmp(sha1, null_sha1, 20)) {\n+\tif (is_null_sha1(sha1)) {\n \t\t/* deleted blob */\n \t\t*size = 0;\n \t\treturn xcalloc(1, 1);\n@@ -611,7 +611,7 @@ static void show_patch_diff(struct combi\n \tstruct sline *sline; /* survived lines */\n \tint mode_differs = 0;\n \tint i, show_hunks;\n-\tint working_tree_file = !memcmp(elem->sha1, null_sha1, 20);\n+\tint working_tree_file = is_null_sha1(elem->sha1);\n \tint abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;\n \tmmfile_t result_file;\n \ndiff --git a/diff.c b/diff.c\nindex 2327e60..6a8c0c9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1102,7 +1102,7 @@ void fill_filespec(struct diff_filespec \n \tif (mode) {\n \t\tspec->mode = canon_mode(mode);\n \t\tmemcpy(spec->sha1, sha1, 20);\n-\t\tspec->sha1_valid = !!memcmp(sha1, null_sha1, 20);\n+\t\tspec->sha1_valid = !is_null_sha1(sha1);\n \t}\n }\n \ndiff --git a/fsck-objects.c b/fsck-objects.c\nindex 4ba3377..b0e882a 100644\n--- a/fsck-objects.c\n+++ b/fsck-objects.c\n@@ -452,7 +452,7 @@ static int fsck_head_link(void)\n \tif (strncmp(git_refs_heads_master + pfxlen, \"refs/heads/\", 11))\n \t\treturn error(\"HEAD points to something strange (%s)\",\n \t\t\t     git_refs_heads_master + pfxlen);\n-\tif (!memcmp(null_sha1, sha1, 20))\n+\tif (is_null_sha1(sha1))\n \t\treturn error(\"HEAD: not a valid git pointer\");\n \treturn 0;\n }\ndiff --git a/sha1_name.c b/sha1_name.c\nindex c5a05fa..f567454 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -191,7 +191,7 @@ const char *find_unique_abbrev(const uns\n \tint status, is_null;\n \tstatic char hex[41];\n \n-\tis_null = !memcmp(sha1, null_sha1, 20);\n+\tis_null = is_null_sha1(sha1);\n \tmemcpy(hex, sha1_to_hex(sha1), 40);\n \tif (len == 40 || !len)\n \t\treturn hex;\n-- \n1.4.2.g460c-dirty\n"},{"id":"25386","messageId":"20060815215812.GB15797@diku.dk","threadId":"5289","inReplyTo":"Pine.LNX.4.63.0608151335020.1475@chino.corp.google.com","subject":"Re: [PATCH] make inline is_null_sha1 global","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2006-08-15T21:58:12Z","receivedAt":"2006-08-15T21:58:12Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"David Rientjes <rientjes@google.com> wrote Tue, Aug 15, 2006:\n> diff --git a/builtin-diff.c b/builtin-diff.c\n> index 82afce7..9003d55 100644\n> --- a/builtin-diff.c\n> +++ b/builtin-diff.c\n> @@ -68,8 +68,7 @@ static void stuff_change(struct diff_opt\n>  {\n>  \tstruct diff_filespec *one, *two;\n>  \n> -\tif (memcmp(null_sha1, old_sha1, 20) &&\n> -\t    memcmp(null_sha1, new_sha1, 20) &&\n> +\tif (is_null_sha1(old_sha1) && is_null_sha1(new_sha1) &&\n>  \t    !memcmp(old_sha1, new_sha1, 20))\n>  \t\treturn;\n>  \n\nLooks like this should be !is_null_sha1(...) in both cases.\n\n-- \nJonas Fonseca\n"},{"id":"25388","messageId":"Pine.LNX.4.63.0608151510120.5555@chino.corp.google.com","threadId":"5289","inReplyTo":"20060815215812.GB15797@diku.dk","subject":"Re: [PATCH] make inline is_null_sha1 global","fromName":"David Rientjes","fromEmail":"rientjes@google.com","sentAt":"2006-08-15T22:11:16Z","receivedAt":"2006-08-15T22:11:16Z","isPatch":true,"sender":{"key":"rientjes@google.com","avatar":null},"body":"On Tue, 15 Aug 2006, Jonas Fonseca wrote:\n\n> Looks like this should be !is_null_sha1(...) in both cases.\n> \n\nCorrect, thanks for pointing that out.  Please ack the following patch that \nfixes it.\n\n\t\tDavid\n\nSigned-off-by: David Rientjes <rientjes@google.com>\n---\n builtin-apply.c |    7 +------\n builtin-diff.c  |    3 +--\n cache.h         |    4 ++++\n combine-diff.c  |    4 ++--\n diff.c          |    2 +-\n fsck-objects.c  |    2 +-\n sha1_name.c     |    2 +-\n 7 files changed, 11 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 4573c9a..1c1d16f 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -1684,7 +1684,7 @@ static int apply_binary(struct buffer_de\n \t}\n \n \tget_sha1_hex(patch->new_sha1_prefix, sha1);\n-\tif (!memcmp(sha1, null_sha1, 20)) {\n+\tif (is_null_sha1(sha1)) {\n \t\tfree(desc->buffer);\n \t\tdesc->alloc = desc->size = 0;\n \t\tdesc->buffer = NULL;\n@@ -1916,11 +1916,6 @@ static int check_patch_list(struct patch\n \treturn error;\n }\n \n-static inline int is_null_sha1(const unsigned char *sha1)\n-{\n-\treturn !memcmp(sha1, null_sha1, 20);\n-}\n-\n static void show_index_list(struct patch *list)\n {\n \tstruct patch *patch;\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 82afce7..40e5c96 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -68,8 +68,7 @@ static void stuff_change(struct diff_opt\n {\n \tstruct diff_filespec *one, *two;\n \n-\tif (memcmp(null_sha1, old_sha1, 20) &&\n-\t    memcmp(null_sha1, new_sha1, 20) &&\n+\tif (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&\n \t    !memcmp(old_sha1, new_sha1, 20))\n \t\treturn;\n \ndiff --git a/cache.h b/cache.h\nindex af77402..c738299 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -210,6 +210,10 @@ extern char *sha1_pack_name(const unsign\n extern char *sha1_pack_index_name(const unsigned char *sha1);\n extern const char *find_unique_abbrev(const unsigned char *sha1, int);\n extern const unsigned char null_sha1[20];\n+static inline int is_null_sha1(const unsigned char *sha1)\n+{\n+\treturn !memcmp(sha1, null_sha1, 20);\n+}\n \n int git_mkstemp(char *path, size_t n, const char *template);\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex 4c6bfed..ce063b4 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -94,7 +94,7 @@ static char *grab_blob(const unsigned ch\n {\n \tchar *blob;\n \tchar type[20];\n-\tif (!memcmp(sha1, null_sha1, 20)) {\n+\tif (is_null_sha1(sha1)) {\n \t\t/* deleted blob */\n \t\t*size = 0;\n \t\treturn xcalloc(1, 1);\n@@ -611,7 +611,7 @@ static void show_patch_diff(struct combi\n \tstruct sline *sline; /* survived lines */\n \tint mode_differs = 0;\n \tint i, show_hunks;\n-\tint working_tree_file = !memcmp(elem->sha1, null_sha1, 20);\n+\tint working_tree_file = is_null_sha1(elem->sha1);\n \tint abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;\n \tmmfile_t result_file;\n \ndiff --git a/diff.c b/diff.c\nindex 2327e60..6a8c0c9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1102,7 +1102,7 @@ void fill_filespec(struct diff_filespec \n \tif (mode) {\n \t\tspec->mode = canon_mode(mode);\n \t\tmemcpy(spec->sha1, sha1, 20);\n-\t\tspec->sha1_valid = !!memcmp(sha1, null_sha1, 20);\n+\t\tspec->sha1_valid = !is_null_sha1(sha1);\n \t}\n }\n \ndiff --git a/fsck-objects.c b/fsck-objects.c\nindex 4ba3377..b0e882a 100644\n--- a/fsck-objects.c\n+++ b/fsck-objects.c\n@@ -452,7 +452,7 @@ static int fsck_head_link(void)\n \tif (strncmp(git_refs_heads_master + pfxlen, \"refs/heads/\", 11))\n \t\treturn error(\"HEAD points to something strange (%s)\",\n \t\t\t     git_refs_heads_master + pfxlen);\n-\tif (!memcmp(null_sha1, sha1, 20))\n+\tif (is_null_sha1(sha1))\n \t\treturn error(\"HEAD: not a valid git pointer\");\n \treturn 0;\n }\ndiff --git a/sha1_name.c b/sha1_name.c\nindex c5a05fa..f567454 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -191,7 +191,7 @@ const char *find_unique_abbrev(const uns\n \tint status, is_null;\n \tstatic char hex[41];\n \n-\tis_null = !memcmp(sha1, null_sha1, 20);\n+\tis_null = is_null_sha1(sha1);\n \tmemcpy(hex, sha1_to_hex(sha1), 40);\n \tif (len == 40 || !len)\n \t\treturn hex;\n-- \n1.4.2.g460c-dirty\n"},{"id":"25391","messageId":"20060815222819.GA1145@diku.dk","threadId":"5289","inReplyTo":"Pine.LNX.4.63.0608151510120.5555@chino.corp.google.com","subject":"Re: [PATCH] make inline is_null_sha1 global","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2006-08-15T22:28:20Z","receivedAt":"2006-08-15T22:28:20Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"David Rientjes <rientjes@google.com> wrote Tue, Aug 15, 2006:\n> On Tue, 15 Aug 2006, Jonas Fonseca wrote:\n> \n> > Looks like this should be !is_null_sha1(...) in both cases.\n> > \n> \n> Correct, thanks for pointing that out.  Please ack the following patch that \n> fixes it.\n> \n> \t\tDavid\n> \n> Signed-off-by: David Rientjes <rientjes@google.com>\n\nAcked-by: Jonas Fonseca <fonseca@diku.dk>\n\n-- \nJonas Fonseca\n"},{"id":"25403","messageId":"7vlkpp41zh.fsf@assigned-by-dhcp.cox.net","threadId":"5289","inReplyTo":"Pine.LNX.4.63.0608151335020.1475@chino.corp.google.com","subject":"Re: [PATCH] make inline is_null_sha1 global","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-16T06:40:50Z","receivedAt":"2006-08-16T06:40:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Makes sense, except the gotcha found by Jonas.\nThanks, both.\n\nBTW, please drop the \"\\n\\t\\tDavid\\n\" from these messages and\nfold lines to a reasonable length.\n"}]}