From e326bce65c2a8b10f40c1869e13c7450a243b109 Mon Sep 17 00:00:00 2001 From: Jason Riedy Date: Mon, 19 Feb 2007 16:27:09 -0800 Subject: Obey NO_C99_FORMAT in fast-import.c. Define UM_FMT and UM10_FMT and use in place of %ju and %10ju, respectively. Both format as unsigned long long, so this assumes the compiler supports long long. Signed-off-by: Jason Riedy Signed-off-by: Junio C Hamano --- fast-import.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'fast-import.c') diff --git a/fast-import.c b/fast-import.c index fd3b117574..8720090a3e 100644 --- a/fast-import.c +++ b/fast-import.c @@ -133,6 +133,15 @@ Format of STDIN stream: #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<data.marked[idnum]; } if (!oe) - die("mark :%ju not declared", orig_idnum); + die("mark :" UM_FMT " not declared", orig_idnum); return oe; } @@ -1361,7 +1370,7 @@ static void dump_marks_helper(FILE *f, } else { for (k = 0; k < 1024; k++) { if (m->data.marked[k]) - fprintf(f, ":%ju %s\n", base + k, + fprintf(f, ":" UM_FMT " %s\n", base + k, sha1_to_hex(m->data.marked[k]->sha1)); } } @@ -1687,7 +1696,7 @@ static void cmd_from(struct branch *b) unsigned long size; char *buf; if (oe->type != OBJ_COMMIT) - die("Mark :%ju not a commit", idnum); + die("Mark :" UM_FMT " not a commit", idnum); hashcpy(b->sha1, oe->sha1); buf = gfi_unpack_entry(oe, &size); if (!buf || size < 46) @@ -1740,7 +1749,7 @@ static struct hash_list *cmd_merge(unsigned int *count) uintmax_t idnum = strtoumax(from + 1, NULL, 10); struct object_entry *oe = find_mark(idnum); if (oe->type != OBJ_COMMIT) - die("Mark :%ju not a commit", idnum); + die("Mark :" UM_FMT " not a commit", idnum); hashcpy(n->sha1, oe->sha1); } else if (get_sha1(from, n->sha1)) die("Invalid ref name or SHA1 expression: %s", from); @@ -1884,7 +1893,7 @@ static void cmd_new_tag(void) from_mark = strtoumax(from + 1, NULL, 10); oe = find_mark(from_mark); if (oe->type != OBJ_COMMIT) - die("Mark :%ju not a commit", from_mark); + die("Mark :" UM_FMT " not a commit", from_mark); hashcpy(sha1, oe->sha1); } else if (!get_sha1(from, sha1)) { unsigned long size; @@ -2059,18 +2068,18 @@ int main(int argc, const char **argv) fprintf(stderr, "%s statistics:\n", argv[0]); fprintf(stderr, "---------------------------------------------------------------------\n"); - fprintf(stderr, "Alloc'd objects: %10ju\n", alloc_count); - fprintf(stderr, "Total objects: %10ju (%10ju duplicates )\n", total_count, duplicate_count); - fprintf(stderr, " blobs : %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]); - fprintf(stderr, " trees : %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]); - fprintf(stderr, " commits: %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]); - fprintf(stderr, " tags : %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]); + fprintf(stderr, "Alloc'd objects: " UM10_FMT "\n", alloc_count); + fprintf(stderr, "Total objects: " UM10_FMT " (" UM10_FMT " duplicates )\n", total_count, duplicate_count); + fprintf(stderr, " blobs : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]); + fprintf(stderr, " trees : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]); + fprintf(stderr, " commits: " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]); + fprintf(stderr, " tags : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]); fprintf(stderr, "Total branches: %10lu (%10lu loads )\n", branch_count, branch_load_count); - fprintf(stderr, " marks: %10ju (%10ju unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count); + fprintf(stderr, " marks: " UM10_FMT " (" UM10_FMT " unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count); fprintf(stderr, " atoms: %10u\n", atom_cnt); - fprintf(stderr, "Memory total: %10ju KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024); + fprintf(stderr, "Memory total: " UM10_FMT " KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024); fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)(total_allocd/1024)); - fprintf(stderr, " objects: %10ju KiB\n", (alloc_count*sizeof(struct object_entry))/1024); + fprintf(stderr, " objects: " UM10_FMT " KiB\n", (alloc_count*sizeof(struct object_entry))/1024); fprintf(stderr, "---------------------------------------------------------------------\n"); pack_report(); fprintf(stderr, "---------------------------------------------------------------------\n"); -- cgit v1.2.1 From 3efb1f343a9d6214a59a814029cab96638e9b915 Mon Sep 17 00:00:00 2001 From: Jason Riedy Date: Tue, 20 Feb 2007 17:34:56 -0800 Subject: Check for PRIuMAX rather than NO_C99_FORMAT in fast-import.c. Thanks to Simon 'corecode' Schubert for the clean-up. Defining the C99 standard PRIuMAX when necessary replaces UM_FMT and the awkward UM10_FMT. There are no direct C99 translations for other uses of NO_C99_FORMAT in git, alas. Signed-off-by: Jason Riedy Signed-off-by: Junio C Hamano --- fast-import.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'fast-import.c') diff --git a/fast-import.c b/fast-import.c index 8720090a3e..1ae125a040 100644 --- a/fast-import.c +++ b/fast-import.c @@ -133,13 +133,8 @@ Format of STDIN stream: #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<data.marked[idnum]; } if (!oe) - die("mark :" UM_FMT " not declared", orig_idnum); + die("mark :%" PRIuMAX " not declared", orig_idnum); return oe; } @@ -1370,7 +1365,7 @@ static void dump_marks_helper(FILE *f, } else { for (k = 0; k < 1024; k++) { if (m->data.marked[k]) - fprintf(f, ":" UM_FMT " %s\n", base + k, + fprintf(f, ":%" PRIuMAX " %s\n", base + k, sha1_to_hex(m->data.marked[k]->sha1)); } } @@ -1696,7 +1691,7 @@ static void cmd_from(struct branch *b) unsigned long size; char *buf; if (oe->type != OBJ_COMMIT) - die("Mark :" UM_FMT " not a commit", idnum); + die("Mark :%" PRIuMAX " not a commit", idnum); hashcpy(b->sha1, oe->sha1); buf = gfi_unpack_entry(oe, &size); if (!buf || size < 46) @@ -1749,7 +1744,7 @@ static struct hash_list *cmd_merge(unsigned int *count) uintmax_t idnum = strtoumax(from + 1, NULL, 10); struct object_entry *oe = find_mark(idnum); if (oe->type != OBJ_COMMIT) - die("Mark :" UM_FMT " not a commit", idnum); + die("Mark :%" PRIuMAX " not a commit", idnum); hashcpy(n->sha1, oe->sha1); } else if (get_sha1(from, n->sha1)) die("Invalid ref name or SHA1 expression: %s", from); @@ -1893,7 +1888,7 @@ static void cmd_new_tag(void) from_mark = strtoumax(from + 1, NULL, 10); oe = find_mark(from_mark); if (oe->type != OBJ_COMMIT) - die("Mark :" UM_FMT " not a commit", from_mark); + die("Mark :%" PRIuMAX " not a commit", from_mark); hashcpy(sha1, oe->sha1); } else if (!get_sha1(from, sha1)) { unsigned long size; @@ -2068,18 +2063,18 @@ int main(int argc, const char **argv) fprintf(stderr, "%s statistics:\n", argv[0]); fprintf(stderr, "---------------------------------------------------------------------\n"); - fprintf(stderr, "Alloc'd objects: " UM10_FMT "\n", alloc_count); - fprintf(stderr, "Total objects: " UM10_FMT " (" UM10_FMT " duplicates )\n", total_count, duplicate_count); - fprintf(stderr, " blobs : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]); - fprintf(stderr, " trees : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]); - fprintf(stderr, " commits: " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]); - fprintf(stderr, " tags : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]); + fprintf(stderr, "Alloc'd objects: %10" PRIuMAX "\n", alloc_count); + fprintf(stderr, "Total objects: %10" PRIuMAX " (%10" PRIuMAX " duplicates )\n", total_count, duplicate_count); + fprintf(stderr, " blobs : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]); + fprintf(stderr, " trees : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]); + fprintf(stderr, " commits: %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]); + fprintf(stderr, " tags : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]); fprintf(stderr, "Total branches: %10lu (%10lu loads )\n", branch_count, branch_load_count); - fprintf(stderr, " marks: " UM10_FMT " (" UM10_FMT " unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count); + fprintf(stderr, " marks: %10" PRIuMAX " (%10" PRIuMAX " unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count); fprintf(stderr, " atoms: %10u\n", atom_cnt); - fprintf(stderr, "Memory total: " UM10_FMT " KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024); + fprintf(stderr, "Memory total: %10" PRIuMAX " KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024); fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)(total_allocd/1024)); - fprintf(stderr, " objects: " UM10_FMT " KiB\n", (alloc_count*sizeof(struct object_entry))/1024); + fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024); fprintf(stderr, "---------------------------------------------------------------------\n"); pack_report(); fprintf(stderr, "---------------------------------------------------------------------\n"); -- cgit v1.2.1 From cc44c7655fe2dd0cfb46e841156634fe622df397 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 20 Feb 2007 01:53:29 -0800 Subject: Mechanical conversion to use prefixcmp() This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano --- fast-import.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'fast-import.c') diff --git a/fast-import.c b/fast-import.c index 32cd1f83e0..8e192c2991 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1392,7 +1392,7 @@ static void read_next_command(void) static void cmd_mark(void) { - if (!strncmp("mark :", command_buf.buf, 6)) { + if (!(-prefixcmp(command_buf.buf, "mark :"))) { next_mark = strtoumax(command_buf.buf + 6, NULL, 10); read_next_command(); } @@ -1405,10 +1405,10 @@ static void *cmd_data (size_t *size) size_t length; char *buffer; - if (strncmp("data ", command_buf.buf, 5)) + if ((-prefixcmp(command_buf.buf, "data "))) die("Expected 'data n' command, found: %s", command_buf.buf); - if (!strncmp("<<", command_buf.buf + 5, 2)) { + if (!(-prefixcmp(command_buf.buf + 5, "<<"))) { char *term = xstrdup(command_buf.buf + 5 + 2); size_t sz = 8192, term_len = command_buf.len - 5 - 2; length = 0; @@ -1595,7 +1595,7 @@ static void file_change_m(struct branch *b) oe = find_mark(strtoumax(p + 1, &x, 10)); hashcpy(sha1, oe->sha1); p = x; - } else if (!strncmp("inline", p, 6)) { + } else if (!(-prefixcmp(p, "inline"))) { inline_data = 1; p += 6; } else { @@ -1668,7 +1668,7 @@ static void cmd_from(struct branch *b) const char *from; struct branch *s; - if (strncmp("from ", command_buf.buf, 5)) + if ((-prefixcmp(command_buf.buf, "from "))) return; if (b->branch_tree.tree) { @@ -1734,7 +1734,7 @@ static struct hash_list *cmd_merge(unsigned int *count) struct branch *s; *count = 0; - while (!strncmp("merge ", command_buf.buf, 6)) { + while (!(-prefixcmp(command_buf.buf, "merge "))) { from = strchr(command_buf.buf, ' ') + 1; n = xmalloc(sizeof(*n)); s = lookup_branch(from); @@ -1780,11 +1780,11 @@ static void cmd_new_commit(void) read_next_command(); cmd_mark(); - if (!strncmp("author ", command_buf.buf, 7)) { + if (!(-prefixcmp(command_buf.buf, "author "))) { author = parse_ident(command_buf.buf + 7); read_next_command(); } - if (!strncmp("committer ", command_buf.buf, 10)) { + if (!(-prefixcmp(command_buf.buf, "committer "))) { committer = parse_ident(command_buf.buf + 10); read_next_command(); } @@ -1805,9 +1805,9 @@ static void cmd_new_commit(void) for (;;) { if (1 == command_buf.len) break; - else if (!strncmp("M ", command_buf.buf, 2)) + else if (!(-prefixcmp(command_buf.buf, "M "))) file_change_m(b); - else if (!strncmp("D ", command_buf.buf, 2)) + else if (!(-prefixcmp(command_buf.buf, "D "))) file_change_d(b); else if (!strcmp("deleteall", command_buf.buf)) file_change_deleteall(b); @@ -1877,7 +1877,7 @@ static void cmd_new_tag(void) read_next_command(); /* from ... */ - if (strncmp("from ", command_buf.buf, 5)) + if ((-prefixcmp(command_buf.buf, "from "))) die("Expected from command, got %s", command_buf.buf); from = strchr(command_buf.buf, ' ') + 1; s = lookup_branch(from); @@ -1904,7 +1904,7 @@ static void cmd_new_tag(void) read_next_command(); /* tagger ... */ - if (strncmp("tagger ", command_buf.buf, 7)) + if ((-prefixcmp(command_buf.buf, "tagger "))) die("Expected tagger command, got %s", command_buf.buf); tagger = parse_ident(command_buf.buf + 7); @@ -1981,7 +1981,7 @@ int main(int argc, const char **argv) if (*a != '-' || !strcmp(a, "--")) break; - else if (!strncmp(a, "--date-format=", 14)) { + else if (!prefixcmp(a, "--date-format=")) { const char *fmt = a + 14; if (!strcmp(fmt, "raw")) whenspec = WHENSPEC_RAW; @@ -1992,15 +1992,15 @@ int main(int argc, const char **argv) else die("unknown --date-format argument %s", fmt); } - else if (!strncmp(a, "--max-pack-size=", 16)) + else if (!prefixcmp(a, "--max-pack-size=")) max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024; - else if (!strncmp(a, "--depth=", 8)) + else if (!prefixcmp(a, "--depth=")) max_depth = strtoul(a + 8, NULL, 0); - else if (!strncmp(a, "--active-branches=", 18)) + else if (!prefixcmp(a, "--active-branches=")) max_active_branches = strtoul(a + 18, NULL, 0); - else if (!strncmp(a, "--export-marks=", 15)) + else if (!prefixcmp(a, "--export-marks=")) mark_file = a + 15; - else if (!strncmp(a, "--export-pack-edges=", 20)) { + else if (!prefixcmp(a, "--export-pack-edges=")) { if (pack_edges) fclose(pack_edges); pack_edges = fopen(a + 20, "a"); @@ -2033,11 +2033,11 @@ int main(int argc, const char **argv) break; else if (!strcmp("blob", command_buf.buf)) cmd_new_blob(); - else if (!strncmp("commit ", command_buf.buf, 7)) + else if (!(-prefixcmp(command_buf.buf, "commit "))) cmd_new_commit(); - else if (!strncmp("tag ", command_buf.buf, 4)) + else if (!(-prefixcmp(command_buf.buf, "tag "))) cmd_new_tag(); - else if (!strncmp("reset ", command_buf.buf, 6)) + else if (!(-prefixcmp(command_buf.buf, "reset "))) cmd_reset_branch(); else if (!strcmp("checkpoint", command_buf.buf)) cmd_checkpoint(); -- cgit v1.2.1 From 599065a3bb94ae9f48e3808b8fafc8443017af28 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 20 Feb 2007 01:54:00 -0800 Subject: prefixcmp(): fix-up mechanical conversion. Previous step converted use of strncmp() with literal string mechanically even when the result is only used as a boolean: if (!strncmp("foo", arg, 3)) ==> if (!(-prefixcmp(arg, "foo"))) This step manually cleans them up to read: if (!prefixcmp(arg, "foo")) Signed-off-by: Junio C Hamano --- fast-import.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'fast-import.c') diff --git a/fast-import.c b/fast-import.c index 8e192c2991..5d040fdb00 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1392,7 +1392,7 @@ static void read_next_command(void) static void cmd_mark(void) { - if (!(-prefixcmp(command_buf.buf, "mark :"))) { + if (!prefixcmp(command_buf.buf, "mark :")) { next_mark = strtoumax(command_buf.buf + 6, NULL, 10); read_next_command(); } @@ -1405,10 +1405,10 @@ static void *cmd_data (size_t *size) size_t length; char *buffer; - if ((-prefixcmp(command_buf.buf, "data "))) + if (prefixcmp(command_buf.buf, "data ")) die("Expected 'data n' command, found: %s", command_buf.buf); - if (!(-prefixcmp(command_buf.buf + 5, "<<"))) { + if (!prefixcmp(command_buf.buf + 5, "<<")) { char *term = xstrdup(command_buf.buf + 5 + 2); size_t sz = 8192, term_len = command_buf.len - 5 - 2; length = 0; @@ -1595,7 +1595,7 @@ static void file_change_m(struct branch *b) oe = find_mark(strtoumax(p + 1, &x, 10)); hashcpy(sha1, oe->sha1); p = x; - } else if (!(-prefixcmp(p, "inline"))) { + } else if (!prefixcmp(p, "inline")) { inline_data = 1; p += 6; } else { @@ -1668,7 +1668,7 @@ static void cmd_from(struct branch *b) const char *from; struct branch *s; - if ((-prefixcmp(command_buf.buf, "from "))) + if (prefixcmp(command_buf.buf, "from ")) return; if (b->branch_tree.tree) { @@ -1734,7 +1734,7 @@ static struct hash_list *cmd_merge(unsigned int *count) struct branch *s; *count = 0; - while (!(-prefixcmp(command_buf.buf, "merge "))) { + while (!prefixcmp(command_buf.buf, "merge ")) { from = strchr(command_buf.buf, ' ') + 1; n = xmalloc(sizeof(*n)); s = lookup_branch(from); @@ -1780,11 +1780,11 @@ static void cmd_new_commit(void) read_next_command(); cmd_mark(); - if (!(-prefixcmp(command_buf.buf, "author "))) { + if (!prefixcmp(command_buf.buf, "author ")) { author = parse_ident(command_buf.buf + 7); read_next_command(); } - if (!(-prefixcmp(command_buf.buf, "committer "))) { + if (!prefixcmp(command_buf.buf, "committer ")) { committer = parse_ident(command_buf.buf + 10); read_next_command(); } @@ -1805,9 +1805,9 @@ static void cmd_new_commit(void) for (;;) { if (1 == command_buf.len) break; - else if (!(-prefixcmp(command_buf.buf, "M "))) + else if (!prefixcmp(command_buf.buf, "M ")) file_change_m(b); - else if (!(-prefixcmp(command_buf.buf, "D "))) + else if (!prefixcmp(command_buf.buf, "D ")) file_change_d(b); else if (!strcmp("deleteall", command_buf.buf)) file_change_deleteall(b); @@ -1877,7 +1877,7 @@ static void cmd_new_tag(void) read_next_command(); /* from ... */ - if ((-prefixcmp(command_buf.buf, "from "))) + if (prefixcmp(command_buf.buf, "from ")) die("Expected from command, got %s", command_buf.buf); from = strchr(command_buf.buf, ' ') + 1; s = lookup_branch(from); @@ -1904,7 +1904,7 @@ static void cmd_new_tag(void) read_next_command(); /* tagger ... */ - if ((-prefixcmp(command_buf.buf, "tagger "))) + if (prefixcmp(command_buf.buf, "tagger ")) die("Expected tagger command, got %s", command_buf.buf); tagger = parse_ident(command_buf.buf + 7); @@ -2033,11 +2033,11 @@ int main(int argc, const char **argv) break; else if (!strcmp("blob", command_buf.buf)) cmd_new_blob(); - else if (!(-prefixcmp(command_buf.buf, "commit "))) + else if (!prefixcmp(command_buf.buf, "commit ")) cmd_new_commit(); - else if (!(-prefixcmp(command_buf.buf, "tag "))) + else if (!prefixcmp(command_buf.buf, "tag ")) cmd_new_tag(); - else if (!(-prefixcmp(command_buf.buf, "reset "))) + else if (!prefixcmp(command_buf.buf, "reset ")) cmd_reset_branch(); else if (!strcmp("checkpoint", command_buf.buf)) cmd_checkpoint(); -- cgit v1.2.1 From df8436622fb553f468180b61032fe34bd6712752 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 26 Feb 2007 14:55:58 -0500 Subject: formalize typename(), and add its reverse type_from_string() Sometime typename() is used, sometimes type_names[] is accessed directly. Let's enforce typename() all the time which allows for validating the type. Also let's add a function to go from a name to a type and use it instead of manual memcpy() when appropriate. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- fast-import.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'fast-import.c') diff --git a/fast-import.c b/fast-import.c index 5d040fdb00..aa9eac3925 100644 --- a/fast-import.c +++ b/fast-import.c @@ -891,7 +891,7 @@ static int store_object( SHA_CTX c; z_stream s; - hdrlen = sprintf((char*)hdr,"%s %lu", type_names[type], + hdrlen = sprintf((char*)hdr,"%s %lu", typename(type), (unsigned long)datlen) + 1; SHA1_Init(&c); SHA1_Update(&c, hdr, hdrlen); @@ -1626,7 +1626,7 @@ static void file_change_m(struct branch *b) } else if (oe) { if (oe->type != OBJ_BLOB) die("Not a blob (actually a %s): %s", - command_buf.buf, type_names[oe->type]); + command_buf.buf, typename(oe->type)); } else { if (sha1_object_info(sha1, type, NULL)) die("Blob not found: %s", command_buf.buf); @@ -1711,7 +1711,7 @@ static void cmd_from(struct branch *b) char *buf; buf = read_object_with_reference(b->sha1, - type_names[OBJ_COMMIT], &size, b->sha1); + commit_type, &size, b->sha1); if (!buf || size < 46) die("Not a valid commit: %s", from); if (memcmp("tree ", buf, 5) @@ -1895,7 +1895,7 @@ static void cmd_new_tag(void) char *buf; buf = read_object_with_reference(sha1, - type_names[OBJ_COMMIT], &size, sha1); + commit_type, &size, sha1); if (!buf || size < 46) die("Not a valid commit: %s", from); free(buf); @@ -1916,7 +1916,7 @@ static void cmd_new_tag(void) size_dbuf(&new_data, 67+strlen(t->name)+strlen(tagger)+msglen); sp = new_data.buffer; sp += sprintf(sp, "object %s\n", sha1_to_hex(sha1)); - sp += sprintf(sp, "type %s\n", type_names[OBJ_COMMIT]); + sp += sprintf(sp, "type %s\n", commit_type); sp += sprintf(sp, "tag %s\n", t->name); sp += sprintf(sp, "tagger %s\n", tagger); *sp++ = '\n'; -- cgit v1.2.1 From 21666f1aae4e890d8f50924f9e80763b27e6a45d Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 26 Feb 2007 14:55:59 -0500 Subject: convert object type handling from a string to a number We currently have two parallel notation for dealing with object types in the code: a string and a numerical value. One of them is obviously redundent, and the most used one requires more stack space and a bunch of strcmp() all over the place. This is an initial step for the removal of the version using a char array found in object reading code paths. The patch is unfortunately large but there is no sane way to split it in smaller parts without breaking the system. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- fast-import.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'fast-import.c') diff --git a/fast-import.c b/fast-import.c index aa9eac3925..65e99c2e8b 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1008,11 +1008,11 @@ static void *gfi_unpack_entry( struct object_entry *oe, unsigned long *sizep) { - static char type[20]; + enum object_type type; struct packed_git *p = all_packs[oe->pack_id]; if (p == pack_data) p->pack_size = pack_size + 20; - return unpack_entry(p, oe->offset, type, sizep); + return unpack_entry(p, oe->offset, &type, sizep); } static const char *get_mode(const char *str, uint16_t *modep) @@ -1049,9 +1049,9 @@ static void load_tree(struct tree_entry *root) t->delta_depth = 0; buf = gfi_unpack_entry(myoe, &size); } else { - char type[20]; - buf = read_sha1_file(sha1, type, &size); - if (!buf || strcmp(type, tree_type)) + enum object_type type; + buf = read_sha1_file(sha1, &type, &size); + if (!buf || type != OBJ_TREE) die("Can't load tree %s", sha1_to_hex(sha1)); } @@ -1573,7 +1573,6 @@ static void file_change_m(struct branch *b) struct object_entry *oe = oe; unsigned char sha1[20]; uint16_t mode, inline_data = 0; - char type[20]; p = get_mode(p, &mode); if (!p) @@ -1628,11 +1627,12 @@ static void file_change_m(struct branch *b) die("Not a blob (actually a %s): %s", command_buf.buf, typename(oe->type)); } else { - if (sha1_object_info(sha1, type, NULL)) + enum object_type type = sha1_object_info(sha1, NULL); + if (type < 0) die("Blob not found: %s", command_buf.buf); - if (strcmp(blob_type, type)) + if (type != OBJ_BLOB) die("Not a blob (actually a %s): %s", - command_buf.buf, type); + typename(type), command_buf.buf); } tree_content_set(&b->branch_tree, p, sha1, S_IFREG | mode); -- cgit v1.2.1