Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Sat, 2 Aug 2008 18:58:34 +0000 (11:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 2 Aug 2008 18:58:34 +0000 (11:58 -0700)
* 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

1  2 
Documentation/git-name-rev.txt
builtin-name-rev.c
index 6e77ab135353aaf713b638a70701717db1706c2c,83d8e4a9fc9757d9c666c3c122978747506b7d6e..abd2237e51dfd86bcea98320edfff8922bc04eb6
@@@ -9,13 -9,13 +9,13 @@@ git-name-rev - Find symbolic names for 
  SYNOPSIS
  --------
  [verse]
 -'git-name-rev' [--tags] [--refs=<pattern>]
 +'git name-rev' [--tags] [--refs=<pattern>]
               ( --all | --stdin | <committish>... )
  
  DESCRIPTION
  -----------
  Finds symbolic names suitable for human digestion for revisions given in any
 -format parsable by git-rev-parse.
 +format parsable by 'git-rev-parse'.
  
  
  OPTIONS
@@@ -38,8 -38,7 +38,7 @@@
        Instead of printing both the SHA-1 and the name, print only
        the name.  If given with --tags the usual tag prefix of
        "tags/" is also omitted from the name, matching the output
-       of 'git-describe' more closely.  This option
-       cannot be combined with --stdin.
 -      of linkgit:git-describe[1] more closely.
++      of `git-describe` more closely.
  
  --no-undefined::
        Die with error code != 0 when a reference is undefined,
@@@ -56,7 -55,7 +55,7 @@@ wrote you about that fantastic commit 3
  Of course, you look into the commit, but that only tells you what happened, but
  not the context.
  
 -Enter git-name-rev:
 +Enter 'git-name-rev':
  
  ------------
  % git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a
diff --combined builtin-name-rev.c
index 85612c4dcb719b460623204046e35486e9d9fe97,ff7d638dc2b71c9c29441b842b49ccf03a9b4618..7055ac3108c5ce815728dce0127639170acfaf98
@@@ -172,10 -172,54 +172,54 @@@ static void show_name(const struct obje
  }
  
  static char const * const name_rev_usage[] = {
 -      "git-name-rev [options] ( --all | --stdin | <commit>... )",
 +      "git name-rev [options] ( --all | --stdin | <commit>... )",
        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 };
  
        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;