* [PATCH] git-describe: allow reflogs as reference points
@ 2006-09-30 22:29 Jeff King
2006-10-01 0:20 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Jeff King @ 2006-09-30 22:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Signed-off-by: Jeff King <peff@peff.net>
---
It's basically impossible to use this in the git repository, since we
prefer tags to reflogs. Should --reflog turn off tag matching? Should
there be a command line option to turn off tags?
Documentation/git-describe.txt | 9 ++++++-
describe.c | 51 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index 2700f35..975da0f 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -8,7 +8,7 @@ git-describe - Show the most recent tag
SYNOPSIS
--------
-'git-describe' [--all] [--tags] [--abbrev=<n>] <committish>...
+'git-describe' [--all] [--tags] [--reflog] [--abbrev=<n>] <committish>...
DESCRIPTION
-----------
@@ -31,6 +31,13 @@ OPTIONS
Instead of using only the annotated tags, use any tag
found in `.git/refs/tags`.
+--reflog=<fmt>::
+ Instead of using only the annotated tags, use reference dates
+ marked in branch reflogs. The output will be of the form
+ 'branch@{date}' where the format of date is specified by <fmt>, which
+ must be one of 'relative', '822', 'git'. If no format is specified,
+ the default is 'relative'.
+
--abbrev=<n>::
Instead of using the default 8 hexadecimal digits as the
abbreviated object name, use <n> digits.
diff --git a/describe.c b/describe.c
index f4029ee..1dc5209 100644
--- a/describe.c
+++ b/describe.c
@@ -6,11 +6,16 @@ #include "refs.h"
#define SEEN (1u << 0)
static const char describe_usage[] =
-"git-describe [--all] [--tags] [--abbrev=<n>] <committish>*";
+"git-describe [--all] [--tags] [--reflog] [--abbrev=<n>] <committish>*";
static int all; /* Default to annotated tags only */
static int tags; /* But allow any tags if --tags is specified */
+#define FMT_DATE_822 1
+#define FMT_DATE_GIT 2
+#define FMT_DATE_REL 3
+static int reflog;
+
static int abbrev = DEFAULT_ABBREV;
static int names, allocs;
@@ -85,6 +90,35 @@ static int get_name(const char *path, co
return 0;
}
+static int get_reflog_name(const char *ref, const unsigned char *head_sha1,
+ int flag, void *cb_data)
+{
+ unsigned char sha1[20];
+ char buf[1024];
+ struct reflog log;
+ struct reflog_entry c;
+
+ snprintf(buf, sizeof(buf), "refs/heads/%s", ref);
+ if (reflog_open(&log, buf) < 0) {
+ if (errno == ENOENT)
+ return 0;
+ die("unable to read log %s: %s\n", log.file, strerror(errno));
+ }
+ reflog_start(&log);
+ while (reflog_next(&log, &c)) {
+ snprintf(buf, sizeof(buf), "%s@{%s}",
+ ref,
+ reflog == FMT_DATE_REL ? show_date(c.date, 0, 1) :
+ reflog == FMT_DATE_GIT ? show_date(c.date, c.tz, 0) :
+ show_rfc2822_date(c.date, c.tz));
+ reflog_entry_to(&c, sha1);
+ add_to_known_names(buf, lookup_commit_reference(sha1), 0);
+ }
+ reflog_close(&log);
+ return 0;
+}
+
+
static int compare_names(const void *_a, const void *_b)
{
struct commit_name *a = *(struct commit_name **)_a;
@@ -114,6 +148,8 @@ static void describe(const char *arg, in
if (!initialized) {
initialized = 1;
for_each_ref(get_name, NULL);
+ if (reflog)
+ for_each_branch_ref(get_reflog_name, NULL);
qsort(name_array, names, sizeof(*name_array), compare_names);
}
@@ -152,6 +188,19 @@ int main(int argc, char **argv)
all = 1;
else if (!strcmp(arg, "--tags"))
tags = 1;
+ else if (!strncmp(arg, "--reflog=", 9)) {
+ if (!strcmp(arg+9, "2822") || !strcmp(arg+9, "822"))
+ reflog = FMT_DATE_822;
+ else if (!strcmp(arg+9, "git"))
+ reflog = FMT_DATE_GIT;
+ else if (!strcmp(arg+9, "relative"))
+ reflog = FMT_DATE_REL;
+ else
+ usage(describe_usage);
+ }
+ else if (!strcmp(arg, "--reflog")) {
+ reflog = FMT_DATE_REL;
+ }
else if (!strncmp(arg, "--abbrev=", 9)) {
abbrev = strtoul(arg + 9, NULL, 10);
if (abbrev < MINIMUM_ABBREV || 40 < abbrev)
--
1.4.2.1.gd4f1-dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] git-describe: allow reflogs as reference points
2006-09-30 22:29 [PATCH] git-describe: allow reflogs as reference points Jeff King
@ 2006-10-01 0:20 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2006-10-01 0:20 UTC (permalink / raw)
To: Jeff King; +Cc: git
Jeff King <peff@peff.net> writes:
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> It's basically impossible to use this in the git repository, since we
> prefer tags to reflogs. Should --reflog turn off tag matching? Should
> there be a command line option to turn off tags?
(Also please see my other message to Linus).
I think the behaviour we want out of the command when using
ref-log and when describing based on well-known points (aka
tags) are mutually incompatible, so I agree --reflog should turn
off tag matching. Also you need to be prepared to handle a
ref-log that happens to have a rewound history. See attached
patch.
I do not however think the patch is useful to get the
information the discussion which lead to this patch wanted to
know, as I described in a separate message today. For example,
asking:
$ git describe --reflog ce74618
answers "next@{3 months ago}-gce74618", in my repository, which
is quite bogus. "next@{3 months ago}" is 47e5c0; it indeed is
an ancestor of ce74618 and it probably was once at the tip of
"next", so you are not giving any incorrect information, but
that one certainly did _not_ contain the change ce74618
introduced, so that form of output is not useful for answering
the question "when did this commit hit this branch".
$ gitk master..next
shows that the commit ce74618 is a direct descendant of the
current "master" (4839bd8), and was merged into "next" for the
first time with 5a98f4e which was done last night.
Another example. Recently somebody on the kernel list was
bitten by an ancient bug in diff.c::emit_rewrite_diff(). The
bug was there in the very first version of this feature (June
19, 2005) and nobody touched the vicinity of the code. I fixed
it on top of recent master.
However, somebody else could have fixed it on top of v0.99 and
then I could have merged the fix from his branch that is based
on v0.99 (the bug is that ancient). I do not enable the reflog
on my "master", but if I did, it would have looked like:
from v0.99^ to v0.99 on July 10th 15:40 2005
from v0.99 to 013aab on July 10th 23:55 2005
...
from 18b633 to 4839bd on Sept 29th 18:54 2006
IOW, my reflog would have recorded v0.99 was once at the tip of
the "master" branch. Using it, describing
git describe --reflog $that_fixes_on_v0_99
would say v0.99 is the closest ancestor of the fix, which is
technically correct. And if I merge that on top of my "master"
creating a new merge commit, that merge commit is the first
commit my "master" branch sees the fix. So when I make the
merge, the reflog would have a new entry at the end:
from 4839bd to xxxxxx on Sept 30th 17:10 2006 merge the fix
and what would be useful is to find this record and notice the
commit is the first one in the "master"'s history that has the
fix as its ancestor.
diff --git a/describe.c b/describe.c
index 1dc5209..cc38651 100644
--- a/describe.c
+++ b/describe.c
@@ -106,13 +106,18 @@ static int get_reflog_name(const char *r
}
reflog_start(&log);
while (reflog_next(&log, &c)) {
+ struct commit *commit;
snprintf(buf, sizeof(buf), "%s@{%s}",
ref,
reflog == FMT_DATE_REL ? show_date(c.date, 0, 1) :
reflog == FMT_DATE_GIT ? show_date(c.date, c.tz, 0) :
show_rfc2822_date(c.date, c.tz));
reflog_entry_to(&c, sha1);
- add_to_known_names(buf, lookup_commit_reference(sha1), 0);
+ commit = lookup_commit_reference(sha1);
+ if (!commit)
+ /* rewound head */
+ continue;
+ add_to_known_names(buf, commit, 0);
}
reflog_close(&log);
return 0;
@@ -147,9 +151,10 @@ static void describe(const char *arg, in
if (!initialized) {
initialized = 1;
- for_each_ref(get_name, NULL);
if (reflog)
for_each_branch_ref(get_reflog_name, NULL);
+ else
+ for_each_ref(get_name, NULL);
qsort(name_array, names, sizeof(*name_array), compare_names);
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-10-01 0:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-30 22:29 [PATCH] git-describe: allow reflogs as reference points Jeff King
2006-10-01 0:20 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox