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

Commit

Permalink
Merge pull request #508 from kleintom/vcs_upstream
Browse files Browse the repository at this point in the history
Only display "VCS Links" when there's a useable upstream link.
  • Loading branch information
pelmers committed Jun 23, 2016
2 parents 19ce5f7 + 129001b commit 24502a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dxr/plugins/omniglot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def items():
yield 'diff', "Diff", self.vcs.generate_diff(vcs_relative_path)
yield 'raw', "Raw", self.vcs.generate_raw(vcs_relative_path)

if self.vcs:
if self.vcs and self.vcs.has_upstream():
vcs_relative_path = relpath(self.absolute_path(), self.vcs.get_root_dir())
yield (5, 'VCS Links', items())

27 changes: 25 additions & 2 deletions dxr/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def is_tracked(self, path):
"""Does the repository track this file?"""
return NotImplemented

def has_upstream(self):
"""Return true if this VCS has a usable upstream."""
return NotImplemented

# Note: the generate_* methods shouldn't be expected to return useful URLs
# unless this VCS has_upstream().

def generate_log(self, path):
"""Construct URL to upstream view of log of file at path."""
return NotImplemented
Expand Down Expand Up @@ -99,8 +106,17 @@ def __init__(self, root):
self.previous_revisions = self.find_previous_revisions(client)
self.upstream = self._construct_upstream_url()

def has_upstream(self):
return self.upstream != ""

def _construct_upstream_url(self):
upstream = urlparse.urlparse(self.invoke_vcs(['paths', 'default'], self.root).strip())
with open(os.devnull, 'w') as devnull:
try:
upstream = urlparse.urlparse(self.invoke_vcs(['paths', 'default'],
self.root, stderr=devnull).strip())
except subprocess.CalledProcessError:
# No default path, so no upstream
return ""
recomb = list(upstream)
if upstream.scheme == 'ssh':
recomb[0] = 'http'
Expand Down Expand Up @@ -168,6 +184,9 @@ def __init__(self, root):
self.revision = self.invoke_vcs(['rev-parse', 'HEAD'], self.root).strip()
self.upstream = self._construct_upstream_url()

def has_upstream(self):
return self.upstream != ""

def _construct_upstream_url(self):
source_urls = self.invoke_vcs(['remote', '-v'], self.root).split('\n')
for src_url in source_urls:
Expand All @@ -185,8 +204,9 @@ def _construct_upstream_url(self):
return repo
warn("Your git remote is not supported yet. Please use a "
"GitHub remote if you would like version control "
"naviagtion links to show.")
"navigation links to show.")
break
return ""

@classmethod
def claim_vcs_source(cls, path, dirs, tree):
Expand Down Expand Up @@ -231,6 +251,9 @@ def __init__(self, root, upstream):
self.upstream = upstream
self.revision = self._p4run(['changes', '-m1', '#have'])[0]['change']

def has_upstream(self):
return self.upstream != ""

@classmethod
def claim_vcs_source(cls, path, dirs, tree):
if 'P4CONFIG' not in os.environ:
Expand Down

0 comments on commit 24502a8

Please sign in to comment.