[PATCH] name-rev: tolerate clock skew in committer dates

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] name-rev: tolerate clock skew in committer dates

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:12

In git.git repository, "git-name-rev v1.3.0~158" cannot name the
rev, while adjacent revs can be named.

This was because it gives up traversal from the tips of existing
refs as soon as it sees a commit that has older commit timestamp
than what is being named.  This is usually a good heuristics,
but v1.3.0~158 has a slightly older commit timestamp than
v1.3.0~157 (i.e. it's child), as these two were made in a
separate repostiory (in fact, in a different continent).

This adds a hardcoded slop value (1 day) to the cut-off
heuristics to work this kind of problem around.  The current
algorithm essentially runs around from the available tips down
to ancient commits and names every single rev available that are
newer than cut-off date, so a single day slop would not add that
much overhead in repositories with long enough history where the
performance of name-rev matters.

I think the algorithm could be made a bit smarter by deepening
the graph on demand as a new commit is asked to be named (this
would require rewriting of name_rev() function not to recurse
itself but use a traversal list like revision.c traverser does),
but that would be a separate issue.

Signed-off-by: Junio C Hamano <redacted>
---
 builtin-name-rev.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index a639e2f..d3c42ed 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -4,6 +4,8 @@
 #include "tag.h"
 #include "refs.h"
 
+#define CUTOFF_DATE_SLOP 86400 /* one day */
+
 static const char name_rev_usage[] =
 	"git-name-rev [--tags | --refs=<pattern>] ( --all | --stdin | committish [committish...] )\n";
 
@@ -216,6 +218,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
 		add_object_array((struct object *)commit, *argv, &revs);
 	}
 
+	if (cutoff)
+		cutoff = cutoff - CUTOFF_DATE_SLOP;
 	for_each_ref(name_ref, &data);
 
 	if (transform_stdin) {
-- 
1.5.2.58.g98ee

Re: [PATCH] name-rev: tolerate clock skew in committer dates

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:43:12

Hi,

On Thu, 24 May 2007, Junio C Hamano wrote:
This adds a hardcoded slop value (1 day) to the cut-off
heuristics to work this kind of problem around.
Sounds sensible. (ACK.)
I think the algorithm could be made a bit smarter by deepening the graph 
on demand as a new commit is asked to be named (this would require 
rewriting of name_rev() function not to recurse itself but use a 
traversal list like revision.c traverser does), but that would be a 
separate issue.
I also wanted to make the decorator (optionally) smarter, to actually do 
something like name_rev on demand, which would be much faster than (and 
coloured, in contrast to) `git log | git -p name-rev --stdin`.

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help