~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    bzrdir,
44
44
    cache_utf8,
45
45
    conflicts as _mod_conflicts,
46
 
    debug,
47
46
    delta,
48
47
    dirstate,
49
48
    errors,
50
49
    generate_ids,
51
50
    globbing,
 
51
    hashcache,
52
52
    ignores,
53
53
    merge,
54
54
    osutils,
55
 
    revision as _mod_revision,
56
55
    revisiontree,
57
56
    textui,
58
 
    trace,
59
57
    transform,
60
58
    urlutils,
61
59
    xml5,
131
129
        """
132
130
        self._format = _format
133
131
        self.bzrdir = _bzrdir
 
132
        from bzrlib.trace import note, mutter
134
133
        assert isinstance(basedir, basestring), \
135
134
            "base directory %r is not a string" % basedir
136
135
        basedir = safe_unicode(basedir)
151
150
        self._dirstate = None
152
151
        self._inventory = None
153
152
        #-------------
154
 
        self._setup_directory_is_tree_reference()
155
 
        self._detect_case_handling()
156
153
 
157
154
    @needs_tree_write_lock
158
155
    def _add(self, files, ids, kinds):
160
157
        state = self.current_dirstate()
161
158
        for f, file_id, kind in zip(files, ids, kinds):
162
159
            f = f.strip('/')
 
160
            assert '//' not in f
 
161
            assert '..' not in f
163
162
            if self.path2id(f):
164
163
                # special case tree root handling.
165
164
                if f == '' and self.path2id(f) == ROOT_ID:
270
269
        self._dirstate = dirstate.DirState.on_file(local_path)
271
270
        return self._dirstate
272
271
 
 
272
    def _directory_is_tree_reference(self, relpath):
 
273
        # as a special case, if a directory contains control files then 
 
274
        # it's a tree reference, except that the root of the tree is not
 
275
        return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
 
276
        # TODO: We could ask all the control formats whether they
 
277
        # recognize this directory, but at the moment there's no cheap api
 
278
        # to do that.  Since we probably can only nest bzr checkouts and
 
279
        # they always use this name it's ok for now.  -- mbp 20060306
 
280
        #
 
281
        # FIXME: There is an unhandled case here of a subdirectory
 
282
        # containing .bzr but not a branch; that will probably blow up
 
283
        # when you try to commit it.  It might happen if there is a
 
284
        # checkout in a subdirectory.  This can be avoided by not adding
 
285
        # it.  mbp 20070306
 
286
 
273
287
    def filter_unversioned_files(self, paths):
274
288
        """Filter out paths that are versioned.
275
289
 
393
407
    def get_file_sha1(self, file_id, path=None, stat_value=None):
394
408
        # check file id is valid unconditionally.
395
409
        entry = self._get_entry(file_id=file_id, path=path)
396
 
        if entry[0] is None:
397
 
            raise errors.NoSuchId(self, file_id)
 
410
        assert entry[0] is not None, 'what error should this raise'
398
411
        if path is None:
399
412
            path = pathjoin(entry[0][0], entry[0][1]).decode('utf8')
400
413
 
401
414
        file_abspath = self.abspath(path)
402
415
        state = self.current_dirstate()
403
 
        if stat_value is None:
404
 
            try:
405
 
                stat_value = os.lstat(file_abspath)
406
 
            except OSError, e:
407
 
                if e.errno == errno.ENOENT:
408
 
                    return None
409
 
                else:
410
 
                    raise
411
416
        link_or_sha1 = state.update_entry(entry, file_abspath,
412
417
                                          stat_value=stat_value)
413
418
        if entry[1][0][0] == 'f':
416
421
 
417
422
    def _get_inventory(self):
418
423
        """Get the inventory for the tree. This is only valid within a lock."""
419
 
        if 'evil' in debug.debug_flags:
420
 
            trace.mutter_callsite(2,
421
 
                "accessing .inventory forces a size of tree translation.")
422
424
        if self._inventory is not None:
423
425
            return self._inventory
424
426
        self._must_be_locked()
453
455
 
454
456
    def has_id(self, file_id):
455
457
        state = self.current_dirstate()
 
458
        file_id = osutils.safe_file_id(file_id)
456
459
        row, parents = self._get_entry(file_id=file_id)
457
460
        if row is None:
458
461
            return False
461
464
 
462
465
    @needs_read_lock
463
466
    def id2path(self, file_id):
464
 
        "Convert a file-id to a path."
 
467
        file_id = osutils.safe_file_id(file_id)
465
468
        state = self.current_dirstate()
466
469
        entry = self._get_entry(file_id=file_id)
467
470
        if entry == (None, None):
469
472
        path_utf8 = osutils.pathjoin(entry[0][0], entry[0][1])
470
473
        return path_utf8.decode('utf8')
471
474
 
472
 
    def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):
473
 
        entry = self._get_entry(path=path)
474
 
        if entry == (None, None):
475
 
            return False # Missing entries are not executable
476
 
        return entry[1][0][3] # Executable?
477
 
 
478
475
    if not osutils.supports_executable():
 
476
        @needs_read_lock
479
477
        def is_executable(self, file_id, path=None):
480
 
            """Test if a file is executable or not.
481
 
 
482
 
            Note: The caller is expected to take a read-lock before calling this.
483
 
            """
 
478
            file_id = osutils.safe_file_id(file_id)
484
479
            entry = self._get_entry(file_id=file_id, path=path)
485
480
            if entry == (None, None):
486
481
                return False
487
482
            return entry[1][0][3]
488
 
 
489
 
        _is_executable_from_path_and_stat = \
490
 
            _is_executable_from_path_and_stat_from_basis
491
483
    else:
 
484
        @needs_read_lock
492
485
        def is_executable(self, file_id, path=None):
493
 
            """Test if a file is executable or not.
494
 
 
495
 
            Note: The caller is expected to take a read-lock before calling this.
496
 
            """
497
 
            self._must_be_locked()
498
486
            if not path:
 
487
                file_id = osutils.safe_file_id(file_id)
499
488
                path = self.id2path(file_id)
500
489
            mode = os.lstat(self.abspath(path)).st_mode
501
490
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
502
491
 
503
 
    def all_file_ids(self):
504
 
        """See Tree.iter_all_file_ids"""
505
 
        self._must_be_locked()
506
 
        result = set()
507
 
        for key, tree_details in self.current_dirstate()._iter_entries():
508
 
            if tree_details[0][0] in ('a', 'r'): # relocated
509
 
                continue
510
 
            result.add(key[2])
511
 
        return result
