97
_default_initializer = None
98
"""The default initializer for making new branches."""
99
"""Construct the current default format branch in a_bzrdir.
101
This creates the current default BzrDir format, and if that
102
supports multiple Branch formats, then the default Branch format
105
print "not usable until we have repositories"
106
raise NotImplementedError("not usable right now")
107
return bzrdir.BzrDir.create(base)
100
109
def __init__(self, *ignored, **ignored_too):
101
110
raise NotImplementedError('The Branch class is abstract')
113
@deprecated_method(zero_eight)
104
114
def open_downlevel(base):
105
115
"""Open a branch which may be of an old format."""
106
116
return Branch.open(base, _unsupported=True)
109
119
def open(base, _unsupported=False):
110
"""Open an existing branch, rooted at 'base' (url)
112
_unsupported is a private parameter to the Branch class.
120
"""Open the repository rooted at base.
122
For instance, if the repository is at URL/.bzr/repository,
123
Repository.open(URL) -> a Repository instance.
114
t = get_transport(base)
115
mutter("trying to open %r with transport %r", base, t)
116
format = BzrBranchFormat.find_format(t)
117
if not _unsupported and not format.is_supported():
118
# see open_downlevel to open legacy branches.
119
raise errors.UnsupportedFormatError(
120
'sorry, branch format %s not supported' % format,
121
['use a different bzr version',
122
'or remove the .bzr directory'
123
' and "bzr init" again'])
124
return format.open(t)
125
control = bzrdir.BzrDir.open(base, _unsupported)
126
return control.open_branch(_unsupported)
127
129
def open_containing(url):
403
369
if revno < 1 or revno > self.revno():
404
370
raise InvalidRevisionNumber(revno)
406
def clone(self, to_location, revision=None, basis_branch=None, to_branch_type=None):
407
"""Copy this branch into the existing directory to_location.
409
Returns the newly created branch object.
412
If not None, only revisions up to this point will be copied.
413
The head of the new branch will be that revision. Must be a
416
to_location -- The destination directory; must either exist and be
417
empty, or not exist, in which case it is created.
420
A local branch to copy revisions from, related to this branch.
421
This is used when branching from a remote (slow) branch, and we have
422
a local branch that might contain some relevant revisions.
425
Branch type of destination branch
427
from bzrlib.workingtree import WorkingTree
428
assert isinstance(to_location, basestring)
429
if not bzrlib.osutils.lexists(to_location):
430
os.mkdir(to_location)
431
if to_branch_type is None:
432
to_branch_type = BzrBranch
433
# FIXME use a branch format here
434
br_to = to_branch_type.initialize(to_location)
435
mutter("copy branch from %s to %s", self, br_to)
436
if basis_branch is not None:
437
basis_branch.push_stores(br_to)
439
revision = self.last_revision()
440
br_to.update_revisions(self, stop_revision=revision)
441
br_to.set_parent(self.base)
442
WorkingTree.create(br_to, to_location).set_root_id(self.get_root_id())
446
def fileid_involved_between_revs(self, from_revid, to_revid):
447
""" This function returns the file_id(s) involved in the
448
changes between the from_revid revision and the to_revid
451
raise NotImplementedError('fileid_involved_between_revs is abstract')
453
def fileid_involved(self, last_revid=None):
454
""" This function returns the file_id(s) involved in the
455
changes up to the revision last_revid
456
If no parametr is passed, then all file_id[s] present in the
457
repository are returned
459
raise NotImplementedError('fileid_involved is abstract')
461
def fileid_involved_by_set(self, changes):
462
""" This function returns the file_id(s) involved in the
463
changes present in the set 'changes'
465
raise NotImplementedError('fileid_involved_by_set is abstract')
467
def fileid_involved_between_revs(self, from_revid, to_revid):
468
""" This function returns the file_id(s) involved in the
469
changes between the from_revid revision and the to_revid
472
raise NotImplementedError('fileid_involved_between_revs is abstract')
474
def fileid_involved(self, last_revid=None):
475
""" This function returns the file_id(s) involved in the
476
changes up to the revision last_revid
477
If no parametr is passed, then all file_id[s] present in the
478
repository are returned
480
raise NotImplementedError('fileid_involved is abstract')
482
def fileid_involved_by_set(self, changes):
483
""" This function returns the file_id(s) involved in the
484
changes present in the set 'changes'
486
raise NotImplementedError('fileid_involved_by_set is abstract')
488
class BzrBranchFormat(object):
373
def clone(self, *args, **kwargs):
374
"""Clone this branch into to_bzrdir preserving all semantic values.
376
revision_id: if not None, the revision history in the new branch will
377
be truncated to end with revision_id.
379
# for API compatability, until 0.8 releases we provide the old api:
380
# def clone(self, to_location, revision=None, basis_branch=None, to_branch_format=None):
381
# after 0.8 releases, the *args and **kwargs should be changed:
382
# def clone(self, to_bzrdir, revision_id=None):
383
if (kwargs.get('to_location', None) or
384
kwargs.get('revision', None) or
385
kwargs.get('basis_branch', None) or
386
(len(args) and isinstance(args[0], basestring))):
387
# backwards compatability api:
388
warn("Branch.clone() has been deprecated for BzrDir.clone() from"
389
" bzrlib 0.8.", DeprecationWarning, stacklevel=3)
392
basis_branch = args[2]
394
basis_branch = kwargs.get('basis_branch', None)
396
basis = basis_branch.bzrdir
401
revision_id = args[1]
403
revision_id = kwargs.get('revision', None)
408
# no default to raise if not provided.
409
url = kwargs.get('to_location')
410
return self.bzrdir.clone(url,
411
revision_id=revision_id,
412
basis=basis).open_branch()
414
# generate args by hand
416
revision_id = args[1]
418
revision_id = kwargs.get('revision_id', None)
422
# no default to raise if not provided.
423
to_bzrdir = kwargs.get('to_bzrdir')
424
result = self._format.initialize(to_bzrdir)
425
self.copy_content_into(result, revision_id=revision_id)
429
def sprout(self, to_bzrdir, revision_id=None):
430
"""Create a new line of development from the branch, into to_bzrdir.
432
revision_id: if not None, the revision history in the new branch will
433
be truncated to end with revision_id.
435
result = self._format.initialize(to_bzrdir)
436
self.copy_content_into(result, revision_id=revision_id)
437
result.set_parent(self.bzrdir.root_transport.base)
441
def copy_content_into(self, destination, revision_id=None):
442
"""Copy the content of self into destination.
444
revision_id: if not None, the revision history in the new branch will
445
be truncated to end with revision_id.
447
new_history = self.revision_history()
448
if revision_id is not None:
450
new_history = new_history[:new_history.index(revision_id) + 1]
452
rev = self.repository.get_revision(revision_id)
453
new_history = rev.get_history(self.repository)[1:]
454
destination.set_revision_history(new_history)
455
parent = self.get_parent()
457
destination.set_parent(parent)
460
class BranchFormat(object):
489
461
"""An encapsulation of the initialization and open routines for a format.
491
463
Formats provide three things:
545
526
return dir_mode, file_mode
547
def initialize(self, url):
548
"""Create a branch of this format at url and return an open branch."""
549
t = get_transport(url)
550
from bzrlib.weavefile import write_weave_v5
551
from bzrlib.weave import Weave
553
# Create an empty weave
555
bzrlib.weavefile.write_weave_v5(Weave(), sio)
556
empty_weave = sio.getvalue()
558
# Since we don't have a .bzr directory, inherit the
559
# mode from the root directory
560
temp_control = LockableFiles(t, '')
561
temp_control._transport.mkdir('.bzr',
562
mode=temp_control._dir_mode)
563
file_mode = temp_control._file_mode
565
mutter('created control directory in ' + t.base)
566
control = t.clone('.bzr')
567
dirs = ['revision-store', 'weaves']
568
lock_file = 'branch-lock'
569
utf8_files = [('README',
570
"This is a Bazaar-NG control directory.\n"
571
"Do not change any files in this directory.\n"),
572
('branch-format', self.get_format_string()),
573
('revision-history', ''),
576
files = [('inventory.weave', StringIO(empty_weave)),
579
# FIXME: RBC 20060125 dont peek under the covers
580
# NB: no need to escape relative paths that are url safe.
581
control.put(lock_file, StringIO(), mode=file_mode)
582
control_files = LockableFiles(control, lock_file)
583
control_files.lock_write()
584
control_files._transport.mkdir_multi(dirs,
585
mode=control_files._dir_mode)
587
for file, content in utf8_files:
588
control_files.put_utf8(file, content)
589
for file, content in files:
590
control_files.put(file, content)
592
control_files.unlock()
593
return BzrBranch(t, _format=self, _control_files=control_files)
528
def initialize(self, a_bzrdir):
529
"""Create a branch of this format in a_bzrdir."""
530
raise NotImplementedError(self.initialized)
595
532
def is_supported(self):
596
533
"""Is this format supported?
604
def open(self, transport):
605
"""Fill out the data in branch for the branch at url."""
606
return BzrBranch(transport, _format=self)
541
def open(self, a_bzrdir, _found=False):
542
"""Return the branch object for a_bzrdir
544
_found is a private parameter, do not use it. It is used to indicate
545
if format probing has already be done.
547
raise NotImplementedError(self.open)
609
550
def register_format(klass, format):
610
551
klass._formats[format.get_format_string()] = format
554
def set_default_format(klass, format):
555
klass._default_format = format
613
558
def unregister_format(klass, format):
614
559
assert klass._formats[format.get_format_string()] is format
615
560
del klass._formats[format.get_format_string()]
618
class BzrBranchFormat4(BzrBranchFormat):
563
class BzrBranchFormat4(BranchFormat):
619
564
"""Bzr branch format 4.
623
- TextStores for texts, inventories,revisions.
625
This format is deprecated: it indexes texts using a text it which is
626
removed in format 5; write support for this format has been removed.
567
- a revision-history file.
568
- a branch-lock lock file [ to be shared with the bzrdir ]
629
def get_format_string(self):
630
"""See BzrBranchFormat.get_format_string()."""
631
return BZR_BRANCH_FORMAT_4
633
def initialize(self, url):
634
"""Format 4 branches cannot be created."""
635
raise UninitializableFormat(self)
637
def is_supported(self):
638
"""Format 4 is not supported.
640
It is not supported because the model changed from 4 to 5 and the
641
conversion logic is expensive - so doing it on the fly was not
571
def initialize(self, a_bzrdir):
572
"""Create a branch of this format in a_bzrdir."""
573
mutter('creating branch in %s', a_bzrdir.transport.base)
574
branch_transport = a_bzrdir.get_branch_transport(self)
575
utf8_files = [('revision-history', ''),
578
control_files = LockableFiles(branch_transport, 'branch-lock')
579
control_files.lock_write()
581
for file, content in utf8_files:
582
control_files.put_utf8(file, content)
584
control_files.unlock()
585
return self.open(a_bzrdir, _found=True)
588
super(BzrBranchFormat4, self).__init__()
589
self._matchingbzrdir = bzrdir.BzrDirFormat6()
591
def open(self, a_bzrdir, _found=False):
592
"""Return the branch object for a_bzrdir
594
_found is a private parameter, do not use it. It is used to indicate
595
if format probing has already be done.
647
class BzrBranchFormat5(BzrBranchFormat):
598
# we are being called directly and must probe.
599
raise NotImplementedError
600
transport = a_bzrdir.get_branch_transport(self)
601
control_files = LockableFiles(transport, 'branch-lock')
602
return BzrBranch(_format=self,
603
_control_files=control_files,
607
class BzrBranchFormat5(BranchFormat):
648
608
"""Bzr branch format 5.
651
- weaves for file texts and inventory
653
- TextStores for revisions and signatures.
611
- a revision-history file.
656
616
def get_format_string(self):
657
"""See BzrBranchFormat.get_format_string()."""
658
return BZR_BRANCH_FORMAT_5
661
class BzrBranchFormat6(BzrBranchFormat):
662
"""Bzr branch format 6.
617
"""See BranchFormat.get_format_string()."""
618
return "Bazaar-NG branch format 5\n"
620
def initialize(self, a_bzrdir):
621
"""Create a branch of this format in a_bzrdir."""
622
mutter('creating branch in %s', a_bzrdir.transport.base)
623
branch_transport = a_bzrdir.get_branch_transport(self)
625
utf8_files = [('revision-history', ''),
629
branch_transport.put(lock_file, StringIO()) # TODO get the file mode from the bzrdir lock files., mode=file_mode)
630
control_files = LockableFiles(branch_transport, 'lock')
631
control_files.lock_write()
632
control_files.put_utf8('format', self.get_format_string())
634
for file, content in utf8_files:
635
control_files.put_utf8(file, content)
637
control_files.unlock()
638
return self.open(a_bzrdir, _found=True, )
641
super(BzrBranchFormat5, self).__init__()
642
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
644
def open(self, a_bzrdir, _found=False):
645
"""Return the branch object for a_bzrdir
647
_found is a private parameter, do not use it. It is used to indicate
648
if format probing has already be done.
651
format = BranchFormat.find_format(a_bzrdir)
652
assert format.__class__ == self.__class__
653
transport = a_bzrdir.get_branch_transport(None)
654
control_files = LockableFiles(transport, 'lock')
655
return BzrBranch(_format=self,
656
_control_files=control_files,
660
class BranchReferenceFormat(BranchFormat):
661
"""Bzr branch reference format.
663
Branch references are used in implementing checkouts, they
664
act as an alias to the real branch which is at some other url.
665
- weaves for file texts and inventory
666
- hash subdirectory based stores.
667
- TextStores for revisions and signatures.
670
671
def get_format_string(self):
671
"""See BzrBranchFormat.get_format_string()."""
672
return BZR_BRANCH_FORMAT_6
675
BzrBranchFormat.register_format(BzrBranchFormat4())
676
BzrBranchFormat.register_format(BzrBranchFormat5())
677
BzrBranchFormat.register_format(BzrBranchFormat6())
679
# TODO: jam 20060108 Create a new branch format, and as part of upgrade
680
# make sure that ancestry.weave is deleted (it is never used, but
681
# used to be created)
672
"""See BranchFormat.get_format_string()."""
673
return "Bazaar-NG Branch Reference Format 1\n"
675
def initialize(self, a_bzrdir, target_branch=None):
676
"""Create a branch of this format in a_bzrdir."""
677
if target_branch is None:
678
# this format does not implement branch itself, thus the implicit
679
# creation contract must see it as uninitializable
680
raise errors.UninitializableFormat(self)
681
mutter('creating branch reference in %s', a_bzrdir.transport.base)
682
branch_transport = a_bzrdir.get_branch_transport(self)
683
# FIXME rbc 20060209 one j-a-ms encoding branch lands this str() cast is not needed.
684
branch_transport.put('location', StringIO(str(target_branch.bzrdir.root_transport.base)))
685
branch_transport.put('format', StringIO(self.get_format_string()))
686
return self.open(a_bzrdir, _found=True)
689
super(BranchReferenceFormat, self).__init__()
690
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
692
def _make_reference_clone_function(format, a_branch):
693
"""Create a clone() routine for a branch dynamically."""
694
def clone(to_bzrdir, revision_id=None):
695
"""See Branch.clone()."""
696
return format.initialize(to_bzrdir, a_branch)
697
# cannot obey revision_id limits when cloning a reference ...
698
# FIXME RBC 20060210 either nuke revision_id for clone, or
699
# emit some sort of warning/error to the caller ?!
702
def open(self, a_bzrdir, _found=False):
703
"""Return the branch that the branch reference in a_bzrdir points at.
705
_found is a private parameter, do not use it. It is used to indicate
706
if format probing has already be done.
709
format = BranchFormat.find_format(a_bzrdir)
710
assert format.__class__ == self.__class__
711
transport = a_bzrdir.get_branch_transport(None)
712
real_bzrdir = bzrdir.BzrDir.open(transport.get('location').read())
713
result = real_bzrdir.open_branch()
714
# this changes the behaviour of result.clone to create a new reference
715
# rather than a copy of the content of the branch.
716
# I did not use a proxy object because that needs much more extensive
717
# testing, and we are only changing one behaviour at the moment.
718
# If we decide to alter more behaviours - i.e. the implicit nickname
719
# then this should be refactored to introduce a tested proxy branch
720
# and a subclass of that for use in overriding clone() and ....
722
result.clone = self._make_reference_clone_function(result)
726
# formats which have no format string are not discoverable
727
# and not independently creatable, so are not registered.
728
__default_format = BzrBranchFormat5()
729
BranchFormat.register_format(__default_format)
730
BranchFormat.register_format(BranchReferenceFormat())
731
BranchFormat.set_default_format(__default_format)
732
_legacy_formats = [BzrBranchFormat4(),
684
735
class BzrBranch(Branch):
685
736
"""A branch stored in the actual filesystem.
700
750
# This should match a prefix with a function which accepts
701
751
REVISION_NAMESPACES = {}
703
def push_stores(self, branch_to):
704
"""See Branch.push_stores."""
705
if (not isinstance(self._branch_format, BzrBranchFormat4) or
706
self._branch_format != branch_to._branch_format):
707
from bzrlib.fetch import greedy_fetch
708
mutter("Using fetch logic to push between %s(%s) and %s(%s)",
709
self, self._branch_format, branch_to, branch_to._branch_format)
710
greedy_fetch(to_branch=branch_to, from_branch=self,
711
revision=self.last_revision())
714
# format 4 to format 4 logic only.
715
store_pairs = ((self.text_store, branch_to.text_store),
716
(self.inventory_store, branch_to.inventory_store),
717
(self.revision_store, branch_to.revision_store))
719
for from_store, to_store in store_pairs:
720
copy_all(from_store, to_store)
721
except UnlistableStore:
722
raise UnlistableBranch(from_store)
724
def __init__(self, transport, init=DEPRECATED_PARAMETER,
753
def __init__(self, transport=DEPRECATED_PARAMETER, init=DEPRECATED_PARAMETER,
725
754
relax_version_check=DEPRECATED_PARAMETER, _format=None,
726
_control_files=None):
755
_control_files=None, a_bzrdir=None):
727
756
"""Create new branch object at a particular location.
729
758
transport -- A Transport object, defining how to access files.
1061
1083
history = self._get_truncated_history(revision)
1062
1084
if not bzrlib.osutils.lexists(to_location):
1063
1085
os.mkdir(to_location)
1064
branch_to = Branch.initialize(to_location)
1086
bzrdir_to = self.bzrdir._format.initialize(to_location)
1087
self.repository.clone(bzrdir_to)
1088
branch_to = bzrdir_to.create_branch()
1065
1089
mutter("copy branch from %s to %s", self, branch_to)
1067
self.repository.copy(branch_to.repository)
1069
# must be done *after* history is copied across
1070
1091
# FIXME duplicate code with base .clone().
1071
1092
# .. would template method be useful here? RBC 20051207
1072
1093
branch_to.set_parent(self.base)
1073
1094
branch_to.append_revision(*history)
1074
# FIXME: this should be in workingtree.clone
1075
WorkingTree.create(branch_to, to_location).set_root_id(self.get_root_id())
1095
WorkingTree.create(branch_to, branch_to.base)
1076
1096
mutter("copied")
1077
1097
return branch_to
1079
def clone(self, to_location, revision=None, basis_branch=None, to_branch_type=None):
1080
# FIXME: clone via create and fetch is probably faster when versioned
1082
if to_branch_type is None:
1083
to_branch_type = BzrBranch
1085
if to_branch_type == BzrBranch \
1086
and self.repository.weave_store.listable() \
1087
and self.repository.revision_store.listable():
1088
return self._clone_weave(to_location, revision, basis_branch)
1090
return Branch.clone(self, to_location, revision, basis_branch, to_branch_type)
1092
def fileid_involved_between_revs(self, from_revid, to_revid):
1093
"""Find file_id(s) which are involved in the changes between revisions.
1095
This determines the set of revisions which are involved, and then
1096
finds all file ids affected by those revisions.
1098
# TODO: jam 20060119 This code assumes that w.inclusions will
1099
# always be correct. But because of the presence of ghosts
1100
# it is possible to be wrong.
1101
# One specific example from Robert Collins:
1102
# Two branches, with revisions ABC, and AD
1103
# C is a ghost merge of D.
1104
# Inclusions doesn't recognize D as an ancestor.
1105
# If D is ever merged in the future, the weave
1106
# won't be fixed, because AD never saw revision C
1107
# to cause a conflict which would force a reweave.
1108
w = self.repository.get_inventory_weave()
1109
from_set = set(w.inclusions([w.lookup(from_revid)]))
1110
to_set = set(w.inclusions([w.lookup(to_revid)]))
1111
included = to_set.difference(from_set)
1112
changed = map(w.idx_to_name, included)
1113
return self._fileid_involved_by_set(changed)
1115
def fileid_involved(self, last_revid=None):
1116
"""Find all file_ids modified in the ancestry of last_revid.
1118
:param last_revid: If None, last_revision() will be used.
1120
w = self.repository.get_inventory_weave()
1122
changed = set(w._names)
1124
included = w.inclusions([w.lookup(last_revid)])
1125
changed = map(w.idx_to_name, included)
1126
return self._fileid_involved_by_set(changed)
1128
def fileid_involved_by_set(self, changes):
1129
"""Find all file_ids modified by the set of revisions passed in.
1131
:param changes: A set() of revision ids
1133
# TODO: jam 20060119 This line does *nothing*, remove it.
1134
# or better yet, change _fileid_involved_by_set so
1135
# that it takes the inventory weave, rather than
1136
# pulling it out by itself.
1137
w = self.repository.get_inventory_weave()
1138
return self._fileid_involved_by_set(changes)
1140
def _fileid_involved_by_set(self, changes):
1141
"""Find the set of file-ids affected by the set of revisions.
1143
:param changes: A set() of revision ids.
1144
:return: A set() of file ids.
1146
This peaks at the Weave, interpreting each line, looking to
1147
see if it mentions one of the revisions. And if so, includes
1148
the file id mentioned.
1149
This expects both the Weave format, and the serialization
1150
to have a single line per file/directory, and to have
1151
fileid="" and revision="" on that line.
1153
assert (isinstance(self._branch_format, BzrBranchFormat5) or
1154
isinstance(self._branch_format, BzrBranchFormat6)), \
1155
"fileid_involved only supported for branches which store inventory as xml"
1157
w = self.repository.get_inventory_weave()
1159
for line in w._weave:
1161
# it is ugly, but it is due to the weave structure
1162
if not isinstance(line, basestring): continue
1164
start = line.find('file_id="')+9
1165
if start < 9: continue
1166
end = line.find('"', start)
1168
file_id = xml.sax.saxutils.unescape(line[start:end])
1170
# check if file_id is already present
1171
if file_id in file_ids: continue
1173
start = line.find('revision="')+10
1174
if start < 10: continue
1175
end = line.find('"', start)
1177
revision_id = xml.sax.saxutils.unescape(line[start:end])
1179
if revision_id in changes:
1180
file_ids.add(file_id)
1185
Branch.set_default_initializer(BzrBranch._initialize)
1188
1100
class BranchTestProviderAdapter(object):
1189
1101
"""A tool to generate a suite testing multiple branch formats at once.
1202
1114
def adapt(self, test):
1203
1115
result = TestSuite()
1204
for format in self._formats:
1116
for branch_format, bzrdir_format in self._formats:
1205
1117
new_test = deepcopy(test)
1206
1118
new_test.transport_server = self._transport_server
1207
1119
new_test.transport_readonly_server = self._transport_readonly_server
1208
new_test.branch_format = format
1120
new_test.bzrdir_format = bzrdir_format
1121
new_test.branch_format = branch_format
1209
1122
def make_new_test_id():
1210
new_id = "%s(%s)" % (new_test.id(), format.__class__.__name__)
1123
new_id = "%s(%s)" % (new_test.id(), branch_format.__class__.__name__)
1211
1124
return lambda: new_id
1212
1125
new_test.id = make_new_test_id()
1213
1126
result.addTest(new_test)
1217
class ScratchBranch(BzrBranch):
1218
"""Special test class: a branch that cleans up after itself.
1220
>>> b = ScratchBranch()
1224
>>> b._transport.__del__()
1229
def __init__(self, files=[], dirs=[], transport=None):
1230
"""Make a test branch.
1232
This creates a temporary directory and runs init-tree in it.
1234
If any files are listed, they are created in the working copy.
1236
if transport is None:
1237
transport = bzrlib.transport.local.ScratchTransport()
1238
# local import for scope restriction
1239
from bzrlib.workingtree import WorkingTree
1240
WorkingTree.create_standalone(transport.base)
1241
super(ScratchBranch, self).__init__(transport)
1243
super(ScratchBranch, self).__init__(transport)
1245
# BzrBranch creates a clone to .bzr and then forgets about the
1246
# original transport. A ScratchTransport() deletes itself and
1247
# everything underneath it when it goes away, so we need to
1248
# grab a local copy to prevent that from happening
1249
self._transport = transport
1252
self._transport.mkdir(d)
1255
self._transport.put(f, 'content of %s' % f)
1259
>>> orig = ScratchBranch(files=["file1", "file2"])
1260
>>> os.listdir(orig.base)
1261
[u'.bzr', u'file1', u'file2']
1262
>>> clone = orig.clone()
1263
>>> if os.name != 'nt':
1264
... os.path.samefile(orig.base, clone.base)
1266
... orig.base == clone.base
1269
>>> os.listdir(clone.base)
1270
[u'.bzr', u'file1', u'file2']
1272
from shutil import copytree
1273
from bzrlib.osutils import mkdtemp
1276
copytree(self.base, base, symlinks=True)
1277
return ScratchBranch(
1278
transport=bzrlib.transport.local.ScratchTransport(base))
1281
1130
######################################################################
1285
def is_control_file(filename):
1286
## FIXME: better check
1287
filename = normpath(filename)
1288
while filename != '':
1289
head, tail = os.path.split(filename)
1290
## mutter('check %r for control file' % ((head, tail),))
1291
if tail == bzrlib.BZRDIR:
1293
if filename == head:
1134
@deprecated_function(zero_eight)
1135
def ScratchBranch(*args, **kwargs):
1136
"""See bzrlib.bzrdir.ScratchDir."""
1137
d = ScratchDir(*args, **kwargs)
1138
return d.open_branch()
1141
@deprecated_function(zero_eight)
1142
def is_control_file(*args, **kwargs):
1143
"""See bzrlib.workingtree.is_control_file."""
1144
return bzrlib.workingtree.is_control_file(*args, **kwargs)