sapling/phabdiff.py
Wez Furlong 628f88d82d hgext: refactor D123 parsing, centralize
Summary:
In addition to being duplicated between these places,
I'd like to re-use this elsewhere.

Test Plan: run-tests continues to pass

Reviewers: #sourcecontrol, ttung, ikostia

Reviewed By: ikostia

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3230128

Tasks: 11013909

Signature: t1:3230128:1461775513:6fc79fda68cd15ded7fb11d52024b5aab56ee880
2016-04-27 09:50:13 -07:00

32 lines
997 B
Python

# phabdiff.py
#
# Copyright 2013 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from mercurial import templatekw
from phabricator import diffprops
import re
def showphabdiff(repo, ctx, templ, **args):
""":phabdiff: String. Return the phabricator diff id for a given hg rev."""
descr = ctx.description()
revision = diffprops.parserevfromcommitmsg(descr)
return 'D' + revision if revision else ''
def showtasks(**args):
""":tasks: String. Return the tasks associated with given hg rev."""
descr = args['ctx'].description()
match = re.search('(Tasks|Task ID): (\d+)(,\s*\d+)*', descr)
tasks = []
if match:
tasksline = match.group(0)
tasks = re.findall("\d+", tasksline)
return templatekw.showlist('task', tasks, **args)
def extsetup(ui):
templatekw.keywords['phabdiff'] = showphabdiff
templatekw.keywords['tasks'] = showtasks