512
 
 
513
492
    @needs_read_lock
514
493
    def __iter__(self):
515
494
        """Iterate through file_ids for this tree.
543
522
                # path is missing on disk.
544
523
                continue
545
524
 
 
525
    @needs_read_lock
546
526
    def kind(self, file_id):
547
527
        """Return the kind of a file.
548
528
 
549
529
        This is always the actual kind that's on disk, regardless of what it
550
530
        was added as.
551
 
 
552
 
        Note: The caller is expected to take a read-lock before calling this.
553
531
        """
554
532
        relpath = self.id2path(file_id)
555
533
        assert relpath != None, \
572
550
        if parent_ids:
573
551
            return parent_ids[0]
574
552
        else:
575
 
            return _mod_revision.NULL_REVISION
 
553
            return None
576
554
 
577
555
    def lock_read(self):
578
556
        """See Branch.lock_read, and WorkingTree.unlock."""
662
640
        if self._inventory is not None:
663
641
            update_inventory = True
664
642
            inv = self.inventory
 
643
            to_dir_ie = inv[to_dir_id]
665
644
            to_dir_id = to_entry[0][2]
666
 
            to_dir_ie = inv[to_dir_id]
667
645
        else:
668
646
            update_inventory = False
669
647
 
733
711
                if from_missing: # implicitly just update our path mapping
734
712
                    move_file = False
735
713
                elif not after:
736
 
                    raise errors.RenameFailedFilesExist(from_rel, to_rel)
 
714
                    raise errors.RenameFailedFilesExist(from_rel, to_rel,
 
715
                        extra="(Use --after to update the Bazaar id)")
737
716
 
738
717
            rollbacks = []
739
718
            def rollback_rename():
945
924
            if not all_versioned:
946
925
                raise errors.PathsNotVersionedError(paths)
947
926
        # -- remove redundancy in supplied paths to prevent over-scanning --
948
 
        search_paths = osutils.minimum_path_selection(paths)
 
927
        search_paths = set()
 
928
        for path in paths:
 
929
            other_paths = paths.difference(set([path]))
 
930
            if not osutils.is_inside_any(other_paths, path):
 
931
                # this is a top level path, we must check it.
 
932
                search_paths.add(path)
949
933
        # sketch: 
950
934
        # for all search_indexs in each path at or under each element of
951
935
        # search_paths, if the detail is relocated: add the id, and add the
1019
1003
 
1020
1004
        WorkingTree4 supplies revision_trees for any basis tree.
1021
1005
        """
 
1006
        revision_id = osutils.safe_revision_id(revision_id)
1022
1007
        dirstate = self.current_dirstate()
1023
1008
        parent_ids = dirstate.get_parent_ids()
1024
1009
        if revision_id not in parent_ids:
1031
1016
    @needs_tree_write_lock
1032
1017
    def set_last_revision(self, new_revision):
1033
1018
        """Change the last revision in the working tree."""
 
1019
        new_revision = osutils.safe_revision_id(new_revision)
1034
1020
        parents = self.get_parent_ids()
1035
1021
        if new_revision in (NULL_REVISION, None):
