155
155
self.cache_root = cache_root
158
class _Branch(Branch):
158
cfg = self.tree_config()
159
return cfg.get_option(u"nickname", default=self.base.split('/')[-1])
161
def _set_nick(self, nick):
162
cfg = self.tree_config()
163
cfg.set_option(nick, "nickname")
164
assert cfg.get_option("nickname") == nick
166
nick = property(_get_nick, _set_nick)
168
def push_stores(self, branch_to):
169
"""Copy the content of this branches store to branch_to."""
170
raise NotImplementedError('push_stores is abstract')
172
def get_transaction(self):
173
"""Return the current active transaction.
175
If no transaction is active, this returns a passthrough object
176
for which all data is immediately flushed and no caching happens.
178
raise NotImplementedError('get_transaction is abstract')
180
def lock_write(self):
181
raise NotImplementedError('lock_write is abstract')
184
raise NotImplementedError('lock_read is abstract')
187
raise NotImplementedError('unlock is abstract')
189
def abspath(self, name):
190
"""Return absolute filename for something in the branch
192
XXX: Robert Collins 20051017 what is this used for? why is it a branch
193
method and not a tree method.
195
raise NotImplementedError('abspath is abstract')
197
def controlfilename(self, file_or_path):
198
"""Return location relative to branch."""
199
raise NotImplementedError('controlfilename is abstract')
201
def controlfile(self, file_or_path, mode='r'):
202
"""Open a control file for this branch.
204
There are two classes of file in the control directory: text
205
and binary. binary files are untranslated byte streams. Text
206
control files are stored with Unix newlines and in UTF-8, even
207
if the platform or locale defaults are different.
209
Controlfiles should almost never be opened in write mode but
210
rather should be atomically copied and replaced using atomicfile.
212
raise NotImplementedError('controlfile is abstract')
214
def put_controlfile(self, path, f, encode=True):
215
"""Write an entry as a controlfile.
217
:param path: The path to put the file, relative to the .bzr control
219
:param f: A file-like or string object whose contents should be copied.
220
:param encode: If true, encode the contents as utf-8
222
raise NotImplementedError('put_controlfile is abstract')
224
def put_controlfiles(self, files, encode=True):
225
"""Write several entries as controlfiles.
227
:param files: A list of [(path, file)] pairs, where the path is the directory
228
underneath the bzr control directory
229
:param encode: If true, encode the contents as utf-8
231
raise NotImplementedError('put_controlfiles is abstract')
233
def get_root_id(self):
234
"""Return the id of this branches root"""
235
raise NotImplementedError('get_root_id is abstract')
237
def set_root_id(self, file_id):
238
raise NotImplementedError('set_root_id is abstract')
240
def add(self, files, ids=None):
241
"""Make files versioned.
243
Note that the command line normally calls smart_add instead,
244
which can automatically recurse.
246
This puts the files in the Added state, so that they will be
247
recorded by the next commit.
250
List of paths to add, relative to the base of the tree.
253
If set, use these instead of automatically generated ids.
254
Must be the same length as the list of files, but may
255
contain None for ids that are to be autogenerated.
257
TODO: Perhaps have an option to add the ids even if the files do
260
TODO: Perhaps yield the ids and paths as they're added.
262
raise NotImplementedError('add is abstract')
264
def print_file(self, file, revno):
265
"""Print `file` to stdout."""
266
raise NotImplementedError('print_file is abstract')
269
"""Return all unknown files.
271
These are files in the working directory that are not versioned or
272
control files or ignored.
274
>>> from bzrlib.workingtree import WorkingTree
275
>>> b = ScratchBranch(files=['foo', 'foo~'])
276
>>> map(str, b.unknowns())
279
>>> list(b.unknowns())
281
>>> WorkingTree(b.base, b).remove('foo')
282
>>> list(b.unknowns())
285
raise NotImplementedError('unknowns is abstract')
287
def append_revision(self, *revision_ids):
288
raise NotImplementedError('append_revision is abstract')
290
def set_revision_history(self, rev_history):
291
raise NotImplementedError('set_revision_history is abstract')
293
def has_revision(self, revision_id):
294
"""True if this branch has a copy of the revision.
296
This does not necessarily imply the revision is merge
297
or on the mainline."""
298
raise NotImplementedError('has_revision is abstract')
300
def get_revision_xml_file(self, revision_id):
301
"""Return XML file object for revision object."""
302
raise NotImplementedError('get_revision_xml_file is abstract')
304
def get_revision_xml(self, revision_id):
305
raise NotImplementedError('get_revision_xml is abstract')
307
def get_revision(self, revision_id):
308
"""Return the Revision object for a named revision"""
309
raise NotImplementedError('get_revision is abstract')
311
def get_revision_delta(self, revno):
312
"""Return the delta for one revision.
314
The delta is relative to its mainline predecessor, or the
315
empty tree for revision 1.
317
assert isinstance(revno, int)
318
rh = self.revision_history()
319
if not (1 <= revno <= len(rh)):
320
raise InvalidRevisionNumber(revno)
322
# revno is 1-based; list is 0-based
324
new_tree = self.revision_tree(rh[revno-1])
326
old_tree = EmptyTree()
328
old_tree = self.revision_tree(rh[revno-2])
330
return compare_trees(old_tree, new_tree)
332
def get_revision_sha1(self, revision_id):
333
"""Hash the stored value of a revision, and return it."""
334
raise NotImplementedError('get_revision_sha1 is abstract')
336
def get_ancestry(self, revision_id):
337
"""Return a list of revision-ids integrated by a revision.
339
This currently returns a list, but the ordering is not guaranteed:
342
raise NotImplementedError('get_ancestry is abstract')
344
def get_inventory(self, revision_id):
345
"""Get Inventory object by hash."""
346
raise NotImplementedError('get_inventory is abstract')
348
def get_inventory_xml(self, revision_id):
349
"""Get inventory XML as a file object."""
350
raise NotImplementedError('get_inventory_xml is abstract')
352
def get_inventory_sha1(self, revision_id):
353
"""Return the sha1 hash of the inventory entry."""
354
raise NotImplementedError('get_inventory_sha1 is abstract')
356
def get_revision_inventory(self, revision_id):
357
"""Return inventory of a past revision."""
358
raise NotImplementedError('get_revision_inventory is abstract')
360
def revision_history(self):
361
"""Return sequence of revision hashes on to this branch."""
362
raise NotImplementedError('revision_history is abstract')
365
"""Return current revision number for this branch.
367
That is equivalent to the number of revisions committed to
370
return len(self.revision_history())
372
def last_revision(self):
373
"""Return last patch hash, or None if no history."""
374
ph = self.revision_history()
380
def missing_revisions(self, other, stop_revision=None, other_history=None):
381
"""Return a list of new revisions that would perfectly fit.
383
If self and other have not diverged, return a list of the revisions
384
present in other, but missing from self.
386
>>> from bzrlib.commit import commit
387
>>> bzrlib.trace.silent = True
388
>>> br1 = ScratchBranch()
389
>>> br2 = ScratchBranch()
390
>>> br1.missing_revisions(br2)
392
>>> commit(br2, "lala!", rev_id="REVISION-ID-1")
393
>>> br1.missing_revisions(br2)
395
>>> br2.missing_revisions(br1)
397
>>> commit(br1, "lala!", rev_id="REVISION-ID-1")
398
>>> br1.missing_revisions(br2)
400
>>> commit(br2, "lala!", rev_id="REVISION-ID-2A")
401
>>> br1.missing_revisions(br2)
403
>>> commit(br1, "lala!", rev_id="REVISION-ID-2B")
404
>>> br1.missing_revisions(br2)
405
Traceback (most recent call last):
406
DivergedBranches: These branches have diverged.
408
self_history = self.revision_history()
409
self_len = len(self_history)
410
if other_history is None:
411
other_history = other.revision_history()
412
other_len = len(other_history)
413
common_index = min(self_len, other_len) -1
414
if common_index >= 0 and \
415
self_history[common_index] != other_history[common_index]:
416
raise DivergedBranches(self, other)
418
if stop_revision is None:
419
stop_revision = other_len
421
assert isinstance(stop_revision, int)
422
if stop_revision > other_len:
423
raise bzrlib.errors.NoSuchRevision(self, stop_revision)
424
return other_history[self_len:stop_revision]
426
def update_revisions(self, other, stop_revision=None, other_history=None):
427
"""Pull in new perfect-fit revisions.
429
:param other: Another Branch to pull from
430
:param stop_revision: Updated until the given revision
431
:param other_history: Alternative history to other.revision_history()
434
raise NotImplementedError('update_revisions is abstract')
436
def pullable_revisions(self, other, stop_revision, other_history=None):
437
raise NotImplementedError('pullable_revisions is abstract')
439
def revision_id_to_revno(self, revision_id):
440
"""Given a revision id, return its revno"""
441
if revision_id is None:
443
history = self.revision_history()
445
return history.index(revision_id) + 1
447
raise bzrlib.errors.NoSuchRevision(self, revision_id)
449
def get_rev_id(self, revno, history=None):
450
"""Find the revision id of the specified revno."""
454
history = self.revision_history()
455
elif revno <= 0 or revno > len(history):
456
raise bzrlib.errors.NoSuchRevision(self, revno)
457
return history[revno - 1]
459
def revision_tree(self, revision_id):
460
"""Return Tree for a revision on this branch.
462
`revision_id` may be None for the null revision, in which case
463
an `EmptyTree` is returned."""
464
raise NotImplementedError('revision_tree is abstract')
466
def working_tree(self):
467
"""Return a `Tree` for the working copy."""
468
raise NotImplementedError('working_tree is abstract')
470
def pull(self, source, overwrite=False):
471
raise NotImplementedError('pull is abstract')
473
def basis_tree(self):
474
"""Return `Tree` object for last revision.
476
If there are no revisions yet, return an `EmptyTree`.
478
return self.revision_tree(self.last_revision())
480
def rename_one(self, from_rel, to_rel):
483
This can change the directory or the filename or both.
485
raise NotImplementedError('rename_one is abstract')
487
def move(self, from_paths, to_name):
490
to_name must exist as a versioned directory.
492
If to_name exists and is a directory, the files are moved into
493
it, keeping their old names. If it is a directory,
495
Note that to_name is only the last component of the new name;
496
this doesn't change the directory.
498
This returns a list of (from_path, to_path) pairs for each
501
raise NotImplementedError('move is abstract')
503
def revert(self, filenames, old_tree=None, backups=True):
504
"""Restore selected files to the versions from a previous tree.
507
If true (default) backups are made of files before
510
raise NotImplementedError('revert is abstract')
512
def pending_merges(self):
513
"""Return a list of pending merges.
515
These are revisions that have been merged into the working
516
directory but not yet committed.
518
raise NotImplementedError('pending_merges is abstract')
520
def add_pending_merge(self, *revision_ids):
521
# TODO: Perhaps should check at this point that the
522
# history of the revision is actually present?
523
raise NotImplementedError('add_pending_merge is abstract')
525
def set_pending_merges(self, rev_list):
526
raise NotImplementedError('set_pending_merges is abstract')
528
def get_parent(self):
529
"""Return the parent location of the branch.
531
This is the default location for push/pull/missing. The usual
532
pattern is that the user can override it by specifying a
535
raise NotImplementedError('get_parent is abstract')
537
def get_push_location(self):
538
"""Return the None or the location to push this branch to."""
539
raise NotImplementedError('get_push_location is abstract')
541
def set_push_location(self, location):
542
"""Set a new push location for this branch."""
543
raise NotImplementedError('set_push_location is abstract')
545
def set_parent(self, url):
546
raise NotImplementedError('set_parent is abstract')
548
def check_revno(self, revno):
550
Check whether a revno corresponds to any revision.
551
Zero (the NULL revision) is considered valid.
554
self.check_real_revno(revno)
556
def check_real_revno(self, revno):
558
Check whether a revno corresponds to a real revision.
559
Zero (the NULL revision) is considered invalid
561
if revno < 1 or revno > self.revno():
562
raise InvalidRevisionNumber(revno)
564
def sign_revision(self, revision_id, gpg_strategy):
565
raise NotImplementedError('sign_revision is abstract')
567
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
568
raise NotImplementedError('store_revision_signature is abstract')
570
class BzrBranch(Branch):
159
571
"""A branch stored in the actual filesystem.
161
573
Note that it's "local" in the context of the filesystem; it doesn't
776
1110
# transaction.register_clean(history, precious=True)
777
1111
return list(history)
780
"""Return current revision number for this branch.
782
That is equivalent to the number of revisions committed to
785
return len(self.revision_history())
787
def last_revision(self):
788
"""Return last patch hash, or None if no history.
790
ph = self.revision_history()
796
def missing_revisions(self, other, stop_revision=None, other_history=None):
797
"""Return a list of new revisions that would perfectly fit.
799
If self and other have not diverged, return a list of the revisions
800
present in other, but missing from self.
802
>>> from bzrlib.commit import commit
803
>>> bzrlib.trace.silent = True
804
>>> br1 = ScratchBranch()
805
>>> br2 = ScratchBranch()
806
>>> br1.missing_revisions(br2)
808
>>> commit(br2, "lala!", rev_id="REVISION-ID-1")
809
>>> br1.missing_revisions(br2)
811
>>> br2.missing_revisions(br1)
813
>>> commit(br1, "lala!", rev_id="REVISION-ID-1")
814
>>> br1.missing_revisions(br2)
816
>>> commit(br2, "lala!", rev_id="REVISION-ID-2A")
817
>>> br1.missing_revisions(br2)
819
>>> commit(br1, "lala!", rev_id="REVISION-ID-2B")
820
>>> br1.missing_revisions(br2)
821
Traceback (most recent call last):
822
DivergedBranches: These branches have diverged.
824
self_history = self.revision_history()
825
self_len = len(self_history)
826
if other_history is None:
827
other_history = other.revision_history()
828
other_len = len(other_history)
829
common_index = min(self_len, other_len) -1
830
if common_index >= 0 and \
831
self_history[common_index] != other_history[common_index]:
832
raise DivergedBranches(self, other)
834
if stop_revision is None:
835
stop_revision = other_len
837
assert isinstance(stop_revision, int)
838
if stop_revision > other_len:
839
raise bzrlib.errors.NoSuchRevision(self, stop_revision)
840
return other_history[self_len:stop_revision]
842
1113
def update_revisions(self, other, stop_revision=None, other_history=None):
843
"""Pull in new perfect-fit revisions.
845
:param other: Another Branch to pull from
846
:param stop_revision: Updated until the given revision
847
:param other_history: Alternative history to other.revision_history()
1114
"""See Branch.update_revisions."""
850
1115
from bzrlib.fetch import greedy_fetch
851
1116
if stop_revision is None:
852
1117
if other_history is not None: