X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-name-rev.c;h=06a38ac8c10126085e6477c205d450da089faae2;hb=6d0d465e20b8c11924bc4e75563324771d0e0d63;hp=f153da012f4e89ff8744ede70911cd4690de79b2;hpb=8de7e9c07e199bd4d856a9360f8865f0d5fde3eb;p=git.git diff --git a/builtin-name-rev.c b/builtin-name-rev.c index f153da012..06a38ac8c 100644 --- a/builtin-name-rev.c +++ b/builtin-name-rev.c @@ -172,10 +172,52 @@ static void show_name(const struct object *obj, } static char const * const name_rev_usage[] = { - "git-name-rev [options] ( --all | --stdin | ... )", + "git name-rev [options] ( --all | --stdin | ... )", NULL }; +static void name_rev_line(char *p, struct name_ref_data *data) +{ + int forty = 0; + char *p_start; + for (p_start = p; *p; p++) { +#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f')) + if (!ishex(*p)) + forty = 0; + else if (++forty == 40 && + !ishex(*(p+1))) { + unsigned char sha1[40]; + const char *name = NULL; + char c = *(p+1); + int p_len = p - p_start + 1; + + forty = 0; + + *(p+1) = 0; + if (!get_sha1(p - 39, sha1)) { + struct object *o = + lookup_object(sha1); + if (o) + name = get_rev_name(o); + } + *(p+1) = c; + + if (!name) + continue; + + if (data->name_only) + printf("%.*s%s", p_len - 40, p_start, name); + else + printf("%.*s (%s)", p_len, p_start, name); + p_start = p + 1; + } + } + + /* flush */ + if (p_start != p) + fwrite(p_start, p - p_start, 1, stdout); +} + int cmd_name_rev(int argc, const char **argv, const char *prefix) { struct object_array revs = { 0, 0, NULL }; @@ -196,7 +238,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) }; git_config(git_default_config, NULL); - argc = parse_options(argc, argv, opts, name_rev_usage, 0); + argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0); if (!!all + !!transform_stdin + !!argc > 1) { error("Specify either a list, or --all, not both!"); usage_with_options(name_rev_usage, opts); @@ -234,47 +276,12 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) if (transform_stdin) { char buffer[2048]; - char *p, *p_start; while (!feof(stdin)) { - int forty = 0; - p = fgets(buffer, sizeof(buffer), stdin); + char *p = fgets(buffer, sizeof(buffer), stdin); if (!p) break; - - for (p_start = p; *p; p++) { -#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f')) - if (!ishex(*p)) - forty = 0; - else if (++forty == 40 && - !ishex(*(p+1))) { - unsigned char sha1[40]; - const char *name = NULL; - char c = *(p+1); - - forty = 0; - - *(p+1) = 0; - if (!get_sha1(p - 39, sha1)) { - struct object *o = - lookup_object(sha1); - if (o) - name = get_rev_name(o); - } - *(p+1) = c; - - if (!name) - continue; - - fwrite(p_start, p - p_start + 1, 1, stdout); - printf(" (%s)", name); - p_start = p + 1; - } - } - - /* flush */ - if (p_start != p) - fwrite(p_start, p - p_start, 1, stdout); + name_rev_line(p, &data); } } else if (all) { int i, max;