From e49c69da2e53c8938f4d58bd478bb68f060e3849 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 2 Nov 2013 22:18:33 +0000 Subject: Show the age of a repository in the index, via javascript This patch adds the age of the repository to the index view, using javascript to give a nice human string for the age. When javascript is not available, the element remains hidden. Signed-off-by: Alberto Bertogli --- git.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'git.py') diff --git a/git.py b/git.py index deddeba..7e7ad74 100644 --- a/git.py +++ b/git.py @@ -207,11 +207,13 @@ class Repo: """Returns a GitCommand() on our path.""" return GitCommand(self.path, cmd) - def for_each_ref(self, pattern = None, sort = None): + def for_each_ref(self, pattern = None, sort = None, count = None): """Returns a list of references.""" cmd = self.cmd('for-each-ref') if sort: cmd.sort = sort + if count: + cmd.count = count if pattern: cmd.arg(pattern) @@ -347,6 +349,15 @@ class Repo: return out.read() + def last_commit_timestamp(self): + """Return the timestamp of the last commit.""" + refs = self.for_each_ref(pattern = 'refs/heads/', + sort = '-committerdate', count = 1) + for obj_id, _, _ in refs: + commit = self.commit(obj_id) + return commit.committer_epoch + return -1 + class Commit (object): """A git commit.""" -- cgit v1.2.3