summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-10-28 11:34:57 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-10-28 11:34:57 (GMT)
commit346956c202739c66b23a0ed9d648b1ffbc972705 (patch)
tree6e8007a29f01b7c60d3326f5edb6f4e09843b273
parent72f1fa78418fb39c234b176b25095a44e1970a4a (diff)
downloadeeshow-346956c202739c66b23a0ed9d648b1ffbc972705.zip
eeshow-346956c202739c66b23a0ed9d648b1ffbc972705.tar.gz
eeshow-346956c202739c66b23a0ed9d648b1ffbc972705.tar.bz2
file/git-file.c (vcs_git_time): getting the right date is a little harder ...
First, we should be using the author ("content") date, not the commit ("envelope") date: http://stackoverflow.com/questions/11856983/why-git-authordate-is-different-from-commitdate Second, the date of the commit where we picked up the file doesn't seem to be very relevant. What we're really interested in is when the file last changed. For this, we need to perform an expensive search.
-rw-r--r--file/git-file.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/file/git-file.c b/file/git-file.c
index 10da07f..6b2d13c 100644
--- a/file/git-file.c
+++ b/file/git-file.c
@@ -486,11 +486,59 @@ fail:
/* ----- Commit time ------------------------------------------------------- */
+/*
+ * @@@ Not very efficient. If there are branches, we will search the ancestry
+ * for each branch, which could mean a lot of times. Should keep track of what
+ * we we've already seen, like git-hist does.
+ */
+
+static void recurse_time(const git_commit *commit, const git_oid *oid,
+ time_t *best)
+{
+ unsigned n, i;
+ git_commit *parent;
+ git_tree *tree;
+ const git_signature *sig;
+
+ sig = git_commit_author(commit);
+#if 0
+ if (!*best || sig->when.time < *best) {
+ if (git_commit_tree(&tree, commit))
+ pfatal_git("recurse_time");
+ if (git_tree_entry_byid(tree, oid))
+ *best = sig->when.time;
+ }
+#else
+ /*
+ * @@@ Stopping lookups when the object in question disappears from
+ * the tree may not be entirely correct (not sure whether it's
+ * actually wrong, though), but it speeds up things tremendously.
+ */
+ if (git_commit_tree(&tree, commit))
+ pfatal_git("recurse_time");
+ if (!git_tree_entry_byid(tree, oid))
+ return;
+ if (!*best || sig->when.time < *best)
+ *best = sig->when.time;
+#endif
+
+ n = git_commit_parentcount(commit);
+ for (i = 0; i != n; i++) {
+ if (git_commit_parent(&parent, commit, i))
+ pfatal_git("git_commit_parent");
+ recurse_time(parent, oid, best);
+ }
+}
+
+
time_t vcs_git_time(void *ctx)
{
const struct vcs_git *vcs_git = ctx;
+ const git_oid *oid = git_object_id(vcs_git->obj);
+ time_t t = 0;
- return git_commit_time(vcs_git->commit);
+ recurse_time(vcs_git->commit, oid, &t);
+ return t;
}