Implement a "patch" view

This commit implements a "patch" view, with a simple plain-text
representation of a commit, that can be used as a patch file.
This commit is contained in:
Alberto Bertogli 2018-10-01 21:25:11 +01:00
parent 722d765973
commit cbb36e087c
2 changed files with 25 additions and 0 deletions

17
git-arr

@ -61,6 +61,7 @@ def load_config(path):
'embed_markdown': 'yes',
'embed_images': 'no',
'ignore': '',
'generate_patch': 'yes',
}
config = configparser.SafeConfigParser(defaults)
@ -120,6 +121,7 @@ def load_config(path):
r.info.max_pages = sys.maxint
r.info.generate_tree = config.getboolean(s, 'tree')
r.info.root_diff = config.getboolean(s, 'rootdiff')
r.info.generate_patch = config.getboolean(s, 'generate_patch')
r.info.web_url = config.get(s, 'web_url')
web_url_file = fullpath + '/' + config.get(s, 'web_url_file')
@ -236,6 +238,19 @@ def commit(repo, cid):
return dict(repo = repo, c=c)
@bottle.route('/r/<repo:repo>/c/<cid:re:[0-9a-f]{5,40}>.patch')
@bottle.view('patch',
# Output is text/plain, don't do HTML escaping.
template_settings={"noescape": True})
def patch(repo, cid):
c = repo.commit(cid)
if not c:
bottle.abort(404, 'Commit not found')
bottle.response.content_type = 'text/plain; charset=utf8'
return dict(repo = repo, c=c)
@bottle.route('/r/<repo:repo>/b/<bname:path>/t/f=<fname:path>.html')
@bottle.route('/r/<repo:repo>/b/<bname:path>/t/<dirname:path>/f=<fname:path>.html')
@bottle.view('blob')
@ -396,6 +411,8 @@ def generate(output, only = None):
for cid in commit_ids:
write_to('r/%s/c/%s/index.html' % (r.name, cid),
commit, (r, cid))
if r.info.generate_patch:
write_to('r/%s/c/%s.patch' % (r.name, cid), patch, (r, cid))
commit_count += 1
# To avoid regenerating files that have not changed, we will

8
views/patch.tpl Normal file

@ -0,0 +1,8 @@
From: {{c.author_name}} <{{c.author_email}}>
Date: {{c.author_date}}
Subject: {{c.subject}}
{{c.body.strip()}}
---
{{c.diff.body}}