1036
1022
            assert len(parents) < 2, (
1054
1040
        :param revision_ids: The revision_ids to set as the parent ids of this
1055
1041
            working tree. Any of these may be ghosts.
1056
1042
        """
 
1043
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1057
1044
        trees = []
1058
1045
        for revision_id in revision_ids:
1059
1046
            try:
1065
1052
            except (errors.NoSuchRevision, errors.RevisionNotPresent):
1066
1053
                revtree = None
1067
1054
            trees.append((revision_id, revtree))
 
1055
        self.current_dirstate()._validate()
1068
1056
        self.set_parent_trees(trees,
1069
1057
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
1058
        self.current_dirstate()._validate()
1070
1059
 
1071
1060
    @needs_tree_write_lock
1072
1061
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
1077
1066
            parent tree - i.e. a ghost.
1078
1067
        """
1079
1068
        dirstate = self.current_dirstate()
 
1069
        dirstate._validate()
1080
1070
        if len(parents_list) > 0:
1081
1071
            if not allow_leftmost_as_ghost and parents_list[0][1] is None:
1082
1072
                raise errors.GhostRevisionUnusableHere(parents_list[0][0])
1085
1075
        # convert absent trees to the null tree, which we convert back to
1086
1076
        # missing on access.
1087
1077
        for rev_id, tree in parents_list:
1088
 
            _mod_revision.check_not_reserved_id(rev_id)
 
1078
            rev_id = osutils.safe_revision_id(rev_id)
1089
1079
            if tree is not None:
1090
1080
                real_trees.append((rev_id, tree))
1091
1081
            else:
1092
1082
                real_trees.append((rev_id,
1093
1083
                    self.branch.repository.revision_tree(None)))
1094
1084
                ghosts.append(rev_id)
 
1085
        dirstate._validate()
1095
1086
        dirstate.set_parent_trees(real_trees, ghosts=ghosts)
 
1087
        dirstate._validate()
1096
1088
        self._make_dirty(reset_inventory=False)
 
1089
        dirstate._validate()
1097
1090
 
1098
1091
    def _set_root_id(self, file_id):
1099
1092
        """See WorkingTree.set_root_id."""
1102
1095
        if state._dirblock_state == dirstate.DirState.IN_MEMORY_MODIFIED:
1103
1096
            self._make_dirty(reset_inventory=True)
1104
1097
 
1105
 
    def _sha_from_stat(self, path, stat_result):
1106
 
        """Get a sha digest from the tree's stat cache.
1107
 
 
1108
 
        The default implementation assumes no stat cache is present.
1109
 
 
1110
 
        :param path: The path.
1111
 
        :param stat_result: The stat result being looked up.
1112
 
        """
1113
 
        return self.current_dirstate().sha1_from_stat(path, stat_result)
1114
 
 
1115
1098
    @needs_read_lock
1116
1099
    def supports_tree_reference(self):
1117
1100
        return self._repo_supports_tree_reference
1118
1101
 
1119
1102
    def unlock(self):
1120
1103
        """Unlock in format 4 trees needs to write the entire dirstate."""
1121
 
        # do non-implementation specific cleanup
1122
 
        self._cleanup()
1123
 
 
1124
1104
        if self._control_files._lock_count == 1:
1125
1105
            # eventually we should do signature checking during read locks for
1126
1106
            # dirstate updates.
1157
1137
            return
1158
1138
        state = self.current_dirstate()
1159
1139
        state._read_dirblocks_if_needed()
1160
 
        ids_to_unversion = set(file_ids)
 
1140
        ids_to_unversion = set()
 
1141
        for file_id in file_ids:
 
1142
            ids_to_unversion.add(osutils.safe_file_id(file_id))
1161
1143
        paths_to_unversion = set()
1162
1144
        # sketch:
1163
1145
        # check if the root is to be unversioned, if so, assert for now.
1193
1175
                    # Mark this file id as having been removed
1194
1176
                    entry = block[1][entry_index]
1195
1177
                    ids_to_unversion.discard(entry[0][2])
1196
 
                    if (entry[1][0][0] in 'ar' # don't remove absent or renamed
1197
 
                                               # entries
 
1178
                    if (entry[1][0][0] == 'a'
1198
1179
                        or not state._make_absent(entry)):
1199
1180
                        entry_index += 1
1200
1181
                # go to the next block. (At the moment we dont delete empty
1225
1206
            for file_id in file_ids:
1226
1207
                self._inventory.remove_recursive_id(file_id)
1227
1208
 
1228
 
    @needs_tree_write_lock
1229
 
    def rename_one(self, from_rel, to_rel, after=False):
1230
 
        """See WorkingTree.rename_one"""
1231
 
        self.flush()
1232
 
        WorkingTree.rename_one(self, from_rel, to_rel, after)
1233
 
 
1234
 
    @needs_tree_write_lock
1235
 
    def apply_inventory_delta(self, changes):
1236
 
        """See MutableTree.apply_inventory_delta"""
1237
 
        state = self.current_dirstate()
1238
 
        state.update_by_delta(changes)
1239
 
        self._make_dirty(reset_inventory=True)
1240
 
 
1241
 
    def update_basis_by_delta(self, new_revid, delta):
1242
 
        """See MutableTree.update_basis_by_delta."""
1243
 
        assert self.last_revision() != new_revid
1244
 
        self.current_dirstate().update_basis_by_delta(delta, new_revid)
1245
 
 
1246
1209
    @needs_read_lock
1247
1210
    def _validate(self):
1248
1211
        self._dirstate._validate()
1250
1213
    @needs_tree_write_lock
1251
1214
    def _write_inventory(self, inv):
1252
1215
        """Write inventory as the current inventory."""
1253
 
        assert not self._dirty, ("attempting to write an inventory when the "
1254
 
            "dirstate is dirty will cause data loss")
 
1216
        assert not self._dirty, "attempting to write an inventory when the dirstate is dirty will cause data loss"
1255
1217
        self.current_dirstate().set_state_from_inventory(inv)
1256
1218
        self._make_dirty(reset_inventory=False)
1257
1219
        if self._inventory is not None:
1281
1243
        """See WorkingTreeFormat.get_format_description()."""
1282
1244
        return "Working tree format 4"
1283
1245
 
1284
 
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1285
 
                   accelerator_tree=None, hardlink=False):
 
1246
    def initialize(self, a_bzrdir, revision_id=None):
1286
1247
        """See WorkingTreeFormat.initialize().
1287
1248
 
1288
1249
        :param revision_id: allows creating a working tree at a different
1289
1250
        revision than the branch is at.
1290
 
        :param accelerator_tree: A tree which can be used for retrieving file
1291
 
            contents more quickly than the revision tree, i.e. a workingtree.
1292
 
            The revision tree will be used for cases where accelerator_tree's
1293
 
            content is different.
1294
 
        :param hardlink: If true, hard-link files from accelerator_tree,
1295
 
            where possible.
1296
1251
 
1297
1252
        These trees get an initial random root id, if their repository supports
1298
1253
        rich root data, TREE_ROOT otherwise.
1299
1254
        """
 
1255
        revision_id = osutils.safe_revision_id(revision_id)
1300
1256
        if not isinstance(a_bzrdir.transport, LocalTransport):
1301
1257
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1302
1258
        transport = a_bzrdir.get_workingtree_transport(self)
1304
1260
        control_files.create_lock()
1305
1261
        control_files.lock_write()
1306
1262
        control_files.put_utf8('format', self.get_format_string())
1307
 
        if from_branch is not None:
1308
 
            branch = from_branch
1309
 
        else:
1310
 
            branch = a_bzrdir.open_branch()
 
1263
        branch = a_bzrdir.open_branch()
1311
1264
        if revision_id is None:
1312
1265
            revision_id = branch.last_revision()
1313
1266
        local_path = transport.local_abspath('dirstate')
1322
1275
                         _control_files=control_files)
1323
1276
        wt._new_tree()
1324
1277
        wt.lock_tree_write()
 
1278
        wt.current_dirstate()._validate()
1325
1279
        try:
1326
1280
            if revision_id in (None, NULL_REVISION):
1327
1281
                if branch.repository.supports_rich_root():
1329
1283
                else:
1330
1284
                    wt._set_root_id(ROOT_ID)
1331
1285
                wt.flush()
1332
 
            basis = None
1333
 
            # frequently, we will get here due to branching.  The accelerator
1334
 
            # tree will be the tree from the branch, so the desired basis
1335
 
            # tree will often be a parent of the accelerator tree.
1336
 
            if accelerator_tree is not None:
1337
 
                try:
1338
 
                    basis = accelerator_tree.revision_tree(revision_id)
1339
 
                except errors.NoSuchRevision:
1340
 
                    pass
1341
 
            if basis is None:
1342
 
                basis = branch.repository.revision_tree(revision_id)
1343
 
            if revision_id == NULL_REVISION:
1344
 
                parents_list = []
1345
 
            else:
1346
 
                parents_list = [(revision_id, basis)]
 
1286
                wt.current_dirstate()._validate()
 
1287
            wt.set_last_revision(revision_id)
 
1288
            wt.flush()
 
1289
            basis = wt.basis_tree()
1347
1290
            basis.lock_read()
1348
 
            try:
1349
 
                wt.set_parent_trees(parents_list, allow_leftmost_as_ghost=True)
 
1291
            # if the basis has a root id we have to use that; otherwise we use
 
1292
            # a new random one
 
1293
            basis_root_id = basis.get_root_id()
 
1294
            if basis_root_id is not None:
 
1295
                wt._set_root_id(basis_root_id)
1350
1296
                wt.flush()
1351
 
                # if the basis has a root id we have to use that; otherwise we
1352
 
                # use a new random one
1353
 
                basis_root_id = basis.get_root_id()
1354
 
                if basis_root_id is not None:
1355
 
                    wt._set_root_id(basis_root_id)
1356
 
                    wt.flush()
