1270
def update_by_delta(self, delta):
1271
"""Apply an inventory delta to the dirstate for tree 0
1273
:param delta: An inventory delta. See Inventory.apply_delta for
1276
self._read_dirblocks_if_needed()
1279
for old_path, new_path, file_id, inv_entry in sorted(delta, reverse=True):
1280
if (file_id in insertions) or (file_id in removals):
1281
raise AssertionError("repeated file id in delta %r" % (file_id,))
1282
if old_path is not None:
1283
old_path = old_path.encode('utf-8')
1284
removals[file_id] = old_path
1285
if new_path is not None:
1286
new_path = new_path.encode('utf-8')
1287
dirname, basename = osutils.split(new_path)
1288
key = (dirname, basename, file_id)
1289
minikind = DirState._kind_to_minikind[inv_entry.kind]
1291
fingerprint = inv_entry.reference_revision
1294
insertions[file_id] = (key, minikind, inv_entry.executable,
1295
fingerprint, new_path)
1296
# Transform moves into delete+add pairs
1297
if None not in (old_path, new_path):
1298
for child in self._iter_child_entries(0, old_path):
1299
if child[0][2] in insertions or child[0][2] in removals:
1301
child_dirname = child[0][0]
1302
child_basename = child[0][1]
1303
minikind = child[1][0][0]
1304
fingerprint = child[1][0][4]
1305
executable = child[1][0][3]
1306
old_child_path = osutils.pathjoin(child[0][0],
1308
removals[child[0][2]] = old_child_path
1309
child_suffix = child_dirname[len(old_path):]
1310
new_child_dirname = (new_path + child_suffix)
1311
key = (new_child_dirname, child_basename, child[0][2])
1312
new_child_path = os.path.join(new_child_dirname,
1314
insertions[child[0][2]] = (key, minikind, executable,
1315
fingerprint, new_child_path)
1316
self._apply_removals(removals.values())
1317
self._apply_insertions(insertions.values())
1319
def _apply_removals(self, removals):
1320
for path in sorted(removals, reverse=True):
1321
dirname, basename = osutils.split(path)
1322
block_i, entry_i, d_present, f_present = \
1323
self._get_block_entry_index(dirname, basename, 0)
1324
entry = self._dirblocks[block_i][1][entry_i]
1325
self._make_absent(entry)
1326
# See if we have a malformed delta: deleting a directory must not
1327
# leave crud behind. This increases the number of bisects needed
1328
# substantially, but deletion or renames of large numbers of paths
1329
# is rare enough it shouldn't be an issue (famous last words?) RBC
1331
block_i, entry_i, d_present, f_present = \
1332
self._get_block_entry_index(path, '', 0)
1334
# The dir block is still present in the dirstate; this could
1335
# be due to it being in a parent tree, or a corrupt delta.
1336
for child_entry in self._dirblocks[block_i][1]:
1337
if child_entry[1][0][0] not in ('r', 'a'):
1338
raise errors.InconsistentDelta(path, entry[0][2],
1339
"The file id was deleted but its children were "
1342
def _apply_insertions(self, adds):
1343
for key, minikind, executable, fingerprint, path_utf8 in sorted(adds):
1344
self.update_minimal(key, minikind, executable, fingerprint,
1345
path_utf8=path_utf8)
1347
def update_basis_by_delta(self, delta, new_revid):
1348
"""Update the parents of this tree after a commit.
1350
This gives the tree one parent, with revision id new_revid. The
1351
inventory delta is applied to the current basis tree to generate the
1352
inventory for the parent new_revid, and all other parent trees are
1355
Note that an exception during the operation of this method will leave
1356
the dirstate in a corrupt state where it should not be saved.
1358
Finally, we expect all changes to be synchronising the basis tree with
1361
:param new_revid: The new revision id for the trees parent.
1362
:param delta: An inventory delta (see apply_inventory_delta) describing
1363
the changes from the current left most parent revision to new_revid.
1365
self._read_dirblocks_if_needed()
1366
self._discard_merge_parents()
1367
if self._ghosts != []:
1368
raise NotImplementedError(self.update_basis_by_delta)
1369
if len(self._parents) == 0:
1370
# setup a blank tree, the most simple way.
1371
empty_parent = DirState.NULL_PARENT_DETAILS
1372
for entry in self._iter_entries():
1373
entry[1].append(empty_parent)
1374
self._parents.append(new_revid)
1376
self._parents[0] = new_revid
1378
delta = sorted(delta, reverse=True)
1382
# The paths this function accepts are unicode and must be encoded as we
1384
encode = cache_utf8.encode
1385
inv_to_entry = self._inv_entry_to_details
1386
# delta is now (deletes, changes), (adds) in reverse lexographical
1388
# deletes in reverse lexographic order are safe to process in situ.
1389
# renames are not, as a rename from any path could go to a path
1390
# lexographically lower, so we transform renames into delete, add pairs,
1391
# expanding them recursively as needed.
1392
# At the same time, to reduce interface friction we convert the input
1393
# inventory entries to dirstate.
1394
root_only = ('', '')
1395
for old_path, new_path, file_id, inv_entry in delta:
1396
if old_path is None:
1397
adds.append((None, encode(new_path), file_id,
1398
inv_to_entry(inv_entry), True))
1399
elif new_path is None:
1400
deletes.append((encode(old_path), None, file_id, None, True))
1401
elif (old_path, new_path) != root_only:
1403
# Because renames must preserve their children we must have
1404
# processed all relocations and removes before hand. The sort
1405
# order ensures we've examined the child paths, but we also
1406
# have to execute the removals, or the split to an add/delete
1407
# pair will result in the deleted item being reinserted, or
1408
# renamed items being reinserted twice - and possibly at the
1409
# wrong place. Splitting into a delete/add pair also simplifies
1410
# the handling of entries with ('f', ...), ('r' ...) because
1411
# the target of the 'r' is old_path here, and we add that to
1412
# deletes, meaning that the add handler does not need to check
1413
# for 'r' items on every pass.
1414
self._update_basis_apply_deletes(deletes)
1416
new_path_utf8 = encode(new_path)
1417
# Split into an add/delete pair recursively.
1418
adds.append((None, new_path_utf8, file_id,
1419
inv_to_entry(inv_entry), False))
1420
# Expunge deletes that we've seen so that deleted/renamed
1421
# children of a rename directory are handled correctly.
1422
new_deletes = reversed(list(self._iter_child_entries(1,
1424
# Remove the current contents of the tree at orig_path, and
1425
# reinsert at the correct new path.
1426
for entry in new_deletes:
1428
source_path = entry[0][0] + '/' + entry[0][1]
1430
source_path = entry[0][1]
1432
target_path = new_path_utf8 + source_path[len(old_path):]
1435
raise AssertionError("cannot rename directory to"
1437
target_path = source_path[len(old_path) + 1:]
1438
adds.append((None, target_path, entry[0][2], entry[1][1], False))
1440
(source_path, target_path, entry[0][2], None, False))
1442
(encode(old_path), new_path, file_id, None, False))
1444
# changes to just the root should not require remove/insertion
1446
changes.append((encode(old_path), encode(new_path), file_id,
1447
inv_to_entry(inv_entry)))
1449
# Finish expunging deletes/first half of renames.
1450
self._update_basis_apply_deletes(deletes)
1451
# Reinstate second half of renames and new paths.
1452
self._update_basis_apply_adds(adds)
1453
# Apply in-situ changes.
1454
self._update_basis_apply_changes(changes)
1456
self._dirblock_state = DirState.IN_MEMORY_MODIFIED
1457
self._header_state = DirState.IN_MEMORY_MODIFIED
1458
self._id_index = None
1461
def _update_basis_apply_adds(self, adds):
1462
"""Apply a sequence of adds to tree 1 during update_basis_by_delta.
1464
They may be adds, or renames that have been split into add/delete
1467
:param adds: A sequence of adds. Each add is a tuple:
1468
(None, new_path_utf8, file_id, (entry_details), real_add). real_add
1469
is False when the add is the second half of a remove-and-reinsert
1470
pair created to handle renames and deletes.
1472
# Adds are accumulated partly from renames, so can be in any input
1475
# adds is now in lexographic order, which places all parents before
1476
# their children, so we can process it linearly.
1478
for old_path, new_path, file_id, new_details, real_add in adds:
1479
# the entry for this file_id must be in tree 0.
1480
entry = self._get_entry(0, file_id, new_path)
1481
if entry[0] is None or entry[0][2] != file_id:
1482
self._changes_aborted = True
1483
raise errors.InconsistentDelta(new_path, file_id,
1484
'working tree does not contain new entry')
1485
if real_add and entry[1][1][0] not in absent:
1486
self._changes_aborted = True
1487
raise errors.InconsistentDelta(new_path, file_id,
1488
'The entry was considered to be a genuinely new record,'
1489
' but there was already an old record for it.')
1490
# We don't need to update the target of an 'r' because the handling
1491
# of renames turns all 'r' situations into a delete at the original
1493
entry[1][1] = new_details
1495
def _update_basis_apply_changes(self, changes):
1496
"""Apply a sequence of changes to tree 1 during update_basis_by_delta.
1498
:param adds: A sequence of changes. Each change is a tuple:
1499
(path_utf8, path_utf8, file_id, (entry_details))
1502
for old_path, new_path, file_id, new_details in changes:
1503
# the entry for this file_id must be in tree 0.
1504
entry = self._get_entry(0, file_id, new_path)
1505
if entry[0] is None or entry[0][2] != file_id:
1506
self._changes_aborted = True
1507
raise errors.InconsistentDelta(new_path, file_id,
1508
'working tree does not contain new entry')
1509
if (entry[1][0][0] in absent or
1510
entry[1][1][0] in absent):
1511
self._changes_aborted = True
1512
raise errors.InconsistentDelta(new_path, file_id,
1513
'changed considered absent')
1514
entry[1][1] = new_details
1516
def _update_basis_apply_deletes(self, deletes):
1517
"""Apply a sequence of deletes to tree 1 during update_basis_by_delta.
1519
They may be deletes, or renames that have been split into add/delete
1522
:param deletes: A sequence of deletes. Each delete is a tuple:
1523
(old_path_utf8, new_path_utf8, file_id, None, real_delete).
1524
real_delete is True when the desired outcome is an actual deletion
1525
rather than the rename handling logic temporarily deleting a path
1526
during the replacement of a parent.
1528
null = DirState.NULL_PARENT_DETAILS
1529
for old_path, new_path, file_id, _, real_delete in deletes:
1530
if real_delete != (new_path is None):
1531
raise AssertionError("bad delete delta")
1532
# the entry for this file_id must be in tree 1.
1533
dirname, basename = osutils.split(old_path)
1534
block_index, entry_index, dir_present, file_present = \
1535
self._get_block_entry_index(dirname, basename, 1)
1536
if not file_present:
1537
self._changes_aborted = True
1538
raise errors.InconsistentDelta(old_path, file_id,
1539
'basis tree does not contain removed entry')
1540
entry = self._dirblocks[block_index][1][entry_index]
1541
if entry[0][2] != file_id:
1542
self._changes_aborted = True
1543
raise errors.InconsistentDelta(old_path, file_id,
1544
'mismatched file_id in tree 1')
1546
if entry[1][0][0] != 'a':
1547
self._changes_aborted = True
1548
raise errors.InconsistentDelta(old_path, file_id,
1549
'This was marked as a real delete, but the WT state'
1550
' claims that it still exists and is versioned.')
1551
del self._dirblocks[block_index][1][entry_index]
1553
if entry[1][0][0] == 'a':
1554
self._changes_aborted = True
1555
raise errors.InconsistentDelta(old_path, file_id,
1556
'The entry was considered a rename, but the source path'
1557
' is marked as absent.')
1558
# For whatever reason, we were asked to rename an entry
1559
# that was originally marked as deleted. This could be
1560
# because we are renaming the parent directory, and the WT
1561
# current state has the file marked as deleted.
1562
elif entry[1][0][0] == 'r':
1563
# implement the rename
1564
del self._dirblocks[block_index][1][entry_index]
1566
# it is being resurrected here, so blank it out temporarily.
1567
self._dirblocks[block_index][1][entry_index][1][1] = null
1569
def _observed_sha1(self, entry, sha1, stat_value,
1570
_stat_to_minikind=_stat_to_minikind, _pack_stat=pack_stat):
1571
"""Note the sha1 of a file.
1573
:param entry: The entry the sha1 is for.
1574
:param sha1: The observed sha1.
1575
:param stat_value: The os.lstat for the file.
1094
def update_entry(self, entry, abspath, stat_value,
1095
_stat_to_minikind=_stat_to_minikind,
1096
_pack_stat=pack_stat):
1097
"""Update the entry based on what is actually on disk.
1099
:param entry: This is the dirblock entry for the file in question.
1100
:param abspath: The path on disk for this file.
1101
:param stat_value: (optional) if we already have done a stat on the
1103
:return: The sha1 hexdigest of the file (40 bytes) or link target of a
1578
1107
minikind = _stat_to_minikind[stat_value.st_mode & 0170000]
2840
2278
self._split_path_cache = {}
2842
2280
def _requires_lock(self):
2843
"""Check that a lock is currently held by someone on the dirstate."""
2281
"""Checks that a lock is currently held by someone on the dirstate"""
2844
2282
if not self._lock_token:
2845
2283
raise errors.ObjectNotLocked(self)
2848
def py_update_entry(state, entry, abspath, stat_value,
2849
_stat_to_minikind=DirState._stat_to_minikind,
2850
_pack_stat=pack_stat):
2851
"""Update the entry based on what is actually on disk.
2853
This function only calculates the sha if it needs to - if the entry is
2854
uncachable, or clearly different to the first parent's entry, no sha
2855
is calculated, and None is returned.
2857
:param state: The dirstate this entry is in.
2858
:param entry: This is the dirblock entry for the file in question.
2859
:param abspath: The path on disk for this file.
2860
:param stat_value: The stat value done on the path.
2861
:return: None, or The sha1 hexdigest of the file (40 bytes) or link
2862
target of a symlink.
2865
minikind = _stat_to_minikind[stat_value.st_mode & 0170000]
2869
packed_stat = _pack_stat(stat_value)
2870
(saved_minikind, saved_link_or_sha1, saved_file_size,
2871
saved_executable, saved_packed_stat) = entry[1][0]
2873
if minikind == 'd' and saved_minikind == 't':
2875
if (minikind == saved_minikind
2876
and packed_stat == saved_packed_stat):
2877
# The stat hasn't changed since we saved, so we can re-use the
2882
# size should also be in packed_stat
2883
if saved_file_size == stat_value.st_size:
2884
return saved_link_or_sha1
2886
# If we have gotten this far, that means that we need to actually
2887
# process this entry.
2890
executable = state._is_executable(stat_value.st_mode,
2892
if state._cutoff_time is None:
2893
state._sha_cutoff_time()
2894
if (stat_value.st_mtime < state._cutoff_time
2895
and stat_value.st_ctime < state._cutoff_time
2896
and len(entry[1]) > 1
2897
and entry[1][1][0] != 'a'):
2898
# Could check for size changes for further optimised
2899
# avoidance of sha1's. However the most prominent case of
2900
# over-shaing is during initial add, which this catches.
2901
# Besides, if content filtering happens, size and sha
2902
# are calculated at the same time, so checking just the size
2903
# gains nothing w.r.t. performance.
2904
link_or_sha1 = state._sha1_file(abspath)
2905
entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
2906
executable, packed_stat)
2908
entry[1][0] = ('f', '', stat_value.st_size,
2909
executable, DirState.NULLSTAT)
2910
elif minikind == 'd':
2912
entry[1][0] = ('d', '', 0, False, packed_stat)
2913
if saved_minikind != 'd':
2914
# This changed from something into a directory. Make sure we
2915
# have a directory block for it. This doesn't happen very
2916
# often, so this doesn't have to be super fast.
2917
block_index, entry_index, dir_present, file_present = \
2918
state._get_block_entry_index(entry[0][0], entry[0][1], 0)
2919
state._ensure_block(block_index, entry_index,
2920
osutils.pathjoin(entry[0][0], entry[0][1]))
2921
elif minikind == 'l':
2922
link_or_sha1 = state._read_link(abspath, saved_link_or_sha1)
2923
if state._cutoff_time is None:
2924
state._sha_cutoff_time()
2925
if (stat_value.st_mtime < state._cutoff_time
2926
and stat_value.st_ctime < state._cutoff_time):
2927
entry[1][0] = ('l', link_or_sha1, stat_value.st_size,
2930
entry[1][0] = ('l', '', stat_value.st_size,
2931
False, DirState.NULLSTAT)
2932
state._dirblock_state = DirState.IN_MEMORY_MODIFIED
2934
update_entry = py_update_entry
2937
class ProcessEntryPython(object):
2939
__slots__ = ["old_dirname_to_file_id", "new_dirname_to_file_id", "uninteresting",
2940
"last_source_parent", "last_target_parent", "include_unchanged",
2941
"use_filesystem_for_exec", "utf8_decode", "searched_specific_files",
2942
"search_specific_files", "state", "source_index", "target_index",
2943
"want_unversioned", "tree"]
2945
def __init__(self, include_unchanged, use_filesystem_for_exec,
2946
search_specific_files, state, source_index, target_index,
2947
want_unversioned, tree):
2948
self.old_dirname_to_file_id = {}
2949
self.new_dirname_to_file_id = {}
2950
# Just a sentry, so that _process_entry can say that this
2951
# record is handled, but isn't interesting to process (unchanged)
2952
self.uninteresting = object()
2953
# Using a list so that we can access the values and change them in
2954
# nested scope. Each one is [path, file_id, entry]
2955
self.last_source_parent = [None, None]
2956
self.last_target_parent = [None, None]
2957
self.include_unchanged = include_unchanged
2958
self.use_filesystem_for_exec = use_filesystem_for_exec
2959
self.utf8_decode = cache_utf8._utf8_decode
2960
# for all search_indexs in each path at or under each element of
2961
# search_specific_files, if the detail is relocated: add the id, and add the
2962
# relocated path as one to search if its not searched already. If the
2963
# detail is not relocated, add the id.
2964
self.searched_specific_files = set()
2965
self.search_specific_files = search_specific_files
2967
self.source_index = source_index
2968
self.target_index = target_index
2969
self.want_unversioned = want_unversioned
2972
def _process_entry(self, entry, path_info, pathjoin=osutils.pathjoin):
2973
"""Compare an entry and real disk to generate delta information.
2975
:param path_info: top_relpath, basename, kind, lstat, abspath for
2976
the path of entry. If None, then the path is considered absent.
2977
(Perhaps we should pass in a concrete entry for this ?)
2978
Basename is returned as a utf8 string because we expect this
2979
tuple will be ignored, and don't want to take the time to
2981
:return: None if these don't match
2982
A tuple of information about the change, or
2983
the object 'uninteresting' if these match, but are
2984
basically identical.
2986
if self.source_index is None:
2987
source_details = DirState.NULL_PARENT_DETAILS
2989
source_details = entry[1][self.source_index]
2990
target_details = entry[1][self.target_index]
2991
target_minikind = target_details[0]
2992
if path_info is not None and target_minikind in 'fdlt':
2993
if not (self.target_index == 0):
2994
raise AssertionError()
2995
link_or_sha1 = update_entry(self.state, entry,
2996
abspath=path_info[4], stat_value=path_info[3])
2997
# The entry may have been modified by update_entry
2998
target_details = entry[1][self.target_index]
2999
target_minikind = target_details[0]
3002
file_id = entry[0][2]
3003
source_minikind = source_details[0]
3004
if source_minikind in 'fdltr' and target_minikind in 'fdlt':
3005
# claimed content in both: diff
3006
# r | fdlt | | add source to search, add id path move and perform
3007
# | | | diff check on source-target
3008
# r | fdlt | a | dangling file that was present in the basis.
3010
if source_minikind in 'r':
3011
# add the source to the search path to find any children it
3012
# has. TODO ? : only add if it is a container ?
3013
if not osutils.is_inside_any(self.searched_specific_files,
3015
self.search_specific_files.add(source_details[1])
3016
# generate the old path; this is needed for stating later
3018
old_path = source_details[1]
3019
old_dirname, old_basename = os.path.split(old_path)
3020
path = pathjoin(entry[0][0], entry[0][1])
3021
old_entry = self.state._get_entry(self.source_index,
3023
# update the source details variable to be the real
3025
if old_entry == (None, None):
3026
raise errors.CorruptDirstate(self.state._filename,
3027
"entry '%s/%s' is considered renamed from %r"
3028
" but source does not exist\n"
3029
"entry: %s" % (entry[0][0], entry[0][1], old_path, entry))
3030
source_details = old_entry[1][self.source_index]
3031
source_minikind = source_details[0]
3033
old_dirname = entry[0][0]
3034
old_basename = entry[0][1]
3035
old_path = path = None
3036
if path_info is None:
3037
# the file is missing on disk, show as removed.
3038
content_change = True
3042
# source and target are both versioned and disk file is present.
3043
target_kind = path_info[2]
3044
if target_kind == 'directory':
3046
old_path = path = pathjoin(old_dirname, old_basename)
3047
self.new_dirname_to_file_id[path] = file_id
3048
if source_minikind != 'd':
3049
content_change = True
3051
# directories have no fingerprint
3052
content_change = False
3054
elif target_kind == 'file':
3055
if source_minikind != 'f':
3056
content_change = True
3058
# If the size is the same, check the sha:
3059
if target_details[2] == source_details[2]:
3060
if link_or_sha1 is None:
3062
statvalue, link_or_sha1 = \
3063
self.state._sha1_provider.stat_and_sha1(
3065
self.state._observed_sha1(entry, link_or_sha1,
3067
content_change = (link_or_sha1 != source_details[1])
3069
# Size changed, so must be different
3070
content_change = True
3071
# Target details is updated at update_entry time
3072
if self.use_filesystem_for_exec:
3073
# We don't need S_ISREG here, because we are sure
3074
# we are dealing with a file.
3075
target_exec = bool(stat.S_IEXEC & path_info[3].st_mode)
3077
target_exec = target_details[3]
3078
elif target_kind == 'symlink':
3079
if source_minikind != 'l':
3080
content_change = True
3082
content_change = (link_or_sha1 != source_details[1])
3084
elif target_kind == 'tree-reference':
3085
if source_minikind != 't':
3086
content_change = True
3088
content_change = False
3091
raise Exception, "unknown kind %s" % path_info[2]
3092
if source_minikind == 'd':
3094
old_path = path = pathjoin(old_dirname, old_basename)
3095
self.old_dirname_to_file_id[old_path] = file_id
3096
# parent id is the entry for the path in the target tree
3097
if old_dirname == self.last_source_parent[0]:
3098
source_parent_id = self.last_source_parent[1]
3101
source_parent_id = self.old_dirname_to_file_id[old_dirname]
3103
source_parent_entry = self.state._get_entry(self.source_index,
3104
path_utf8=old_dirname)
3105
source_parent_id = source_parent_entry[0][2]
3106
if source_parent_id == entry[0][2]:
3107
# This is the root, so the parent is None
3108
source_parent_id = None
3110
self.last_source_parent[0] = old_dirname
3111
self.last_source_parent[1] = source_parent_id
3112
new_dirname = entry[0][0]
3113
if new_dirname == self.last_target_parent[0]:
3114
target_parent_id = self.last_target_parent[1]
3117
target_parent_id = self.new_dirname_to_file_id[new_dirname]
3119
# TODO: We don't always need to do the lookup, because the
3120
# parent entry will be the same as the source entry.
3121
target_parent_entry = self.state._get_entry(self.target_index,
3122
path_utf8=new_dirname)
3123
if target_parent_entry == (None, None):
3124
raise AssertionError(
3125
"Could not find target parent in wt: %s\nparent of: %s"
3126
% (new_dirname, entry))
3127
target_parent_id = target_parent_entry[0][2]
3128
if target_parent_id == entry[0][2]:
3129
# This is the root, so the parent is None
3130
target_parent_id = None
3132
self.last_target_parent[0] = new_dirname
3133
self.last_target_parent[1] = target_parent_id
3135
source_exec = source_details[3]
3136
if (self.include_unchanged
3138
or source_parent_id != target_parent_id
3139
or old_basename != entry[0][1]
3140
or source_exec != target_exec
3142
if old_path is None:
3143
old_path = path = pathjoin(old_dirname, old_basename)
3144
old_path_u = self.utf8_decode(old_path)[0]
3147
old_path_u = self.utf8_decode(old_path)[0]
3148
if old_path == path:
3151
path_u = self.utf8_decode(path)[0]
3152
source_kind = DirState._minikind_to_kind[source_minikind]
3153
return (entry[0][2],
3154
(old_path_u, path_u),
3157
(source_parent_id, target_parent_id),
3158
(self.utf8_decode(old_basename)[0], self.utf8_decode(entry[0][1])[0]),
3159
(source_kind, target_kind),
3160
(source_exec, target_exec))
3162
return self.uninteresting
3163
elif source_minikind in 'a' and target_minikind in 'fdlt':
3164
# looks like a new file
3165
path = pathjoin(entry[0][0], entry[0][1])
3166
# parent id is the entry for the path in the target tree
3167
# TODO: these are the same for an entire directory: cache em.
3168
parent_id = self.state._get_entry(self.target_index,
3169
path_utf8=entry[0][0])[0][2]
3170
if parent_id == entry[0][2]:
3172
if path_info is not None:
3174
if self.use_filesystem_for_exec:
3175
# We need S_ISREG here, because we aren't sure if this
3178
stat.S_ISREG(path_info[3].st_mode)
3179
and stat.S_IEXEC & path_info[3].st_mode)
3181
target_exec = target_details[3]
3182
return (entry[0][2],
3183
(None, self.utf8_decode(path)[0]),
3187
(None, self.utf8_decode(entry[0][1])[0]),
3188
(None, path_info[2]),
3189
(None, target_exec))
3191
# Its a missing file, report it as such.
3192
return (entry[0][2],
3193
(None, self.utf8_decode(path)[0]),
3197
(None, self.utf8_decode(entry[0][1])[0]),
3200
elif source_minikind in 'fdlt' and target_minikind in 'a':
3201
# unversioned, possibly, or possibly not deleted: we dont care.
3202
# if its still on disk, *and* theres no other entry at this
3203
# path [we dont know this in this routine at the moment -
3204
# perhaps we should change this - then it would be an unknown.
3205
old_path = pathjoin(entry[0][0], entry[0][1])
3206
# parent id is the entry for the path in the target tree
3207
parent_id = self.state._get_entry(self.source_index, path_utf8=entry[0][0])[0][2]
3208
if parent_id == entry[0][2]:
3210
return (entry[0][2],
3211
(self.utf8_decode(old_path)[0], None),
3215
(self.utf8_decode(entry[0][1])[0], None),
3216
(DirState._minikind_to_kind[source_minikind], None),
3217
(source_details[3], None))
3218
elif source_minikind in 'fdlt' and target_minikind in 'r':
3219
# a rename; could be a true rename, or a rename inherited from
3220
# a renamed parent. TODO: handle this efficiently. Its not
3221
# common case to rename dirs though, so a correct but slow
3222
# implementation will do.
3223
if not osutils.is_inside_any(self.searched_specific_files, target_details[1]):
3224
self.search_specific_files.add(target_details[1])
3225
elif source_minikind in 'ra' and target_minikind in 'ra':
3226
# neither of the selected trees contain this file,
3227
# so skip over it. This is not currently directly tested, but
3228
# is indirectly via test_too_much.TestCommands.test_conflicts.
3231
raise AssertionError("don't know how to compare "
3232
"source_minikind=%r, target_minikind=%r"
3233
% (source_minikind, target_minikind))
3234
## import pdb;pdb.set_trace()
3240
def iter_changes(self):
3241
"""Iterate over the changes."""
3242
utf8_decode = cache_utf8._utf8_decode
3243
_cmp_by_dirs = cmp_by_dirs
3244
_process_entry = self._process_entry
3245
uninteresting = self.uninteresting
3246
search_specific_files = self.search_specific_files
3247
searched_specific_files = self.searched_specific_files
3248
splitpath = osutils.splitpath
3250
# compare source_index and target_index at or under each element of search_specific_files.
3251
# follow the following comparison table. Note that we only want to do diff operations when
3252
# the target is fdl because thats when the walkdirs logic will have exposed the pathinfo
3256
# Source | Target | disk | action
3257
# r | fdlt | | add source to search, add id path move and perform
3258
# | | | diff check on source-target
3259
# r | fdlt | a | dangling file that was present in the basis.
3261
# r | a | | add source to search
3263
# r | r | | this path is present in a non-examined tree, skip.
3264
# r | r | a | this path is present in a non-examined tree, skip.
3265
# a | fdlt | | add new id
3266
# a | fdlt | a | dangling locally added file, skip
3267
# a | a | | not present in either tree, skip
3268
# a | a | a | not present in any tree, skip
3269
# a | r | | not present in either tree at this path, skip as it
3270
# | | | may not be selected by the users list of paths.
3271
# a | r | a | not present in either tree at this path, skip as it
3272
# | | | may not be selected by the users list of paths.
3273
# fdlt | fdlt | | content in both: diff them
3274
# fdlt | fdlt | a | deleted locally, but not unversioned - show as deleted ?
3275
# fdlt | a | | unversioned: output deleted id for now
3276
# fdlt | a | a | unversioned and deleted: output deleted id
3277
# fdlt | r | | relocated in this tree, so add target to search.
3278
# | | | Dont diff, we will see an r,fd; pair when we reach
3279
# | | | this id at the other path.
3280
# fdlt | r | a | relocated in this tree, so add target to search.
3281
# | | | Dont diff, we will see an r,fd; pair when we reach
3282
# | | | this id at the other path.
3284
# TODO: jam 20070516 - Avoid the _get_entry lookup overhead by
3285
# keeping a cache of directories that we have seen.
3287
while search_specific_files:
3288
# TODO: the pending list should be lexically sorted? the
3289
# interface doesn't require it.
3290
current_root = search_specific_files.pop()
3291
current_root_unicode = current_root.decode('utf8')
3292
searched_specific_files.add(current_root)
3293
# process the entries for this containing directory: the rest will be
3294
# found by their parents recursively.
3295
root_entries = self.state._entries_for_path(current_root)
3296
root_abspath = self.tree.abspath(current_root_unicode)
3298
root_stat = os.lstat(root_abspath)
3300
if e.errno == errno.ENOENT:
3301
# the path does not exist: let _process_entry know that.
3302
root_dir_info = None
3304
# some other random error: hand it up.
3307
root_dir_info = ('', current_root,
3308
osutils.file_kind_from_stat_mode(root_stat.st_mode), root_stat,
3310
if root_dir_info[2] == 'directory':
3311
if self.tree._directory_is_tree_reference(
3312
current_root.decode('utf8')):
3313
root_dir_info = root_dir_info[:2] + \
3314
('tree-reference',) + root_dir_info[3:]
3316
if not root_entries and not root_dir_info:
3317
# this specified path is not present at all, skip it.
3319
path_handled = False
3320
for entry in root_entries:
3321
result = _process_entry(entry, root_dir_info)
3322
if result is not None:
3324
if result is not uninteresting:
3326
if self.want_unversioned and not path_handled and root_dir_info:
3327
new_executable = bool(
3328
stat.S_ISREG(root_dir_info[3].st_mode)
3329
and stat.S_IEXEC & root_dir_info[3].st_mode)
3331
(None, current_root_unicode),
3335
(None, splitpath(current_root_unicode)[-1]),
3336
(None, root_dir_info[2]),
3337
(None, new_executable)
3339
initial_key = (current_root, '', '')
3340
block_index, _ = self.state._find_block_index_from_key(initial_key)
3341
if block_index == 0:
3342
# we have processed the total root already, but because the
3343
# initial key matched it we should skip it here.
3345
if root_dir_info and root_dir_info[2] == 'tree-reference':
3346
current_dir_info = None
3348
dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
3350
current_dir_info = dir_iterator.next()
3352
# on win32, python2.4 has e.errno == ERROR_DIRECTORY, but
3353
# python 2.5 has e.errno == EINVAL,
3354
# and e.winerror == ERROR_DIRECTORY
3355
e_winerror = getattr(e, 'winerror', None)
3356
win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
3357
# there may be directories in the inventory even though
3358
# this path is not a file on disk: so mark it as end of
3360
if e.errno in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
3361
current_dir_info = None
3362
elif (sys.platform == 'win32'
3363
and (e.errno in win_errors
3364
or e_winerror in win_errors)):
3365
current_dir_info = None
3369
if current_dir_info[0][0] == '':
3370
# remove .bzr from iteration
3371
bzr_index = bisect.bisect_left(current_dir_info[1], ('.bzr',))
3372
if current_dir_info[1][bzr_index][0] != '.bzr':
3373
raise AssertionError()
3374
del current_dir_info[1][bzr_index]
3375
# walk until both the directory listing and the versioned metadata
3377
if (block_index < len(self.state._dirblocks) and
3378
osutils.is_inside(current_root, self.state._dirblocks[block_index][0])):
3379
current_block = self.state._dirblocks[block_index]
3381
current_block = None
3382
while (current_dir_info is not None or
3383
current_block is not None):
3384
if (current_dir_info and current_block
3385
and current_dir_info[0][0] != current_block[0]):
3386
if _cmp_by_dirs(current_dir_info[0][0], current_block[0]) < 0:
3387
# filesystem data refers to paths not covered by the dirblock.
3388
# this has two possibilities:
3389
# A) it is versioned but empty, so there is no block for it
3390
# B) it is not versioned.
3392
# if (A) then we need to recurse into it to check for
3393
# new unknown files or directories.
3394
# if (B) then we should ignore it, because we don't
3395
# recurse into unknown directories.
3397
while path_index < len(current_dir_info[1]):
3398
current_path_info = current_dir_info[1][path_index]
3399
if self.want_unversioned:
3400
if current_path_info[2] == 'directory':
3401
if self.tree._directory_is_tree_reference(
3402
current_path_info[0].decode('utf8')):
3403
current_path_info = current_path_info[:2] + \
3404
('tree-reference',) + current_path_info[3:]
3405
new_executable = bool(
3406
stat.S_ISREG(current_path_info[3].st_mode)
3407
and stat.S_IEXEC & current_path_info[3].st_mode)
3409
(None, utf8_decode(current_path_info[0])[0]),
3413
(None, utf8_decode(current_path_info[1])[0]),
3414
(None, current_path_info[2]),
3415
(None, new_executable))
3416
# dont descend into this unversioned path if it is
3418
if current_path_info[2] in ('directory',
3420
del current_dir_info[1][path_index]
3424
# This dir info has been handled, go to the next
3426
current_dir_info = dir_iterator.next()
3427
except StopIteration:
3428
current_dir_info = None
3430
# We have a dirblock entry for this location, but there
3431
# is no filesystem path for this. This is most likely
3432
# because a directory was removed from the disk.
3433
# We don't have to report the missing directory,
3434
# because that should have already been handled, but we
3435
# need to handle all of the files that are contained
3437
for current_entry in current_block[1]:
3438
# entry referring to file not present on disk.
3439
# advance the entry only, after processing.
3440
result = _process_entry(current_entry, None)
3441
if result is not None:
3442
if result is not uninteresting:
3445
if (block_index < len(self.state._dirblocks) and
3446
osutils.is_inside(current_root,
3447
self.state._dirblocks[block_index][0])):
3448
current_block = self.state._dirblocks[block_index]
3450
current_block = None
3453
if current_block and entry_index < len(current_block[1]):
3454
current_entry = current_block[1][entry_index]
3456
current_entry = None
3457
advance_entry = True
3459
if current_dir_info and path_index < len(current_dir_info[1]):
3460
current_path_info = current_dir_info[1][path_index]
3461
if current_path_info[2] == 'directory':
3462
if self.tree._directory_is_tree_reference(
3463
current_path_info[0].decode('utf8')):
3464
current_path_info = current_path_info[:2] + \
3465
('tree-reference',) + current_path_info[3:]
3467
current_path_info = None
3469
path_handled = False
3470
while (current_entry is not None or
3471
current_path_info is not None):
3472
if current_entry is None:
3473
# the check for path_handled when the path is advanced
3474
# will yield this path if needed.
3476
elif current_path_info is None:
3477
# no path is fine: the per entry code will handle it.
3478
result = _process_entry(current_entry, current_path_info)
3479
if result is not None:
3480
if result is not uninteresting:
3482
elif (current_entry[0][1] != current_path_info[1]
3483
or current_entry[1][self.target_index][0] in 'ar'):
3484
# The current path on disk doesn't match the dirblock
3485
# record. Either the dirblock is marked as absent, or
3486
# the file on disk is not present at all in the
3487
# dirblock. Either way, report about the dirblock
3488
# entry, and let other code handle the filesystem one.
3490
# Compare the basename for these files to determine
3492
if current_path_info[1] < current_entry[0][1]:
3493
# extra file on disk: pass for now, but only
3494
# increment the path, not the entry
3495
advance_entry = False
3497
# entry referring to file not present on disk.
3498
# advance the entry only, after processing.
3499
result = _process_entry(current_entry, None)
3500
if result is not None:
3501
if result is not uninteresting:
3503
advance_path = False
3505
result = _process_entry(current_entry, current_path_info)
3506
if result is not None:
3508
if result is not uninteresting:
3510
if advance_entry and current_entry is not None:
3512
if entry_index < len(current_block[1]):
3513
current_entry = current_block[1][entry_index]
3515
current_entry = None
3517
advance_entry = True # reset the advance flaga
3518
if advance_path and current_path_info is not None:
3519
if not path_handled:
3520
# unversioned in all regards
3521
if self.want_unversioned:
3522
new_executable = bool(
3523
stat.S_ISREG(current_path_info[3].st_mode)
3524
and stat.S_IEXEC & current_path_info[3].st_mode)
3526
relpath_unicode = utf8_decode(current_path_info[0])[0]
3527
except UnicodeDecodeError:
3528
raise errors.BadFilenameEncoding(
3529
current_path_info[0], osutils._fs_enc)
3531
(None, relpath_unicode),
3535
(None, utf8_decode(current_path_info[1])[0]),
3536
(None, current_path_info[2]),
3537
(None, new_executable))
3538
# dont descend into this unversioned path if it is
3540
if current_path_info[2] in ('directory'):
3541
del current_dir_info[1][path_index]
3543
# dont descend the disk iterator into any tree
3545
if current_path_info[2] == 'tree-reference':
3546
del current_dir_info[1][path_index]
3549
if path_index < len(current_dir_info[1]):
3550
current_path_info = current_dir_info[1][path_index]
3551
if current_path_info[2] == 'directory':
3552
if self.tree._directory_is_tree_reference(
3553
current_path_info[0].decode('utf8')):
3554
current_path_info = current_path_info[:2] + \
3555
('tree-reference',) + current_path_info[3:]
3557
current_path_info = None
3558
path_handled = False
3560
advance_path = True # reset the advance flagg.
3561
if current_block is not None:
3563
if (block_index < len(self.state._dirblocks) and
3564
osutils.is_inside(current_root, self.state._dirblocks[block_index][0])):
3565
current_block = self.state._dirblocks[block_index]
3567
current_block = None
3568
if current_dir_info is not None:
3570
current_dir_info = dir_iterator.next()
3571
except StopIteration:
3572
current_dir_info = None
3573
_process_entry = ProcessEntryPython
3576
2286
# Try to load the compiled form if possible
3578
2288
from bzrlib._dirstate_helpers_c import (