Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
#include "cache.h"
|
2017-06-15 02:07:36 +08:00
|
|
|
#include "config.h"
|
2014-10-01 18:28:42 +08:00
|
|
|
#include "lockfile.h"
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
#include "commit.h"
|
2005-12-28 06:36:49 +08:00
|
|
|
#include "tag.h"
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
#include "refs.h"
|
2007-01-10 19:36:36 +08:00
|
|
|
#include "builtin.h"
|
2007-05-21 15:20:25 +08:00
|
|
|
#include "exec_cmd.h"
|
2007-10-08 02:54:08 +08:00
|
|
|
#include "parse-options.h"
|
2009-10-21 21:35:22 +08:00
|
|
|
#include "diff.h"
|
2013-11-15 03:18:35 +08:00
|
|
|
#include "hashmap.h"
|
2013-07-08 05:42:23 +08:00
|
|
|
#include "argv-array.h"
|
2017-03-22 06:57:18 +08:00
|
|
|
#include "run-command.h"
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
|
2013-10-31 17:25:41 +08:00
|
|
|
#define SEEN (1u << 0)
|
2007-01-14 06:30:53 +08:00
|
|
|
#define MAX_TAGS (FLAG_BITS - 1)
|
|
|
|
|
2007-10-08 02:54:08 +08:00
|
|
|
static const char * const describe_usage[] = {
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git describe [<options>] [<commit-ish>...]"),
|
|
|
|
N_("git describe [<options>] --dirty"),
|
2007-10-08 02:54:08 +08:00
|
|
|
NULL
|
|
|
|
};
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
|
2007-01-14 06:30:53 +08:00
|
|
|
static int debug; /* Display lots of verbose info */
|
2008-10-13 22:39:46 +08:00
|
|
|
static int all; /* Any valid ref can be used */
|
|
|
|
static int tags; /* Allow lightweight tags */
|
2008-02-25 17:43:33 +08:00
|
|
|
static int longformat;
|
2013-05-18 04:56:18 +08:00
|
|
|
static int first_parent;
|
2010-10-29 02:28:04 +08:00
|
|
|
static int abbrev = -1; /* unspecified */
|
2007-01-14 06:30:53 +08:00
|
|
|
static int max_candidates = 10;
|
2013-11-15 03:18:35 +08:00
|
|
|
static struct hashmap names;
|
2010-12-09 14:47:29 +08:00
|
|
|
static int have_util;
|
2017-01-19 07:06:07 +08:00
|
|
|
static struct string_list patterns = STRING_LIST_INIT_NODUP;
|
2017-01-19 07:06:08 +08:00
|
|
|
static struct string_list exclude_patterns = STRING_LIST_INIT_NODUP;
|
2008-03-03 00:51:57 +08:00
|
|
|
static int always;
|
2017-03-22 06:57:18 +08:00
|
|
|
static const char *suffix, *dirty, *broken;
|
2009-10-21 21:35:22 +08:00
|
|
|
|
|
|
|
/* diff-index command arguments to check if working tree is dirty. */
|
|
|
|
static const char *diff_index_args[] = {
|
|
|
|
"diff-index", "--quiet", "HEAD", "--", NULL
|
|
|
|
};
|
|
|
|
|
2007-01-15 11:16:55 +08:00
|
|
|
struct commit_name {
|
2013-11-15 03:18:35 +08:00
|
|
|
struct hashmap_entry entry;
|
2017-02-22 07:47:22 +08:00
|
|
|
struct object_id peeled;
|
2008-02-28 14:22:36 +08:00
|
|
|
struct tag *tag;
|
2010-04-13 07:25:29 +08:00
|
|
|
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
|
|
|
|
unsigned name_checked:1;
|
2017-02-22 07:47:22 +08:00
|
|
|
struct object_id oid;
|
2013-05-25 17:08:00 +08:00
|
|
|
char *path;
|
2007-01-15 11:16:55 +08:00
|
|
|
};
|
2013-10-31 17:25:41 +08:00
|
|
|
|
2007-01-14 17:37:44 +08:00
|
|
|
static const char *prio_names[] = {
|
2017-03-28 00:50:05 +08:00
|
|
|
N_("head"), N_("lightweight"), N_("annotated"),
|
2007-01-14 17:37:44 +08:00
|
|
|
};
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
|
2017-07-01 03:14:05 +08:00
|
|
|
static int commit_name_cmp(const void *unused_cmp_data,
|
|
|
|
const struct commit_name *cn1,
|
|
|
|
const struct commit_name *cn2,
|
|
|
|
const void *peeled)
|
2013-11-15 03:18:35 +08:00
|
|
|
{
|
2017-02-22 07:47:22 +08:00
|
|
|
return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
|
2013-11-15 03:18:35 +08:00
|
|
|
}
|
|
|
|
|
2017-02-22 07:47:22 +08:00
|
|
|
static inline struct commit_name *find_commit_name(const struct object_id *peeled)
|
2010-12-09 14:46:08 +08:00
|
|
|
{
|
2017-02-22 07:47:22 +08:00
|
|
|
return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);
|
2010-12-09 14:47:29 +08:00
|
|
|
}
|
|
|
|
|
2010-04-13 07:25:29 +08:00
|
|
|
static int replace_name(struct commit_name *e,
|
|
|
|
int prio,
|
2017-02-22 07:47:22 +08:00
|
|
|
const struct object_id *oid,
|
2010-04-13 07:25:29 +08:00
|
|
|
struct tag **tag)
|
|
|
|
{
|
|
|
|
if (!e || e->prio < prio)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (e->prio == 2 && prio == 2) {
|
|
|
|
/* Multiple annotated tags point to the same commit.
|
|
|
|
* Select one to keep based upon their tagger date.
|
|
|
|
*/
|
|
|
|
struct tag *t;
|
|
|
|
|
|
|
|
if (!e->tag) {
|
2017-05-07 06:10:19 +08:00
|
|
|
t = lookup_tag(&e->oid);
|
2010-04-13 07:25:29 +08:00
|
|
|
if (!t || parse_tag(t))
|
|
|
|
return 1;
|
|
|
|
e->tag = t;
|
|
|
|
}
|
|
|
|
|
2017-05-07 06:10:19 +08:00
|
|
|
t = lookup_tag(oid);
|
2010-04-13 07:25:29 +08:00
|
|
|
if (!t || parse_tag(t))
|
|
|
|
return 0;
|
|
|
|
*tag = t;
|
|
|
|
|
|
|
|
if (e->tag->date < t->date)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-28 08:09:37 +08:00
|
|
|
static void add_to_known_names(const char *path,
|
2017-02-22 07:47:22 +08:00
|
|
|
const struct object_id *peeled,
|
2008-02-28 14:22:36 +08:00
|
|
|
int prio,
|
2017-02-22 07:47:22 +08:00
|
|
|
const struct object_id *oid)
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
{
|
2010-12-09 14:46:08 +08:00
|
|
|
struct commit_name *e = find_commit_name(peeled);
|
2010-04-13 07:25:29 +08:00
|
|
|
struct tag *tag = NULL;
|
2017-02-22 07:47:22 +08:00
|
|
|
if (replace_name(e, prio, oid, &tag)) {
|
2010-12-09 14:43:32 +08:00
|
|
|
if (!e) {
|
|
|
|
e = xmalloc(sizeof(struct commit_name));
|
2017-02-22 07:47:22 +08:00
|
|
|
oidcpy(&e->peeled, peeled);
|
|
|
|
hashmap_entry_init(e, sha1hash(peeled->hash));
|
2013-11-15 03:18:35 +08:00
|
|
|
hashmap_add(&names, e);
|
2013-05-25 17:08:00 +08:00
|
|
|
e->path = NULL;
|
2010-12-09 14:43:32 +08:00
|
|
|
}
|
2010-04-13 07:25:29 +08:00
|
|
|
e->tag = tag;
|
2007-01-15 11:16:55 +08:00
|
|
|
e->prio = prio;
|
2010-04-13 07:25:29 +08:00
|
|
|
e->name_checked = 0;
|
2017-02-22 07:47:22 +08:00
|
|
|
oidcpy(&e->oid, oid);
|
2013-05-25 17:08:00 +08:00
|
|
|
free(e->path);
|
|
|
|
e->path = xstrdup(path);
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 02:38:34 +08:00
|
|
|
static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data)
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
{
|
2013-12-01 04:55:40 +08:00
|
|
|
int is_tag = starts_with(path, "refs/tags/");
|
2015-05-26 02:38:34 +08:00
|
|
|
struct object_id peeled;
|
2013-03-01 05:53:00 +08:00
|
|
|
int is_annotated, prio;
|
2008-02-24 16:07:25 +08:00
|
|
|
|
2013-03-01 05:53:00 +08:00
|
|
|
/* Reject anything outside refs/tags/ unless --all */
|
|
|
|
if (!all && !is_tag)
|
2008-02-24 16:07:28 +08:00
|
|
|
return 0;
|
|
|
|
|
2017-01-19 07:06:08 +08:00
|
|
|
/*
|
|
|
|
* If we're given exclude patterns, first exclude any tag which match
|
|
|
|
* any of the exclude pattern.
|
|
|
|
*/
|
|
|
|
if (exclude_patterns.nr) {
|
|
|
|
struct string_list_item *item;
|
|
|
|
|
|
|
|
if (!is_tag)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for_each_string_list_item(item, &exclude_patterns) {
|
2017-06-23 05:38:08 +08:00
|
|
|
if (!wildmatch(item->string, path + 10, 0))
|
2017-01-19 07:06:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 07:06:07 +08:00
|
|
|
/*
|
|
|
|
* If we're given patterns, accept only tags which match at least one
|
|
|
|
* pattern.
|
|
|
|
*/
|
|
|
|
if (patterns.nr) {
|
2017-09-16 13:53:44 +08:00
|
|
|
int found = 0;
|
2017-01-19 07:06:07 +08:00
|
|
|
struct string_list_item *item;
|
|
|
|
|
|
|
|
if (!is_tag)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for_each_string_list_item(item, &patterns) {
|
2017-10-18 13:19:01 +08:00
|
|
|
if (!wildmatch(item->string, path + 10, 0)) {
|
2017-09-16 13:53:44 +08:00
|
|
|
found = 1;
|
2017-01-19 07:06:07 +08:00
|
|
|
break;
|
2017-09-16 13:53:44 +08:00
|
|
|
}
|
|
|
|
}
|
2017-01-19 07:06:07 +08:00
|
|
|
|
2017-09-16 13:53:44 +08:00
|
|
|
if (!found)
|
2017-01-19 07:06:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2013-03-01 05:53:00 +08:00
|
|
|
|
|
|
|
/* Is it annotated? */
|
2015-05-26 02:38:34 +08:00
|
|
|
if (!peel_ref(path, peeled.hash)) {
|
|
|
|
is_annotated = !!oidcmp(oid, &peeled);
|
2008-02-24 16:07:25 +08:00
|
|
|
} else {
|
2015-05-26 02:38:34 +08:00
|
|
|
oidcpy(&peeled, oid);
|
2013-03-01 05:53:00 +08:00
|
|
|
is_annotated = 0;
|
2008-02-24 16:07:25 +08:00
|
|
|
}
|
2005-12-28 08:09:37 +08:00
|
|
|
|
2013-03-01 05:53:00 +08:00
|
|
|
/*
|
|
|
|
* By default, we only use annotated tags, but with --tags
|
|
|
|
* we fall back to lightweight ones (even without --tags,
|
|
|
|
* we still remember lightweight ones, only to give hints
|
|
|
|
* in an error message). --all allows any refs to be used.
|
2005-12-28 06:40:17 +08:00
|
|
|
*/
|
2013-03-01 05:53:00 +08:00
|
|
|
if (is_annotated)
|
|
|
|
prio = 2;
|
|
|
|
else if (is_tag)
|
|
|
|
prio = 1;
|
2005-12-28 08:09:37 +08:00
|
|
|
else
|
|
|
|
prio = 0;
|
|
|
|
|
2017-02-22 07:47:22 +08:00
|
|
|
add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-10 19:39:47 +08:00
|
|
|
struct possible_tag {
|
|
|
|
struct commit_name *name;
|
2007-01-14 17:37:44 +08:00
|
|
|
int depth;
|
|
|
|
int found_order;
|
2007-01-14 06:30:53 +08:00
|
|
|
unsigned flag_within;
|
2007-01-10 19:39:47 +08:00
|
|
|
};
|
|
|
|
|
2007-01-14 17:37:44 +08:00
|
|
|
static int compare_pt(const void *a_, const void *b_)
|
|
|
|
{
|
|
|
|
struct possible_tag *a = (struct possible_tag *)a_;
|
|
|
|
struct possible_tag *b = (struct possible_tag *)b_;
|
|
|
|
if (a->depth != b->depth)
|
|
|
|
return a->depth - b->depth;
|
|
|
|
if (a->found_order != b->found_order)
|
|
|
|
return a->found_order - b->found_order;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-27 14:54:21 +08:00
|
|
|
static unsigned long finish_depth_computation(
|
|
|
|
struct commit_list **list,
|
|
|
|
struct possible_tag *best)
|
|
|
|
{
|
|
|
|
unsigned long seen_commits = 0;
|
|
|
|
while (*list) {
|
|
|
|
struct commit *c = pop_commit(list);
|
|
|
|
struct commit_list *parents = c->parents;
|
|
|
|
seen_commits++;
|
|
|
|
if (c->object.flags & best->flag_within) {
|
|
|
|
struct commit_list *a = *list;
|
|
|
|
while (a) {
|
|
|
|
struct commit *i = a->item;
|
|
|
|
if (!(i->object.flags & best->flag_within))
|
|
|
|
break;
|
|
|
|
a = a->next;
|
|
|
|
}
|
|
|
|
if (!a)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
best->depth++;
|
|
|
|
while (parents) {
|
|
|
|
struct commit *p = parents->item;
|
|
|
|
parse_commit(p);
|
|
|
|
if (!(p->object.flags & SEEN))
|
2010-11-27 09:58:14 +08:00
|
|
|
commit_list_insert_by_date(p, list);
|
2007-01-27 14:54:21 +08:00
|
|
|
p->object.flags |= c->object.flags;
|
|
|
|
parents = parents->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return seen_commits;
|
|
|
|
}
|
|
|
|
|
2008-02-28 14:22:36 +08:00
|
|
|
static void display_name(struct commit_name *n)
|
|
|
|
{
|
|
|
|
if (n->prio == 2 && !n->tag) {
|
2017-05-07 06:10:19 +08:00
|
|
|
n->tag = lookup_tag(&n->oid);
|
2010-04-13 07:25:29 +08:00
|
|
|
if (!n->tag || parse_tag(n->tag))
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("annotated tag %s not available"), n->path);
|
2010-04-13 07:25:29 +08:00
|
|
|
}
|
|
|
|
if (n->tag && !n->name_checked) {
|
|
|
|
if (!n->tag->tag)
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("annotated tag %s has no embedded name"), n->path);
|
2008-12-27 06:02:01 +08:00
|
|
|
if (strcmp(n->tag->tag, all ? n->path + 5 : n->path))
|
2011-02-23 07:42:23 +08:00
|
|
|
warning(_("tag '%s' is really '%s' here"), n->tag->tag, n->path);
|
2010-04-13 07:25:29 +08:00
|
|
|
n->name_checked = 1;
|
2008-02-28 14:22:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n->tag)
|
|
|
|
printf("%s", n->tag->tag);
|
|
|
|
else
|
|
|
|
printf("%s", n->path);
|
2008-03-04 05:08:26 +08:00
|
|
|
}
|
|
|
|
|
2017-02-22 07:47:22 +08:00
|
|
|
static void show_suffix(int depth, const struct object_id *oid)
|
2008-03-04 05:08:26 +08:00
|
|
|
{
|
2017-02-22 07:47:22 +08:00
|
|
|
printf("-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
|
2008-02-28 14:22:36 +08:00
|
|
|
}
|
|
|
|
|
2006-06-28 17:04:39 +08:00
|
|
|
static void describe(const char *arg, int last_one)
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
{
|
2017-02-22 07:47:22 +08:00
|
|
|
struct object_id oid;
|
2007-01-14 06:30:53 +08:00
|
|
|
struct commit *cmit, *gave_up_on = NULL;
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
struct commit_list *list;
|
|
|
|
struct commit_name *n;
|
2007-01-14 17:37:44 +08:00
|
|
|
struct possible_tag all_matches[MAX_TAGS];
|
2007-01-14 06:30:53 +08:00
|
|
|
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
|
|
|
|
unsigned long seen_commits = 0;
|
2009-10-29 06:10:06 +08:00
|
|
|
unsigned int unannotated_cnt = 0;
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
|
2017-02-22 07:47:22 +08:00
|
|
|
if (get_oid(arg, &oid))
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("Not a valid object name %s"), arg);
|
Convert lookup_commit* to struct object_id
Convert lookup_commit, lookup_commit_or_die,
lookup_commit_reference, and lookup_commit_reference_gently to take
struct object_id arguments.
Introduce a temporary in parse_object buffer in order to convert this
function. This is required since in order to convert parse_object and
parse_object_buffer, lookup_commit_reference_gently and
lookup_commit_or_die would need to be converted. Not introducing a
temporary would therefore require that lookup_commit_or_die take a
struct object_id *, but lookup_commit would take unsigned char *,
leaving a confusing and hard-to-use interface.
parse_object_buffer will lose this temporary in a later patch.
This commit was created with manual changes to commit.c, commit.h, and
object.c, plus the following semantic patch:
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1.hash, E2)
+ lookup_commit_reference_gently(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1->hash, E2)
+ lookup_commit_reference_gently(E1, E2)
@@
expression E1;
@@
- lookup_commit_reference(E1.hash)
+ lookup_commit_reference(&E1)
@@
expression E1;
@@
- lookup_commit_reference(E1->hash)
+ lookup_commit_reference(E1)
@@
expression E1;
@@
- lookup_commit(E1.hash)
+ lookup_commit(&E1)
@@
expression E1;
@@
- lookup_commit(E1->hash)
+ lookup_commit(E1)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1.hash, E2)
+ lookup_commit_or_die(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1->hash, E2)
+ lookup_commit_or_die(E1, E2)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-07 06:10:10 +08:00
|
|
|
cmit = lookup_commit_reference(&oid);
|
2006-01-12 05:57:42 +08:00
|
|
|
if (!cmit)
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("%s is not a valid '%s' object"), arg, commit_type);
|
2006-01-12 05:57:42 +08:00
|
|
|
|
2017-02-22 07:47:22 +08:00
|
|
|
n = find_commit_name(&cmit->object.oid);
|
2009-11-18 21:32:26 +08:00
|
|
|
if (n && (tags || all || n->prio == 2)) {
|
2008-03-04 05:08:26 +08:00
|
|
|
/*
|
|
|
|
* Exact match to an existing ref.
|
|
|
|
*/
|
2008-02-28 14:22:36 +08:00
|
|
|
display_name(n);
|
2008-03-04 05:08:26 +08:00
|
|
|
if (longformat)
|
2017-02-22 07:47:22 +08:00
|
|
|
show_suffix(0, n->tag ? &n->tag->tagged->oid : &oid);
|
2017-03-22 06:57:18 +08:00
|
|
|
if (suffix)
|
|
|
|
printf("%s", suffix);
|
2008-02-28 14:22:36 +08:00
|
|
|
printf("\n");
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-24 16:07:31 +08:00
|
|
|
if (!max_candidates)
|
2015-11-10 10:22:28 +08:00
|
|
|
die(_("no tag exactly matches '%s'"), oid_to_hex(&cmit->object.oid));
|
2007-01-14 06:30:53 +08:00
|
|
|
if (debug)
|
2011-02-23 07:42:23 +08:00
|
|
|
fprintf(stderr, _("searching to describe %s\n"), arg);
|
2007-01-14 06:30:53 +08:00
|
|
|
|
2010-12-09 14:47:29 +08:00
|
|
|
if (!have_util) {
|
2013-11-15 03:18:35 +08:00
|
|
|
struct hashmap_iter iter;
|
|
|
|
struct commit *c;
|
|
|
|
struct commit_name *n = hashmap_iter_first(&names, &iter);
|
|
|
|
for (; n; n = hashmap_iter_next(&iter)) {
|
Convert lookup_commit* to struct object_id
Convert lookup_commit, lookup_commit_or_die,
lookup_commit_reference, and lookup_commit_reference_gently to take
struct object_id arguments.
Introduce a temporary in parse_object buffer in order to convert this
function. This is required since in order to convert parse_object and
parse_object_buffer, lookup_commit_reference_gently and
lookup_commit_or_die would need to be converted. Not introducing a
temporary would therefore require that lookup_commit_or_die take a
struct object_id *, but lookup_commit would take unsigned char *,
leaving a confusing and hard-to-use interface.
parse_object_buffer will lose this temporary in a later patch.
This commit was created with manual changes to commit.c, commit.h, and
object.c, plus the following semantic patch:
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1.hash, E2)
+ lookup_commit_reference_gently(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1->hash, E2)
+ lookup_commit_reference_gently(E1, E2)
@@
expression E1;
@@
- lookup_commit_reference(E1.hash)
+ lookup_commit_reference(&E1)
@@
expression E1;
@@
- lookup_commit_reference(E1->hash)
+ lookup_commit_reference(E1)
@@
expression E1;
@@
- lookup_commit(E1.hash)
+ lookup_commit(&E1)
@@
expression E1;
@@
- lookup_commit(E1->hash)
+ lookup_commit(E1)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1.hash, E2)
+ lookup_commit_or_die(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1->hash, E2)
+ lookup_commit_or_die(E1, E2)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-07 06:10:10 +08:00
|
|
|
c = lookup_commit_reference_gently(&n->peeled, 1);
|
2013-11-15 03:18:35 +08:00
|
|
|
if (c)
|
|
|
|
c->util = n;
|
|
|
|
}
|
2010-12-09 14:47:29 +08:00
|
|
|
have_util = 1;
|
|
|
|
}
|
|
|
|
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
list = NULL;
|
2007-01-14 06:30:53 +08:00
|
|
|
cmit->object.flags = SEEN;
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
commit_list_insert(cmit, &list);
|
|
|
|
while (list) {
|
2007-01-10 19:39:47 +08:00
|
|
|
struct commit *c = pop_commit(&list);
|
2007-01-14 06:27:52 +08:00
|
|
|
struct commit_list *parents = c->parents;
|
2007-01-14 06:30:53 +08:00
|
|
|
seen_commits++;
|
2007-01-15 11:16:55 +08:00
|
|
|
n = c->util;
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
if (n) {
|
2009-10-29 06:10:06 +08:00
|
|
|
if (!tags && !all && n->prio < 2) {
|
|
|
|
unannotated_cnt++;
|
|
|
|
} else if (match_cnt < max_candidates) {
|
2007-01-14 06:30:53 +08:00
|
|
|
struct possible_tag *t = &all_matches[match_cnt++];
|
|
|
|
t->name = n;
|
|
|
|
t->depth = seen_commits - 1;
|
|
|
|
t->flag_within = 1u << match_cnt;
|
2007-01-26 01:40:03 +08:00
|
|
|
t->found_order = match_cnt;
|
2007-01-14 06:30:53 +08:00
|
|
|
c->object.flags |= t->flag_within;
|
|
|
|
if (n->prio == 2)
|
|
|
|
annotated_cnt++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gave_up_on = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (cur_match = 0; cur_match < match_cnt; cur_match++) {
|
|
|
|
struct possible_tag *t = &all_matches[cur_match];
|
|
|
|
if (!(c->object.flags & t->flag_within))
|
|
|
|
t->depth++;
|
|
|
|
}
|
|
|
|
if (annotated_cnt && !list) {
|
|
|
|
if (debug)
|
2011-02-23 07:42:23 +08:00
|
|
|
fprintf(stderr, _("finished search at %s\n"),
|
2015-11-10 10:22:28 +08:00
|
|
|
oid_to_hex(&c->object.oid));
|
2007-01-14 06:30:53 +08:00
|
|
|
break;
|
2007-01-14 06:27:52 +08:00
|
|
|
}
|
|
|
|
while (parents) {
|
|
|
|
struct commit *p = parents->item;
|
|
|
|
parse_commit(p);
|
2007-01-14 06:30:53 +08:00
|
|
|
if (!(p->object.flags & SEEN))
|
2010-11-27 09:58:14 +08:00
|
|
|
commit_list_insert_by_date(p, &list);
|
2007-01-14 06:30:53 +08:00
|
|
|
p->object.flags |= c->object.flags;
|
2007-01-14 06:27:52 +08:00
|
|
|
parents = parents->next;
|
2013-05-18 04:56:18 +08:00
|
|
|
|
|
|
|
if (first_parent)
|
|
|
|
break;
|
2007-01-10 19:39:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-03 00:51:57 +08:00
|
|
|
if (!match_cnt) {
|
2015-11-10 10:22:28 +08:00
|
|
|
struct object_id *oid = &cmit->object.oid;
|
2008-03-03 00:51:57 +08:00
|
|
|
if (always) {
|
2015-11-10 10:22:28 +08:00
|
|
|
printf("%s", find_unique_abbrev(oid->hash, abbrev));
|
2017-03-22 06:57:18 +08:00
|
|
|
if (suffix)
|
|
|
|
printf("%s", suffix);
|
2009-10-21 21:35:22 +08:00
|
|
|
printf("\n");
|
2008-03-03 00:51:57 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-10-29 06:10:06 +08:00
|
|
|
if (unannotated_cnt)
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("No annotated tags can describe '%s'.\n"
|
|
|
|
"However, there were unannotated tags: try --tags."),
|
2015-11-10 10:22:28 +08:00
|
|
|
oid_to_hex(oid));
|
2009-10-29 06:10:06 +08:00
|
|
|
else
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("No tags can describe '%s'.\n"
|
|
|
|
"Try --always, or create some tags."),
|
2015-11-10 10:22:28 +08:00
|
|
|
oid_to_hex(oid));
|
2008-03-03 00:51:57 +08:00
|
|
|
}
|
2007-01-10 19:39:47 +08:00
|
|
|
|
2016-09-29 23:27:31 +08:00
|
|
|
QSORT(all_matches, match_cnt, compare_pt);
|
2007-01-27 14:54:21 +08:00
|
|
|
|
|
|
|
if (gave_up_on) {
|
2010-11-27 09:58:14 +08:00
|
|
|
commit_list_insert_by_date(gave_up_on, &list);
|
2007-01-27 14:54:21 +08:00
|
|
|
seen_commits--;
|
|
|
|
}
|
|
|
|
seen_commits += finish_depth_computation(&list, &all_matches[0]);
|
|
|
|
free_commit_list(list);
|
|
|
|
|
2007-01-14 06:30:53 +08:00
|
|
|
if (debug) {
|
2017-03-28 00:50:05 +08:00
|
|
|
static int label_width = -1;
|
|
|
|
if (label_width < 0) {
|
|
|
|
int i, w;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(prio_names); i++) {
|
|
|
|
w = strlen(_(prio_names[i]));
|
|
|
|
if (label_width < w)
|
|
|
|
label_width = w;
|
|
|
|
}
|
|
|
|
}
|
2007-01-14 06:30:53 +08:00
|
|
|
for (cur_match = 0; cur_match < match_cnt; cur_match++) {
|
|
|
|
struct possible_tag *t = &all_matches[cur_match];
|
2017-03-28 00:50:05 +08:00
|
|
|
fprintf(stderr, " %-*s %8d %s\n",
|
|
|
|
label_width, _(prio_names[t->name->prio]),
|
2007-01-14 06:30:53 +08:00
|
|
|
t->depth, t->name->path);
|
|
|
|
}
|
2011-02-23 07:42:23 +08:00
|
|
|
fprintf(stderr, _("traversed %lu commits\n"), seen_commits);
|
2007-01-14 06:30:53 +08:00
|
|
|
if (gave_up_on) {
|
|
|
|
fprintf(stderr,
|
2011-02-23 07:42:23 +08:00
|
|
|
_("more than %i tags found; listed %i most recent\n"
|
|
|
|
"gave up search at %s\n"),
|
2007-01-14 06:30:53 +08:00
|
|
|
max_candidates, max_candidates,
|
2015-11-10 10:22:28 +08:00
|
|
|
oid_to_hex(&gave_up_on->object.oid));
|
2007-01-14 06:30:53 +08:00
|
|
|
}
|
2007-01-10 19:39:47 +08:00
|
|
|
}
|
2008-02-28 14:22:36 +08:00
|
|
|
|
|
|
|
display_name(all_matches[0].name);
|
|
|
|
if (abbrev)
|
2017-02-22 07:47:22 +08:00
|
|
|
show_suffix(all_matches[0].depth, &cmit->object.oid);
|
2017-03-22 06:57:18 +08:00
|
|
|
if (suffix)
|
|
|
|
printf("%s", suffix);
|
2008-02-28 14:22:36 +08:00
|
|
|
printf("\n");
|
2007-01-10 19:39:47 +08:00
|
|
|
|
2007-01-14 06:30:53 +08:00
|
|
|
if (!last_one)
|
|
|
|
clear_commit_marks(cmit, -1);
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
}
|
|
|
|
|
2007-01-10 19:36:36 +08:00
|
|
|
int cmd_describe(int argc, const char **argv, const char *prefix)
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
{
|
2007-05-21 15:20:25 +08:00
|
|
|
int contains = 0;
|
2007-10-08 02:54:08 +08:00
|
|
|
struct option options[] = {
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL(0, "contains", &contains, N_("find the tag that comes after the commit")),
|
|
|
|
OPT_BOOL(0, "debug", &debug, N_("debug search strategy on stderr")),
|
|
|
|
OPT_BOOL(0, "all", &all, N_("use any ref")),
|
|
|
|
OPT_BOOL(0, "tags", &tags, N_("use any tag, even unannotated")),
|
|
|
|
OPT_BOOL(0, "long", &longformat, N_("always use long format")),
|
|
|
|
OPT_BOOL(0, "first-parent", &first_parent, N_("only follow first parent")),
|
2007-10-08 02:54:08 +08:00
|
|
|
OPT__ABBREV(&abbrev),
|
2008-02-24 16:07:31 +08:00
|
|
|
OPT_SET_INT(0, "exact-match", &max_candidates,
|
2012-08-20 20:32:07 +08:00
|
|
|
N_("only output exact matches"), 0),
|
2007-10-08 02:54:08 +08:00
|
|
|
OPT_INTEGER(0, "candidates", &max_candidates,
|
2012-08-20 20:32:07 +08:00
|
|
|
N_("consider <n> most recent tags (default: 10)")),
|
2017-01-19 07:06:07 +08:00
|
|
|
OPT_STRING_LIST(0, "match", &patterns, N_("pattern"),
|
2012-08-20 20:32:07 +08:00
|
|
|
N_("only consider tags matching <pattern>")),
|
2017-01-19 07:06:08 +08:00
|
|
|
OPT_STRING_LIST(0, "exclude", &exclude_patterns, N_("pattern"),
|
|
|
|
N_("do not consider tags matching <pattern>")),
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL(0, "always", &always,
|
|
|
|
N_("show abbreviated commit object as fallback")),
|
2012-08-20 20:32:07 +08:00
|
|
|
{OPTION_STRING, 0, "dirty", &dirty, N_("mark"),
|
2013-08-03 19:51:19 +08:00
|
|
|
N_("append <mark> on dirty working tree (default: \"-dirty\")"),
|
|
|
|
PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
|
2017-03-22 06:57:18 +08:00
|
|
|
{OPTION_STRING, 0, "broken", &broken, N_("mark"),
|
|
|
|
N_("append <mark> on broken working tree (default: \"-broken\")"),
|
|
|
|
PARSE_OPT_OPTARG, NULL, (intptr_t) "-broken"},
|
2007-10-08 02:54:08 +08:00
|
|
|
OPT_END(),
|
|
|
|
};
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
|
2010-10-29 02:28:04 +08:00
|
|
|
git_config(git_default_config, NULL);
|
2009-05-24 02:53:12 +08:00
|
|
|
argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
|
2010-10-29 02:28:04 +08:00
|
|
|
if (abbrev < 0)
|
|
|
|
abbrev = DEFAULT_ABBREV;
|
|
|
|
|
2008-02-24 16:07:31 +08:00
|
|
|
if (max_candidates < 0)
|
|
|
|
max_candidates = 0;
|
2007-10-08 02:54:08 +08:00
|
|
|
else if (max_candidates > MAX_TAGS)
|
|
|
|
max_candidates = MAX_TAGS;
|
2006-01-12 05:57:42 +08:00
|
|
|
|
2007-01-10 19:36:29 +08:00
|
|
|
save_commit_buffer = 0;
|
2006-09-14 09:03:59 +08:00
|
|
|
|
2008-02-25 17:43:33 +08:00
|
|
|
if (longformat && abbrev == 0)
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("--long is incompatible with --abbrev=0"));
|
2008-02-25 17:43:33 +08:00
|
|
|
|
2007-05-21 15:20:25 +08:00
|
|
|
if (contains) {
|
2017-01-19 07:06:07 +08:00
|
|
|
struct string_list_item *item;
|
2013-07-08 05:42:23 +08:00
|
|
|
struct argv_array args;
|
|
|
|
|
|
|
|
argv_array_init(&args);
|
2013-07-19 05:46:51 +08:00
|
|
|
argv_array_pushl(&args, "name-rev",
|
|
|
|
"--peel-tag", "--name-only", "--no-undefined",
|
2013-07-08 05:42:23 +08:00
|
|
|
NULL);
|
2008-03-03 00:51:57 +08:00
|
|
|
if (always)
|
2013-07-08 05:42:23 +08:00
|
|
|
argv_array_push(&args, "--always");
|
2007-12-22 05:49:54 +08:00
|
|
|
if (!all) {
|
2013-07-08 05:42:23 +08:00
|
|
|
argv_array_push(&args, "--tags");
|
2017-01-19 07:06:07 +08:00
|
|
|
for_each_string_list_item(item, &patterns)
|
|
|
|
argv_array_pushf(&args, "--refs=refs/tags/%s", item->string);
|
2017-01-19 07:06:08 +08:00
|
|
|
for_each_string_list_item(item, &exclude_patterns)
|
|
|
|
argv_array_pushf(&args, "--exclude=refs/tags/%s", item->string);
|
2013-07-08 05:42:23 +08:00
|
|
|
}
|
describe --contains: default to HEAD when no commit-ish is given
'git describe --contains' doesn't default to HEAD when no commit is
given, and it doesn't produce any output, not even an error:
~/src/git ((v2.5.0))$ ./git describe --contains
~/src/git ((v2.5.0))$ ./git describe --contains HEAD
v2.5.0^0
Unlike other 'git describe' options, the '--contains' code path is
implemented by calling 'name-rev' with a bunch of options plus all the
commit-ishes that were passed to 'git describe'. If no commit-ish was
present, then 'name-rev' got invoked with none, which then leads to the
behavior illustrated above.
Porcelain commands usually default to HEAD when no commit-ish is given,
and 'git describe' already does so in all other cases, so it should do
so with '--contains' as well.
Pass HEAD to 'name-rev' when no commit-ish is given on the command line
to make '--contains' behave consistently with other 'git describe'
options. While at it, use argv_array_pushv() instead of the loop to
pass commit-ishes to 'git name-rev'.
'git describe's short help already indicates that the commit-ish is
optional, but the synopsis in the man page doesn't, so update it
accordingly as well.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-25 00:15:18 +08:00
|
|
|
if (argc)
|
|
|
|
argv_array_pushv(&args, argv);
|
|
|
|
else
|
|
|
|
argv_array_push(&args, "HEAD");
|
2013-07-08 05:42:23 +08:00
|
|
|
return cmd_name_rev(args.argc, args.argv, prefix);
|
2007-05-21 15:20:25 +08:00
|
|
|
}
|
|
|
|
|
2017-07-01 03:14:05 +08:00
|
|
|
hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, NULL, 0);
|
2015-05-26 02:38:34 +08:00
|
|
|
for_each_rawref(get_name, NULL);
|
2013-11-15 03:18:35 +08:00
|
|
|
if (!names.size && !always)
|
2011-02-23 07:42:23 +08:00
|
|
|
die(_("No names found, cannot describe anything."));
|
2009-10-18 00:30:48 +08:00
|
|
|
|
2007-10-08 02:54:08 +08:00
|
|
|
if (argc == 0) {
|
2017-03-22 06:57:18 +08:00
|
|
|
if (broken) {
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
argv_array_pushv(&cp.args, diff_index_args);
|
|
|
|
cp.git_cmd = 1;
|
|
|
|
cp.no_stdin = 1;
|
|
|
|
cp.no_stdout = 1;
|
|
|
|
|
|
|
|
if (!dirty)
|
|
|
|
dirty = "-dirty";
|
|
|
|
|
|
|
|
switch (run_command(&cp)) {
|
|
|
|
case 0:
|
|
|
|
suffix = NULL;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
suffix = dirty;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* diff-index aborted abnormally */
|
|
|
|
suffix = broken;
|
|
|
|
}
|
|
|
|
} else if (dirty) {
|
2011-08-01 09:52:41 +08:00
|
|
|
static struct lock_file index_lock;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
read_cache_preload(NULL);
|
|
|
|
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
fd = hold_locked_index(&index_lock, 0);
|
|
|
|
if (0 <= fd)
|
|
|
|
update_index_if_able(&the_index, &index_lock);
|
|
|
|
|
|
|
|
if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1,
|
|
|
|
diff_index_args, prefix))
|
2017-03-22 06:57:18 +08:00
|
|
|
suffix = NULL;
|
|
|
|
else
|
|
|
|
suffix = dirty;
|
2011-08-01 09:52:41 +08:00
|
|
|
}
|
2006-01-16 14:25:35 +08:00
|
|
|
describe("HEAD", 1);
|
2009-10-21 21:35:22 +08:00
|
|
|
} else if (dirty) {
|
2013-09-05 03:04:31 +08:00
|
|
|
die(_("--dirty is incompatible with commit-ishes"));
|
2017-03-22 06:57:18 +08:00
|
|
|
} else if (broken) {
|
|
|
|
die(_("--broken is incompatible with commit-ishes"));
|
2007-10-08 02:54:08 +08:00
|
|
|
} else {
|
2013-10-31 17:25:41 +08:00
|
|
|
while (argc-- > 0)
|
2007-10-08 02:54:08 +08:00
|
|
|
describe(*argv++, argc == 0);
|
|
|
|
}
|
Add a "git-describe" command
It shows you the most recent tag that is reachable from a particular
commit is.
Maybe this is something that "git-name-rev" should be taught to do,
instead of having a separate command for it. Regardless, I find it useful.
What it does is to take any random commit, and "name" it by looking up the
most recent commit that is tagged and reachable from that commit. If the
match is exact, it will just print out that ref-name directly. Otherwise
it will print out the ref-name, followed by the 8-character "short SHA".
IOW, with something like Junios current tree, I get:
[torvalds@g5 git]$ git-describe parent
refs/tags/v1.0.4-g2414721b
ie the current head of my "parent" branch (ie Junio) is based on v1.0.4,
but since it has a few commits on top of that, it has added the git hash
of the thing to the end: "-g" + 8-char shorthand for the commit
2414721b194453f058079d897d13c4e377f92dc6.
Doing a "git-describe" on a tag-name will just show the full tag path:
[torvalds@g5 git]$ git-describe v1.0.4
refs/tags/v1.0.4
unless there are _other_ tags pointing to that commit, in which case it
will just choose one at random.
This is useful for two things:
- automatic version naming in Makefiles, for example. We could use it in
git itself: when doing "git --version", we could use this to give a
much more useful description of exactly what version was installed.
- for any random commit (say, you use "gitk <pathname>" or
"git-whatchanged" to look at what has changed in some file), you can
figure out what the last version of the repo was. Ie, say I find a bug
in commit 39ca371c45b04cd50d0974030ae051906fc516b6, I just do:
[torvalds@g5 linux]$ git-describe 39ca371c45b04cd50d0974030ae051906fc516b6
refs/tags/v2.6.14-rc4-g39ca371c
and I now know that it was _not_ in v2.6.14-rc4, but was presumably in
v2.6.14-rc5.
The latter is useful when you want to see what "version timeframe" a
commit happened in.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-25 05:50:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|