2006-08-03 15:24:35 +00:00
|
|
|
#include "builtin.h"
|
2005-10-26 13:10:20 +00:00
|
|
|
#include "cache.h"
|
2017-06-14 18:07:36 +00:00
|
|
|
#include "config.h"
|
2005-10-26 13:10:20 +00:00
|
|
|
#include "commit.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "refs.h"
|
2007-10-15 20:57:59 +00:00
|
|
|
#include "parse-options.h"
|
2013-07-07 21:14:22 +00:00
|
|
|
#include "sha1-lookup.h"
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2007-05-24 19:20:42 +00:00
|
|
|
#define CUTOFF_DATE_SLOP 86400 /* one day */
|
|
|
|
|
2005-10-26 13:10:20 +00:00
|
|
|
typedef struct rev_name {
|
|
|
|
const char *tip_name;
|
2017-04-26 19:29:31 +00:00
|
|
|
timestamp_t taggerdate;
|
2005-10-26 13:10:20 +00:00
|
|
|
int generation;
|
2007-08-27 11:37:33 +00:00
|
|
|
int distance;
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
int from_tag;
|
2005-10-26 13:10:20 +00:00
|
|
|
} rev_name;
|
|
|
|
|
2017-05-20 05:39:43 +00:00
|
|
|
static timestamp_t cutoff = TIME_MAX;
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2007-08-27 11:37:33 +00:00
|
|
|
/* How many generations are maximally preferred over _one_ merge traversal? */
|
|
|
|
#define MERGE_TRAVERSAL_WEIGHT 65535
|
|
|
|
|
2017-03-29 14:39:15 +00:00
|
|
|
static int is_better_name(struct rev_name *name,
|
|
|
|
const char *tip_name,
|
2017-05-30 02:16:39 +00:00
|
|
|
timestamp_t taggerdate,
|
2017-03-29 14:39:15 +00:00
|
|
|
int generation,
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
int distance,
|
|
|
|
int from_tag)
|
2017-03-29 14:39:15 +00:00
|
|
|
{
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
/*
|
|
|
|
* When comparing names based on tags, prefer names
|
|
|
|
* based on the older tag, even if it is farther away.
|
|
|
|
*/
|
|
|
|
if (from_tag && name->from_tag)
|
|
|
|
return (name->taggerdate > taggerdate ||
|
|
|
|
(name->taggerdate == taggerdate &&
|
|
|
|
name->distance > distance));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We know that at least one of them is a non-tag at this point.
|
|
|
|
* favor a tag over a non-tag.
|
|
|
|
*/
|
|
|
|
if (name->from_tag != from_tag)
|
|
|
|
return from_tag;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are now looking at two non-tags. Tiebreak to favor
|
|
|
|
* shorter hops.
|
|
|
|
*/
|
|
|
|
if (name->distance != distance)
|
|
|
|
return name->distance > distance;
|
|
|
|
|
|
|
|
/* ... or tiebreak to favor older date */
|
|
|
|
if (name->taggerdate != taggerdate)
|
|
|
|
return name->taggerdate > taggerdate;
|
|
|
|
|
|
|
|
/* keep the current one if we cannot decide */
|
|
|
|
return 0;
|
2017-03-29 14:39:15 +00:00
|
|
|
}
|
|
|
|
|
2005-10-26 13:10:20 +00:00
|
|
|
static void name_rev(struct commit *commit,
|
2017-04-26 19:29:31 +00:00
|
|
|
const char *tip_name, timestamp_t taggerdate,
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
int generation, int distance, int from_tag,
|
2005-10-26 13:10:20 +00:00
|
|
|
int deref)
|
|
|
|
{
|
2006-06-18 01:26:18 +00:00
|
|
|
struct rev_name *name = (struct rev_name *)commit->util;
|
2005-10-26 13:10:20 +00:00
|
|
|
struct commit_list *parents;
|
2005-11-29 04:51:44 +00:00
|
|
|
int parent_number = 1;
|
2017-05-04 13:59:06 +00:00
|
|
|
char *to_free = NULL;
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2013-10-24 08:53:01 +00:00
|
|
|
parse_commit(commit);
|
2005-10-26 13:10:20 +00:00
|
|
|
|
|
|
|
if (commit->date < cutoff)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (deref) {
|
2017-05-04 13:59:06 +00:00
|
|
|
tip_name = to_free = xstrfmt("%s^0", tip_name);
|
2005-10-26 13:10:20 +00:00
|
|
|
|
|
|
|
if (generation)
|
|
|
|
die("generation: %d, but deref?", generation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == NULL) {
|
|
|
|
name = xmalloc(sizeof(rev_name));
|
2006-06-18 01:26:18 +00:00
|
|
|
commit->util = name;
|
2005-10-26 13:10:20 +00:00
|
|
|
goto copy_data;
|
2017-03-29 14:39:15 +00:00
|
|
|
} else if (is_better_name(name, tip_name, taggerdate,
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
generation, distance, from_tag)) {
|
2005-10-26 13:10:20 +00:00
|
|
|
copy_data:
|
|
|
|
name->tip_name = tip_name;
|
2016-04-22 13:39:01 +00:00
|
|
|
name->taggerdate = taggerdate;
|
2005-10-26 13:10:20 +00:00
|
|
|
name->generation = generation;
|
2007-08-27 11:37:33 +00:00
|
|
|
name->distance = distance;
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
name->from_tag = from_tag;
|
2017-05-04 13:59:06 +00:00
|
|
|
} else {
|
|
|
|
free(to_free);
|
2005-10-26 13:10:20 +00:00
|
|
|
return;
|
2017-05-04 13:59:06 +00:00
|
|
|
}
|
2005-10-26 13:10:20 +00:00
|
|
|
|
|
|
|
for (parents = commit->parents;
|
|
|
|
parents;
|
|
|
|
parents = parents->next, parent_number++) {
|
2005-11-29 04:51:44 +00:00
|
|
|
if (parent_number > 1) {
|
2015-09-24 21:08:37 +00:00
|
|
|
size_t len;
|
2015-09-24 21:07:03 +00:00
|
|
|
char *new_name;
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2015-09-24 21:08:37 +00:00
|
|
|
strip_suffix(tip_name, "^0", &len);
|
2005-10-26 13:10:20 +00:00
|
|
|
if (generation > 0)
|
2015-09-24 21:08:37 +00:00
|
|
|
new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
|
2015-09-24 21:07:03 +00:00
|
|
|
generation, parent_number);
|
2005-10-26 13:10:20 +00:00
|
|
|
else
|
2015-09-24 21:08:37 +00:00
|
|
|
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
|
2015-09-24 21:07:03 +00:00
|
|
|
parent_number);
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2016-04-22 13:39:01 +00:00
|
|
|
name_rev(parents->item, new_name, taggerdate, 0,
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
distance + MERGE_TRAVERSAL_WEIGHT,
|
|
|
|
from_tag, 0);
|
2005-10-26 13:10:20 +00:00
|
|
|
} else {
|
2016-04-22 13:39:01 +00:00
|
|
|
name_rev(parents->item, tip_name, taggerdate,
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
generation + 1, distance + 1,
|
|
|
|
from_tag, 0);
|
2005-10-26 13:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 12:35:31 +00:00
|
|
|
static int subpath_matches(const char *path, const char *filter)
|
|
|
|
{
|
|
|
|
const char *subpath = path;
|
|
|
|
|
|
|
|
while (subpath) {
|
2014-02-15 02:01:46 +00:00
|
|
|
if (!wildmatch(filter, subpath, 0, NULL))
|
2013-06-18 12:35:31 +00:00
|
|
|
return subpath - path;
|
|
|
|
subpath = strchr(subpath, '/');
|
|
|
|
if (subpath)
|
|
|
|
subpath++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-07 21:13:41 +00:00
|
|
|
static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
|
|
|
|
{
|
|
|
|
if (shorten_unambiguous)
|
|
|
|
refname = shorten_unambiguous_ref(refname, 0);
|
2013-11-30 20:55:40 +00:00
|
|
|
else if (starts_with(refname, "refs/heads/"))
|
2013-07-07 21:13:41 +00:00
|
|
|
refname = refname + 11;
|
2013-11-30 20:55:40 +00:00
|
|
|
else if (starts_with(refname, "refs/"))
|
2013-07-07 21:13:41 +00:00
|
|
|
refname = refname + 5;
|
|
|
|
return refname;
|
|
|
|
}
|
|
|
|
|
2007-02-17 18:22:35 +00:00
|
|
|
struct name_ref_data {
|
|
|
|
int tags_only;
|
2007-05-21 07:20:25 +00:00
|
|
|
int name_only;
|
2017-01-18 23:06:05 +00:00
|
|
|
struct string_list ref_filters;
|
2017-01-18 23:06:06 +00:00
|
|
|
struct string_list exclude_filters;
|
2007-02-17 18:22:35 +00:00
|
|
|
};
|
|
|
|
|
2013-07-07 21:14:22 +00:00
|
|
|
static struct tip_table {
|
|
|
|
struct tip_table_entry {
|
2017-05-01 02:28:57 +00:00
|
|
|
struct object_id oid;
|
2013-07-07 21:14:22 +00:00
|
|
|
const char *refname;
|
|
|
|
} *table;
|
|
|
|
int nr;
|
|
|
|
int alloc;
|
|
|
|
int sorted;
|
|
|
|
} tip_table;
|
|
|
|
|
2017-05-01 02:28:57 +00:00
|
|
|
static void add_to_tip_table(const struct object_id *oid, const char *refname,
|
2013-07-07 21:14:22 +00:00
|
|
|
int shorten_unambiguous)
|
|
|
|
{
|
|
|
|
refname = name_ref_abbrev(refname, shorten_unambiguous);
|
|
|
|
|
|
|
|
ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc);
|
2017-05-01 02:28:57 +00:00
|
|
|
oidcpy(&tip_table.table[tip_table.nr].oid, oid);
|
2013-07-07 21:14:22 +00:00
|
|
|
tip_table.table[tip_table.nr].refname = xstrdup(refname);
|
|
|
|
tip_table.nr++;
|
|
|
|
tip_table.sorted = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tipcmp(const void *a_, const void *b_)
|
|
|
|
{
|
|
|
|
const struct tip_table_entry *a = a_, *b = b_;
|
2017-05-01 02:28:57 +00:00
|
|
|
return oidcmp(&a->oid, &b->oid);
|
2013-07-07 21:14:22 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 18:38:37 +00:00
|
|
|
static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
|
2005-10-26 13:10:20 +00:00
|
|
|
{
|
object: convert parse_object* to take struct object_id
Make parse_object, parse_object_or_die, and parse_object_buffer take a
pointer to struct object_id. Remove the temporary variables inserted
earlier, since they are no longer necessary. Transform all of the
callers using the following semantic patch:
@@
expression E1;
@@
- parse_object(E1.hash)
+ parse_object(&E1)
@@
expression E1;
@@
- parse_object(E1->hash)
+ parse_object(E1)
@@
expression E1, E2;
@@
- parse_object_or_die(E1.hash, E2)
+ parse_object_or_die(&E1, E2)
@@
expression E1, E2;
@@
- parse_object_or_die(E1->hash, E2)
+ parse_object_or_die(E1, E2)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1.hash, E2, E3, E4, E5)
+ parse_object_buffer(&E1, E2, E3, E4, E5)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1->hash, E2, E3, E4, E5)
+ parse_object_buffer(E1, E2, E3, E4, E5)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-06 22:10:38 +00:00
|
|
|
struct object *o = parse_object(oid);
|
2007-02-17 18:22:35 +00:00
|
|
|
struct name_ref_data *data = cb_data;
|
2013-06-18 12:35:31 +00:00
|
|
|
int can_abbreviate_output = data->tags_only && data->name_only;
|
2005-10-26 13:10:20 +00:00
|
|
|
int deref = 0;
|
2017-04-26 19:29:31 +00:00
|
|
|
timestamp_t taggerdate = TIME_MAX;
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2013-11-30 20:55:40 +00:00
|
|
|
if (data->tags_only && !starts_with(path, "refs/tags/"))
|
2007-02-17 18:22:35 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-01-18 23:06:06 +00:00
|
|
|
if (data->exclude_filters.nr) {
|
|
|
|
struct string_list_item *item;
|
|
|
|
|
|
|
|
for_each_string_list_item(item, &data->exclude_filters) {
|
|
|
|
if (subpath_matches(path, item->string) >= 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 23:06:05 +00:00
|
|
|
if (data->ref_filters.nr) {
|
|
|
|
struct string_list_item *item;
|
|
|
|
int matched = 0;
|
|
|
|
|
|
|
|
/* See if any of the patterns match. */
|
|
|
|
for_each_string_list_item(item, &data->ref_filters) {
|
|
|
|
/*
|
|
|
|
* Check all patterns even after finding a match, so
|
|
|
|
* that we can see if a match with a subpath exists.
|
|
|
|
* When a user asked for 'refs/tags/v*' and 'v1.*',
|
|
|
|
* both of which match, the user is showing her
|
|
|
|
* willingness to accept a shortened output by having
|
|
|
|
* the 'v1.*' in the acceptable refnames, so we
|
|
|
|
* shouldn't stop when seeing 'refs/tags/v1.4' matches
|
|
|
|
* 'refs/tags/v*'. We should show it as 'v1.4'.
|
|
|
|
*/
|
|
|
|
switch (subpath_matches(path, item->string)) {
|
|
|
|
case -1: /* did not match */
|
|
|
|
break;
|
|
|
|
case 0: /* matched fully */
|
|
|
|
matched = 1;
|
|
|
|
break;
|
|
|
|
default: /* matched subpath */
|
|
|
|
matched = 1;
|
|
|
|
can_abbreviate_output = 1;
|
|
|
|
break;
|
|
|
|
}
|
2013-06-18 12:35:31 +00:00
|
|
|
}
|
2017-01-18 23:06:05 +00:00
|
|
|
|
|
|
|
/* If none of the patterns matched, stop now */
|
|
|
|
if (!matched)
|
|
|
|
return 0;
|
2013-06-18 12:35:31 +00:00
|
|
|
}
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2017-05-01 02:28:57 +00:00
|
|
|
add_to_tip_table(oid, path, can_abbreviate_output);
|
2013-07-07 21:14:22 +00:00
|
|
|
|
2006-07-12 03:45:31 +00:00
|
|
|
while (o && o->type == OBJ_TAG) {
|
2005-10-26 13:10:20 +00:00
|
|
|
struct tag *t = (struct tag *) o;
|
|
|
|
if (!t->tagged)
|
|
|
|
break; /* broken repository */
|
object: convert parse_object* to take struct object_id
Make parse_object, parse_object_or_die, and parse_object_buffer take a
pointer to struct object_id. Remove the temporary variables inserted
earlier, since they are no longer necessary. Transform all of the
callers using the following semantic patch:
@@
expression E1;
@@
- parse_object(E1.hash)
+ parse_object(&E1)
@@
expression E1;
@@
- parse_object(E1->hash)
+ parse_object(E1)
@@
expression E1, E2;
@@
- parse_object_or_die(E1.hash, E2)
+ parse_object_or_die(&E1, E2)
@@
expression E1, E2;
@@
- parse_object_or_die(E1->hash, E2)
+ parse_object_or_die(E1, E2)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1.hash, E2, E3, E4, E5)
+ parse_object_buffer(&E1, E2, E3, E4, E5)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1->hash, E2, E3, E4, E5)
+ parse_object_buffer(E1, E2, E3, E4, E5)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-06 22:10:38 +00:00
|
|
|
o = parse_object(&t->tagged->oid);
|
2005-10-26 13:10:20 +00:00
|
|
|
deref = 1;
|
2016-04-22 13:39:01 +00:00
|
|
|
taggerdate = t->date;
|
2005-10-26 13:10:20 +00:00
|
|
|
}
|
2006-07-12 03:45:31 +00:00
|
|
|
if (o && o->type == OBJ_COMMIT) {
|
2005-10-26 13:10:20 +00:00
|
|
|
struct commit *commit = (struct commit *)o;
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
int from_tag = starts_with(path, "refs/tags/");
|
2005-10-26 13:10:20 +00:00
|
|
|
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
if (taggerdate == ULONG_MAX)
|
|
|
|
taggerdate = ((struct commit *)o)->date;
|
2013-07-07 21:13:41 +00:00
|
|
|
path = name_ref_abbrev(path, can_abbreviate_output);
|
name-rev: favor describing with tags and use committer date to tiebreak
"git name-rev" assigned a phony "far in the future" date to tips of
refs that are not pointing at tag objects, and favored names based
on a ref with the oldest date. This made it almost impossible for
an unannotated tags and branches to be counted as a viable base,
which was especially problematic when the command is run with the
"--tags" option. If an unannotated tag that points at an ancient
commit and an annotated tag that points at a much newer commit
reaches the commit that is being named, the old unannotated tag was
ignored.
Update the "taggerdate" field of the rev-name structure, which is
initialized from the tip of ref, to have the committer date if the
object at the tip of ref is a commit, not a tag, so that we can
optionally take it into account when doing "is this name better?"
comparison logic.
When "name-rev" is run without the "--tags" option, the general
expectation is still to name the commit based on a tag if possible,
but use non-tag refs as fallback, and tiebreak among these non-tag
refs by favoring names with shorter hops from the tip. The use of a
phony "far in the future" date in the original code was an effective
way to ensure this expectation is held: a non-tag tip gets the same
"far in the future" timestamp, giving precedence to tags, and among
non-tag tips, names with shorter hops are preferred over longer
hops, without taking the "taggerdate" into account. As we are
taking over the "taggerdate" field to store the committer date for
tips with commits:
(1) keep the original logic when comparing names based on two refs
both of which are from refs/tags/;
(2) favoring a name based on a ref in refs/tags/ hierarchy over
a ref outside the hierarchy;
(3) between two names based on a ref both outside refs/tags/, give
precedence to a name with shorter hops and use "taggerdate"
only to tie-break.
A change to t4202 is a natural consequence. The test creates a
commit on a branch "side" and points at it with an unannotated tag
"refs/tags/side-2". The original code couldn't decide which one to
favor at all, and gave a name based on a branch (simply because
refs/heads/side sorts earlier than refs/tags/side-2). Because the
updated logic is taught to favor refs in refs/tags/ hierarchy, the
the test is updated to expect to see tags/side-2 instead.
[mjg: open-coded the comparisons in is_better_name(), dropping a
helper macro used in the original]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-29 14:39:16 +00:00
|
|
|
name_rev(commit, xstrdup(path), taggerdate, 0, 0,
|
|
|
|
from_tag, deref);
|
2005-10-26 13:10:20 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-07 21:14:22 +00:00
|
|
|
static const unsigned char *nth_tip_table_ent(size_t ix, void *table_)
|
|
|
|
{
|
|
|
|
struct tip_table_entry *table = table_;
|
2017-05-01 02:28:57 +00:00
|
|
|
return table[ix].oid.hash;
|
2013-07-07 21:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *get_exact_ref_match(const struct object *o)
|
|
|
|
{
|
|
|
|
int found;
|
|
|
|
|
|
|
|
if (!tip_table.table || !tip_table.nr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!tip_table.sorted) {
|
2016-09-29 15:27:31 +00:00
|
|
|
QSORT(tip_table.table, tip_table.nr, tipcmp);
|
2013-07-07 21:14:22 +00:00
|
|
|
tip_table.sorted = 1;
|
|
|
|
}
|
|
|
|
|
2015-11-10 02:22:29 +00:00
|
|
|
found = sha1_pos(o->oid.hash, tip_table.table, tip_table.nr,
|
2013-07-07 21:14:22 +00:00
|
|
|
nth_tip_table_ent);
|
|
|
|
if (0 <= found)
|
|
|
|
return tip_table.table[found].refname;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-28 19:46:44 +00:00
|
|
|
/* may return a constant string or use "buf" as scratch space */
|
|
|
|
static const char *get_rev_name(const struct object *o, struct strbuf *buf)
|
2005-10-26 13:10:20 +00:00
|
|
|
{
|
2006-06-18 01:26:18 +00:00
|
|
|
struct rev_name *n;
|
|
|
|
struct commit *c;
|
|
|
|
|
2006-07-12 03:45:31 +00:00
|
|
|
if (o->type != OBJ_COMMIT)
|
2013-07-07 21:14:22 +00:00
|
|
|
return get_exact_ref_match(o);
|
2006-06-18 01:26:18 +00:00
|
|
|
c = (struct commit *) o;
|
|
|
|
n = c->util;
|
2005-10-26 13:10:20 +00:00
|
|
|
if (!n)
|
2007-12-24 11:18:22 +00:00
|
|
|
return NULL;
|
2005-10-26 13:10:20 +00:00
|
|
|
|
|
|
|
if (!n->generation)
|
|
|
|
return n->tip_name;
|
2007-02-20 00:08:48 +00:00
|
|
|
else {
|
|
|
|
int len = strlen(n->tip_name);
|
|
|
|
if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
|
|
|
|
len -= 2;
|
2017-03-28 19:46:44 +00:00
|
|
|
strbuf_reset(buf);
|
|
|
|
strbuf_addf(buf, "%.*s~%d", len, n->tip_name, n->generation);
|
|
|
|
return buf->buf;
|
2007-02-20 00:08:48 +00:00
|
|
|
}
|
2005-10-26 13:10:20 +00:00
|
|
|
}
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 00:42:35 +00:00
|
|
|
|
2008-03-02 16:51:57 +00:00
|
|
|
static void show_name(const struct object *obj,
|
|
|
|
const char *caller_name,
|
|
|
|
int always, int allow_undefined, int name_only)
|
|
|
|
{
|
|
|
|
const char *name;
|
2015-11-10 02:22:28 +00:00
|
|
|
const struct object_id *oid = &obj->oid;
|
2017-03-28 19:46:44 +00:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2008-03-02 16:51:57 +00:00
|
|
|
|
|
|
|
if (!name_only)
|
2015-11-10 02:22:28 +00:00
|
|
|
printf("%s ", caller_name ? caller_name : oid_to_hex(oid));
|
2017-03-28 19:46:44 +00:00
|
|
|
name = get_rev_name(obj, &buf);
|
2008-03-02 16:51:57 +00:00
|
|
|
if (name)
|
|
|
|
printf("%s\n", name);
|
|
|
|
else if (allow_undefined)
|
|
|
|
printf("undefined\n");
|
|
|
|
else if (always)
|
2015-11-10 02:22:28 +00:00
|
|
|
printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
|
2008-03-02 16:51:57 +00:00
|
|
|
else
|
2015-11-10 02:22:28 +00:00
|
|
|
die("cannot describe '%s'", oid_to_hex(oid));
|
2017-03-28 19:46:44 +00:00
|
|
|
strbuf_release(&buf);
|
2008-03-02 16:51:57 +00:00
|
|
|
}
|
|
|
|
|
2007-10-15 20:57:59 +00:00
|
|
|
static char const * const name_rev_usage[] = {
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git name-rev [<options>] <commit>..."),
|
|
|
|
N_("git name-rev [<options>] --all"),
|
|
|
|
N_("git name-rev [<options>] --stdin"),
|
2007-10-15 20:57:59 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2008-08-02 18:04:22 +00:00
|
|
|
static void name_rev_line(char *p, struct name_ref_data *data)
|
|
|
|
{
|
2017-03-28 19:46:44 +00:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2008-08-02 18:04:22 +00:00
|
|
|
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;
|
2017-05-01 02:28:57 +00:00
|
|
|
else if (++forty == GIT_SHA1_HEXSZ &&
|
2008-08-02 18:04:22 +00:00
|
|
|
!ishex(*(p+1))) {
|
2017-05-01 02:28:57 +00:00
|
|
|
struct object_id oid;
|
2008-08-02 18:04:22 +00:00
|
|
|
const char *name = NULL;
|
|
|
|
char c = *(p+1);
|
2008-08-03 13:44:33 +00:00
|
|
|
int p_len = p - p_start + 1;
|
2008-08-02 18:04:22 +00:00
|
|
|
|
|
|
|
forty = 0;
|
|
|
|
|
|
|
|
*(p+1) = 0;
|
2017-05-01 02:28:57 +00:00
|
|
|
if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
|
2008-08-02 18:04:22 +00:00
|
|
|
struct object *o =
|
2017-05-01 02:28:57 +00:00
|
|
|
lookup_object(oid.hash);
|
2008-08-02 18:04:22 +00:00
|
|
|
if (o)
|
2017-03-28 19:46:44 +00:00
|
|
|
name = get_rev_name(o, &buf);
|
2008-08-02 18:04:22 +00:00
|
|
|
}
|
|
|
|
*(p+1) = c;
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
continue;
|
|
|
|
|
2008-08-03 13:44:33 +00:00
|
|
|
if (data->name_only)
|
2017-05-01 02:28:57 +00:00
|
|
|
printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name);
|
2008-08-03 13:44:33 +00:00
|
|
|
else
|
|
|
|
printf("%.*s (%s)", p_len, p_start, name);
|
2008-08-02 18:04:22 +00:00
|
|
|
p_start = p + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* flush */
|
|
|
|
if (p_start != p)
|
|
|
|
fwrite(p_start, p - p_start, 1, stdout);
|
2017-03-28 19:46:44 +00:00
|
|
|
|
|
|
|
strbuf_release(&buf);
|
2008-08-02 18:04:22 +00:00
|
|
|
}
|
|
|
|
|
2006-08-03 15:24:35 +00:00
|
|
|
int cmd_name_rev(int argc, const char **argv, const char *prefix)
|
2005-10-26 13:10:20 +00:00
|
|
|
{
|
2010-08-29 02:04:17 +00:00
|
|
|
struct object_array revs = OBJECT_ARRAY_INIT;
|
2013-07-18 21:46:51 +00:00
|
|
|
int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
|
2017-01-18 23:06:06 +00:00
|
|
|
struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP };
|
2007-10-15 20:57:59 +00:00
|
|
|
struct option opts[] = {
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
|
|
|
|
OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
|
2017-01-18 23:06:05 +00:00
|
|
|
OPT_STRING_LIST(0, "refs", &data.ref_filters, N_("pattern"),
|
2012-08-20 12:32:27 +00:00
|
|
|
N_("only use refs matching <pattern>")),
|
2017-01-18 23:06:06 +00:00
|
|
|
OPT_STRING_LIST(0, "exclude", &data.exclude_filters, N_("pattern"),
|
|
|
|
N_("ignore refs matching <pattern>")),
|
2007-10-15 20:57:59 +00:00
|
|
|
OPT_GROUP(""),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "all", &all, N_("list all commits reachable from all refs")),
|
|
|
|
OPT_BOOL(0, "stdin", &transform_stdin, N_("read from stdin")),
|
|
|
|
OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
|
|
|
|
OPT_BOOL(0, "always", &always,
|
2012-08-20 12:32:27 +00:00
|
|
|
N_("show abbreviated commit object as fallback")),
|
2013-07-18 21:46:51 +00:00
|
|
|
{
|
|
|
|
/* A Hidden OPT_BOOL */
|
|
|
|
OPTION_SET_INT, 0, "peel-tag", &peel_tag, NULL,
|
|
|
|
N_("dereference tags in the input (internal use)"),
|
|
|
|
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1,
|
|
|
|
},
|
2007-10-15 20:57:59 +00:00
|
|
|
OPT_END(),
|
|
|
|
};
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2008-05-14 17:46:53 +00:00
|
|
|
git_config(git_default_config, NULL);
|
2009-05-23 18:53:12 +00:00
|
|
|
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
|
2013-08-07 07:32:25 +00:00
|
|
|
if (all + transform_stdin + !!argc > 1) {
|
2007-10-15 20:57:59 +00:00
|
|
|
error("Specify either a list, or --all, not both!");
|
|
|
|
usage_with_options(name_rev_usage, opts);
|
|
|
|
}
|
|
|
|
if (all || transform_stdin)
|
|
|
|
cutoff = 0;
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2007-10-15 20:57:59 +00:00
|
|
|
for (; argc; argc--, argv++) {
|
2017-05-01 02:28:57 +00:00
|
|
|
struct object_id oid;
|
2013-07-18 21:11:35 +00:00
|
|
|
struct object *object;
|
2005-10-26 13:10:20 +00:00
|
|
|
struct commit *commit;
|
|
|
|
|
2017-05-01 02:28:57 +00:00
|
|
|
if (get_oid(*argv, &oid)) {
|
2005-10-26 13:10:20 +00:00
|
|
|
fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
|
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-07-18 21:11:35 +00:00
|
|
|
commit = NULL;
|
object: convert parse_object* to take struct object_id
Make parse_object, parse_object_or_die, and parse_object_buffer take a
pointer to struct object_id. Remove the temporary variables inserted
earlier, since they are no longer necessary. Transform all of the
callers using the following semantic patch:
@@
expression E1;
@@
- parse_object(E1.hash)
+ parse_object(&E1)
@@
expression E1;
@@
- parse_object(E1->hash)
+ parse_object(E1)
@@
expression E1, E2;
@@
- parse_object_or_die(E1.hash, E2)
+ parse_object_or_die(&E1, E2)
@@
expression E1, E2;
@@
- parse_object_or_die(E1->hash, E2)
+ parse_object_or_die(E1, E2)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1.hash, E2, E3, E4, E5)
+ parse_object_buffer(&E1, E2, E3, E4, E5)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1->hash, E2, E3, E4, E5)
+ parse_object_buffer(E1, E2, E3, E4, E5)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-06 22:10:38 +00:00
|
|
|
object = parse_object(&oid);
|
2013-07-18 21:11:35 +00:00
|
|
|
if (object) {
|
|
|
|
struct object *peeled = deref_tag(object, *argv, 0);
|
|
|
|
if (peeled && peeled->type == OBJ_COMMIT)
|
|
|
|
commit = (struct commit *)peeled;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!object) {
|
|
|
|
fprintf(stderr, "Could not get object for %s. Skipping.\n",
|
2005-10-26 13:10:20 +00:00
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-07-18 21:11:35 +00:00
|
|
|
if (commit) {
|
|
|
|
if (cutoff > commit->date)
|
|
|
|
cutoff = commit->date;
|
|
|
|
}
|
2013-07-18 21:46:51 +00:00
|
|
|
|
|
|
|
if (peel_tag) {
|
|
|
|
if (!commit) {
|
|
|
|
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
|
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
object = (struct object *)commit;
|
|
|
|
}
|
2013-07-18 21:11:35 +00:00
|
|
|
add_object_array(object, *argv, &revs);
|
2005-10-26 13:10:20 +00:00
|
|
|
}
|
|
|
|
|
2007-05-24 19:20:42 +00:00
|
|
|
if (cutoff)
|
|
|
|
cutoff = cutoff - CUTOFF_DATE_SLOP;
|
2015-05-25 18:38:37 +00:00
|
|
|
for_each_ref(name_ref, &data);
|
2005-10-26 13:10:20 +00:00
|
|
|
|
|
|
|
if (transform_stdin) {
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
while (!feof(stdin)) {
|
2008-08-02 18:04:22 +00:00
|
|
|
char *p = fgets(buffer, sizeof(buffer), stdin);
|
2005-10-26 13:10:20 +00:00
|
|
|
if (!p)
|
|
|
|
break;
|
2008-08-02 18:04:22 +00:00
|
|
|
name_rev_line(p, &data);
|
2005-10-26 13:10:20 +00:00
|
|
|
}
|
|
|
|
} else if (all) {
|
2006-06-30 04:38:55 +00:00
|
|
|
int i, max;
|
2005-10-26 13:10:20 +00:00
|
|
|
|
2006-06-30 04:38:55 +00:00
|
|
|
max = get_max_object_index();
|
2008-06-05 23:31:55 +00:00
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
struct object *obj = get_indexed_object(i);
|
2011-11-15 23:51:05 +00:00
|
|
|
if (!obj || obj->type != OBJ_COMMIT)
|
2008-06-05 23:31:55 +00:00
|
|
|
continue;
|
|
|
|
show_name(obj, NULL,
|
2008-03-02 16:51:57 +00:00
|
|
|
always, allow_undefined, data.name_only);
|
2008-06-05 23:31:55 +00:00
|
|
|
}
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 00:42:35 +00:00
|
|
|
} else {
|
|
|
|
int i;
|
2008-03-02 16:51:57 +00:00
|
|
|
for (i = 0; i < revs.nr; i++)
|
|
|
|
show_name(revs.objects[i].item, revs.objects[i].name,
|
|
|
|
always, allow_undefined, data.name_only);
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 00:42:35 +00:00
|
|
|
}
|
2005-10-26 13:10:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|