/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-11 20:04:42 UTC
  • mto: (0.200.1749 master)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180211200442-e91ab29r1a8xwcb5
Fix some more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    changes_from_tree,
35
35
    cleanup_mode,
36
36
    index_entry_from_stat,
 
37
    refresh_index,
37
38
    )
38
39
from dulwich.object_store import (
39
40
    tree_lookup_path,
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
        count = 0
311
313
        try:
312
314
            del self.index[encoded_path]
313
315
        except KeyError:
314
316
            # A directory, perhaps?
315
317
            for p in list(self.index):
316
318
                if p.startswith(encoded_path+b"/"):
 
319
                    count += 1
317
320
                    del self.index[p]
318
 
        # FIXME: remove empty directories
 
321
        else:
 
322
            count = 1
 
323
        return count
319
324
 
320
325
    def unversion(self, paths, file_ids=None):
321
326
        with self.lock_tree_write():
370
375
            for f in files:
371
376
                if f == '':
372
377
                    continue
373
 
                fid = self.path2id(f)
374
 
                if not fid:
375
 
                    message = "%s is not versioned." % (f,)
376
378
                else:
377
379
                    abs_path = self.abspath(f)
378
380
                    if verbose:
382
384
                        else:
383
385
                            new_status = '?'
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')
387
389
                    # Unversion file
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):
394
 
                            if force:
395
 
                                osutils.rmtree(abs_path)
396
 
                                message = "deleted %s" % (f,)
397
 
                            else:
398
 
                                message = backup(f)
399
 
                        else:
 
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,)
 
397
                        else:
 
398
                            message = "%s is not versioned." % (f,)
 
399
                    else:
 
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):
 
404
                                if force:
 
405
                                    osutils.rmtree(abs_path)
 
406
                                    message = "deleted %s" % (f,)
 
407
                                else:
 
408
                                    message = backup(f)
 
409
                            else:
 
410
                                if not keep_files:
 
411
                                    osutils.delete_any(abs_path)
 
412
                                    message = "deleted %s" % (f,)
403
413
 
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)
554
564
 
555
565
    def flush(self):
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)
560
 
            self.index.write()
 
566
        # TODO: Maybe this should only write on dirty ?
 
567
        if self._lock_mode != 'w':
 
568
            raise errors.NotWriteLocked(self)
 
569
        self.index.write()
561
570
 
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(
1128
1137
    """
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)