~bzr/bzr-webserve/webserve-dev

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# cmd_inventory.py - web interface for bazaar
# this code is derived by the hgweb server of the Matt Mackall's mercurial
# project
#
# Copyright 2006 Goffredo Baroncelli <kreijack@inwind.it>
#
# This file is part of bazaar-webserve.
#
# bazaar-webserve is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# bazaar-webserve is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bazaar-webserve; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


import hgweb
from hgweb import (
    WebServeErrorRevisionNotFound,
    WebServeErrorPathNotFound
)


def dname(path):
    d = path.rfind('/')
    if d>= 0:
        return path[:d]
    else:
        return ""


def fname(path):
    d = path.rfind('/')
    return path[d+1:]


def filelist(webserve, rev, inv, path2):
    parity=0
    for fpath, entry in inv.entries():
        if dname(fpath) != path2:
            continue
        bname = fname(fpath)
        #FIXME: remeber of the link, and the x attribute
        if entry.kind == "file":
            yield webserve.t("inventoryfileentry",
                            perm = entry.executable,
                            parity = parity,
                            name = bname,
                            fullname = fpath,
                            id = entry.file_id,
                            entryrevision = entry.revision,
                            rev = rev,
                            filesize = entry.text_size,
            )
        elif entry.kind == "directory":
            yield webserve.t("inventorydirentry",
                            perm = entry.executable,
                            parity = parity,
                            name = bname + '/',
                            path = fpath,
                            id = entry.file_id,
                            entryrevision = entry.revision,
                            rev = rev,
            )
        elif entry.kind == "symlink":
            yield webserve.t("inventorylinkentry",
                            perm = entry.executable,
                            parity = parity,
                            name = bname,
                            fullname = fpath,
                            id = entry.file_id,
                            entryrevision = entry.revision,
                            rev = rev,
            )
        parity = 1 - parity


def inventory(webserve, rev, path=None, pathrevid=None):

    rev = webserve.get_revid(rev)

    if not webserve.revision_history.exist_revision(rev):
        raise WebServeErrorRevisionNotFound(rev)

    inv = webserve.branch.repository.get_revision_inventory(rev)
    if not path:
        path2 = ""
        path = "/"
        file_id = None
        pathrevid = rev
    else:
        pathrevid = webserve.get_revid(pathrevid, rev)
        if not webserve.revision_history.exist_revision(pathrevid):
            raise WebServeErrorRevisionNotFound(pathrevid)
        file_id = webserve.get_fileid(path, pathrevid)
        if file_id == None or not inv.has_id(file_id):
            raise WebServeErrorPathNotFound(rev, path, pathrevid)
        path2 = inv.id2path(file_id)

    revision = webserve.branch.repository.get_revision(rev)
    yield webserve.t("inventory",
                 rev = rev,
                 invnav = webserve.template_nav_revid(
                        "invnaventry", rev, path=path,
                        pathrevid=pathrevid),
                 path = path,
                 actualpath = path2,
                 linkpath = webserve.template_path(rev, path, pathrevid),
                 pathrevid = pathrevid,
                 revlink = webserve.template_revid(rev),
                 fileid = file_id and file_id or "",
                 parent = dname(path[:-1]),
                 entries = [x for x in filelist(webserve, rev, inv, path2)],
                 author = revision.committer,
                 desc = revision.message,
                 date = revision.timestamp,
    )