aboutsummaryrefslogtreecommitdiff
path: root/vcsbrowsers.py
blob: ea7931c8e35861feced919d0b329d9523b7fe589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# convenience wrappers to construct links 
# into the webinterfaces of different VCSs

import re

class VCSBrowser(object):
    def __init__(self, url):
        self.url = url.rstrip('/')

    def commit(self, commtid):
        raise NotImplemented

    def branch(self, branch):
        raise NotImplemented


class GitWebBrowser(VCSBrowser):
    """
    URLs for gitweb:
    e.g. http://git.debian.org/?p=pkg-libvirt/gtk-vnc.git
    """
    def __init__(self, url):
        url = re.sub(r';a=summary$', '', url)
        VCSBrowser.__init__(self, url)

    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 HgBrowser(VCSBrowser):
    """
    URLs for Mercurial:
    e.g. http://hg.et.redhat.com/virt/applications/virtinst--devel
    """

    def commit(self, commitid):
        return "%s?cs=%s" % (self.url, commitid)