aboutsummaryrefslogtreecommitdiff
path: root/vcsbrowsers.py
diff options
context:
space:
mode:
Diffstat (limited to 'vcsbrowsers.py')
-rw-r--r--vcsbrowsers.py43
1 files changed, 38 insertions, 5 deletions
diff --git a/vcsbrowsers.py b/vcsbrowsers.py
index ea7931c..ba33cb1 100644
--- a/vcsbrowsers.py
+++ b/vcsbrowsers.py
@@ -1,8 +1,9 @@
-# convenience wrappers to construct links
+# convenience wrappers to construct links
# into the webinterfaces of different VCSs
import re
+
class VCSBrowser(object):
def __init__(self, url):
self.url = url.rstrip('/')
@@ -16,18 +17,52 @@ class VCSBrowser(object):
class GitWebBrowser(VCSBrowser):
"""
+ GitWeb based repo browser
+
URLs for gitweb:
e.g. http://git.debian.org/?p=pkg-libvirt/gtk-vnc.git
"""
+ repotype = "gitweb"
+
def __init__(self, url):
url = re.sub(r';a=summary$', '', url)
VCSBrowser.__init__(self, url)
+ @classmethod
+ def check(cls, url):
+ return True if '/?p=' in url else False
+
def commit(self, commitid):
return "%s;a=commitdiff;h=%s" % (self.url, commitid)
- def branch(self, branch):
- return "%s;a=shortlog;h=refs/heads/%s" % (self.url, branch)
+
+class CGitBrowser(VCSBrowser):
+ repotype = "cgit"
+
+ def __init__(self, url):
+ VCSBrowser.__init__(self, url)
+
+ @classmethod
+ def check(cls, url):
+ return True if '/cgit' in url else False
+
+ def commit(self, commitid):
+ return "%s/commit/?id=%s" % (self.url, commitid)
+
+
+def guess_git_repo(url):
+ """
+ >>> guess_git_repo("http://example.com/?p=foo").repotype
+ 'gitweb'
+ >>> guess_git_repo("http://example.com/cgit/foo").repotype
+ 'cgit'
+ >>> guess_git_repo("http://example.com/bar/foo").repotype
+ 'cgit'
+ """
+ for repotype in [CGitBrowser, GitWebBrowser]:
+ if repotype.check(url):
+ return repotype(url)
+ return CGitBrowser(url)
class HgBrowser(VCSBrowser):
@@ -38,5 +73,3 @@ class HgBrowser(VCSBrowser):
def commit(self, commitid):
return "%s?cs=%s" % (self.url, commitid)
-
-