|
|
@ -5,12 +5,14 @@ |
|
|
|
#include "builtin.h" |
|
|
|
#include "builtin.h" |
|
|
|
#include "exec_cmd.h" |
|
|
|
#include "exec_cmd.h" |
|
|
|
#include "parse-options.h" |
|
|
|
#include "parse-options.h" |
|
|
|
|
|
|
|
#include "diff.h" |
|
|
|
|
|
|
|
|
|
|
|
#define SEEN (1u<<0) |
|
|
|
#define SEEN (1u<<0) |
|
|
|
#define MAX_TAGS (FLAG_BITS - 1) |
|
|
|
#define MAX_TAGS (FLAG_BITS - 1) |
|
|
|
|
|
|
|
|
|
|
|
static const char * const describe_usage[] = { |
|
|
|
static const char * const describe_usage[] = { |
|
|
|
"git describe [options] <committish>*", |
|
|
|
"git describe [options] <committish>*", |
|
|
|
|
|
|
|
"git describe [options] --dirty", |
|
|
|
NULL |
|
|
|
NULL |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -23,6 +25,13 @@ static int max_candidates = 10; |
|
|
|
static int found_names; |
|
|
|
static int found_names; |
|
|
|
static const char *pattern; |
|
|
|
static const char *pattern; |
|
|
|
static int always; |
|
|
|
static int always; |
|
|
|
|
|
|
|
static const char *dirty; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* diff-index command arguments to check if working tree is dirty. */ |
|
|
|
|
|
|
|
static const char *diff_index_args[] = { |
|
|
|
|
|
|
|
"diff-index", "--quiet", "HEAD", "--", NULL |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct commit_name { |
|
|
|
struct commit_name { |
|
|
|
struct tag *tag; |
|
|
|
struct tag *tag; |
|
|
@ -199,6 +208,8 @@ static void describe(const char *arg, int last_one) |
|
|
|
display_name(n); |
|
|
|
display_name(n); |
|
|
|
if (longformat) |
|
|
|
if (longformat) |
|
|
|
show_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1); |
|
|
|
show_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1); |
|
|
|
|
|
|
|
if (dirty) |
|
|
|
|
|
|
|
printf("%s", dirty); |
|
|
|
printf("\n"); |
|
|
|
printf("\n"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -256,7 +267,10 @@ static void describe(const char *arg, int last_one) |
|
|
|
if (!match_cnt) { |
|
|
|
if (!match_cnt) { |
|
|
|
const unsigned char *sha1 = cmit->object.sha1; |
|
|
|
const unsigned char *sha1 = cmit->object.sha1; |
|
|
|
if (always) { |
|
|
|
if (always) { |
|
|
|
printf("%s\n", find_unique_abbrev(sha1, abbrev)); |
|
|
|
printf("%s", find_unique_abbrev(sha1, abbrev)); |
|
|
|
|
|
|
|
if (dirty) |
|
|
|
|
|
|
|
printf("%s", dirty); |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
die("cannot describe '%s'", sha1_to_hex(sha1)); |
|
|
|
die("cannot describe '%s'", sha1_to_hex(sha1)); |
|
|
@ -291,6 +305,8 @@ static void describe(const char *arg, int last_one) |
|
|
|
display_name(all_matches[0].name); |
|
|
|
display_name(all_matches[0].name); |
|
|
|
if (abbrev) |
|
|
|
if (abbrev) |
|
|
|
show_suffix(all_matches[0].depth, cmit->object.sha1); |
|
|
|
show_suffix(all_matches[0].depth, cmit->object.sha1); |
|
|
|
|
|
|
|
if (dirty) |
|
|
|
|
|
|
|
printf("%s", dirty); |
|
|
|
printf("\n"); |
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
|
|
if (!last_one) |
|
|
|
if (!last_one) |
|
|
@ -315,6 +331,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix) |
|
|
|
"only consider tags matching <pattern>"), |
|
|
|
"only consider tags matching <pattern>"), |
|
|
|
OPT_BOOLEAN(0, "always", &always, |
|
|
|
OPT_BOOLEAN(0, "always", &always, |
|
|
|
"show abbreviated commit object as fallback"), |
|
|
|
"show abbreviated commit object as fallback"), |
|
|
|
|
|
|
|
{OPTION_STRING, 0, "dirty", &dirty, "mark", |
|
|
|
|
|
|
|
"append <mark> on dirty working tree (default: \"-dirty\")", |
|
|
|
|
|
|
|
PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"}, |
|
|
|
OPT_END(), |
|
|
|
OPT_END(), |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -355,7 +374,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix) |
|
|
|
die("No names found, cannot describe anything."); |
|
|
|
die("No names found, cannot describe anything."); |
|
|
|
|
|
|
|
|
|
|
|
if (argc == 0) { |
|
|
|
if (argc == 0) { |
|
|
|
|
|
|
|
if (dirty && !cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1, diff_index_args, prefix)) |
|
|
|
|
|
|
|
dirty = NULL; |
|
|
|
describe("HEAD", 1); |
|
|
|
describe("HEAD", 1); |
|
|
|
|
|
|
|
} else if (dirty) { |
|
|
|
|
|
|
|
die("--dirty is incompatible with committishes"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
while (argc-- > 0) { |
|
|
|
while (argc-- > 0) { |
|
|
|
describe(*argv++, argc == 0); |
|
|
|
describe(*argv++, argc == 0); |
|
|
|