From 7adab6520975d9a8650a214ca519f2357707bd65 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 20 Feb 2007 19:22:14 -0800 Subject: git_browse: actually moved heads_table and tags_table to seperate files created shortlog_table --- bn_django/git_browse/models.py | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'bn_django/git_browse/models.py') diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index be097f8..db69bfc 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -49,16 +49,47 @@ class Repository(models.Model): heads = dict() for h in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/heads/'): f = open(GITBROWSE_BASE + self.slug + '/.git/refs/heads/' + h,'r') - heads[h] = f.readline() - f.close + heads[h.strip()] = f.readline().strip() + f.close() tags = dict() for t in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/tags/'): f = open(GITBROWSE_BASE + self.slug + '/.git/refs/tags/' + t,'r') - tags[t] = f.readline() - f.close - + tags[t.strip()] = f.readline().strip() + f.close() return (GITPREFIX, heads, tags) + + def shortlog(self): + import commands + + GITPREFIX = 'cd ' + GITBROWSE_BASE + self.slug + '; ' + GITCOMMAND \ + + ' --git-dir=' + GITBROWSE_BASE + self.slug + '/.git ' + logtxt = commands.getoutput(GITPREFIX + ' log --relative-date --max-count=6 | cat') + log_items = logtxt.split('\ncommit ') + if (log_items[0] == ''): + log_items.pop(0) + if (log_items[0].startswith('commit ')): + log_items[0] = log_items[0][7:] + shortlog = list() + for li in log_items: + logobj = dict() + lines = li.splitlines() + if len(lines) < 3: continue + logobj['hash'] = lines[0].strip() + logobj['shorthash'] = lines[0].strip()[:5] + logobj['author'] = lines[1][8:] + logobj['date'] = lines[2][8:] + if len(lines) > 4: + logobj['description'] = lines[4][4:] + else: + logobj['description'] = '(none)' + # here we truncate commit comments for shortlogs + logobj['shortdescription'] = logobj['description'][:128] + shortlog.append(logobj) + return shortlog + + + class Tree(models.Model): repo = models.ForeignKey(Repository) mode = models.CharField("file mode/permissions", blank=False,maxlength=4) -- cgit v1.2.3