Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'abbeyj/perforce-permalinks'
Browse files Browse the repository at this point in the history
Close #538.
  • Loading branch information
pelmers committed May 16, 2016
2 parents 5f661b9 + 51abe47 commit 2d77439
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions dxr/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def __init__(self, root, upstream):
have = self._p4run(['have'])
self.have = dict((x['path'][len(root) + 1:], x) for x in have)
self.upstream = upstream
self.revision = self._p4run(['changes', '-m1', '#have'])[0]['change']

@classmethod
def claim_vcs_source(cls, path, dirs, tree):
Expand All @@ -242,7 +243,7 @@ def _p4run(self, args):
ret = []
env = os.environ
env["PWD"] = self.root
proc = subprocess.Popen(['p4', '-G'] + args,
proc = subprocess.Popen([self.command, '-G'] + args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
cwd=self.root,
Expand Down Expand Up @@ -281,6 +282,17 @@ def display_rev(self, path):
info = self.have[path]
return '#' + info['haveRev']

@classmethod
def get_contents(cls, path, revision, stderr=None):
directory, filename = split(path)
env = os.environ
env["PWD"] = directory
return subprocess.check_output([cls.command,
'print',
'-q',
filename + '@' + revision],
cwd=directory, env=env, stderr=stderr)


every_vcs = [Mercurial, Git, Perforce]

Expand Down Expand Up @@ -326,7 +338,7 @@ def file_contents_at_rev(abspath, revision):
"""Attempt to return the contents of a file at a specific revision."""

with open(os.devnull, 'w') as devnull:
for cls in [Mercurial, Git]:
for cls in every_vcs:
try:
return cls.get_contents(abspath, revision, stderr=devnull)
except subprocess.CalledProcessError:
Expand Down

0 comments on commit 2d77439

Please sign in to comment.