sapling/hgext3rd/arcdiff.py
Thomas Jacob a32f14a7e1 arcdiff: add CA path/timeout support to Phabricator conduit calls
Summary:
Fixing SSL verify bug

https://fb.facebook.com/groups/scm/permalink/1472198416163107/

Test Plan:
PYTHONPATH=/home/tja/local/facebook-hg-rpms/fb-hgext/ /home/tja/local/facebook-hg-rpms/hg-crew/hg diff --since-last-arc-diff
no longer fails with SSL error


$ source hg-dev
$ cd fb-hgext/tests
(hg-dev) tja@devvm2620:tests  (6b76aa8)$ rt
.s.............................................................ss.s.....s.......s....ss..s..s......s.....s..ss...s........s.ss......s..s...................................s........................................................................
Skipped test-p4fastimport-gitfusion-race-condition.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import-branch.t: missing feature: Perforce server and client
Skipped test-p4fastimport-blobcommit.t: missing feature: Perforce server and client
Skipped test-p4fastimport-blobcommit-lfs.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import-incremental.t: missing feature: Perforce server and client
Skipped test-p4fastimport-limit.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import-lfs.t: missing feature: Perforce server and client
Skipped test-lfs-test-server.t: missing lfs-test-server
Skipped test-p4fastimport-import-modes.t: missing feature: Perforce server and client
Skipped test-infinitepush-sql.t: missing getdb.sh
Skipped test-p4fastimport-criss-cross.t: missing feature: Perforce server and client
Skipped test-p4fastimport-transaction.t: missing feature: Perforce server and client
Skipped test-p4fastimport-case-insensitive-rename.t: missing feature: Perforce server and client
Skipped test-infinitepush-backup-sql.t: missing getdb.sh
Skipped test-p4fastimport-import-deletes.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import-client-mapping.t: missing feature: Perforce server and client
Skipped test-p4fastimport-case-insensitivity.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import-special-characters.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import-parallel.t: missing feature: Perforce server and client
Skipped test-p4fastimport-import-badclient.t: missing feature: Perforce server and client
# Ran 223 tests, 21 skipped, 0 failed.

Reviewers: #mercurial, mitrandir

Reviewed By: mitrandir

Subscribers: mitrandir, mjpieters, awestern, medson, #sourcecontrol, samuelkelly

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

Signature: 6272329:1510245174:2969aa7ab17b45f6656e93301806c0a9b157db29
2017-11-09 08:43:57 -08:00

73 lines
2.3 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.
import os
from mercurial import commands, error, extensions
from mercurial.i18n import _
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):
timeout = repo.ui.configint('ssl', 'timeout', 5)
ca_certs = repo.ui.configpath('web', 'cacerts')
client = conduit.Client(ca_certs=ca_certs, timeout=timeout)
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(os.path.join(repo.root, p) for p in prev | curr)
return orig(ui, repo, *pats, **opts)