{"thread":{"id":"41369","subject":"[PATCH] Use GIT_SHA1_RAWSZ as array size instead magic number 20","startedAt":"2016-02-08T12:11:22Z","lastAt":"2016-02-08T12:11:22Z","messageCount":1,"participants":["Brilliantov Kirill Vladimirovich"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"277725","messageId":"1454933482-31920-1-git-send-email-brilliantovkv@byterg.ru","threadId":"41369","inReplyTo":null,"subject":"[PATCH] Use GIT_SHA1_RAWSZ as array size instead magic number 20","fromName":"Brilliantov Kirill Vladimirovich","fromEmail":"brilliantovkv@byterg.ru","sentAt":"2016-02-08T12:11:22Z","receivedAt":"2016-02-08T12:11:22Z","isPatch":true,"sender":{"key":"brilliantovkv@byterg.ru","avatar":null},"body":"Signed-off-by: Brilliantov Kirill Vladimirovich <brilliantovkv@byterg.ru>\n---\n builtin/apply.c         |  4 ++--\n builtin/blame.c         |  2 +-\n builtin/cat-file.c      |  8 ++++----\n builtin/checkout.c      | 18 +++++++++---------\n builtin/commit-tree.c   |  6 +++---\n builtin/commit.c        |  6 +++---\n builtin/describe.c      |  4 ++--\n builtin/diff-tree.c     |  8 ++++----\n builtin/diff.c          |  2 +-\n builtin/fast-export.c   |  6 +++---\n builtin/fmt-merge-msg.c | 12 ++++++------\n builtin/grep.c          |  2 +-\n builtin/hash-object.c   |  2 +-\n builtin/index-pack.c    |  6 +++---\n 14 files changed, 43 insertions(+), 43 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex deb1364..63d14ca 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -202,8 +202,8 @@ struct patch {\n \tstruct fragment *fragments;\n \tchar *result;\n \tsize_t resultsize;\n-\tchar old_sha1_prefix[41];\n-\tchar new_sha1_prefix[41];\n+\tchar old_sha1_prefix[GIT_SHA1_HEXSZ + 1];\n+\tchar new_sha1_prefix[GIT_SHA1_HEXSZ + 1];\n \tstruct patch *next;\n \n \t/* three-way fallback result */\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 55bf5fa..e1fd8d5 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -120,7 +120,7 @@ struct origin {\n \t */\n \tstruct blame_entry *suspects;\n \tmmfile_t file;\n-\tunsigned char blob_sha1[20];\n+\tunsigned char blob_sha1[GIT_SHA1_RAWSZ];\n \tunsigned mode;\n \t/* guilty gets set when shipping any suspects to the final\n \t * blame list instead of other commits\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 54db118..36fea66 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -23,7 +23,7 @@ struct batch_options {\n static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\tint unknown_type)\n {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tenum object_type type;\n \tchar *buf;\n \tunsigned long size;\n@@ -93,7 +93,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \n \tcase 0:\n \t\tif (type_from_string(exp_type) == OBJ_BLOB) {\n-\t\t\tunsigned char blob_sha1[20];\n+\t\t\tunsigned char blob_sha1[GIT_SHA1_RAWSZ];\n \t\t\tif (sha1_object_info(sha1, NULL) == OBJ_TAG) {\n \t\t\t\tchar *buffer = read_sha1_file(sha1, &type, &size);\n \t\t\t\tconst char *target;\n@@ -128,12 +128,12 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n }\n \n struct expand_data {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tenum object_type type;\n \tunsigned long size;\n \tunsigned long disk_size;\n \tconst char *rest;\n-\tunsigned char delta_base_sha1[20];\n+\tunsigned char delta_base_sha1[GIT_SHA1_RAWSZ];\n \n \t/*\n \t * If mark_query is true, we do not expand anything, but rather\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 5af84a3..acec04f 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -175,9 +175,9 @@ static int checkout_merged(int pos, struct checkout *state)\n \tconst char *path = ce->name;\n \tmmfile_t ancestor, ours, theirs;\n \tint status;\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tmmbuffer_t result_buf;\n-\tunsigned char threeway[3][20];\n+\tunsigned char threeway[3][GIT_SHA1_RAWSZ];\n \tunsigned mode = 0;\n \n \tmemset(threeway, 0, sizeof(threeway));\n@@ -241,7 +241,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tint pos;\n \tstruct checkout state;\n \tstatic char *ps_matched;\n-\tunsigned char rev[20];\n+\tunsigned char rev[GIT_SHA1_RAWSZ];\n \tint flag;\n \tstruct commit *head;\n \tint errs = 0;\n@@ -806,7 +806,7 @@ static int switch_branches(const struct checkout_opts *opts,\n \tint ret = 0;\n \tstruct branch_info old;\n \tvoid *path_to_free;\n-\tunsigned char rev[20];\n+\tunsigned char rev[GIT_SHA1_RAWSZ];\n \tint flag, writeout_error = 0;\n \tmemset(&old, 0, sizeof(old));\n \told.path = path_to_free = resolve_refdup(\"HEAD\", 0, rev, &flag);\n@@ -900,12 +900,12 @@ static int parse_branchname_arg(int argc, const char **argv,\n \t\t\t\tint dwim_new_local_branch_ok,\n \t\t\t\tstruct branch_info *new,\n \t\t\t\tstruct checkout_opts *opts,\n-\t\t\t\tunsigned char rev[20])\n+\t\t\t\tunsigned char rev[GIT_SHA1_RAWSZ])\n {\n \tstruct tree **source_tree = &opts->source_tree;\n \tconst char **new_branch = &opts->new_branch;\n \tint argcount = 0;\n-\tunsigned char branch_rev[20];\n+\tunsigned char branch_rev[GIT_SHA1_RAWSZ];\n \tconst char *arg;\n \tint dash_dash_pos;\n \tint has_dash_dash = 0;\n@@ -1105,7 +1105,7 @@ static int checkout_branch(struct checkout_opts *opts,\n \n \tif (new->path && !opts->force_detach && !opts->new_branch &&\n \t    !opts->ignore_other_worktrees) {\n-\t\tunsigned char sha1[20];\n+\t\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \t\tint flag;\n \t\tchar *head_ref = resolve_refdup(\"HEAD\", 0, sha1, &flag);\n \t\tif (head_ref &&\n@@ -1115,7 +1115,7 @@ static int checkout_branch(struct checkout_opts *opts,\n \t}\n \n \tif (!new->commit && opts->new_branch) {\n-\t\tunsigned char rev[20];\n+\t\tunsigned char rev[GIT_SHA1_RAWSZ];\n \t\tint flag;\n \n \t\tif (!read_ref_full(\"HEAD\", 0, rev, &flag) &&\n@@ -1229,7 +1229,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t * remote branches, erroring out for invalid or ambiguous cases.\n \t */\n \tif (argc) {\n-\t\tunsigned char rev[20];\n+\t\tunsigned char rev[GIT_SHA1_RAWSZ];\n \t\tint dwim_ok =\n \t\t\t!opts.patch_mode &&\n \t\t\tdwim_new_local_branch &&\ndiff --git a/builtin/commit-tree.c b/builtin/commit-tree.c\nindex 3feeffe..d50a732 100644\n--- a/builtin/commit-tree.c\n+++ b/builtin/commit-tree.c\n@@ -44,8 +44,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n {\n \tint i, got_tree = 0;\n \tstruct commit_list *parents = NULL;\n-\tunsigned char tree_sha1[20];\n-\tunsigned char commit_sha1[20];\n+\tunsigned char tree_sha1[GIT_SHA1_RAWSZ];\n+\tunsigned char commit_sha1[GIT_SHA1_RAWSZ];\n \tstruct strbuf buffer = STRBUF_INIT;\n \n \tgit_config(commit_tree_config, NULL);\n@@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n \t\tif (!strcmp(arg, \"-p\")) {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \t\t\tif (argc <= ++i)\n \t\t\t\tusage(commit_tree_usage);\n \t\t\tif (get_sha1_commit(argv[i], sha1))\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex b3bd2d4..79eca8d 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1317,7 +1317,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n {\n \tstatic struct wt_status s;\n \tint fd;\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tstatic struct option builtin_status_options[] = {\n \t\tOPT__VERBOSE(&verbose, N_(\"be verbose\")),\n \t\tOPT_SET_INT('s', \"short\", &status_format,\n@@ -1419,7 +1419,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,\n \tstruct rev_info rev;\n \tstruct commit *commit;\n \tstruct strbuf format = STRBUF_INIT;\n-\tunsigned char junk_sha1[20];\n+\tunsigned char junk_sha1[GIT_SHA1_RAWSZ];\n \tconst char *head;\n \tstruct pretty_print_context pctx = {0};\n \tstruct strbuf author_ident = STRBUF_INIT;\n@@ -1629,7 +1629,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tstruct strbuf author_ident = STRBUF_INIT;\n \tconst char *index_file, *reflog_msg;\n \tchar *nl;\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tstruct commit_list *parents = NULL, **pptr = &parents;\n \tstruct stat statbuf;\n \tstruct commit *current_head = NULL;\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 8a25abe..04958ad 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -43,7 +43,7 @@ struct commit_name {\n \tstruct tag *tag;\n \tunsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */\n \tunsigned name_checked:1;\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tchar *path;\n };\n \n@@ -237,7 +237,7 @@ static void show_suffix(int depth, const unsigned char *sha1)\n \n static void describe(const char *arg, int last_one)\n {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tstruct commit *cmit, *gave_up_on = NULL;\n \tstruct commit_list *list;\n \tstruct commit_name *n;\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 2a12b81..5478785 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -18,7 +18,7 @@ static int diff_tree_commit_sha1(const unsigned char *sha1)\n /* Diff one or more commits. */\n static int stdin_diff_commit(struct commit *commit, char *line, int len)\n {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tif (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {\n \t\t/* Graft the fake parents locally to the commit */\n \t\tint pos = 41;\n@@ -42,7 +42,7 @@ static int stdin_diff_commit(struct commit *commit, char *line, int len)\n /* Diff two trees. */\n static int stdin_diff_trees(struct tree *tree1, char *line, int len)\n {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tstruct tree *tree2;\n \tif (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1))\n \t\treturn error(\"Need exactly two trees, separated by a space\");\n@@ -60,7 +60,7 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len)\n static int diff_tree_stdin(char *line)\n {\n \tint len = strlen(line);\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tstruct object *obj;\n \n \tif (!len || line[len-1] != '\\n')\n@@ -164,7 +164,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \t\t\topt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |\n \t\t\t\t\t       DIFF_SETUP_USE_CACHE);\n \t\twhile (fgets(line, sizeof(line), stdin)) {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \n \t\t\tif (get_sha1_hex(line, sha1)) {\n \t\t\t\tfputs(line, stdout);\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 52c98a9..84b8397 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -21,7 +21,7 @@\n #define DIFF_NO_INDEX_IMPLICIT 2\n \n struct blobinfo {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tconst char *name;\n \tunsigned mode;\n };\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 2471297..e5eeb8e 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -326,7 +326,7 @@ static void print_path(const char *path)\n static void *generate_fake_sha1(const void *old, size_t *len)\n {\n \tstatic uint32_t counter = 1; /* avoid null sha1 */\n-\tunsigned char *out = xcalloc(20, 1);\n+\tunsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1);\n \tput_be32(out + 16, counter++);\n \treturn out;\n }\n@@ -797,7 +797,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)\n \n \tfor (i = 0; i < info->nr; i++) {\n \t\tstruct rev_cmdline_entry *e = info->rev + i;\n-\t\tunsigned char sha1[20];\n+\t\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \t\tstruct commit *commit;\n \t\tchar *full_name;\n \n@@ -912,7 +912,7 @@ static void import_marks(char *input_file)\n \twhile (fgets(line, sizeof(line), f)) {\n \t\tuint32_t mark;\n \t\tchar *line_end, *mark_end;\n-\t\tunsigned char sha1[20];\n+\t\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \t\tstruct object *object;\n \t\tstruct commit *commit;\n \t\tenum object_type type;\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex e5658c3..b3615de 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -41,7 +41,7 @@ struct src_data {\n };\n \n struct origin_data {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tunsigned is_local_branch:1;\n };\n \n@@ -59,8 +59,8 @@ static struct string_list origins = STRING_LIST_INIT_DUP;\n struct merge_parents {\n \tint alloc, nr;\n \tstruct merge_parent {\n-\t\tunsigned char given[20];\n-\t\tunsigned char commit[20];\n+\t\tunsigned char given[GIT_SHA1_RAWSZ];\n+\t\tunsigned char commit[GIT_SHA1_RAWSZ];\n \t\tunsigned char used;\n \t} *item;\n };\n@@ -106,7 +106,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)\n \tstruct src_data *src_data;\n \tstruct string_list_item *item;\n \tint pulling_head = 0;\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \n \tif (len < 43 || line[40] != '\\t')\n \t\treturn 1;\n@@ -546,7 +546,7 @@ static void find_merge_parents(struct merge_parents *result,\n \t\tint len;\n \t\tchar *p = in->buf + pos;\n \t\tchar *newline = strchr(p, '\\n');\n-\t\tunsigned char sha1[20];\n+\t\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \t\tstruct commit *parent;\n \t\tstruct object *obj;\n \n@@ -596,7 +596,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,\n \t\t  struct fmt_merge_msg_opts *opts)\n {\n \tint i = 0, pos = 0;\n-\tunsigned char head_sha1[20];\n+\tunsigned char head_sha1[GIT_SHA1_RAWSZ];\n \tconst char *current_branch;\n \tvoid *current_branch_to_free;\n \tstruct merge_parents merge_parents;\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 8c516a9..24e825e 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -817,7 +817,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t/* Check revs and then paths */\n \tfor (i = 0; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-\t\tunsigned char sha1[20];\n+\t\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \t\tstruct object_context oc;\n \t\t/* Is it a rev? */\n \t\tif (!get_sha1_with_context(arg, 0, sha1, &oc)) {\ndiff --git a/builtin/hash-object.c b/builtin/hash-object.c\nindex ff20395..4f992e1 100644\n--- a/builtin/hash-object.c\n+++ b/builtin/hash-object.c\n@@ -32,7 +32,7 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,\n \t\t    int literally)\n {\n \tstruct stat st;\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \n \tif (fstat(fd, &st) < 0 ||\n \t    (literally\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 6a01509..da2f001 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -56,7 +56,7 @@ struct ofs_delta_entry {\n };\n \n struct ref_delta_entry {\n-\tunsigned char sha1[20];\n+\tunsigned char sha1[GIT_SHA1_RAWSZ];\n \tint obj_no;\n };\n \n@@ -1110,7 +1110,7 @@ static void parse_pack_objects(unsigned char *sha1)\n {\n \tint i, nr_delays = 0;\n \tstruct ofs_delta_entry *ofs_delta = ofs_deltas;\n-\tunsigned char ref_delta_sha1[20];\n+\tunsigned char ref_delta_sha1[GIT_SHA1_RAWSZ];\n \tstruct stat st;\n \n \tif (verbose)\n@@ -1239,7 +1239,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \n \tif (fix_thin_pack) {\n \t\tstruct sha1file *f;\n-\t\tunsigned char read_sha1[20], tail_sha1[20];\n+\t\tunsigned char read_sha1[GIT_SHA1_RAWSZ], tail_sha1[GIT_SHA1_RAWSZ];\n \t\tstruct strbuf msg = STRBUF_INIT;\n \t\tint nr_unresolved = nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas;\n \t\tint nr_objects_initial = nr_objects;\n-- \n2.1.4\n"}]}