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 CVSWEB_BASE = "http://pserver.samba.org/cgi-bin/cvsweb"
36 VIEWCVS_BASE = "http://websvn.samba.org/cgi-bin/viewcvs.cgi"
37 UNPACKED_BASE = "http://svn.samba.org/ftp/unpacked"
38 GITWEB_BASE = "http://gitweb.samba.org"
41 class History(object):
43 def __init__(self, db):
47 return util.LoadStructure(os.path.join(HISTORYDIR, "history.%s" % tree))
49 def diff(self, author, date, tree, revision):
50 """get recent cvs/svn entries"""
52 t = self.db.trees[tree]
55 self._cvs_diff(t, author, date, tree)
56 elif t["scm"] == "svn":
57 self._svn_diff(t, revision, tree)
58 elif t["scm"] == "git":
59 self._git_diff(t, revision, tree)
61 raise Exception("Unknown VCS %s" % t["scm"])
63 def _svn_diff(self, t, revision, tree):
64 """show recent svn entries"""
66 os.chdir(os.path.join(UNPACKED_DIR, tree))
68 # determine the most recent version known to this database
69 for l in commands.getoutput("svn info").splitlines():
70 if l.startswith("Revision"):
71 current_revision = l.strip().split(":")
74 raise Exception("Unable to find current revision")
76 if (not revision.isdigit() or int(revision) < 0 or
77 int(revision) > int(current_revision)):
78 raise Exception("unknown revision[%s]" % revision)
82 # backwards? why? well, usually our users are looking for the newest
83 # stuff, so it's most likely to be found sooner
84 for i in range(len(log), 0, -1):
85 if log[i]["REVISION"] == revision:
89 raise Exception("Unable to locate commit information revision[%s]." % revision)
91 # get information about the current diff
92 title = "SVN Diff in %s:%s for revision r%s" % (
93 tree, t["branch"], revision)
95 old_revision = revision - 1
96 cmd = "svn diff -r %s:%s" % (old_revision, revision)
98 return (title, entry, tree, [(cmd, commands.getoutput("%s 2> /dev/null" % cmd))])
100 def _cvs_diff(self, t, author, date, tree):
101 """show recent cvs entries"""
102 os.chdir(os.path.join(UNPACKED_DIR, tree))
104 log = self._log(tree)
106 # for paranoia, check that the date string is a valid date
107 if not date[0].isdigit():
108 raise Exception("unknown date")
111 if author == log[i]["AUTHOR"] and date == log[i]["DATE"]:
115 raise Exception("Unable to locate commit information author[%s] data[%s]." % (
118 t1 = time.ctime(date-60+(TIMEOFFSET*60*60)).strip()
119 t2 = time.ctime(date+60+(TIMEOFFSET*60*60)).strip()
121 title = "CVS Diff in %s:%s for %s" % (tree, t["branch"], t1)
123 if entry["TAG"] != "" and entry["REVISIONS"] != "":
124 raise Exception("sorry, cvs diff on branches not currently possible due to a limitation in cvs")
126 os.environ['CVS_PASSFILE'] = os.path.join(BASEDIR, ".cvspass")
128 if entry["REVISIONS"]:
130 for f in entry["REVISIONS"].keys():
131 if entry["REVISIONS"][f]["REV1"] == "NONE":
132 cmd = "cvs rdiff -u -r 0 -r %s %s" % (entry["REVISIONS"][f]["REV2"], f)
133 elif entry["REVISIONS"][f]["REV2"] == "NONE":
134 cmd = "cvs rdiff -u -r %s -r 0 %s" % (
135 entry["REVISIONS"][f]["REV1"], f)
137 cmd = "cvs diff -b -u -r %s -r %s %s" % (
138 entry["REVISIONS"][f]["REV1"], entry["REVISIONS"][f]["REV2"], f)
140 diffs.append((cmd, commands.getoutput("%s 2> /dev/null" % cmd)))
142 cmd = "cvs diff -b -u -D \"%s %s\" -D \"%s %s\" %s" % (
143 t1, TIMEZONE, t2, TIMEZONE, entry["FILES"])
145 diffs = [(cmd, commands.getoutput("%s 2> /dev/null" % cmd))]
146 return (title, entry, tree, diffs)
148 def _git_diff(self, t, revision, tree):
149 """show recent git entries"""
150 os.chdir(os.path.join(UNPACKED_DIR, tree))
152 log = self._log(tree)
154 # backwards? why? well, usually our users are looking for the newest
155 # stuff, so it's most likely to be found sooner
156 for i in range(len(log), 0, -1):
157 if log[i]["REVISION"] == revision:
161 raise Exception("Unable to locate commit information revision[%s]." % revision)
163 # get information about the current diff
164 title = "GIT Diff in %s:%s for revision %s" % (
165 tree, t["branch"], revision)
167 cmd = "git diff %s^ %s ./" % (revision, revision)
168 return (title, entry, tree, [(cmd, commands.getoutput("%s 2> /dev/null" % cmd))])
170 def authors(self, tree):
171 log = self._log(tree)
174 authors.add(entry["AUTHOR"])
177 def history(self, tree, author=None):
178 """get commit history for the given tree"""
179 log = self._log(tree)
181 # what? backwards? why is that? oh... I know... we want the newest first
182 for i in range(len(log), 0, -1):
184 if (author is None or
187 (author == entry["AUTHOR"])):