/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2220.2.3 by Martin Pool
Add tag: revision namespace.
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
18
import bisect
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
19
import datetime
20
import re
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
21
22
from bzrlib import (
23
    errors,
2325.2.5 by Marien Zwart
Call osutils.safe_revision_id instead of duplicating it.
24
    osutils,
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
25
    revision,
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
26
    symbol_versioning,
27
    trace,
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
28
    tsort,
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
29
    )
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
30
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
31
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
32
_marker = []
33
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
34
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
35
class RevisionInfo(object):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
36
    """The results of applying a revision specification to a branch."""
37
38
    help_txt = """The results of applying a revision specification to a branch.
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
39
40
    An instance has two useful attributes: revno, and rev_id.
41
42
    They can also be accessed as spec[0] and spec[1] respectively,
43
    so that you can write code like:
44
    revno, rev_id = RevisionSpec(branch, spec)
45
    although this is probably going to be deprecated later.
46
47
    This class exists mostly to be the return value of a RevisionSpec,
48
    so that you can access the member you're interested in (number or id)
49
    or treat the result as a tuple.
50
    """
51
52
    def __init__(self, branch, revno, rev_id=_marker):
53
        self.branch = branch
54
        self.revno = revno
55
        if rev_id is _marker:
56
            # allow caller to be lazy
57
            if self.revno is None:
58
                self.rev_id = None
59
            else:
60
                self.rev_id = branch.get_rev_id(self.revno)
61
        else:
62
            self.rev_id = rev_id
63
64
    def __nonzero__(self):
65
        # first the easy ones...
66
        if self.rev_id is None:
67
            return False
68
        if self.revno is not None:
69
            return True
70
        # TODO: otherwise, it should depend on how I was built -
71
        # if it's in_history(branch), then check revision_history(),
72
        # if it's in_store(branch), do the check below
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
73
        return self.branch.repository.has_revision(self.rev_id)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
74
75
    def __len__(self):
76
        return 2
77
78
    def __getitem__(self, index):
79
        if index == 0: return self.revno
80
        if index == 1: return self.rev_id
81
        raise IndexError(index)
82
83
    def get(self):
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
84
        return self.branch.repository.get_revision(self.rev_id)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
85
86
    def __eq__(self, other):
87
        if type(other) not in (tuple, list, type(self)):
88
            return False
89
        if type(other) is type(self) and self.branch is not other.branch:
90
            return False
91
        return tuple(self) == tuple(other)
92
93
    def __repr__(self):
94
        return '<bzrlib.revisionspec.RevisionInfo object %s, %s for %r>' % (
95
            self.revno, self.rev_id, self.branch)
96
2220.2.3 by Martin Pool
Add tag: revision namespace.
97
    @staticmethod
98
    def from_revision_id(branch, revision_id, revs):
99
        """Construct a RevisionInfo given just the id.
100
101
        Use this if you don't know or care what the revno is.
102
        """
103
        try:
104
            revno = revs.index(revision_id) + 1
105
        except ValueError:
106
            revno = None
107
        return RevisionInfo(branch, revno, revision_id)
108
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
109
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
110
# classes in this list should have a "prefix" attribute, against which
111
# string specs are matched
112
SPEC_TYPES = []
1948.4.35 by John Arbash Meinel
Move the _revno_regex to a more logical location
113
_revno_regex = None
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
114
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
115
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
116
class RevisionSpec(object):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
117
    """A parsed revision specification."""
118
119
    help_txt = """A parsed revision specification.
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
120
121
    A revision specification can be an integer, in which case it is
122
    assumed to be a revno (though this will translate negative values
123
    into positive ones); or it can be a string, in which case it is
124
    parsed for something like 'date:' or 'revid:' etc.
125
126
    Revision specs are an UI element, and they have been moved out
127
    of the branch class to leave "back-end" classes unaware of such
128
    details.  Code that gets a revno or rev_id from other code should
129
    not be using revision specs - revnos and revision ids are the
130
    accepted ways to refer to revisions internally.
131
132
    (Equivalent to the old Branch method get_revision_info())
133
    """
134
135
    prefix = None
136
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
137
    def __new__(cls, spec, _internal=False):
138
        if _internal:
139
            return object.__new__(cls, spec, _internal=_internal)
