308
309
def _unversion_path(self, path):
309
310
assert self._lock_mode is not None
310
311
encoded_path = path.encode("utf-8")
312
314
del self.index[encoded_path]
314
316
# A directory, perhaps?
315
317
for p in list(self.index):
316
318
if p.startswith(encoded_path+b"/"):
317
320
del self.index[p]
318
# FIXME: remove empty directories
320
325
def unversion(self, paths, file_ids=None):
321
326
with self.lock_tree_write():
384
386
# XXX: Really should be a more abstract reporter interface
385
kind_ch = osutils.kind_marker(self.kind(fid))
387
kind_ch = osutils.kind_marker(self.kind(f))
386
388
to_file.write(new_status + ' ' + f + kind_ch + '\n')
388
# FIXME: _unversion_path() is O(size-of-index) for directories
389
self._unversion_path(f)
390
message = "removed %s" % (f,)
391
if osutils.lexists(abs_path):
390
# TODO(jelmer): _unversion_path() is O(size-of-index) for directories
391
if self._unversion_path(f) == 0:
392
392
if (osutils.isdir(abs_path) and
393
len(os.listdir(abs_path)) > 0):
395
osutils.rmtree(abs_path)
396
message = "deleted %s" % (f,)
393
len(os.listdir(abs_path)) == 0):
400
394
if not keep_files:
401
395
osutils.delete_any(abs_path)
402
message = "deleted %s" % (f,)
396
message = "removed %s" % (f,)
398
message = "%s is not versioned." % (f,)
400
message = "removed %s" % (f,)
401
if osutils.lexists(abs_path):
402
if (osutils.isdir(abs_path) and
403
len(os.listdir(abs_path)) > 0):
405
osutils.rmtree(abs_path)
406
message = "deleted %s" % (f,)
411
osutils.delete_any(abs_path)
412
message = "deleted %s" % (f,)
404
414
# print only one message (if any) per file.
405
415
if message is not None:
553
563
return set(self._iter_files_recursive()) - set(self.index)
556
with self.lock_tree_write():
557
# TODO: Maybe this should only write on dirty ?
558
if self._lock_mode != 'w':
559
raise errors.NotWriteLocked(self)
566
# TODO: Maybe this should only write on dirty ?
567
if self._lock_mode != 'w':
568
raise errors.NotWriteLocked(self)
562
571
def __iter__(self):
563
572
with self.lock_read():
607
616
path = self._fileid_map.lookup_path(file_id)
608
617
except ValueError:
609
618
raise errors.NoSuchId(self, file_id)
610
# FIXME: What about directories?
611
619
if self._is_versioned(path):
612
620
return path.decode("utf-8")
613
621
raise errors.NoSuchId(self, file_id)
1080
1088
target_fileid_map = self.target._fileid_map
1081
1089
ret = tree_delta_from_git_changes(changes, self.target.mapping,
1082
1090
(source_fileid_map, target_fileid_map),
1083
specific_files=specific_files, require_versioned=require_versioned)
1091
specific_files=specific_files, require_versioned=require_versioned,
1092
include_root=include_root)
1084
1093
if want_unversioned:
1085
1094
for e in self.target.extras():
1086
1095
ret.unversioned.append(
1129
1138
# TODO(jelmer): Avoid creating and storing tree objects; ideally, use
1130
1139
# dulwich.index.changes_from_tree with a include_trees argument.
1140
refresh_index(target.index, target.abspath('.').encode(sys.getfilesystemencoding()))
1131
1141
to_tree_sha = target.index.commit(store)
1142
target.index.write()
1132
1143
return store.tree_changes(from_tree_sha, to_tree_sha, include_trees=True,
1133
1144
want_unchanged=want_unchanged)