aboutsummaryrefslogtreecommitdiff
path: root/vcsbrowsers.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2015-11-07 17:27:34 +0100
committerGuido Günther <agx@sigxcpu.org>2015-11-07 17:34:48 +0100
commitf92da491e7bdce8aeac3a167ca38abdd61cdb9bd (patch)
treeccac45ca13915ca836e265c8d921e9bee54e1a5e /vcsbrowsers.py
parent86c4772ea9b2f93e418329e86ee215c13d5ee5e7 (diff)
Distinguish gitweb and cgit
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)
-
-