2 # script to show recent checkins in cvs / svn / git
4 # Copyright (C) Andrew Tridgell <tridge@samba.org> 2001
5 # Copyright (C) Martin Pool <mbp@samba.org> 2003
6 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 from buildfarm import util
29 BASEDIR = "/home/build/master"
30 HISTORYDIR = "/home/build/master/cache"
33 UNPACKED_DIR = "/home/ftp/pub/unpacked"
35 class History(object):
37 def __init__(self, db):
41 return util.LoadStructure(os.path.join(HISTORYDIR, "history.%s" % tree))
43 def diff(self, author, date, tree, revision):
44 """get recent cvs/svn entries"""
46 t = self.db.trees[tree]
49 self._cvs_diff(t, author, date, tree)
51 self._svn_diff(t, revision, tree)
53 self._git_diff(t, revision, tree)
55 raise Exception("Unknown VCS %s" % t.scm)
57 def _svn_diff(self, t, revision, tree):
58 """show recent svn entries"""
60 os.chdir(os.path.join(UNPACKED_DIR, tree))
62 # determine the most recent version known to this database
63 for l in commands.getoutput("svn info").splitlines():
64 if l.startswith("Revision"):
65 current_revision = l.strip().split(":")
68 raise Exception("Unable to find current revision")
70 if (not revision.isdigit() or int(revision) < 0 or
71 int(revision) > int(current_revision)):
72 raise Exception("unknown revision[%s]" % revision)
76 # backwards? why? well, usually our users are looking for the newest
77 # stuff, so it's most likely to be found sooner
78 for i in range(len(log), 0, -1):
79 if log[i]["REVISION"] == revision:
83 raise Exception("Unable to locate commit information revision[%s]." % revision)
85 # get information about the current diff
86 title = "SVN Diff in %s:%s for revision r%s" % (
87 tree, t.branch, revision)
89 old_revision = revision - 1
90 cmd = "svn diff -r %s:%s" % (old_revision, revision)
92 return (title, entry, tree, [(cmd, commands.getoutput("%s 2> /dev/null" % cmd))])
94 def _cvs_diff(self, t, author, date, tree):
95 """show recent cvs entries"""
96 os.chdir(os.path.join(UNPACKED_DIR, tree))
100 # for paranoia, check that the date string is a valid date
101 if not date[0].isdigit():
102 raise Exception("unknown date")
105 if author == log[i]["AUTHOR"] and date == log[i]["DATE"]:
109 raise Exception("Unable to locate commit information author[%s] data[%s]." % (
112 t1 = time.ctime(date-60+(TIMEOFFSET*60*60)).strip()
113 t2 = time.ctime(date+60+(TIMEOFFSET*60*60)).strip()
115 title = "CVS Diff in %s:%s for %s" % (tree, t.branch, t1)
117 if entry["TAG"] != "" and entry["REVISIONS"] != "":
118 raise Exception("sorry, cvs diff on branches not currently possible due to a limitation in cvs")
120 os.environ['CVS_PASSFILE'] = os.path.join(BASEDIR, ".cvspass")
122 if entry["REVISIONS"]:
124 for f in entry["REVISIONS"].keys():
125 if entry["REVISIONS"][f]["REV1"] == "NONE":
126 cmd = "cvs rdiff -u -r 0 -r %s %s" % (entry["REVISIONS"][f]["REV2"], f)
127 elif entry["REVISIONS"][f]["REV2"] == "NONE":
128 cmd = "cvs rdiff -u -r %s -r 0 %s" % (
129 entry["REVISIONS"][f]["REV1"], f)
131 cmd = "cvs diff -b -u -r %s -r %s %s" % (
132 entry["REVISIONS"][f]["REV1"], entry["REVISIONS"][f]["REV2"], f)
134 diffs.append((cmd, commands.getoutput("%s 2> /dev/null" % cmd)))
136 cmd = "cvs diff -b -u -D \"%s %s\" -D \"%s %s\" %s" % (
137 t1, TIMEZONE, t2, TIMEZONE, entry["FILES"])
139 diffs = [(cmd, commands.getoutput("%s 2> /dev/null" % cmd))]
140 return (title, entry, tree, diffs)
142 def _git_diff(self, t, revision, tree):
143 """show recent git entries"""
144 os.chdir(os.path.join(UNPACKED_DIR, tree))
146 log = self._log(tree)
148 # backwards? why? well, usually our users are looking for the newest
149 # stuff, so it's most likely to be found sooner
150 for i in range(len(log), 0, -1):
151 if log[i]["REVISION"] == revision:
155 raise Exception("Unable to locate commit information revision[%s]." % revision)
157 # get information about the current diff
158 title = "GIT Diff in %s:%s for revision %s" % (
159 tree, t.branch, revision)
161 cmd = "git diff %s^ %s ./" % (revision, revision)
162 return (title, entry, tree, [(cmd, commands.getoutput("%s 2> /dev/null" % cmd))])
164 def authors(self, tree):
165 log = self._log(tree)
168 authors.add(entry["AUTHOR"])
171 def history(self, tree, author=None):
172 """get commit history for the given tree"""
173 log = self._log(tree)
175 # what? backwards? why is that? oh... I know... we want the newest first
176 for i in range(len(log), 0, -1):
178 if (author is None or
181 (author == entry["AUTHOR"])):