1357
 
                transform.build_tree(basis, wt, accelerator_tree,
1358
 
                                     hardlink=hardlink)
1359
 
            finally:
1360
 
                basis.unlock()
 
1297
            transform.build_tree(basis, wt)
 
1298
            basis.unlock()
1361
1299
        finally:
1362
1300
            control_files.unlock()
1363
1301
            wt.unlock()
1388
1326
 
1389
1327
    def __init__(self, dirstate, revision_id, repository):
1390
1328
        self._dirstate = dirstate
1391
 
        self._revision_id = revision_id
 
1329
        self._revision_id = osutils.safe_revision_id(revision_id)
1392
1330
        self._repository = repository
1393
1331
        self._inventory = None
1394
1332
        self._locked = 0
1398
1336
        return "<%s of %s in %s>" % \
1399
1337
            (self.__class__.__name__, self._revision_id, self._dirstate)
1400
1338
 
1401
 
    def annotate_iter(self, file_id,
1402
 
                      default_revision=_mod_revision.CURRENT_REVISION):
 
1339
    def annotate_iter(self, file_id):
1403
1340
        """See Tree.annotate_iter"""
1404
 
        w = self._get_weave(file_id)
 
1341
        w = self._repository.weave_store.get_weave(file_id,
 
1342
                           self._repository.get_transaction())
1405
1343
        return w.annotate_iter(self.inventory[file_id].revision)
1406
1344
 
1407
 
    def _get_ancestors(self, default_revision):
1408
 
        return set(self._repository.get_ancestry(self._revision_id,
1409
 
                                                 topo_sorted=False))
1410
1345
    def _comparison_data(self, entry, path):
1411
1346
        """See Tree._comparison_data."""
1412
1347
        if entry is None:
1429
1364
    def get_root_id(self):
1430
1365
        return self.path2id('')
1431
1366
 
1432
 
    def id2path(self, file_id):
1433
 
        "Convert a file-id to a path."
1434
 
        entry = self._get_entry(file_id=file_id)
1435
 
        if entry == (None, None):
1436
 
            raise errors.NoSuchId(tree=self, file_id=file_id)
1437
 
        path_utf8 = osutils.pathjoin(entry[0][0], entry[0][1])
1438
 
        return path_utf8.decode('utf8')
1439
 
 
1440
1367
    def _get_parent_index(self):
1441
1368
        """Return the index in the dirstate referenced by this tree."""
1442
1369
        return self._dirstate.get_parent_ids().index(self._revision_id) + 1
1454
1381
        """
1455
1382
        if file_id is None and path is None:
1456
1383
            raise errors.BzrError('must supply file_id or path')
 
1384
        file_id = osutils.safe_file_id(file_id)
1457
1385
        if path is not None:
1458
1386
            path = path.encode('utf8')
1459
1387
        parent_index = self._get_parent_index()
1552
1480
            return parent_details[1]
1553
1481
        return None
1554
1482
 
1555
 
    @symbol_versioning.deprecated_method(symbol_versioning.zero_ninety)
1556
 
    def get_weave(self, file_id):
1557
 
        return self._get_weave(file_id)
1558
 
 
1559
 
    def _get_weave(self, file_id):
1560
 
        return self._repository.weave_store.get_weave(file_id,
1561
 
                self._repository.get_transaction())
1562
 
 
1563
 
    def get_file(self, file_id, path=None):
 
1483
    def get_file(self, file_id):
1564
1484
        return StringIO(self.get_file_text(file_id))
1565
1485
 
1566
1486
    def get_file_lines(self, file_id):
1567
 
        entry = self._get_entry(file_id=file_id)[1]
1568
 
        if entry == None:
1569
 
            raise errors.NoSuchId(tree=self, file_id=file_id)
1570
 
        return self._get_weave(file_id).get_lines(entry[1][4])
 
1487
        ie = self.inventory[file_id]
 
1488
        return self._repository.weave_store.get_weave(file_id,
 
1489
                self._repository.get_transaction()).get_lines(ie.revision)
1571
1490
 
1572
1491
    def get_file_size(self, file_id):
1573
1492
        return self.inventory[file_id].text_size
1578
1497
    def get_reference_revision(self, file_id, path=None):
1579
1498
        return self.inventory[file_id].reference_revision
1580
1499
 
1581
 
    def iter_files_bytes(self, desired_files):
1582
 
        """See Tree.iter_files_bytes.
1583
 
 
1584
 
        This version is implemented on top of Repository.iter_files_bytes"""
1585
 
        parent_index = self._get_parent_index()
1586
 
        repo_desired_files = []
1587
 
        for file_id, identifier in desired_files:
1588
 
            entry = self._get_entry(file_id)
1589
 
            if entry == (None, None):
1590
 
                raise errors.NoSuchId(self, file_id)
1591
 
            repo_desired_files.append((file_id, entry[1][parent_index][4],
1592
 
                                       identifier))
1593
 
        return self._repository.iter_files_bytes(repo_desired_files)
1594
 
 
1595
1500
    def get_symlink_target(self, file_id):
1596
1501
        entry = self._get_entry(file_id=file_id)
1597
1502
        parent_index = self._get_parent_index()
1625
1530
        return bool(self.path2id(filename))
1626
1531
 
1627
1532
    def kind(self, file_id):
1628
 
        entry = self._get_entry(file_id=file_id)[1]
1629
 
        if entry == None:
1630
 
            raise errors.NoSuchId(tree=self, file_id=file_id)
1631
 
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1632
 
 
1633
 
    def stored_kind(self, file_id):
1634
 
        """See Tree.stored_kind"""
1635
 
        return self.kind(file_id)
1636
 
 
1637
 
    def path_content_summary(self, path):
1638
 
        """See Tree.path_content_summary."""
1639
 
        id = self.inventory.path2id(path)
1640
 
        if id is None:
1641
 
            return ('missing', None, None, None)
1642
 
        entry = self._inventory[id]
1643
 
        kind = entry.kind
1644
 
        if kind == 'file':
1645
 
            return (kind, entry.text_size, entry.executable, entry.text_sha1)
1646
 
        elif kind == 'symlink':
1647
 
            return (kind, None, None, entry.symlink_target)
1648
 
        else:
1649
 
            return (kind, None, None, None)
 
1533
        return self.inventory[file_id].kind
1650
1534
 
1651
1535
    def is_executable(self, file_id, path=None):
1652
1536
        ie = self.inventory[file_id]
1760
1644
    _matching_to_tree_format = WorkingTreeFormat4()
1761
1645
    _test_mutable_trees_to_test_trees = make_source_parent_tree
1762
1646
 
1763
 
    def iter_changes(self, include_unchanged=False,
 
1647
    def _iter_changes(self, include_unchanged=False,
1764
1648
                      specific_files=None, pb=None, extra_trees=[],
1765
1649
                      require_versioned=True, want_unversioned=False):
1766
1650
        """Return the changes from source to target.
