diff options
Diffstat (limited to 'bn_django/git_browse/models.py')
-rw-r--r-- | bn_django/git_browse/models.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index c914cac..2af2c98 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -106,6 +106,37 @@ class Tree(models.Model): def get_admin_url(self): return "%s/code/tree/%s/" % (ADMIN_URL, self.id) + def update(self): + import commands + if (not self.id): return + + self.id = self.id.strip() + tree_ls = commands.getoutput(GITPREFIX + ' ls-tree --full-name ' \ + + self.id) + tree_objs = list() + blob_objs = list() + for line in tree_ls.splitlines(): + l = line.split() + if len(l) < 4: + continue + if l[1] == 'tree': + t = Tree(id=l[2]) + t.path = ' '.join(l[3:]) + if self.path and self.path != '/': + t.path = self.path + '/' + t.path + t.name = t.path + tree_objs.append(t) + if l[1] == 'blob': + i = Item(id=l[2]) + i.path = ' '.join(l[3:]) + if self.path and self.path != '/': + i.path = self.path + '/' + i.path + i.name=i.path + blob_objs.append(i) + self.tree_objs = tree_objs + self.blob_objs = blob_objs + self.all_objs = tree_objs + blob_objs + def tree_from_str(s): s = s.split(); if len(s) != 4: return @@ -183,8 +214,6 @@ class Commit(models.Model): self.id = self.id.strip() raw = commands.getoutput(GITPREFIX + ' cat-file -p ' + self.id) - self.rawdiff = commands.getoutput(GITPREFIX + ' diff ' + self.id \ - +' | cat') raw = raw.splitlines() if len(raw) < 3: return @@ -196,6 +225,8 @@ class Commit(models.Model): self.author_date = time.ctime(int(raw[2].split()[-2])) self.committer = raw[3].split()[1] self.committer_date = time.ctime(int(raw[3].split()[-2])) + self.rawdiff = commands.getoutput(GITPREFIX + ' diff ' \ + + self.parenthash + ' ' + self.id + ' | cat') if len(raw) > 4: for l in raw[4:]: self.comment += str(l) + '\n' |