Skip to content

Commit

Permalink
Support trunk in the branch graph
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc committed Oct 16, 2010
1 parent 22ace09 commit ddd2b1a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
6 changes: 6 additions & 0 deletions README.rst
Expand Up @@ -29,6 +29,7 @@ CONFIGURATION
[svn]
server-url = http://svnserver/repo/
branches-path = branches
trunk-path = trunk
username = username
password = password

Expand All @@ -51,3 +52,8 @@ CONFIGURATION
url = http://svnserver/changeset/%s

where %s is where the revision will go.

Configure the number of commits to display before the first branch::

[graph]
cut-off-point = 10
8 changes: 8 additions & 0 deletions svn_branch_graph/cache.py
Expand Up @@ -36,6 +36,10 @@ def is_expired(self, cached_time):
def cache(self, key, value):
conn = sqlite3.connect(self.database_path)
c = conn.cursor()
if isinstance(key, str):
key = unicode(key, 'utf-8')
if isinstance(value, str):
value = unicode(value, 'utf-8')
c.execute('insert into svn_branch_graph_cache VALUES (?, ?, ?)',
(key, now(), value))
conn.commit()
Expand All @@ -44,7 +48,11 @@ def cache(self, key, value):
def get(self, key):
conn = sqlite3.connect(self.database_path)
c = conn.cursor()
if isinstance(key, str):
key = unicode(key, 'utf-8')
c.execute('select * from svn_branch_graph_cache where key=?', (key,))
for row in c:
if not self.is_expired(row[1]):
if isinstance(row[2], unicode):
return row[2].encode('utf-8')
return row[2]
49 changes: 31 additions & 18 deletions svn_branch_graph/main.py
Expand Up @@ -18,12 +18,13 @@
server_url = config.get('svn', 'server-url')

branches_path = config.get('svn', 'branches-path')
if not branches_path:
branches_path = 'branches'
trunk_path = config.get('svn', 'trunk-path')

username = config.get('svn', 'username')
password = config.get('svn', 'password')

cut_off_point = int(config.get('graph', 'cut-off-point'))

cache_enabled = False
if config.has_section('cache'):
cache_enabled = config.get('cache', 'enable') == 'True'
Expand All @@ -49,10 +50,6 @@ def call(cmd):
cache_database.cache(json.dumps(cmd), stdout)
return p.returncode, stdout

def get_branch_url():
svn_branches_url = '%s%s' % (server_url, branches_path)
return svn_branches_url

def get_svn_ls(svn_branches_url):
command = ['svn', 'ls', '--non-interactive', svn_branches_url]
if username:
Expand Down Expand Up @@ -101,20 +98,19 @@ def get_svn_log(svn_branch_url):
svn_log.reverse()
return svn_log, copyfrom

BRANCH_COOKIE = 'svn-branches'


class Index(object):
def GET(self):
"""Returns the main page of svn branch graph, with a list of
checkboxes to select which branches
"""
svn_branches_url = get_branch_url()
branches = get_svn_ls(svn_branches_url)
branches = get_svn_ls('%s%s' % (server_url, branches_path))
# only include folders
branches = [b.strip('/') for b in branches if b.endswith('/')]
return render.index(
svn_branches_url,
server_url,
trunk_path,
branches_path,
branches,
)

Expand All @@ -127,24 +123,41 @@ def GET(self):
- `branch`: list of branch names
"""
i = web.input(branch=[], branch_regexp='')
svn_branch_url = get_branch_url()

if i.branch_regexp:
pattern = re.compile(i.branch_regexp)
branches = get_svn_ls(svn_branch_url)
branches = [b.strip('/') for b in branches if pattern.match(b)]
pattern = re.compile('%s/?$' % i.branch_regexp)
branches = get_svn_ls('%s%s' % (server_url, branches_path))
branches = ['%s/%s' % (branches_path, b.strip('/'))
for b in branches if pattern.match(b)]
if pattern.match('trunk'):
branches.append(trunk_path)
else:
branches = i.branch

svn_logs = []
copyfromlist = {}
for branch in branches:
logs, copyfrom = get_svn_log('/'.join([svn_branch_url, branch]))
copyfromlist[branch] = copyfrom
logs, copyfrom = get_svn_log('/'.join([server_url, branch]))
if branch == trunk_path:
readable = 'trunk'
else:
readable = branch.replace(branches_path, '').strip('/')
for log in logs:
log.setdefault('branch', branch)
log['branch'] = readable
copyfromlist[readable] = copyfrom
svn_logs.extend(logs)
svn_logs.sort(lambda a, b: cmp(a['revision'], b['revision']))

if svn_logs:
initial_branch = svn_logs[0]['branch']
index = 0
for i, log in enumerate(svn_logs):
if log['branch'] != initial_branch:
index = i
break
if index > cut_off_point:
svn_logs = svn_logs[index - cut_off_point:]

changeset_url = None
if config.has_section('changeset'):
changeset_url = config.get('changeset', 'url')
Expand Down
2 changes: 1 addition & 1 deletion svn_branch_graph/templates/graph.html
Expand Up @@ -105,7 +105,7 @@

// try to compress the number of dots to display
if (info.branch == previousBranch) {
x += 1;
x += this.radius / 2;
} else {
x += this.radius * 3;
}
Expand Down
10 changes: 7 additions & 3 deletions svn_branch_graph/templates/index.html
@@ -1,7 +1,7 @@
$def with (svn_branches_url, branches)
$def with (svn_server_url, trunk_path, branches_path, branches)
<html>
<head>
<title>svn_branch_graph $svn_branches_url</title>
<title>svn_branch_graph $svn_server_url</title>
<style type="text/css">
body {
font-family: Arial;
Expand All @@ -23,9 +23,13 @@

<p>Or, please select the branches to include in the graph:</p>
<form action="get-graph">
<div class="branch">
<input name="branch" type="checkbox" id="trunk" value="$trunk_path" />
<label for="trunk">trunk</label>
</div>
$for (i, branch) in enumerate(branches):
<div class="branch">
<input name="branch" type="checkbox" id="$branch" value="$branch" />
<input name="branch" type="checkbox" id="$branch" value="$branches_path/$branch" />
<label for="$branch">$branch</label>
</div>
<div style="clear: both;"></div>
Expand Down

0 comments on commit ddd2b1a

Please sign in to comment.