140
141
        symbol_versioning.warn('Creating a RevisionSpec directly has'
142
                               ' been deprecated in version 0.11. Use'
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
143
                               ' RevisionSpec.from_string()'
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
144
                               ' instead.',
145
                               DeprecationWarning, stacklevel=2)
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
146
        return RevisionSpec.from_string(spec)
147
148
    @staticmethod
149
    def from_string(spec):
150
        """Parse a revision spec string into a RevisionSpec object.
151
152
        :param spec: A string specified by the user
153
        :return: A RevisionSpec object that understands how to parse the
154
            supplied notation.
155
        """
156
        if not isinstance(spec, (type(None), basestring)):
157
            raise TypeError('error')
158
159
        if spec is None:
160
            return RevisionSpec(None, _internal=True)
161
162
        assert isinstance(spec, basestring), \
163
            "You should only supply strings not %s" % (type(spec),)
164
165
        for spectype in SPEC_TYPES:
166
            if spec.startswith(spectype.prefix):
167
                trace.mutter('Returning RevisionSpec %s for %s',
168
                             spectype.__name__, spec)
169
                return spectype(spec, _internal=True)
170
        else:
171
            # RevisionSpec_revno is special cased, because it is the only
172
            # one that directly handles plain integers
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
173
            # TODO: This should not be special cased rather it should be
174
            # a method invocation on spectype.canparse()
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
175
            global _revno_regex
176
            if _revno_regex is None:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
177
                _revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
178
            if _revno_regex.match(spec) is not None:
179
                return RevisionSpec_revno(spec, _internal=True)
180
181
            raise errors.NoSuchRevisionSpec(spec)
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
182
183
    def __init__(self, spec, _internal=False):
184
        """Create a RevisionSpec referring to the Null revision.
185
186
        :param spec: The original spec supplied by the user
187
        :param _internal: Used to ensure that RevisionSpec is not being
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
188
            called directly. Only from RevisionSpec.from_string()
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
189
        """
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
190
        if not _internal:
191
            # XXX: Update this after 0.10 is released
192
            symbol_versioning.warn('Creating a RevisionSpec directly has'
193
                                   ' been deprecated in version 0.11. Use'
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
194
                                   ' RevisionSpec.from_string()'
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
195
                                   ' instead.',
196
                                   DeprecationWarning, stacklevel=2)
197
        self.user_spec = spec
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
198
        if self.prefix and spec.startswith(self.prefix):
199
            spec = spec[len(self.prefix):]
200
        self.spec = spec
201
202
    def _match_on(self, branch, revs):
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
203
        trace.mutter('Returning RevisionSpec._match_on: None')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
204
        return RevisionInfo(branch, 0, None)
205
206
    def _match_on_and_check(self, branch, revs):
207
        info = self._match_on(branch, revs)
208
        if info:
209
            return info
210
        elif info == (0, None):
211
            # special case - the empty tree
212
            return info
213
        elif self.prefix:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
214
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
215
        else:
1948.4.2 by John Arbash Meinel
Update _match_on_and_check to raise the right error
216
            raise errors.InvalidRevisionSpec(self.spec, branch)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
217
218
    def in_history(self, branch):
1732.3.1 by Matthieu Moy
Implementation of -r revno:N:/path/to/branch
219
        if branch:
220
            revs = branch.revision_history()
221
        else:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
222
            # this should never trigger.
223
            # TODO: make it a deprecated code path. RBC 20060928
1732.3.1 by Matthieu Moy
Implementation of -r revno:N:/path/to/branch
224
            revs = None
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
225
        return self._match_on_and_check(branch, revs)
226
1432 by Robert Collins
branch: namespace
227
        # FIXME: in_history is somewhat broken,
228
        # it will return non-history revisions in many
229
        # circumstances. The expected facility is that
230
        # in_history only returns revision-history revs,
231
        # in_store returns any rev. RBC 20051010
232
    # aliases for now, when we fix the core logic, then they
233
    # will do what you expect.
234
    in_store = in_history
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
235
236
    def in_branch(self, branch, need_revno=True):
237
        """Evaluate this revision spec and return a RevisionInfo object.
238
239
        If need_revno is False, the returned RevisionInfo object might
240
        have the revno attribute set as None (for performance reasons),
241
        even if the revno exists in the specified branch.
242
243
        The default implementation is an alias for RevisionSpec.in_history.
244
        """
