28
28
from inventory import InventoryEntry, Inventory
29
29
from osutils import isdir, quotefn, isfile, uuid, sha_file, username, chomp, \
30
30
format_date, compact_date, pumpfile, user_email, rand_bytes, splitpath, \
31
joinpath, sha_string, file_kind, local_time_offset, appendpath
31
joinpath, sha_string, file_kind, local_time_offset
32
32
from store import ImmutableStore
33
33
from revision import Revision
34
34
from errors import bailout
162
162
self.controlfile('README', 'w').write(
163
163
"This is a Bazaar-NG control directory.\n"
164
164
"Do not change any files in this directory.")
165
self.controlfile('branch-format', 'wb').write(BZR_BRANCH_FORMAT)
165
self.controlfile('branch-format', 'w').write(BZR_BRANCH_FORMAT)
166
166
for d in ('text-store', 'inventory-store', 'revision-store'):
167
167
os.mkdir(self.controlfilename(d))
168
168
for f in ('revision-history', 'merged-patches',
180
180
In the future, we might need different in-memory Branch
181
181
classes to support downlevel branches. But not yet.
183
# This ignores newlines so that we can open branches created
184
# on Windows from Linux and so on. I think it might be better
185
# to always make all internal files in unix format.
183
# read in binary mode to detect newline wierdness.
186
184
fmt = self.controlfile('branch-format', 'rb').read()
187
fmt.replace('\r\n', '')
188
185
if fmt != BZR_BRANCH_FORMAT:
189
186
bailout('sorry, branch format %r not supported' % fmt,
190
187
['use a different bzr version',
548
542
mutter("committing patch r%d" % (self.revno() + 1))
550
544
mutter("append to revision-history")
551
f = self.controlfile('revision-history', 'at')
552
f.write(rev_id + '\n')
545
self.controlfile('revision-history', 'at').write(rev_id + '\n')
556
note("commited r%d" % self.revno())
559
550
def get_revision(self, revision_id):
705
def rename_one(self, from_rel, to_rel):
706
tree = self.working_tree()
708
if not tree.has_filename(from_rel):
709
bailout("can't rename: old working file %r does not exist" % from_rel)
710
if tree.has_filename(to_rel):
711
bailout("can't rename: new working file %r already exists" % to_rel)
713
file_id = inv.path2id(from_rel)
715
bailout("can't rename: old name %r is not versioned" % from_rel)
717
if inv.path2id(to_rel):
718
bailout("can't rename: new name %r is already versioned" % to_rel)
720
to_dir, to_tail = os.path.split(to_rel)
721
to_dir_id = inv.path2id(to_dir)
722
if to_dir_id == None and to_dir != '':
723
bailout("can't determine destination directory id for %r" % to_dir)
725
mutter("rename_one:")
726
mutter(" file_id {%s}" % file_id)
727
mutter(" from_rel %r" % from_rel)
728
mutter(" to_rel %r" % to_rel)
729
mutter(" to_dir %r" % to_dir)
730
mutter(" to_dir_id {%s}" % to_dir_id)
732
inv.rename(file_id, to_dir_id, to_tail)
733
os.rename(self.abspath(from_rel), self.abspath(to_rel))
735
self._write_inventory(inv)
739
def rename(self, from_paths, to_name):
742
If to_name exists and is a directory, the files are moved into
743
it, keeping their old names. If it is a directory,
745
Note that to_name is only the last component of the new name;
746
this doesn't change the directory.
748
## TODO: Option to move IDs only
749
assert not isinstance(from_paths, basestring)
750
tree = self.working_tree()
752
dest_dir = isdir(self.abspath(to_name))
754
# TODO: Wind back properly if some can't be moved?
755
dest_dir_id = inv.path2id(to_name)
756
if not dest_dir_id and to_name != '':
757
bailout("destination %r is not a versioned directory" % to_name)
759
name_tail = splitpath(f)[-1]
760
dest_path = appendpath(to_name, name_tail)
761
print "%s => %s" % (f, dest_path)
762
inv.rename(inv.path2id(f), dest_dir_id, name_tail)
763
os.rename(self.abspath(f), self.abspath(dest_path))
764
self._write_inventory(inv)
766
if len(from_paths) != 1:
767
bailout("when moving multiple files, destination must be a directory")
768
bailout("rename to non-directory %r not implemented sorry" % to_name)
772
697
def show_status(branch, show_all=False):
773
698
"""Display single-line status for non-ignored working files.
847
772
If any files are listed, they are created in the working copy.
849
774
Branch.__init__(self, tempfile.mkdtemp(), init=True)
851
os.mkdir(self.abspath(d))
854
776
file(os.path.join(self.base, f), 'w').write('content of %s' % f)
857
779
def __del__(self):
858
780
"""Destroy the test branch, removing the scratch directory."""
860
shutil.rmtree(self.base)
862
# Work around for shutil.rmtree failing on Windows when
863
# readonly files are encountered
864
for root, dirs, files in os.walk(self.base, topdown=False):
866
os.chmod(os.path.join(root, name), 0700)
867
shutil.rmtree(self.base)
781
shutil.rmtree(self.base)