1767
1651
 
1768
 
        :return: An iterator that yields tuples. See InterTree.iter_changes
 
1652
        :return: An iterator that yields tuples. See InterTree._iter_changes
1769
1653
            for details.
1770
1654
        :param specific_files: An optional list of file paths to restrict the
1771
1655
            comparison to. When mapping filenames to ids, all matches in all
1782
1666
            output. An unversioned file is defined as one with (False, False)
1783
1667
            for the versioned pair.
1784
1668
        """
1785
 
        utf8_decode = cache_utf8._utf8_decode
 
1669
        utf8_decode_or_none = cache_utf8._utf8_decode_with_None
1786
1670
        _minikind_to_kind = dirstate.DirState._minikind_to_kind
1787
 
        cmp_by_dirs = dirstate.cmp_by_dirs
1788
1671
        # NB: show_status depends on being able to pass in non-versioned files
1789
1672
        # and report them as unknown
1790
1673
        # TODO: handle extra trees in the dirstate.
1791
 
        if (extra_trees or specific_files == []):
 
1674
        # TODO: handle comparisons as an empty tree as a different special
 
1675
        # case? mbp 20070226
 
1676
        if extra_trees or (self.source._revision_id == NULL_REVISION):
1792
1677
            # we can't fast-path these cases (yet)
1793
 
            for f in super(InterDirStateTree, self).iter_changes(
 
1678
            for f in super(InterDirStateTree, self)._iter_changes(
1794
1679
                include_unchanged, specific_files, pb, extra_trees,
1795
1680
                require_versioned, want_unversioned=want_unversioned):
1796
1681
                yield f
1797
1682
            return
1798
1683
        parent_ids = self.target.get_parent_ids()
1799
 
        assert (self.source._revision_id in parent_ids
1800
 
                or self.source._revision_id == NULL_REVISION), \
 
1684
        assert (self.source._revision_id in parent_ids), \
1801
1685
                "revision {%s} is not stored in {%s}, but %s " \
1802
1686
                "can only be used for trees stored in the dirstate" \
1803
 
                % (self.source._revision_id, self.target, self.iter_changes)
 
1687
                % (self.source._revision_id, self.target, self._iter_changes)
1804
1688
        target_index = 0
1805
1689
        if self.source._revision_id == NULL_REVISION:
1806
1690
            source_index = None
1810
1694
                "Failure: source._revision_id: %s not in target.parent_ids(%s)" % (
1811
1695
                self.source._revision_id, parent_ids)
1812
1696
            source_index = 1 + parent_ids.index(self.source._revision_id)
1813
 
            indices = (source_index, target_index)
 
1697
            indices = (source_index,target_index)
1814
1698
        # -- make all specific_files utf8 --
1815
1699
        if specific_files:
1816
1700
            specific_files_utf8 = set()
1916
1800
        NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
1917
1801
        # Using a list so that we can access the values and change them in
1918
1802
        # nested scope. Each one is [path, file_id, entry]
1919
 
        last_source_parent = [None, None]
1920
 
        last_target_parent = [None, None]
 
1803
        last_source_parent = [None, None, None]
 
1804
        last_target_parent = [None, None, None]
1921
1805
 
1922
1806
        use_filesystem_for_exec = (sys.platform != 'win32')
1923
1807
 
1924
 
        # Just a sentry, so that _process_entry can say that this
1925
 
        # record is handled, but isn't interesting to process (unchanged)
1926
 
        uninteresting = object()
1927
 
 
1928
 
 
1929
 
        old_dirname_to_file_id = {}
1930
 
        new_dirname_to_file_id = {}
1931
 
        # TODO: jam 20070516 - Avoid the _get_entry lookup overhead by
1932
 
        #       keeping a cache of directories that we have seen.
1933
 
 
1934
1808
        def _process_entry(entry, path_info):
1935
1809
            """Compare an entry and real disk to generate delta information.
1936
1810
 
1940
1814
                Basename is returned as a utf8 string because we expect this
1941
1815
                tuple will be ignored, and don't want to take the time to
1942
1816
                decode.
1943
 
            :return: None if these don't match
1944
 
                     A tuple of information about the change, or
1945
 
                     the object 'uninteresting' if these match, but are
1946
 
                     basically identical.