245
        return self.in_history(branch)
246
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
247
    def __repr__(self):
248
        # this is mostly for helping with testing
1948.4.32 by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/
249
        return '<%s %s>' % (self.__class__.__name__,
250
                              self.user_spec)
1881.1.1 by Matthieu Moy
Fixed and tested "bzr diff" outside a working tree.
251
    
1881.1.4 by Matthieu Moy
needs_tree -> needs_branch
252
    def needs_branch(self):
253
        """Whether this revision spec needs a branch.
254
1711.2.99 by John Arbash Meinel
minor typo fix
255
        Set this to False the branch argument of _match_on is not used.
256
        """
1881.1.1 by Matthieu Moy
Fixed and tested "bzr diff" outside a working tree.
257
        return True
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
258
1907.4.1 by Matthieu Moy
Fixed merge to work nicely with -r revno:N:path
259
    def get_branch(self):
260
        """When the revision specifier contains a branch location, return it.
261
        
262
        Otherwise, return None.
263
        """
264
        return None
265
1907.4.9 by Matthieu Moy
missing newline
266
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
267
# private API
268
269
class RevisionSpec_revno(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
270
    """Selects a revision using a number."""
271
272
    help_txt = """Selects a revision using a number.
2023.1.1 by ghigo
add topics help
273
274
    Use an integer to specify a revision in the history of the branch.
275
    Optionally a branch can be specified. The 'revno:' prefix is optional.
276
    A negative number will count from the end of the branch (-1 is the
277
    last revision, -2 the previous one). If the negative number is larger
278
    than the branch's history, the first revision is returned.
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
279
    Examples::
280
2023.1.1 by ghigo
add topics help
281
      revno:1                   -> return the first revision
282
      revno:3:/path/to/branch   -> return the 3rd revision of
283
                                   the branch '/path/to/branch'
284
      revno:-1                  -> The last revision in a branch.
285
      -2:http://other/branch    -> The second to last revision in the
286
                                   remote branch.
287
      -1000000                  -> Most likely the first revision, unless
288
                                   your history is very long.
289
    """
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
290
    prefix = 'revno:'
291
292
    def _match_on(self, branch, revs):
293
        """Lookup a revision by revision number"""
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
294
        loc = self.spec.find(':')
295
        if loc == -1:
296
            revno_spec = self.spec
297
            branch_spec = None
298
        else:
299
            revno_spec = self.spec[:loc]
300
            branch_spec = self.spec[loc+1:]
301
302
        if revno_spec == '':
1948.4.6 by John Arbash Meinel
A small bugfix, and more tests for revno:
303
            if not branch_spec:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
304
                raise errors.InvalidRevisionSpec(self.user_spec,
1948.4.5 by John Arbash Meinel
Fix tests for negative entries, and add tests for revno:
305
                        branch, 'cannot have an empty revno and no branch')
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
306
            revno = None
307
        else:
308
            try:
309
                revno = int(revno_spec)
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
310
                dotted = False
311
            except ValueError:
312
                # dotted decimal. This arguably should not be here
313
                # but the from_string method is a little primitive 
314
                # right now - RBC 20060928
315
                try:
316
                    match_revno = tuple((int(number) for number in revno_spec.split('.')))
317
                except ValueError, e:
318
                    raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
319
320
                dotted = True
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
321
1948.4.6 by John Arbash Meinel
A small bugfix, and more tests for revno:
322
        if branch_spec:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
323
            # the user has override the branch to look in.
324
            # we need to refresh the revision_history map and
325
            # the branch object.
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
326
            from bzrlib.branch import Branch
327
            branch = Branch.open(branch_spec)
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
328
            revs = None
1948.4.22 by John Arbash Meinel
Refactor common code from integer revno handlers
329
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
330
        if dotted:
331
            branch.lock_read()
332
            try:
2418.5.9 by John Arbash Meinel
Have RevisionSpec_revno() also use the new helper
333
                revision_id_to_revno = branch.get_revision_id_to_revno_map()
334
                revisions = [revision_id for revision_id, revno
335
                             in revision_id_to_revno.iteritems()
336
                             if revno == match_revno]
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
337
            finally:
338
                branch.unlock()
339
            if len(revisions) != 1:
340
                return RevisionInfo(branch, None, None)
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
341
            else:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
342
                # there is no traditional 'revno' for dotted-decimal revnos.
343
                # so for  API compatability we return None.
2418.5.9 by John Arbash Meinel
Have RevisionSpec_revno() also use the new helper
344
                return RevisionInfo(branch, None, revisions[0])
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
345
        else:
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
346
            last_revno, last_revision_id = branch.last_revision_info()
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
347
            if revno < 0:
2249.4.2 by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
348
                # if get_rev_id supported negative revnos, there would not be a
349
                # need for this special case.
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
350
                if (-revno) >= last_revno:
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
351
                    revno = 1
352
                else:
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
353
                    revno = last_revno + revno + 1
1988.4.5 by Robert Collins
revisions can now be specified using dotted-decimal revision numbers.
354
            try:
355
                revision_id = branch.get_rev_id(revno, revs)
356
            except errors.NoSuchRevision:
357
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
358
        return RevisionInfo(branch, revno, revision_id)
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
359
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
360
    def in_branch(self, branch, need_revno=True):
361
        return self._match_on(branch, None)
362
1881.1.4 by Matthieu Moy
needs_tree -> needs_branch
363
    def needs_branch(self):
1881.1.1 by Matthieu Moy
Fixed and tested "bzr diff" outside a working tree.
364
        return self.spec.find(':') == -1
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
365
1907.4.1 by Matthieu Moy
Fixed merge to work nicely with -r revno:N:path
366
    def get_branch(self):
367
        if self.spec.find(':') == -1:
368
            return None
369
        else:
370
            return self.spec[self.spec.find(':')+1:]
371
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
372
# Old compatibility 
373
RevisionSpec_int = RevisionSpec_revno
374
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
375
SPEC_TYPES.append(RevisionSpec_revno)
376
377
378
class RevisionSpec_revid(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
379
    """Selects a revision using the revision id."""
380
381
    help_txt = """Selects a revision using the revision id.
2023.1.1 by ghigo
add topics help
382
383
    Supply a specific revision id, that can be used to specify any
384
    revision id in the ancestry of the branch. 
385
    Including merges, and pending merges.
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
386
    Examples::
387
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
388
      revid:aaaa@bbbb-123456789 -> Select revision 'aaaa@bbbb-123456789'
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
389
    """
390
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
391
    prefix = 'revid:'
392
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
393
    def _match_on(self, branch, revs, need_revno=True):
2325.2.5 by Marien Zwart
Call osutils.safe_revision_id instead of duplicating it.
394
        # self.spec comes straight from parsing the command line arguments,
395
        # so we expect it to be a Unicode string. Switch it to the internal
396
        # representation.
397
        revision_id = osutils.safe_revision_id(self.spec, warn=False)
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
398
        if need_revno:
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
399
            try:
400
                revno = branch.revision_id_to_revno(revision_id)
401
            except errors.NoSuchRevision:
402
                revno = None
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
403
        else:
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
404
            revno = None
405
        return RevisionInfo(branch, revno, revision_id)
3060.3.3 by Lukáš Lalinský
Make RevisionSpec_revid and RevisionSpec_revno not load the whole revision history.
406
407
    def in_branch(self, branch, need_revno=True):
408
        # Same as RevisionSpec.in_history, but without history loading.
409
        return self._match_on(branch, None, need_revno)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
410
411
SPEC_TYPES.append(RevisionSpec_revid)
412
413
414
class RevisionSpec_last(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
415
    """Selects the nth revision from the end."""
416
417
    help_txt = """Selects the nth revision from the end.
2023.1.1 by ghigo
add topics help
418
419
    Supply a positive number to get the nth revision from the end.
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
420
    This is the same as supplying negative numbers to the 'revno:' spec.
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
421
    Examples::
422
2023.1.1 by ghigo
add topics help
423
      last:1        -> return the last revision
424
      last:3        -> return the revision 2 before the end.
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
425
    """
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
426
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
427
    prefix = 'last:'
428
429
    def _match_on(self, branch, revs):
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
430
        last_revno, last_revision_id = branch.last_revision_info()
431
1948.4.9 by John Arbash Meinel
Cleanup and test last:
432
        if self.spec == '':
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
433
            if not last_revno:
1948.4.26 by John Arbash Meinel
Get rid of direct imports of exceptions
434
                raise errors.NoCommits(branch)
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
435
            return RevisionInfo(branch, last_revno, last_revision_id)
1948.4.9 by John Arbash Meinel
Cleanup and test last:
436
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
437
        try:
438
            offset = int(self.spec)
1948.4.9 by John Arbash Meinel
Cleanup and test last:
439
        except ValueError, e:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
440
            raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
1948.4.9 by John Arbash Meinel
Cleanup and test last:
441
442
        if offset <= 0:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
443
            raise errors.InvalidRevisionSpec(self.user_spec, branch,
1948.4.9 by John Arbash Meinel
Cleanup and test last:
444
                                             'you must supply a positive value')
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
445
446
        revno = last_revno - offset + 1
1948.4.9 by John Arbash Meinel
Cleanup and test last:
447
        try:
448
            revision_id = branch.get_rev_id(revno, revs)
449
        except errors.NoSuchRevision:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
450
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
1948.4.9 by John Arbash Meinel
Cleanup and test last:
451
        return RevisionInfo(branch, revno, revision_id)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
452
3060.3.2 by Lukáš Lalinský
Make RevisionSpec_last not load the whole history.
453
    def in_branch(self, branch, need_revno=True):
454
        # Same as RevisionSpec.in_history, but without history loading.
455
        return self._match_on(branch, None)
456
457
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
458
SPEC_TYPES.append(RevisionSpec_last)
459
460
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
461
class RevisionSpec_before(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
462
    """Selects the parent of the revision specified."""
463
464
    help_txt = """Selects the parent of the revision specified.
2023.1.1 by ghigo
add topics help
465
466
    Supply any revision spec to return the parent of that revision.
467
    It is an error to request the parent of the null revision (before:0).
468
    This is mostly useful when inspecting revisions that are not in the
469
    revision history of a branch.
470
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
471
    Examples::
472
2023.1.1 by ghigo
add topics help
473
      before:1913    -> Return the parent of revno 1913 (revno 1912)
474
      before:revid:aaaa@bbbb-1234567890  -> return the parent of revision
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
475
                                            aaaa@bbbb-1234567890
2023.1.1 by ghigo
add topics help
476
      bzr diff -r before:revid:aaaa..revid:aaaa
477
            -> Find the changes between revision 'aaaa' and its parent.
478
               (what changes did 'aaaa' introduce)
479
    """
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
480
481
    prefix = 'before:'
482
    
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
483
    def _match_on(self, branch, revs, need_revno=True, in_branch=False):
484
        revspec = RevisionSpec.from_string(self.spec)
485
        if in_branch:
486
            r = revspec.in_branch(branch, need_revno)
487
        else:
488
            r = revspec._match_on(branch, revs)
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
489
        if r.revno == 0:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
490
            raise errors.InvalidRevisionSpec(self.user_spec, branch,
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
491
                                         'cannot go before the null: revision')
492
        if r.revno is None:
493
            # We need to use the repository history here
494
            rev = branch.repository.get_revision(r.rev_id)
495
            if not rev.parent_ids:
496
                revno = 0
2598.5.10 by Aaron Bentley
Return NULL_REVISION instead of None for the null revision
497
                revision_id = revision.NULL_REVISION
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
498
            else:
499
                revision_id = rev.parent_ids[0]
3060.3.6 by Lukáš Lalinský
Implement partial history cache in BzrBranch6.
500
                if need_revno:
501
                    try:
502
                        revno = branch.revision_id_to_revno(revision_id)
503
                    except errors.NoSuchRevision:
504
                        revno = None
505
                else:
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
506
                    revno = None
507
        else:
508
            revno = r.revno - 1
509
            try:
510
                revision_id = branch.get_rev_id(revno, revs)
1948.4.26 by John Arbash Meinel
Get rid of direct imports of exceptions
511
            except errors.NoSuchRevision:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
512
                raise errors.InvalidRevisionSpec(self.user_spec,
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
513
                                                 branch)
514
        return RevisionInfo(branch, revno, revision_id)
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
515
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
516
    def in_branch(self, branch, need_revno=True):
517
        return self._match_on(branch, None, need_revno, True)
518
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
519
SPEC_TYPES.append(RevisionSpec_before)
520
521
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
522
class RevisionSpec_tag(RevisionSpec):
2220.2.3 by Martin Pool
Add tag: revision namespace.
523
    """Select a revision identified by tag name"""
524
525
    help_txt = """Selects a revision identified by a tag name.
526
1551.10.34 by Aaron Bentley
Fix tag: help
527
    Tags are stored in the branch and created by the 'tag' command.
2220.2.3 by Martin Pool
Add tag: revision namespace.
528
    """
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
529
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
530
    prefix = 'tag:'
531
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
532
    def _match_on(self, branch, revs, need_revno=True):
2220.2.3 by Martin Pool
Add tag: revision namespace.
533
        # Can raise tags not supported, NoSuchTag, etc
3060.3.5 by Lukáš Lalinský
Add support for in_branch for the remaining RevisionSpec subclasses.
534
        revision_id = branch.tags.lookup_tag(self.spec)
535
        if need_revno:
536
            try:
537
                revno = branch.revision_id_to_revno(revision_id)
538
            except errors.NoSuchRevision:
539
                revno = None
540
        else:
541
            revno = None
542
        return RevisionInfo(branch, revno, revision_id)
543
544
    def in_branch(self, branch, need_revno=True):
545
        return self._match_on(branch, None, need_revno)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
546
547
SPEC_TYPES.append(RevisionSpec_tag)
548
549
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
550
class _RevListToTimestamps(object):
551
    """This takes a list of revisions, and allows you to bisect by date"""
552
553
    __slots__ = ['revs', 'branch']
554
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
555
    def __init__(self, revs, branch):
556
        self.revs = revs
557
        self.branch = branch
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
558
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
559
    def __getitem__(self, index):
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
560
        """Get the date of the index'd item"""
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
561
        r = self.branch.repository.get_revision(self.revs[index])
562
        # TODO: Handle timezone.
563
        return datetime.datetime.fromtimestamp(r.timestamp)
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
564
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
565
    def __len__(self):
566
        return len(self.revs)
567
568
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
569
class RevisionSpec_date(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
570
    """Selects a revision on the basis of a datestamp."""
571
572
    help_txt = """Selects a revision on the basis of a datestamp.
2023.1.1 by ghigo
add topics help
573
574
    Supply a datestamp to select the first revision that matches the date.
575
    Date can be 'yesterday', 'today', 'tomorrow' or a YYYY-MM-DD string.
576
    Matches the first entry after a given date (either at midnight or
577
    at a specified time).
578
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
579
    One way to display all the changes since yesterday would be::
2666.1.5 by Ian Clatworthy
Incorporate feedback from Alex B. & James W.
580
2023.1.1 by ghigo
add topics help
581
        bzr log -r date:yesterday..-1
582
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
583
    Examples::
584
2023.1.1 by ghigo
add topics help
585
      date:yesterday            -> select the first revision since yesterday
586
      date:2006-08-14,17:10:14  -> select the first revision after
587
                                   August 14th, 2006 at 5:10pm.
588
    """    
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
589
    prefix = 'date:'
590
    _date_re = re.compile(
591
            r'(?P<date>(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d))?'
592
            r'(,|T)?\s*'
593
            r'(?P<time>(?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d))?)?'
594
        )
595
596
    def _match_on(self, branch, revs):
2023.1.1 by ghigo
add topics help
597
        """Spec for date revisions:
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
598
          date:value
599
          value can be 'yesterday', 'today', 'tomorrow' or a YYYY-MM-DD string.
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
600
          matches the first entry after a given date (either at midnight or
601
          at a specified time).
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
602
        """
2070.4.3 by John Arbash Meinel
code and doc cleanup
603
        #  XXX: This doesn't actually work
604
        #  So the proper way of saying 'give me all entries for today' is:
605
        #      -r date:yesterday..date:today
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
606
        today = datetime.datetime.fromordinal(datetime.date.today().toordinal())
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
607
        if self.spec.lower() == 'yesterday':
608
            dt = today - datetime.timedelta(days=1)
609
        elif self.spec.lower() == 'today':
610
            dt = today
611
        elif self.spec.lower() == 'tomorrow':
612
            dt = today + datetime.timedelta(days=1)
613
        else:
614
            m = self._date_re.match(self.spec)
615
            if not m or (not m.group('date') and not m.group('time')):
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
616
                raise errors.InvalidRevisionSpec(self.user_spec,
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
617
                                                 branch, 'invalid date')
618
619
            try:
620
                if m.group('date'):
621
                    year = int(m.group('year'))
622
                    month = int(m.group('month'))
623
                    day = int(m.group('day'))
624
                else:
625
                    year = today.year
626
                    month = today.month
627
                    day = today.day
628
629
                if m.group('time'):
630
                    hour = int(m.group('hour'))
631
                    minute = int(m.group('minute'))
632
                    if m.group('second'):
633
                        second = int(m.group('second'))
634
                    else:
635
                        second = 0
636
                else:
637
                    hour, minute, second = 0,0,0
638
            except ValueError:
1948.4.27 by John Arbash Meinel
Deprecate calling RevisionSpec directly, and instead use a helper function. Also merge the old RevisionSpec_int class into RevisionSpec_revno
639
                raise errors.InvalidRevisionSpec(self.user_spec,
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
640
                                                 branch, 'invalid date')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
641
642
            dt = datetime.datetime(year=year, month=month, day=day,
643
                    hour=hour, minute=minute, second=second)
1704.2.27 by Martin Pool
Run bisection search for revision date with lock held. (Robert Widhopf-Frenk)
644
        branch.lock_read()
645
        try:
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
646
            rev = bisect.bisect(_RevListToTimestamps(revs, branch), dt)
1704.2.27 by Martin Pool
Run bisection search for revision date with lock held. (Robert Widhopf-Frenk)
647
        finally:
648
            branch.unlock()
1688.2.2 by Guillaume Pinot
Binary search for 'date:' revision.
649
        if rev == len(revs):
650
            return RevisionInfo(branch, None)
651
        else:
652
            return RevisionInfo(branch, rev + 1)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
653
654
SPEC_TYPES.append(RevisionSpec_date)
655
656
657
class RevisionSpec_ancestor(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
658
    """Selects a common ancestor with a second branch."""
659
660
    help_txt = """Selects a common ancestor with a second branch.
2023.1.1 by ghigo
add topics help
661
662
    Supply the path to a branch to select the common ancestor.
663
664
    The common ancestor is the last revision that existed in both
665
    branches. Usually this is the branch point, but it could also be
666
    a revision that was merged.
667
668
    This is frequently used with 'diff' to return all of the changes
669
    that your branch introduces, while excluding the changes that you
670
    have not merged from the remote branch.
671
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
672
    Examples::
673
2023.1.1 by ghigo
add topics help
674
      ancestor:/path/to/branch
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
675
      $ bzr diff -r ancestor:../../mainline/branch
2023.1.1 by ghigo
add topics help
676
    """
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
677
    prefix = 'ancestor:'
678
679
    def _match_on(self, branch, revs):
1551.10.33 by Aaron Bentley
Updates from review
680
        trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
681
        return self._find_revision_info(branch, self.spec)
682
683
    @staticmethod
684
    def _find_revision_info(branch, other_location):
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
685
        from bzrlib.branch import Branch
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
686
1551.10.33 by Aaron Bentley
Updates from review
687
        other_branch = Branch.open(other_location)
1390 by Robert Collins
pair programming worx... merge integration and weave
688
        revision_a = branch.last_revision()
689
        revision_b = other_branch.last_revision()
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
690
        for r, b in ((revision_a, branch), (revision_b, other_branch)):
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
691
            if r in (None, revision.NULL_REVISION):
1948.4.26 by John Arbash Meinel
Get rid of direct imports of exceptions
692
                raise errors.NoCommits(b)
3010.1.12 by Robert Collins
Lock branches while doing revision specification lookups.
693
        branch.lock_read()
694
        other_branch.lock_read()
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
695
        try:
3010.1.12 by Robert Collins
Lock branches while doing revision specification lookups.
696
            graph = branch.repository.get_graph(other_branch.repository)
697
            revision_a = revision.ensure_null(revision_a)
698
            revision_b = revision.ensure_null(revision_b)
699
            if revision.NULL_REVISION in (revision_a, revision_b):
700
                rev_id = revision.NULL_REVISION
701
            else:
702
                rev_id = graph.find_unique_lca(revision_a, revision_b)
703
                if rev_id == revision.NULL_REVISION:
704
                    raise errors.NoCommonAncestor(revision_a, revision_b)
705
            try:
706
                revno = branch.revision_id_to_revno(rev_id)
707
            except errors.NoSuchRevision:
708
                revno = None
709
            return RevisionInfo(branch, revno, rev_id)
710
        finally:
711
            branch.unlock()
712
            other_branch.unlock()
1551.10.33 by Aaron Bentley
Updates from review
713
714
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
715
SPEC_TYPES.append(RevisionSpec_ancestor)
1432 by Robert Collins
branch: namespace
716
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
717
1432 by Robert Collins
branch: namespace
718
class RevisionSpec_branch(RevisionSpec):
2070.4.14 by John Arbash Meinel
Switch revisionspec to use the help defined as help_txt rather than the doc string
719
    """Selects the last revision of a specified branch."""
720
721
    help_txt = """Selects the last revision of a specified branch.
2023.1.1 by ghigo
add topics help
722
723
    Supply the path to a branch to select its last revision.
724
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
725
    Examples::
726
2023.1.1 by ghigo
add topics help
727
      branch:/path/to/branch
1432 by Robert Collins
branch: namespace
728
    """
729
    prefix = 'branch:'
730
731
    def _match_on(self, branch, revs):
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
732
        from bzrlib.branch import Branch
733
        other_branch = Branch.open(self.spec)
1432 by Robert Collins
branch: namespace
734
        revision_b = other_branch.last_revision()
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
735
        if revision_b in (None, revision.NULL_REVISION):
1948.4.26 by John Arbash Meinel
Get rid of direct imports of exceptions
736
            raise errors.NoCommits(other_branch)
1432 by Robert Collins
branch: namespace
737
        # pull in the remote revisions so we can diff
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
738
        branch.fetch(other_branch, revision_b)
1432 by Robert Collins
branch: namespace
739
        try:
740
            revno = branch.revision_id_to_revno(revision_b)
1948.4.26 by John Arbash Meinel
Get rid of direct imports of exceptions
741
        except errors.NoSuchRevision:
1432 by Robert Collins
branch: namespace
742
            revno = None
743
        return RevisionInfo(branch, revno, revision_b)
744
        
745
SPEC_TYPES.append(RevisionSpec_branch)
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
746
747
1551.10.33 by Aaron Bentley
Updates from review
748
class RevisionSpec_submit(RevisionSpec_ancestor):
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
749
    """Selects a common ancestor with a submit branch."""
750
751
    help_txt = """Selects a common ancestor with the submit branch.
752
753
    Diffing against this shows all the changes that were made in this branch,
754
    and is a good predictor of what merge will do.  The submit branch is
755
    used by the bundle and merge directive comands.  If no submit branch
756
    is specified, the parent branch is used instead.
757
758
    The common ancestor is the last revision that existed in both
759
    branches. Usually this is the branch point, but it could also be
760
    a revision that was merged.
761
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
762
    Examples::
763
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
764
      $ bzr diff -r submit:
765
    """
1551.10.33 by Aaron Bentley
Updates from review
766
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
767
    prefix = 'submit:'
768
769
    def _match_on(self, branch, revs):
770
        trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
771
        submit_location = branch.get_submit_branch()
1551.10.35 by Aaron Bentley
Add note about which branch is selected by submit:
772
        location_type = 'submit branch'
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
773
        if submit_location is None:
774
            submit_location = branch.get_parent()
1551.10.35 by Aaron Bentley
Add note about which branch is selected by submit:
775
            location_type = 'parent branch'
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
776
        if submit_location is None:
777
            raise errors.NoSubmitBranch(branch)
1551.10.35 by Aaron Bentley
Add note about which branch is selected by submit:
778
        trace.note('Using %s %s', location_type, submit_location)
1551.10.33 by Aaron Bentley
Updates from review
779
        return self._find_revision_info(branch, submit_location)
780
1551.10.35 by Aaron Bentley
Add note about which branch is selected by submit:
781
1551.10.33 by Aaron Bentley
Updates from review
782
SPEC_TYPES.append(RevisionSpec_submit)