Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dxr/plugins/omniglot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 @@ -230,6 +250,9 @@ def __init__(self, root, upstream):
self.have = dict((x['path'][len(root) + 1:], x) for x in have)
self.upstream = upstream

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

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