From cbb36e087c1bcf1c81de53e920baf0c681abfd87 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Mon, 1 Oct 2018 21:25:11 +0100 Subject: [PATCH] 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. --- git-arr | 17 +++++++++++++++++ views/patch.tpl | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 views/patch.tpl diff --git a/git-arr b/git-arr index ca0ccfa..5c4e7db 100755 --- a/git-arr +++ b/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//c/.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//b//t/f=.html') @bottle.route('/r//b//t//f=.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 diff --git a/views/patch.tpl b/views/patch.tpl new file mode 100644 index 0000000..ab3fca1 --- /dev/null +++ b/views/patch.tpl @@ -0,0 +1,8 @@ +From: {{c.author_name}} <{{c.author_email}}> +Date: {{c.author_date}} +Subject: {{c.subject}} + +{{c.body.strip()}} +--- + +{{c.diff.body}}