sapling/hgext3rd/arcdiff.py
Jun Wu 9fea0c3f0c doc: replace "commit" where it is used as a noun with "changeset"
Summary:
"changeset" is a more official term and let's use it. Note that this patch
only changes documentation / i18n messages visible to the users and header
comment blocks to developers. Other places like comments in the code are
untouched.

With the "dialect" extension enabled, users will still see the more friendly
term - "commit".

Test Plan:
`arc unit`. Note the remotefilelog failure is probably unrelated - seems
related to ongoing / upcoming manifest refactoring upstream.

Reviewers: #sourcecontrol, rmcelroy

Reviewed By: rmcelroy

Subscribers: mjpieters

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

Signature: t1:3900394:1474470348:6a1b5691e2599cc47df18b227d56d1f9d3c7c906
2016-09-21 15:45:25 +01:00

74 lines
2.2 KiB
Python

# arcdiff.py - extension adding an option to the diff command to show changes
# since the last arcanist diff
#
# Copyright 2016 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 cmdutil, commands, error, extensions, hg, scmutil, util
from mercurial.i18n import _
import json
import os
import re
import subprocess
from phabricator import (
arcconfig,
conduit,
diffprops,
)
def extsetup(ui):
entry = extensions.wrapcommand(commands.table, 'diff', _diff)
options = entry[1]
options.append(('', 'since-last-arc-diff', None,
_('show changes since last `arc diff`')))
def _differentialhash(ui, repo, phabrev):
client = conduit.Client()
try:
client.apply_arcconfig(arcconfig.load_for_path(repo.root))
diffid = diffprops.getcurrentdiffidforrev(client, phabrev)
if diffid is None:
return None
localcommits = diffprops.getlocalcommitfordiffid(client, diffid)
return localcommits.get('commit', None) if localcommits else None
except conduit.ClientError as e:
ui.warn(_('Error calling conduit: %s\n') % str(e))
return None
except arcconfig.ArcConfigError as e:
raise error.Abort(str(e))
def _diff(orig, ui, repo, *pats, **opts):
if not opts.get('since_last_arc_diff'):
return orig(ui, repo, *pats, **opts)
ctx = repo['.']
phabrev = diffprops.parserevfromcommitmsg(ctx.description())
if phabrev is None:
mess = _('local changeset is not associated with a differential '
'revision')
raise error.Abort(mess)
rev = _differentialhash(ui, repo, phabrev)
if rev is None:
mess = _('unable to determine previous changeset hash')
raise error.Abort(mess)
rev = str(rev)
opts['rev'] = [rev]
# if patterns aren't provided, restrict diff to files in both changesets
# this prevents performing a diff on rebased changes
if len(pats) == 0:
prev = set(repo.unfiltered()[rev].files())
curr = set(repo['.'].files())
pats = tuple(prev | curr)
return orig(ui, repo, *pats, **opts)