summaryrefslogtreecommitdiff
path: root/builtin-name-rev.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2008-08-02 11:58:34 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2008-08-02 11:58:34 -0700
commit372c767610c4e4d7f4832d037ac51a62a59875a3 (patch)
tree9e0efda79c236ceeba4b727c89b79818358034b2 /builtin-name-rev.c
parentMerge branch 'maint' (diff)
parentgit-name-rev: allow --name-only in combination with --stdin (diff)
downloadtgif-372c767610c4e4d7f4832d037ac51a62a59875a3.tar.xz
Merge branch 'maint'
* maint: git-name-rev: allow --name-only in combination with --stdin builtin-name-rev.c: split deeply nested part from the main function Conflicts: Documentation/git-name-rev.txt
Diffstat (limited to 'builtin-name-rev.c')
-rw-r--r--builtin-name-rev.c83
1 files changed, 46 insertions, 37 deletions
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 85612c4dcb..7055ac3108 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -176,6 +176,50 @@ static char const * const name_rev_usage[] = {
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);
+
+ 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) {
+ fwrite(p_start, p - p_start + 1 - 40, 1, stdout);
+ printf(name);
+ } else {
+ 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);
+}
+
int cmd_name_rev(int argc, const char **argv, const char *prefix)
{
struct object_array revs = { 0, 0, NULL };
@@ -234,47 +278,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;