From: Junio C Hamano Date: Mon, 31 Aug 2015 22:39:10 +0000 (-0700) Subject: Merge branch 'sg/describe-contains' X-Git-Tag: v2.6.0-rc0~17 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e95c3fb54fd43b5fca47bcfd946c3a009752cf3a?hp=-c Merge branch 'sg/describe-contains' "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 --- e95c3fb54fd43b5fca47bcfd946c3a009752cf3a diff --combined Documentation/git-describe.txt index e045fc73f8,363e501511..c8f28c8c86 --- a/Documentation/git-describe.txt +++ b/Documentation/git-describe.txt @@@ -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=] ... + 'git describe' [--all] [--tags] [--contains] [--abbrev=] [...] 'git describe' [--all] [--tags] [--contains] [--abbrev=] --dirty[=] DESCRIPTION @@@ -27,7 -27,7 +27,7 @@@ see the -a and -s options to linkgit:gi OPTIONS ------- ...:: - Commit-ish object names to describe. + Commit-ish object names to describe. Defaults to HEAD if omitted. --dirty[=]:: Describe the working tree. diff --combined builtin/describe.c index a36c829e57,d06673a378..7df554326b --- a/builtin/describe.c +++ b/builtin/describe.c @@@ -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] *"), - N_("git describe [options] --dirty"), + N_("git describe [] [...]"), + N_("git describe [] --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; } @@@ -119,10 -127,10 +119,10 @@@ } } -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 */ @@@ -134,10 -142,10 +134,10 @@@ 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; } @@@ -154,7 -162,7 +154,7 @@@ 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); }