1947
1817
            """
1948
1818
            if source_index is None:
1949
1819
                source_details = NULL_PARENT_DETAILS
1960
1830
                target_minikind = target_details[0]
1961
1831
            else:
1962
1832
                link_or_sha1 = None
1963
 
            file_id = entry[0][2]
1964
1833
            source_minikind = source_details[0]
1965
1834
            if source_minikind in 'fdltr' and target_minikind in 'fdlt':
1966
1835
                # claimed content in both: diff
1983
1852
                                                 path_utf8=old_path)
1984
1853
                    # update the source details variable to be the real
1985
1854
                    # location.
1986
 
                    if old_entry == (None, None):
1987
 
                        raise errors.CorruptDirstate(state._filename,
1988
 
                            "entry '%s/%s' is considered renamed from %r"
1989
 
                            " but source does not exist\n"
1990
 
                            "entry: %s" % (entry[0][0], entry[0][1], old_path, entry))
1991
1855
                    source_details = old_entry[1][source_index]
1992
1856
                    source_minikind = source_details[0]
1993
1857
                else:
1994
1858
                    old_dirname = entry[0][0]
1995
1859
                    old_basename = entry[0][1]
1996
 
                    old_path = path = None
 
1860
                    old_path = path = pathjoin(old_dirname, old_basename)
1997
1861
                if path_info is None:
1998
1862
                    # the file is missing on disk, show as removed.
1999
1863
                    content_change = True
2003
1867
                    # source and target are both versioned and disk file is present.
2004
1868
                    target_kind = path_info[2]
2005
1869
                    if target_kind == 'directory':
2006
 
                        if path is None:
2007
 
                            old_path = path = pathjoin(old_dirname, old_basename)
2008
 
                        new_dirname_to_file_id[path] = file_id
2009
1870
                        if source_minikind != 'd':
2010
1871
                            content_change = True
2011
1872
                        else:
2040
1901
                        target_exec = False
2041
1902
                    else:
2042
1903
                        raise Exception, "unknown kind %s" % path_info[2]
2043
 
                if source_minikind == 'd':
2044
 
                    if path is None:
2045
 
                        old_path = path = pathjoin(old_dirname, old_basename)
2046
 
                    old_dirname_to_file_id[old_path] = file_id
2047
1904
                # parent id is the entry for the path in the target tree
2048
1905
                if old_dirname == last_source_parent[0]:
2049
1906
                    source_parent_id = last_source_parent[1]
2050
1907
                else:
2051
 
                    try:
2052
 
                        source_parent_id = old_dirname_to_file_id[old_dirname]
2053
 
                    except KeyError:
2054
 
                        source_parent_entry = state._get_entry(source_index,
2055
 
                                                               path_utf8=old_dirname)
2056
 
                        source_parent_id = source_parent_entry[0][2]
 
1908
                    source_parent_entry = state._get_entry(source_index,
 
1909
                                                           path_utf8=old_dirname)
 
1910
                    source_parent_id = source_parent_entry[0][2]
2057
1911
                    if source_parent_id == entry[0][2]:
2058
1912
                        # This is the root, so the parent is None
2059
1913
                        source_parent_id = None
2060
1914
                    else:
2061
1915
                        last_source_parent[0] = old_dirname
2062
1916
                        last_source_parent[1] = source_parent_id
 
1917
                        last_source_parent[2] = source_parent_entry
2063
1918
                new_dirname = entry[0][0]
2064
1919
                if new_dirname == last_target_parent[0]:
2065
1920
                    target_parent_id = last_target_parent[1]
2066
1921
                else:
2067
 
                    try:
2068
 
                        target_parent_id = new_dirname_to_file_id[new_dirname]
2069
 
                    except KeyError:
2070
 
                        # TODO: We don't always need to do the lookup, because the
2071
 
                        #       parent entry will be the same as the source entry.
2072
 
                        target_parent_entry = state._get_entry(target_index,
2073
 
                                                               path_utf8=new_dirname)
2074
 
                        assert target_parent_entry != (None, None), (
2075
 
                            "Could not find target parent in wt: %s\nparent of: %s"
2076
 
                            % (new_dirname, entry))
2077
 
                        target_parent_id = target_parent_entry[0][2]
 
1922
                    # TODO: We don't always need to do the lookup, because the
 
1923
                    #       parent entry will be the same as the source entry.
 
1924
                    target_parent_entry = state._get_entry(target_index,
 
1925
                                                           path_utf8=new_dirname)
 
1926
                    assert target_parent_entry != (None, None), (
 
1927
                        "Could not find target parent in wt: %s\nparent of: %s"
 
1928
                        % (new_dirname, entry))
 
1929
                    target_parent_id = target_parent_entry[0][2]
2078
1930
                    if target_parent_id == entry[0][2]:
2079
1931
                        # This is the root, so the parent is None
2080
1932
                        target_parent_id = None
2081
1933
                    else:
2082
1934
                        last_target_parent[0] = new_dirname
2083
1935
                        last_target_parent[1] = target_parent_id
 
1936
                        last_target_parent[2] = target_parent_entry
2084
1937
 
2085
1938
                source_exec = source_details[3]
2086
 
                if (include_unchanged
2087
 
                    or content_change
2088
 
                    or source_parent_id != target_parent_id
2089
 
                    or old_basename != entry[0][1]
2090
 
                    or source_exec != target_exec
2091
 
                    ):
2092
 
                    if old_path is None:
2093
 
                        old_path = path = pathjoin(old_dirname, old_basename)
2094
 
                        old_path_u = utf8_decode(old_path)[0]
2095
 
                        path_u = old_path_u
2096
 
                    else:
2097
 
                        old_path_u = utf8_decode(old_path)[0]
2098
 
                        if old_path == path:
2099
 
                            path_u = old_path_u
2100
 
                        else:
2101
 
                            path_u = utf8_decode(path)[0]
2102
 
                    source_kind = _minikind_to_kind[source_minikind]
2103
 
                    return (entry[0][2],
2104
 
                           (old_path_u, path_u),
2105
 
                           content_change,
2106
 
                           (True, True),
2107
 
                           (source_parent_id, target_parent_id),
2108
 
                           (utf8_decode(old_basename)[0], utf8_decode(entry[0][1])[0]),
2109
 
                           (source_kind, target_kind),
2110
 
                           (source_exec, target_exec))
2111
 
                else:
2112
 
                    return uninteresting
 
1939
                return ((entry[0][2], (old_path, path), content_change,
 
1940
                        (True, True),
 
1941
                        (source_parent_id, target_parent_id),
 
1942
                        (old_basename, entry[0][1]),
 
1943
                        (_minikind_to_kind[source_minikind], target_kind),
 
1944
                        (source_exec, target_exec)),)
2113
1945
            elif source_minikind in 'a' and target_minikind in 'fdlt':
2114
1946
                # looks like a new file
2115
1947
                if path_info is not None:
2128
1960
                            and stat.S_IEXEC & path_info[3].st_mode)
2129
1961
                    else:
2130
1962
                        target_exec = target_details[3]
2131
 
                    return (entry[0][2],
2132
 
                           (None, utf8_decode(path)[0]),
2133
 
                           True,
2134
 
                           (False, True),
2135
 
                           (None, parent_id),
2136
 
                           (None, utf8_decode(entry[0][1])[0]),
2137
 
                           (None, path_info[2]),
2138
 
                           (None, target_exec))
 
1963
                    return ((entry[0][2], (None, path), True,
 
1964
                            (False, True),
 
1965
                            (None, parent_id),
 
1966
                            (None, entry[0][1]),
 
1967
                            (None, path_info[2]),
 
1968
                            (None, target_exec)),)
2139
1969
                else:
2140
1970
                    # but its not on disk: we deliberately treat this as just
2141
1971
                    # never-present. (Why ?! - RBC 20070224)
2150
1980
                parent_id = state._get_entry(source_index, path_utf8=entry[0][0])[0][2]
2151
1981
                if parent_id == entry[0][2]:
2152
1982
                    parent_id = None
2153
 
                return (entry[0][2],
2154
 
                       (utf8_decode(old_path)[0], None),
2155
 
                       True,
2156
 
                       (True, False),
2157
 
                       (parent_id, None),
2158
 
                       (utf8_decode(entry[0][1])[0], None),
2159
 
                       (_minikind_to_kind[source_minikind], None),
2160
 
                       (source_details[3], None))
 
1983
                return ((entry[0][2], (old_path, None), True,
 
1984
                        (True, False),
 
1985
                        (parent_id, None),
 
1986
                        (entry[0][1], None),
 
1987
                        (_minikind_to_kind[source_minikind], None),
 
1988
                        (source_details[3], None)),)
2161
1989
            elif source_minikind in 'fdlt' and target_minikind in 'r':
2162
1990
                # a rename; could be a true rename, or a rename inherited from
2163
1991
                # a renamed parent. TODO: handle this efficiently. Its not
2175
2003
                    "source_minikind=%r, target_minikind=%r"
2176
2004
                    % (source_minikind, target_minikind))
2177
2005
                ## import pdb;pdb.set_trace()
2178
 
            return None
 
2006
            return ()
2179
2007
 
2180
2008
        while search_specific_files:
2181
2009
            # TODO: the pending list should be lexically sorted?  the
2211
2039
                continue
2212
2040
            path_handled = False
2213
2041
            for entry in root_entries:
2214
 
                result = _process_entry(entry, root_dir_info)
2215
 
                if result is not None:
 
2042
                for result in _process_entry(entry, root_dir_info):
 
2043
                    # this check should probably be outside the loop: one
 
2044
                    # 'iterate two trees' api, and then _iter_changes filters
 
2045
                    # unchanged pairs. - RBC 20070226
2216
2046
                    path_handled = True
2217
 
                    if result is not uninteresting:
2218
 
                        yield result
 
2047
                    if (include_unchanged
 
2048
                        or result[2]                    # content change
 
2049
                        or result[3][0] != result[3][1] # versioned status
 
2050
                        or result[4][0] != result[4][1] # parent id
 
2051
                        or result[5][0] != result[5][1] # name
 
2052
                        or result[6][0] != result[6][1] # kind
 
2053
                        or result[7][0] != result[7][1] # executable
 
2054
                        ):
 
2055
                        yield (result[0],
 
2056
                               (utf8_decode_or_none(result[1][0]),
 
2057
                                utf8_decode_or_none(result[1][1])),
 
2058
                               result[2],
 
2059
                               result[3],
 
2060
                               result[4],
 
2061
                               (utf8_decode_or_none(result[5][0]),
 
2062
                                utf8_decode_or_none(result[5][1])),
 
2063
                               result[6],
 
2064
                               result[7],
 
2065
                              )
2219
2066
            if want_unversioned and not path_handled and root_dir_info:
2220
2067
                new_executable = bool(
2221
2068
                    stat.S_ISREG(root_dir_info[3].st_mode)
2275
2122
                   current_block is not None):
2276
2123
                if (current_dir_info and current_block
2277
2124
                    and current_dir_info[0][0] != current_block[0]):
2278
 
                    if cmp_by_dirs(current_dir_info[0][0], current_block[0]) < 0:
 
2125
                    if current_dir_info[0][0] < current_block[0] :
2279
2126
                        # filesystem data refers to paths not covered by the dirblock.
2280
2127
                        # this has two possibilities:
2281
2128
                        # A) it is versioned but empty, so there is no block for it
2298
2145
                                        stat.S_ISREG(current_path_info[3].st_mode)
2299
2146
                                        and stat.S_IEXEC & current_path_info[3].st_mode)
2300
2147
                                    yield (None,
2301
 
                                        (None, utf8_decode(current_path_info[0])[0]),
 
2148
                                        (None, utf8_decode_or_none(current_path_info[0])),
2302
2149
                                        True,
2303
2150
                                        (False, False),
2304
2151
                                        (None, None),
2305
 
                                        (None, utf8_decode(current_path_info[1])[0]),
 
2152
                                        (None, utf8_decode_or_none(current_path_info[1])),
2306
2153
                                        (None, current_path_info[2]),
2307
2154
                                        (None, new_executable))
2308
2155
                                # dont descend into this unversioned path if it is
2329
2176
                        for current_entry in current_block[1]:
2330
2177
                            # entry referring to file not present on disk.
2331
2178
                            # advance the entry only, after processing.
2332
 
                            result = _process_entry(current_entry, None)
2333
 
                            if result is not None:
2334
 
                                if result is not uninteresting:
2335
 
                                    yield result
 
2179
                            for result in _process_entry(current_entry, None):
 
2180
                                # this check should probably be outside the loop: one
 
2181
                                # 'iterate two trees' api, and then _iter_changes filters
 
2182
                                # unchanged pairs. - RBC 20070226
 
2183
                                if (include_unchanged
 
2184
                                    or result[2]                    # content change
 
2185
                                    or result[3][0] != result[3][1] # versioned status
 
2186
                                    or result[4][0] != result[4][1] # parent id
 
2187
                                    or result[5][0] != result[5][1] # name
 
2188
                                    or result[6][0] != result[6][1] # kind
 
2189
                                    or result[7][0] != result[7][1] # executable
 
2190
                                    ):
 
2191
                                    yield (result[0],
 
2192
                                           (utf8_decode_or_none(result[1][0]),
 
2193
                                            utf8_decode_or_none(result[1][1])),
 
2194
                                           result[2],
 
2195
                                           result[3],
 
2196
                                           result[4],
 
2197
                                           (utf8_decode_or_none(result[5][0]),
 
2198
                                            utf8_decode_or_none(result[5][1])),
 
2199
                                           result[6],
 
2200
                                           result[7],
 
2201
                                          )
2336
2202
                        block_index +=1
2337
2203
                        if (block_index < len(state._dirblocks) and
2338
2204
                            osutils.is_inside(current_root,
2367
2233
                        pass
2368
2234
                    elif current_path_info is None:
2369
2235
                        # no path is fine: the per entry code will handle it.
2370
 
                        result = _process_entry(current_entry, current_path_info)
2371
 
                        if result is not None:
2372
 
                            if result is not uninteresting:
2373
 
                                yield result
2374
 
                    elif (current_entry[0][1] != current_path_info[1]
2375
 
                          or current_entry[1][target_index][0] in 'ar'):
2376
 
                        # The current path on disk doesn't match the dirblock
2377
 
                        # record. Either the dirblock is marked as absent, or
2378
 
                        # the file on disk is not present at all in the
2379
 
                        # dirblock. Either way, report about the dirblock
2380
 
                        # entry, and let other code handle the filesystem one.
2381
 
 
2382
 
                        # Compare the basename for these files to determine
2383
 
                        # which comes first
 
2236
                        for result in _process_entry(current_entry, current_path_info):
 
2237
                            # this check should probably be outside the loop: one
 
2238
                            # 'iterate two trees' api, and then _iter_changes filters
 
2239
                            # unchanged pairs. - RBC 20070226
 
2240
                            if (include_unchanged
 
2241
                                or result[2]                    # content change
 
2242
                                or result[3][0] != result[3][1] # versioned status
 
2243
                                or result[4][0] != result[4][1] # parent id
 
2244
                                or result[5][0] != result[5][1] # name
 
2245
                                or result[6][0] != result[6][1] # kind
 
2246
                                or result[7][0] != result[7][1] # executable
 
2247
                                ):
 
2248
                                yield (result[0],
 
2249
                                       (utf8_decode_or_none(result[1][0]),
 
2250
                                        utf8_decode_or_none(result[1][1])),
 
2251
                                       result[2],
 
2252
                                       result[3],
 
2253
                                       result[4],
 
2254
                                       (utf8_decode_or_none(result[5][0]),
 
2255
                                        utf8_decode_or_none(result[5][1])),
 
2256
                                       result[6],
 
2257
                                       result[7],
 
2258
                                      )
 
2259
                    elif current_entry[0][1] != current_path_info[1]:
2384
2260
                        if current_path_info[1] < current_entry[0][1]:
2385
2261
                            # extra file on disk: pass for now, but only
2386
2262
                            # increment the path, not the entry
2388
2264
                        else:
2389
2265
                            # entry referring to file not present on disk.
2390
2266
                            # advance the entry only, after processing.
2391
 
                            result = _process_entry(current_entry, None)
2392
 
                            if result is not None:
2393
 
                                if result is not uninteresting:
2394
 
                                    yield result
 
2267
                            for result in _process_entry(current_entry, None):
 
2268
                                # this check should probably be outside the loop: one
 
2269
                                # 'iterate two trees' api, and then _iter_changes filters
 
2270
                                # unchanged pairs. - RBC 20070226
 
2271
                                path_handled = True
 
2272
                                if (include_unchanged
 
2273
                                    or result[2]                    # content change
 
2274
                                    or result[3][0] != result[3][1] # versioned status
 
2275
                                    or result[4][0] != result[4][1] # parent id
 
2276
                                    or result[5][0] != result[5][1] # name
 
2277
                                    or result[6][0] != result[6][1] # kind
 
2278
                                    or result[7][0] != result[7][1] # executable
 
2279
                                    ):
 
2280
                                    yield (result[0],
 
2281
                                           (utf8_decode_or_none(result[1][0]),
 
2282
                                            utf8_decode_or_none(result[1][1])),
 
2283
                                           result[2],
 
2284
                                           result[3],
 
2285
                                           result[4],
 
2286
                                           (utf8_decode_or_none(result[5][0]),
 
2287
                                            utf8_decode_or_none(result[5][1])),
 
2288
                                           result[6],
 
2289
                                           result[7],
 
2290
                                          )
2395
2291
                            advance_path = False
 
2292
                    elif current_entry[1][target_index][0] in 'ar':
 
2293
                        # The path matches, but the current entry is marked as
 
2294
                        # not being here. So we don't want to consider this
 
2295
                        # as a match. We still need to process the current
 
2296
                        # entry, though.
 
2297
                        advance_path = False
 
2298
                        path_handled = False
 
2299
                        for result in _process_entry(current_entry, None):
 
2300
                            if (include_unchanged
 
2301
                                or result[2]                    # content change
 
2302
                                or result[3][0] != result[3][1] # versioned status
 
2303
                                or result[4][0] != result[4][1] # parent id
 
2304
                                or result[5][0] != result[5][1] # name
 
2305
                                or result[6][0] != result[6][1] # kind
 
2306
                                or result[7][0] != result[7][1] # executable
 
2307
                                ):
 
2308
                                yield (result[0],
 
2309
                                       (utf8_decode_or_none(result[1][0]),
 
2310
                                        utf8_decode_or_none(result[1][1])),
 
2311
                                       result[2],
 
2312
                                       result[3],
 
2313
                                       result[4],
 
2314
                                       (utf8_decode_or_none(result[5][0]),
 
2315
                                        utf8_decode_or_none(result[5][1])),
 
2316
                                       result[6],
 
2317
                                       result[7],
 
2318
                                      )
2396
2319
                    else:
2397
 
                        result = _process_entry(current_entry, current_path_info)
2398
 
                        if result is not None:
 
2320
                        for result in _process_entry(current_entry, current_path_info):
 
2321
                            # this check should probably be outside the loop: one
 
2322
                            # 'iterate two trees' api, and then _iter_changes filters
 
2323
                            # unchanged pairs. - RBC 20070226
2399
2324
                            path_handled = True
2400
 
                            if result is not uninteresting:
2401
 
                                yield result
 
2325
                            if (include_unchanged
 
2326
                                or result[2]                    # content change
 
2327
                                or result[3][0] != result[3][1] # versioned status
 
2328
                                or result[4][0] != result[4][1] # parent id
 
2329
                                or result[5][0] != result[5][1] # name
 
2330
                                or result[6][0] != result[6][1] # kind
 
2331
                                or result[7][0] != result[7][1] # executable
 
2332
                                ):
 
2333
                                yield (result[0],
 
2334
                                       (utf8_decode_or_none(result[1][0]),
 
2335
                                        utf8_decode_or_none(result[1][1])),
 
2336
                                       result[2],
 
2337
                                       result[3],
 
2338
                                       result[4],
 
2339
                                       (utf8_decode_or_none(result[5][0]),
 
2340
                                        utf8_decode_or_none(result[5][1])),
 
2341
                                       result[6],
 
2342
                                       result[7],
 
2343
                                      )
2402
2344
                    if advance_entry and current_entry is not None:
2403
2345
                        entry_index += 1
2404
2346
                        if entry_index < len(current_block[1]):
2415
2357
                                    stat.S_ISREG(current_path_info[3].st_mode)
2416
2358
                                    and stat.S_IEXEC & current_path_info[3].st_mode)
2417
2359
                                yield (None,
2418
 
                                    (None, utf8_decode(current_path_info[0])[0]),
 
2360
                                    (None, utf8_decode_or_none(current_path_info[0])),
2419
2361
                                    True,
2420
2362
                                    (False, False),
2421
2363
                                    (None, None),
2422
 
                                    (None, utf8_decode(current_path_info[1])[0]),
 
2364
                                    (None, utf8_decode_or_none(current_path_info[1])),
2423
2365
                                    (None, current_path_info[2]),
2424
2366
                                    (None, new_executable))
2425
2367
                            # dont descend into this unversioned path if it is