1
"""Extract data suitable for web presentation from Bazaar branches.
3
The module is the interface between Loggerhead and bzrlib. Other code in
4
Loggerhead should not use bzrlib APIs, and functions and methods in this
5
module should not return bzrlib data types.
7
The core method is `History.getRevisionInfo`. This method is meant to be
8
cheap, so you should not worry about calling it multiple times with the same
9
argument or calling it just to retreive a subset of the information it
12
Revisions are described using good old bzrlib revision ids.
14
Revision ids, file ids, file names and file paths are always utf-8 encoded 8
18
class FileDelta(object):
19
"""Information about how an inventory entry changed in a revision.
21
All attribute names are fairly self explanatory. The ``*_parent`` fields
22
are the file id of the parent or ``None`` for the root.
34
:type content_change: ``bool``
35
:ivar execute_change: A boolean reflecting the new state if it changed, or
36
``None`` if it did not.
37
:type execute_change: ``bool`` or ``None``
41
class FileChanges(object):
42
"""Contains information about which files changed in a revision.
44
Note that the 'files changed' information is relative to left-most parent
45
by default, as in 'bzr log -v'.
47
:ivar deltas: A list of `FileDelta` objects.
48
:ivar fileset: ``set(d.file_id for d in self.deltas)``, but cached.
51
class RevisionInfo(object):
52
"""Contains all the immutable information Loggerhead needs about a
56
:ivar date: The date and time this revision was committed.
57
:type date: ``datetime.datetime``
58
:ivar committer: The committer.
59
:type committer: utf-8 encoded ``str``
60
:ivar revprops: The branch properties.
61
:type revprops: A dictionary mapping ``str``\ s to ``str``\ s (both utf-8
63
:ivar message: The commit message of this revision.
64
:type message: utf-8 encoded ``str``
65
:ivar parents: The list of the revids of the revision's parents.
68
class BranchRevisionInfo(object):
69
"""Contains all the mutable information Loggerhead needs about a
70
particular revision, and points to the immutable data.
72
:ivar revno: The dotted revno of this revision in this branch.
74
:ivar where_merged: The list of revids that have this revision as a
76
:ivar info: The corresponding `RevisionInfo`.
79
class FileEntry(object):
80
"""An entry in the list returned by `getFileList`.
82
:ivar path: The path of the object in the revision passed to
84
:ivar fileid: Obvious.
85
:ivar kind: one of ``'file'``, ``'executable'``, ``'link'`` or
88
:ivar last_changed_revid: The revid of the revision in which this path
89
last changed. Not that this is recursive,
90
i.e. the last_changed_revid for a directory is
91
the revid in which the directory or anything
92
contained in in changed.x
93
:ivar size: The size of this object in this revision in bytes.
97
class History(object):
98
"""Provide the information loggerhead needs about a bzrlib Branch.
100
An instance of this class is effectively a wrapper around a
101
`bzrlib.branch.Branch` that translates the information provided by bzrlib
102
into a form convenient for use in loggerhead.
104
:ivar last_revision: The revid of the tip of the branch.
108
def fromBranch(cls, branch):
109
"""Create and initialize a `History` object from a
110
`bzrlib.branch.Branch`.
114
"""Decide whether this History object is still current.
116
At least to start with, an out of date History object should be thrown
117
away and a fresh one created.
120
def getRevisionInfo(self, revid):
121
"""Find the `BranchRevisionInfo` object for a given revision id.
123
This operation is to be thought of as 'cheap', which is to say that
124
you should not worry about calling it repeatedly with the same
125
argument or about calling it just to retrieve a subset of the
126
information it includes.
128
:param revid: a revision id.
129
:returns: a `BranchRevisionInfo` object or ``None`` if the given
130
revision id does not exist in the branch.
133
def getChanges(self, revid, other_revid=None):
134
"""Find the `FileChanges` object between two revision.
136
:param revid: A revision id.
137
:param other_revid: The revision id to compare against. If ``None``
138
or not given, compare against the leftmost parent
140
:returns: The corresponding `FileChanges` object.
143
# There will need to be some more methods here to allow searching for
144
# revisions by date, committer, commit message, etc...
146
def getDiff(self, revidA, revidB):
147
"""Compute the diff between two revisions.
149
Not sure what this will return yet, probably something similar to but
150
more structured than the 'chunks' loggerhead already works with.
153
def getDirList(self, fileid, revid):
154
"""List the files in the given directory as of the given revision.
156
:return: a list of `FileEntry` objects.
159
def getFileAnnotation(self, fileid, revid):
160
"""Annotate the given file.
162
Not sure what this should return, mostly likely a list of
163
(revid-or-None, line contents) (and ``None`` for a binary file).
166
def getFileText(self, fileid, revid):
167
"""Fetch the contents of a file at a particular revision.
169
:returns: (filename, data)
170
:rtype: ``(str, str)``
173
def getBundle(self, revid, compare_revid=None):
174
"""Return a bundle for this revision.
176
Relative to compare_revid, or left-most parent if this is not supplied
179
:return: A bundle (in a string).
182
def normalizeRevivionSpec(self, revspec):
183
"""Convert a revid or revno or 'head' to a revid.
185
:returns: a revision id.
188
def normalizeFileArguments(self, revid, fileid, filepath):
189
"""Handle various ways of specifying a file in the branch.
191
One of ``fileid`` and ``filepath`` should be None.
193
:returns: (fileid, filepath)