mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
c32c5f4b4c
Summary: Further goal is to make smartlog be able to display "landed as smth" near local commits that has been landed. smth may be either the hash of public rebased commit pulled from server or a phabricator diff id. Differential Revision: https://phabricator.fb.com/D2908465
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
# pullcreatemarkers.py - create obsolescence markers on pull for better rebases
|
|
#
|
|
# Copyright 2015 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.
|
|
#
|
|
# The goal of this extensions is to create obsolescence markers locally for
|
|
# commits previously landed.
|
|
# It uses the phabricator revision number in the commit message to detect the
|
|
# relationship between a draft commit and its landed counterpart.
|
|
# Thanks to these markers, less information is displayed and rebases can have
|
|
# less irrelevant conflicts.
|
|
|
|
import re
|
|
from mercurial import commands
|
|
from mercurial import obsolete
|
|
from mercurial import phases
|
|
from mercurial.extensions import wrapcommand
|
|
|
|
def getdiff(rev):
|
|
m = re.findall("Differential Revision: https://phabricator.fb.com/D(.*)",
|
|
rev.description(),
|
|
re.MULTILINE)
|
|
if m:
|
|
try:
|
|
diffnum = int(m[0])
|
|
return diffnum
|
|
except ValueError:
|
|
return None
|
|
else:
|
|
return None
|
|
|
|
def extsetup(ui):
|
|
wrapcommand(commands.table, 'pull', _pull)
|
|
|
|
def _pull(orig, ui, repo, *args, **opts):
|
|
if not obsolete.isenabled(repo, obsolete.createmarkersopt):
|
|
return orig(ui, repo, *args, **opts)
|
|
maxrevbeforepull = len(repo.changelog)
|
|
r = orig(ui, repo, *args, **opts)
|
|
maxrevafterpull = len(repo.changelog)
|
|
|
|
# Collect the diff number of the landed diffs
|
|
landeddiffs = {}
|
|
for rev in range(maxrevbeforepull, maxrevafterpull):
|
|
n = repo[rev]
|
|
if n.phase() == phases.public:
|
|
diff = getdiff(n)
|
|
if diff is not None:
|
|
landeddiffs[diff] = n
|
|
|
|
# Try to find match with the drafts
|
|
for rev in repo.revs("draft()"):
|
|
n = repo[rev]
|
|
diff = getdiff(n)
|
|
if diff in landeddiffs:
|
|
obsolete.createmarkers(repo,
|
|
[(n, (landeddiffs[diff],))], metadata={'landed': str(diff)})
|
|
|
|
return r
|