X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-name-rev.c;h=08c8aabf9428447abad7def693d7b22c5330e180;hb=9a7a1e03d5e530cdad98c41c109e3319c008ce69;hp=f153da012f4e89ff8744ede70911cd4690de79b2;hpb=bc9c3e0b932c5e14de749e07f5045197e7d6cd76;p=git.git diff --git a/builtin-name-rev.c b/builtin-name-rev.c index f153da012..08c8aabf9 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 }; @@ -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;