Merge branch 'sg/describe-contains'
authorJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 22:39:10 +0000 (15:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 22:39:10 +0000 (15:39 -0700)
"git describe" without argument defaulted to describe the HEAD
commit, but "git describe --contains" didn't. Arguably, in a
repository used for active development, such defaulting would not
be very useful as the tip of branch is typically not tagged, but it
is better to be consistent.

* sg/describe-contains:
describe --contains: default to HEAD when no commit-ish is given

1  2 
Documentation/git-describe.txt
builtin/describe.c
index e045fc73f88ae63a20c18af1b146dc1211a266ec,363e50151106d1863a174c902c4d42ab2a1beb54..c8f28c8c864523c948763d7554f49def36156336
@@@ -3,13 -3,13 +3,13 @@@ git-describe(1
  
  NAME
  ----
 -git-describe - Show the most recent tag that is reachable from a commit
 +git-describe - Describe a commit using the most recent tag reachable from it
  
  
  SYNOPSIS
  --------
  [verse]
- 'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] <commit-ish>...
+ 'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>...]
  'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>]
  
  DESCRIPTION
@@@ -27,7 -27,7 +27,7 @@@ see the -a and -s options to linkgit:gi
  OPTIONS
  -------
  <commit-ish>...::
-       Commit-ish object names to describe.
+       Commit-ish object names to describe.  Defaults to HEAD if omitted.
  
  --dirty[=<mark>]::
        Describe the working tree.
diff --combined builtin/describe.c
index a36c829e571e155c6b6b35c05ee2ef39ce37f406,d06673a37821e0716919f7e68d47d596f57792f6..7df554326b08581c49f391d061be14cd1164ea88
@@@ -1,5 -1,4 +1,5 @@@
  #include "cache.h"
 +#include "lockfile.h"
  #include "commit.h"
  #include "tag.h"
  #include "refs.h"
@@@ -14,8 -13,8 +14,8 @@@
  #define MAX_TAGS      (FLAG_BITS - 1)
  
  static const char * const describe_usage[] = {
 -      N_("git describe [options] <commit-ish>*"),
 -      N_("git describe [options] --dirty"),
 +      N_("git describe [<options>] [<commit-ish>...]"),
 +      N_("git describe [<options>] --dirty"),
        NULL
  };
  
@@@ -57,9 -56,18 +57,9 @@@ static int commit_name_cmp(const struc
        return hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled);
  }
  
 -static inline unsigned int hash_sha1(const unsigned char *sha1)
 -{
 -      unsigned int hash;
 -      memcpy(&hash, sha1, sizeof(hash));
 -      return hash;
 -}
 -
  static inline struct commit_name *find_commit_name(const unsigned char *peeled)
  {
 -      struct commit_name key;
 -      hashmap_entry_init(&key, hash_sha1(peeled));
 -      return hashmap_get(&names, &key, peeled);
 +      return hashmap_get_from_hash(&names, sha1hash(peeled), peeled);
  }
  
  static int replace_name(struct commit_name *e,
@@@ -106,7 -114,7 +106,7 @@@ static void add_to_known_names(const ch
                if (!e) {
                        e = xmalloc(sizeof(struct commit_name));
                        hashcpy(e->peeled, peeled);
 -                      hashmap_entry_init(e, hash_sha1(peeled));
 +                      hashmap_entry_init(e, sha1hash(peeled));
                        hashmap_add(&names, e);
                        e->path = NULL;
                }
        }
  }
  
 -static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 +static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data)
  {
        int is_tag = starts_with(path, "refs/tags/");
 -      unsigned char peeled[20];
 +      struct object_id peeled;
        int is_annotated, prio;
  
        /* Reject anything outside refs/tags/ unless --all */
                return 0;
  
        /* Is it annotated? */
 -      if (!peel_ref(path, peeled)) {
 -              is_annotated = !!hashcmp(sha1, peeled);
 +      if (!peel_ref(path, peeled.hash)) {
 +              is_annotated = !!oidcmp(oid, &peeled);
        } else {
 -              hashcpy(peeled, sha1);
 +              oidcpy(&peeled, oid);
                is_annotated = 0;
        }
  
        else
                prio = 0;
  
 -      add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);
 +      add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);
        return 0;
  }
  
@@@ -443,10 -451,10 +443,10 @@@ int cmd_describe(int argc, const char *
                        if (pattern)
                                argv_array_pushf(&args, "--refs=refs/tags/%s", pattern);
                }
-               while (*argv) {
-                       argv_array_push(&args, *argv);
-                       argv++;
-               }
+               if (argc)
+                       argv_array_pushv(&args, argv);
+               else
+                       argv_array_push(&args, "HEAD");
                return cmd_name_rev(args.argc, args.argv, prefix);
        }