From c075aea5da6c35edfe86da7d3edced67cdb009c8 Mon Sep 17 00:00:00 2001
From: Junio C Hamano <junkio@cox.net>
Date: Thu, 24 May 2007 12:20:42 -0700
Subject: [PATCH 1/2] name-rev: tolerate clock skew in committer dates

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.

Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 builtin-name-rev.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index ef16385907..2d94eaaa6a 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";
 
@@ -208,6 +210,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) {

From 0b1f113075aafb0c91a406d984d0152e55c981da Mon Sep 17 00:00:00 2001
From: Carlos Rica <jasampler@gmail.com>
Date: Fri, 25 May 2007 03:46:22 +0200
Subject: [PATCH 2/2] fix memory leak in parse_object when check_sha1_signature
 fails

When check_sha1_signature fails, program is not terminated:
it prints an error message and returns NULL, so the
buffer returned by read_sha1_file should be freed before.

Signed-off-by: Carlos Rica <jasampler@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 object.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/object.c b/object.c
index 78a44a6ef4..ccd7dd796e 100644
--- a/object.c
+++ b/object.c
@@ -185,6 +185,7 @@ struct object *parse_object(const unsigned char *sha1)
 	if (buffer) {
 		struct object *obj;
 		if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0) {
+			free(buffer);
 			error("sha1 mismatch %s\n", sha1_to_hex(sha1));
 			return NULL;
 		}