1091
def update_entry(self, entry, abspath, stat_value,
1092
_stat_to_minikind=_stat_to_minikind,
1093
_pack_stat=pack_stat):
1094
"""Update the entry based on what is actually on disk.
1096
:param entry: This is the dirblock entry for the file in question.
1097
:param abspath: The path on disk for this file.
1098
:param stat_value: (optional) if we already have done a stat on the
1100
:return: The sha1 hexdigest of the file (40 bytes) or link target of a
1277
def update_by_delta(self, delta):
1278
"""Apply an inventory delta to the dirstate for tree 0
1280
:param delta: An inventory delta. See Inventory.apply_delta for
1283
self._read_dirblocks_if_needed()
1286
for old_path, new_path, file_id, inv_entry in sorted(delta, reverse=True):
1287
if (file_id in insertions) or (file_id in removals):
1288
raise AssertionError("repeated file id in delta %r" % (file_id,))
1289
if old_path is not None:
1290
old_path = old_path.encode('utf-8')
1291
removals[file_id] = old_path
1292
if new_path is not None:
1293
new_path = new_path.encode('utf-8')
1294
dirname, basename = osutils.split(new_path)
1295
key = (dirname, basename, file_id)
1296
minikind = DirState._kind_to_minikind[inv_entry.kind]
1298
fingerprint = inv_entry.reference_revision
1301
insertions[file_id] = (key, minikind, inv_entry.executable,
1302
fingerprint, new_path)
1303
# Transform moves into delete+add pairs
1304
if None not in (old_path, new_path):
1305
for child in self._iter_child_entries(0, old_path):
1306
if child[0][2] in insertions or child[0][2] in removals:
1308
child_dirname = child[0][0]
1309
child_basename = child[0][1]
1310
minikind = child[1][0][0]
1311
fingerprint = child[1][0][4]
1312
executable = child[1][0][3]
1313
old_child_path = osutils.pathjoin(child[0][0],
1315
removals[child[0][2]] = old_child_path
1316
child_suffix = child_dirname[len(old_path):]
1317
new_child_dirname = (new_path + child_suffix)
1318
key = (new_child_dirname, child_basename, child[0][2])
1319
new_child_path = os.path.join(new_child_dirname,
1321
insertions[child[0][2]] = (key, minikind, executable,
1322
fingerprint, new_child_path)
1323
self._apply_removals(removals.values())
1324
self._apply_insertions(insertions.values())
1326
def _apply_removals(self, removals):
1327
for path in sorted(removals, reverse=True):
1328
dirname, basename = osutils.split(path)
1329
block_i, entry_i, d_present, f_present = \
1330
self._get_block_entry_index(dirname, basename, 0)
1331
entry = self._dirblocks[block_i][1][entry_i]
1332
self._make_absent(entry)
1333
# See if we have a malformed delta: deleting a directory must not
1334
# leave crud behind. This increases the number of bisects needed
1335
# substantially, but deletion or renames of large numbers of paths
1336
# is rare enough it shouldn't be an issue (famous last words?) RBC
1338
block_i, entry_i, d_present, f_present = \
1339
self._get_block_entry_index(path, '', 0)
1341
# The dir block is still present in the dirstate; this could
1342
# be due to it being in a parent tree, or a corrupt delta.
1343
for child_entry in self._dirblocks[block_i][1]:
1344
if child_entry[1][0][0] not in ('r', 'a'):
1345
raise errors.InconsistentDelta(path, entry[0][2],
1346
"The file id was deleted but its children were "
1349
def _apply_insertions(self, adds):
1350
for key, minikind, executable, fingerprint, path_utf8 in sorted(adds):
1351
self.update_minimal(key, minikind, executable, fingerprint,
1352
path_utf8=path_utf8)
1354
def update_basis_by_delta(self, delta, new_revid):
1355
"""Update the parents of this tree after a commit.
1357
This gives the tree one parent, with revision id new_revid. The
1358
inventory delta is applied to the current basis tree to generate the
1359
inventory for the parent new_revid, and all other parent trees are
1362
Note that an exception during the operation of this method will leave
1363
the dirstate in a corrupt state where it should not be saved.
1365
Finally, we expect all changes to be synchronising the basis tree with
1368
:param new_revid: The new revision id for the trees parent.
1369
:param delta: An inventory delta (see apply_inventory_delta) describing
1370
the changes from the current left most parent revision to new_revid.
1372
self._read_dirblocks_if_needed()
1373
self._discard_merge_parents()
1374
if self._ghosts != []:
1375
raise NotImplementedError(self.update_basis_by_delta)
1376
if len(self._parents) == 0:
1377
# setup a blank tree, the most simple way.
1378
empty_parent = DirState.NULL_PARENT_DETAILS
1379
for entry in self._iter_entries():
1380
entry[1].append(empty_parent)
1381
self._parents.append(new_revid)
1383
self._parents[0] = new_revid
1385
delta = sorted(delta, reverse=True)
1389
# The paths this function accepts are unicode and must be encoded as we
1391
encode = cache_utf8.encode
1392
inv_to_entry = self._inv_entry_to_details
1393
# delta is now (deletes, changes), (adds) in reverse lexographical
1395
# deletes in reverse lexographic order are safe to process in situ.
1396
# renames are not, as a rename from any path could go to a path
1397
# lexographically lower, so we transform renames into delete, add pairs,
1398
# expanding them recursively as needed.
1399
# At the same time, to reduce interface friction we convert the input
1400
# inventory entries to dirstate.
1401
root_only = ('', '')
1402
for old_path, new_path, file_id, inv_entry in delta:
1403
if old_path is None:
1404
adds.append((None, encode(new_path), file_id,
1405
inv_to_entry(inv_entry), True))
1406
elif new_path is None:
1407
deletes.append((encode(old_path), None, file_id, None, True))
1408
elif (old_path, new_path) != root_only:
1410
# Because renames must preserve their children we must have
1411
# processed all relocations and removes before hand. The sort
1412
# order ensures we've examined the child paths, but we also
1413
# have to execute the removals, or the split to an add/delete
1414
# pair will result in the deleted item being reinserted, or
1415
# renamed items being reinserted twice - and possibly at the
1416
# wrong place. Splitting into a delete/add pair also simplifies
1417
# the handling of entries with ('f', ...), ('r' ...) because
1418
# the target of the 'r' is old_path here, and we add that to
1419
# deletes, meaning that the add handler does not need to check
1420
# for 'r' items on every pass.
1421
self._update_basis_apply_deletes(deletes)
1423
new_path_utf8 = encode(new_path)
1424
# Split into an add/delete pair recursively.
1425
adds.append((None, new_path_utf8, file_id,
1426
inv_to_entry(inv_entry), False))
1427
# Expunge deletes that we've seen so that deleted/renamed
1428
# children of a rename directory are handled correctly.
1429
new_deletes = reversed(list(self._iter_child_entries(1,
1431
# Remove the current contents of the tree at orig_path, and
1432
# reinsert at the correct new path.
1433
for entry in new_deletes:
1435
source_path = entry[0][0] + '/' + entry[0][1]
1437
source_path = entry[0][1]
1439
target_path = new_path_utf8 + source_path[len(old_path):]
1442
raise AssertionError("cannot rename directory to"
1444
target_path = source_path[len(old_path) + 1:]
1445
adds.append((None, target_path, entry[0][2], entry[1][1], False))
1447
(source_path, target_path, entry[0][2], None, False))
1449
(encode(old_path), new_path, file_id, None, False))
1451
# changes to just the root should not require remove/insertion
1453
changes.append((encode(old_path), encode(new_path), file_id,
1454
inv_to_entry(inv_entry)))
1456
# Finish expunging deletes/first half of renames.
1457
self._update_basis_apply_deletes(deletes)
1458
# Reinstate second half of renames and new paths.
1459
self._update_basis_apply_adds(adds)
1460
# Apply in-situ changes.
1461
self._update_basis_apply_changes(changes)
1463
self._dirblock_state = DirState.IN_MEMORY_MODIFIED
1464
self._header_state = DirState.IN_MEMORY_MODIFIED
1465
self._id_index = None
1468
def _update_basis_apply_adds(self, adds):
1469
"""Apply a sequence of adds to tree 1 during update_basis_by_delta.
1471
They may be adds, or renames that have been split into add/delete
1474
:param adds: A sequence of adds. Each add is a tuple:
1475
(None, new_path_utf8, file_id, (entry_details), real_add). real_add
1476
is False when the add is the second half of a remove-and-reinsert
1477
pair created to handle renames and deletes.
1479
# Adds are accumulated partly from renames, so can be in any input
1482
# adds is now in lexographic order, which places all parents before
1483
# their children, so we can process it linearly.
1485
for old_path, new_path, file_id, new_details, real_add in adds:
1486
# the entry for this file_id must be in tree 0.
1487
entry = self._get_entry(0, file_id, new_path)
1488
if entry[0] is None or entry[0][2] != file_id:
1489
self._changes_aborted = True
1490
raise errors.InconsistentDelta(new_path, file_id,
1491
'working tree does not contain new entry')
1492
if real_add and entry[1][1][0] not in absent:
1493
self._changes_aborted = True
1494
raise errors.InconsistentDelta(new_path, file_id,
1495
'The entry was considered to be a genuinely new record,'
1496
' but there was already an old record for it.')
1497
# We don't need to update the target of an 'r' because the handling
1498
# of renames turns all 'r' situations into a delete at the original
1500
entry[1][1] = new_details
1502
def _update_basis_apply_changes(self, changes):
1503
"""Apply a sequence of changes to tree 1 during update_basis_by_delta.
1505
:param adds: A sequence of changes. Each change is a tuple:
1506
(path_utf8, path_utf8, file_id, (entry_details))
1509
for old_path, new_path, file_id, new_details in changes:
1510
# the entry for this file_id must be in tree 0.
1511
entry = self._get_entry(0, file_id, new_path)
1512
if entry[0] is None or entry[0][2] != file_id:
1513
self._changes_aborted = True
1514
raise errors.InconsistentDelta(new_path, file_id,
1515
'working tree does not contain new entry')
1516
if (entry[1][0][0] in absent or
1517
entry[1][1][0] in absent):
1518
self._changes_aborted = True
1519
raise errors.InconsistentDelta(new_path, file_id,
1520
'changed considered absent')
1521
entry[1][1] = new_details
1523
def _update_basis_apply_deletes(self, deletes):
1524
"""Apply a sequence of deletes to tree 1 during update_basis_by_delta.
1526
They may be deletes, or renames that have been split into add/delete
1529
:param deletes: A sequence of deletes. Each delete is a tuple:
1530
(old_path_utf8, new_path_utf8, file_id, None, real_delete).
1531
real_delete is True when the desired outcome is an actual deletion
1532
rather than the rename handling logic temporarily deleting a path
1533
during the replacement of a parent.
1535
null = DirState.NULL_PARENT_DETAILS
1536
for old_path, new_path, file_id, _, real_delete in deletes:
1537
if real_delete != (new_path is None):
1538
raise AssertionError("bad delete delta")
1539
# the entry for this file_id must be in tree 1.
1540
dirname, basename = osutils.split(old_path)
1541
block_index, entry_index, dir_present, file_present = \
1542
self._get_block_entry_index(dirname, basename, 1)
1543
if not file_present:
1544
self._changes_aborted = True
1545
raise errors.InconsistentDelta(old_path, file_id,
1546
'basis tree does not contain removed entry')
1547
entry = self._dirblocks[block_index][1][entry_index]
1548
if entry[0][2] != file_id:
1549
self._changes_aborted = True
1550
raise errors.InconsistentDelta(old_path, file_id,
1551
'mismatched file_id in tree 1')
1553
if entry[1][0][0] != 'a':
1554
self._changes_aborted = True
1555
raise errors.InconsistentDelta(old_path, file_id,
1556
'This was marked as a real delete, but the WT state'
1557
' claims that it still exists and is versioned.')
1558
del self._dirblocks[block_index][1][entry_index]
1560
if entry[1][0][0] == 'a':
1561
self._changes_aborted = True
1562
raise errors.InconsistentDelta(old_path, file_id,
1563
'The entry was considered a rename, but the source path'
1564
' is marked as absent.')
1565
# For whatever reason, we were asked to rename an entry
1566
# that was originally marked as deleted. This could be
1567
# because we are renaming the parent directory, and the WT
1568
# current state has the file marked as deleted.
1569
elif entry[1][0][0] == 'r':
1570
# implement the rename
1571
del self._dirblocks[block_index][1][entry_index]
1573
# it is being resurrected here, so blank it out temporarily.
1574
self._dirblocks[block_index][1][entry_index][1][1] = null
1576
def _observed_sha1(self, entry, sha1, stat_value,
1577
_stat_to_minikind=_stat_to_minikind, _pack_stat=pack_stat):
1578
"""Note the sha1 of a file.
1580
:param entry: The entry the sha1 is for.
1581
:param sha1: The observed sha1.
1582
:param stat_value: The os.lstat for the file.
1104
1585
minikind = _stat_to_minikind[stat_value.st_mode & 0170000]
2367
2847
self._split_path_cache = {}
2369
2849
def _requires_lock(self):
2370
"""Checks that a lock is currently held by someone on the dirstate"""
2850
"""Check that a lock is currently held by someone on the dirstate."""
2371
2851
if not self._lock_token:
2372
2852
raise errors.ObjectNotLocked(self)
2375
def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache={}):
2376
"""Return the index where to insert dirname into the dirblocks.
2378
The return value idx is such that all directories blocks in dirblock[:idx]
2379
have names < dirname, and all blocks in dirblock[idx:] have names >=
2382
Optional args lo (default 0) and hi (default len(dirblocks)) bound the
2383
slice of a to be searched.
2855
def py_update_entry(state, entry, abspath, stat_value,
2856
_stat_to_minikind=DirState._stat_to_minikind,
2857
_pack_stat=pack_stat):
2858
"""Update the entry based on what is actually on disk.
2860
This function only calculates the sha if it needs to - if the entry is
2861
uncachable, or clearly different to the first parent's entry, no sha
2862
is calculated, and None is returned.
2864
:param state: The dirstate this entry is in.
2865
:param entry: This is the dirblock entry for the file in question.
2866
:param abspath: The path on disk for this file.
2867
:param stat_value: The stat value done on the path.
2868
:return: None, or The sha1 hexdigest of the file (40 bytes) or link
2869
target of a symlink.
2388
dirname_split = cache[dirname]
2872
minikind = _stat_to_minikind[stat_value.st_mode & 0170000]
2389
2873
except KeyError:
2390
dirname_split = dirname.split('/')
2391
cache[dirname] = dirname_split
2394
# Grab the dirname for the current dirblock
2395
cur = dirblocks[mid][0]
2397
cur_split = cache[cur]
2399
cur_split = cur.split('/')
2400
cache[cur] = cur_split
2401
if cur_split < dirname_split: lo = mid+1
2876
packed_stat = _pack_stat(stat_value)
2877
(saved_minikind, saved_link_or_sha1, saved_file_size,
2878
saved_executable, saved_packed_stat) = entry[1][0]
2880
if minikind == 'd' and saved_minikind == 't':
2882
if (minikind == saved_minikind
2883
and packed_stat == saved_packed_stat):
2884
# The stat hasn't changed since we saved, so we can re-use the
2889
# size should also be in packed_stat
2890
if saved_file_size == stat_value.st_size:
2891
return saved_link_or_sha1
2893
# If we have gotten this far, that means that we need to actually
2894
# process this entry.
2897
executable = state._is_executable(stat_value.st_mode,
2899
if state._cutoff_time is None:
2900
state._sha_cutoff_time()
2901
if (stat_value.st_mtime < state._cutoff_time
2902
and stat_value.st_ctime < state._cutoff_time
2903
and len(entry[1]) > 1
2904
and entry[1][1][0] != 'a'):
2905
# Could check for size changes for further optimised
2906
# avoidance of sha1's. However the most prominent case of
2907
# over-shaing is during initial add, which this catches.
2908
# Besides, if content filtering happens, size and sha
2909
# are calculated at the same time, so checking just the size
2910
# gains nothing w.r.t. performance.
2911
link_or_sha1 = state._sha1_file(abspath)
2912
entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
2913
executable, packed_stat)
2915
entry[1][0] = ('f', '', stat_value.st_size,
2916
executable, DirState.NULLSTAT)
2917
elif minikind == 'd':
2919
entry[1][0] = ('d', '', 0, False, packed_stat)
2920
if saved_minikind != 'd':
2921
# This changed from something into a directory. Make sure we
2922
# have a directory block for it. This doesn't happen very
2923
# often, so this doesn't have to be super fast.
2924
block_index, entry_index, dir_present, file_present = \
2925
state._get_block_entry_index(entry[0][0], entry[0][1], 0)
2926
state._ensure_block(block_index, entry_index,
2927
osutils.pathjoin(entry[0][0], entry[0][1]))
2928
elif minikind == 'l':
2929
link_or_sha1 = state._read_link(abspath, saved_link_or_sha1)
2930
if state._cutoff_time is None:
2931
state._sha_cutoff_time()
2932
if (stat_value.st_mtime < state._cutoff_time
2933
and stat_value.st_ctime < state._cutoff_time):
2934
entry[1][0] = ('l', link_or_sha1, stat_value.st_size,
2937
entry[1][0] = ('l', '', stat_value.st_size,
2938
False, DirState.NULLSTAT)
2939
state._dirblock_state = DirState.IN_MEMORY_MODIFIED
2943
class ProcessEntryPython(object):
2945
__slots__ = ["old_dirname_to_file_id", "new_dirname_to_file_id", "uninteresting",
2946
"last_source_parent", "last_target_parent", "include_unchanged",
2947
"use_filesystem_for_exec", "utf8_decode", "searched_specific_files",
2948
"search_specific_files", "state", "source_index", "target_index",
2949
"want_unversioned", "tree"]
2951
def __init__(self, include_unchanged, use_filesystem_for_exec,
2952
search_specific_files, state, source_index, target_index,
2953
want_unversioned, tree):
2954
self.old_dirname_to_file_id = {}
2955
self.new_dirname_to_file_id = {}
2956
# Just a sentry, so that _process_entry can say that this
2957
# record is handled, but isn't interesting to process (unchanged)
2958
self.uninteresting = object()
2959
# Using a list so that we can access the values and change them in
2960
# nested scope. Each one is [path, file_id, entry]
2961
self.last_source_parent = [None, None]
2962
self.last_target_parent = [None, None]
2963
self.include_unchanged = include_unchanged
2964
self.use_filesystem_for_exec = use_filesystem_for_exec
2965
self.utf8_decode = cache_utf8._utf8_decode
2966
# for all search_indexs in each path at or under each element of
2967
# search_specific_files, if the detail is relocated: add the id, and add the
2968
# relocated path as one to search if its not searched already. If the
2969
# detail is not relocated, add the id.
2970
self.searched_specific_files = set()
2971
self.search_specific_files = search_specific_files
2973
self.source_index = source_index
2974
self.target_index = target_index
2975
self.want_unversioned = want_unversioned
2978
def _process_entry(self, entry, path_info, pathjoin=osutils.pathjoin):
2979
"""Compare an entry and real disk to generate delta information.
2981
:param path_info: top_relpath, basename, kind, lstat, abspath for
2982
the path of entry. If None, then the path is considered absent.
2983
(Perhaps we should pass in a concrete entry for this ?)
2984
Basename is returned as a utf8 string because we expect this
2985
tuple will be ignored, and don't want to take the time to
2987
:return: None if these don't match
2988
A tuple of information about the change, or
2989
the object 'uninteresting' if these match, but are
2990
basically identical.
2992
if self.source_index is None:
2993
source_details = DirState.NULL_PARENT_DETAILS
2995
source_details = entry[1][self.source_index]
2996
target_details = entry[1][self.target_index]
2997
target_minikind = target_details[0]
2998
if path_info is not None and target_minikind in 'fdlt':
2999
if not (self.target_index == 0):
3000
raise AssertionError()
3001
link_or_sha1 = update_entry(self.state, entry,
3002
abspath=path_info[4], stat_value=path_info[3])
3003
# The entry may have been modified by update_entry
3004
target_details = entry[1][self.target_index]
3005
target_minikind = target_details[0]
3008
file_id = entry[0][2]
3009
source_minikind = source_details[0]
3010
if source_minikind in 'fdltr' and target_minikind in 'fdlt':
3011
# claimed content in both: diff
3012
# r | fdlt | | add source to search, add id path move and perform
3013
# | | | diff check on source-target
3014
# r | fdlt | a | dangling file that was present in the basis.
3016
if source_minikind in 'r':
3017
# add the source to the search path to find any children it
3018
# has. TODO ? : only add if it is a container ?
3019
if not osutils.is_inside_any(self.searched_specific_files,
3021
self.search_specific_files.add(source_details[1])
3022
# generate the old path; this is needed for stating later
3024
old_path = source_details[1]
3025
old_dirname, old_basename = os.path.split(old_path)
3026
path = pathjoin(entry[0][0], entry[0][1])
3027
old_entry = self.state._get_entry(self.source_index,
3029
# update the source details variable to be the real
3031
if old_entry == (None, None):
3032
raise errors.CorruptDirstate(self.state._filename,
3033
"entry '%s/%s' is considered renamed from %r"
3034
" but source does not exist\n"
3035
"entry: %s" % (entry[0][0], entry[0][1], old_path, entry))
3036
source_details = old_entry[1][self.source_index]
3037
source_minikind = source_details[0]
3039
old_dirname = entry[0][0]
3040
old_basename = entry[0][1]
3041
old_path = path = None
3042
if path_info is None:
3043
# the file is missing on disk, show as removed.
3044
content_change = True
3048
# source and target are both versioned and disk file is present.
3049
target_kind = path_info[2]
3050
if target_kind == 'directory':
3052
old_path = path = pathjoin(old_dirname, old_basename)
3053
self.new_dirname_to_file_id[path] = file_id
3054
if source_minikind != 'd':
3055
content_change = True
3057
# directories have no fingerprint
3058
content_change = False
3060
elif target_kind == 'file':
3061
if source_minikind != 'f':
3062
content_change = True
3064
# Check the sha. We can't just rely on the size as
3065
# content filtering may mean differ sizes actually
3066
# map to the same content
3067
if link_or_sha1 is None:
3069
statvalue, link_or_sha1 = \
3070
self.state._sha1_provider.stat_and_sha1(
3072
self.state._observed_sha1(entry, link_or_sha1,
3074
content_change = (link_or_sha1 != source_details[1])
3075
# Target details is updated at update_entry time
3076
if self.use_filesystem_for_exec:
3077
# We don't need S_ISREG here, because we are sure
3078
# we are dealing with a file.
3079
target_exec = bool(stat.S_IEXEC & path_info[3].st_mode)
3081
target_exec = target_details[3]
3082
elif target_kind == 'symlink':
3083
if source_minikind != 'l':
3084
content_change = True
3086
content_change = (link_or_sha1 != source_details[1])
3088
elif target_kind == 'tree-reference':
3089
if source_minikind != 't':
3090
content_change = True
3092
content_change = False
3095
raise Exception, "unknown kind %s" % path_info[2]
3096
if source_minikind == 'd':
3098
old_path = path = pathjoin(old_dirname, old_basename)
3099
self.old_dirname_to_file_id[old_path] = file_id
3100
# parent id is the entry for the path in the target tree
3101
if old_dirname == self.last_source_parent[0]:
3102
source_parent_id = self.last_source_parent[1]
3105
source_parent_id = self.old_dirname_to_file_id[old_dirname]
3107
source_parent_entry = self.state._get_entry(self.source_index,
3108
path_utf8=old_dirname)
3109
source_parent_id = source_parent_entry[0][2]
3110
if source_parent_id == entry[0][2]:
3111
# This is the root, so the parent is None
3112
source_parent_id = None
3114
self.last_source_parent[0] = old_dirname
3115
self.last_source_parent[1] = source_parent_id
3116
new_dirname = entry[0][0]
3117
if new_dirname == self.last_target_parent[0]:
3118
target_parent_id = self.last_target_parent[1]
3121
target_parent_id = self.new_dirname_to_file_id[new_dirname]
3123
# TODO: We don't always need to do the lookup, because the
3124
# parent entry will be the same as the source entry.
3125
target_parent_entry = self.state._get_entry(self.target_index,
3126
path_utf8=new_dirname)
3127
if target_parent_entry == (None, None):
3128
raise AssertionError(
3129
"Could not find target parent in wt: %s\nparent of: %s"
3130
% (new_dirname, entry))
3131
target_parent_id = target_parent_entry[0][2]
3132
if target_parent_id == entry[0][2]:
3133
# This is the root, so the parent is None
3134
target_parent_id = None
3136
self.last_target_parent[0] = new_dirname
3137
self.last_target_parent[1] = target_parent_id
3139
source_exec = source_details[3]
3140
if (self.include_unchanged
3142
or source_parent_id != target_parent_id
3143
or old_basename != entry[0][1]
3144
or source_exec != target_exec
3146
if old_path is None:
3147
old_path = path = pathjoin(old_dirname, old_basename)
3148
old_path_u = self.utf8_decode(old_path)[0]
3151
old_path_u = self.utf8_decode(old_path)[0]
3152
if old_path == path:
3155
path_u = self.utf8_decode(path)[0]
3156
source_kind = DirState._minikind_to_kind[source_minikind]
3157
return (entry[0][2],
3158
(old_path_u, path_u),
3161
(source_parent_id, target_parent_id),
3162
(self.utf8_decode(old_basename)[0], self.utf8_decode(entry[0][1])[0]),
3163
(source_kind, target_kind),
3164
(source_exec, target_exec))
3166
return self.uninteresting
3167
elif source_minikind in 'a' and target_minikind in 'fdlt':
3168
# looks like a new file
3169
path = pathjoin(entry[0][0], entry[0][1])
3170
# parent id is the entry for the path in the target tree
3171
# TODO: these are the same for an entire directory: cache em.
3172
parent_id = self.state._get_entry(self.target_index,
3173
path_utf8=entry[0][0])[0][2]
3174
if parent_id == entry[0][2]:
3176
if path_info is not None:
3178
if self.use_filesystem_for_exec:
3179
# We need S_ISREG here, because we aren't sure if this
3182
stat.S_ISREG(path_info[3].st_mode)
3183
and stat.S_IEXEC & path_info[3].st_mode)
3185
target_exec = target_details[3]
3186
return (entry[0][2],
3187
(None, self.utf8_decode(path)[0]),
3191
(None, self.utf8_decode(entry[0][1])[0]),
3192
(None, path_info[2]),
3193
(None, target_exec))
3195
# Its a missing file, report it as such.
3196
return (entry[0][2],
3197
(None, self.utf8_decode(path)[0]),
3201
(None, self.utf8_decode(entry[0][1])[0]),
3204
elif source_minikind in 'fdlt' and target_minikind in 'a':
3205
# unversioned, possibly, or possibly not deleted: we dont care.
3206
# if its still on disk, *and* theres no other entry at this
3207
# path [we dont know this in this routine at the moment -
3208
# perhaps we should change this - then it would be an unknown.
3209
old_path = pathjoin(entry[0][0], entry[0][1])
3210
# parent id is the entry for the path in the target tree
3211
parent_id = self.state._get_entry(self.source_index, path_utf8=entry[0][0])[0][2]
3212
if parent_id == entry[0][2]:
3214
return (entry[0][2],
3215
(self.utf8_decode(old_path)[0], None),
3219
(self.utf8_decode(entry[0][1])[0], None),
3220
(DirState._minikind_to_kind[source_minikind], None),
3221
(source_details[3], None))
3222
elif source_minikind in 'fdlt' and target_minikind in 'r':
3223
# a rename; could be a true rename, or a rename inherited from
3224
# a renamed parent. TODO: handle this efficiently. Its not
3225
# common case to rename dirs though, so a correct but slow
3226
# implementation will do.
3227
if not osutils.is_inside_any(self.searched_specific_files, target_details[1]):
3228
self.search_specific_files.add(target_details[1])
3229
elif source_minikind in 'ra' and target_minikind in 'ra':
3230
# neither of the selected trees contain this file,
3231
# so skip over it. This is not currently directly tested, but
3232
# is indirectly via test_too_much.TestCommands.test_conflicts.
3235
raise AssertionError("don't know how to compare "
3236
"source_minikind=%r, target_minikind=%r"
3237
% (source_minikind, target_minikind))
3238
## import pdb;pdb.set_trace()
3244
def iter_changes(self):
3245
"""Iterate over the changes."""
3246
utf8_decode = cache_utf8._utf8_decode
3247
_cmp_by_dirs = cmp_by_dirs
3248
_process_entry = self._process_entry
3249
uninteresting = self.uninteresting
3250
search_specific_files = self.search_specific_files
3251
searched_specific_files = self.searched_specific_files
3252
splitpath = osutils.splitpath
3254
# compare source_index and target_index at or under each element of search_specific_files.
3255
# follow the following comparison table. Note that we only want to do diff operations when
3256
# the target is fdl because thats when the walkdirs logic will have exposed the pathinfo
3260
# Source | Target | disk | action
3261
# r | fdlt | | add source to search, add id path move and perform
3262
# | | | diff check on source-target
3263
# r | fdlt | a | dangling file that was present in the basis.
3265
# r | a | | add source to search
3267
# r | r | | this path is present in a non-examined tree, skip.
3268
# r | r | a | this path is present in a non-examined tree, skip.
3269
# a | fdlt | | add new id
3270
# a | fdlt | a | dangling locally added file, skip
3271
# a | a | | not present in either tree, skip
3272
# a | a | a | not present in any tree, skip
3273
# a | r | | not present in either tree at this path, skip as it
3274
# | | | may not be selected by the users list of paths.
3275
# a | r | a | not present in either tree at this path, skip as it
3276
# | | | may not be selected by the users list of paths.
3277
# fdlt | fdlt | | content in both: diff them
3278
# fdlt | fdlt | a | deleted locally, but not unversioned - show as deleted ?
3279
# fdlt | a | | unversioned: output deleted id for now
3280
# fdlt | a | a | unversioned and deleted: output deleted id
3281
# fdlt | r | | relocated in this tree, so add target to search.
3282
# | | | Dont diff, we will see an r,fd; pair when we reach
3283
# | | | this id at the other path.
3284
# fdlt | r | a | relocated in this tree, so add target to search.
3285
# | | | Dont diff, we will see an r,fd; pair when we reach
3286
# | | | this id at the other path.
3288
# TODO: jam 20070516 - Avoid the _get_entry lookup overhead by
3289
# keeping a cache of directories that we have seen.
3291
while search_specific_files:
3292
# TODO: the pending list should be lexically sorted? the
3293
# interface doesn't require it.
3294
current_root = search_specific_files.pop()
3295
current_root_unicode = current_root.decode('utf8')
3296
searched_specific_files.add(current_root)
3297
# process the entries for this containing directory: the rest will be
3298
# found by their parents recursively.
3299
root_entries = self.state._entries_for_path(current_root)
3300
root_abspath = self.tree.abspath(current_root_unicode)
3302
root_stat = os.lstat(root_abspath)
3304
if e.errno == errno.ENOENT:
3305
# the path does not exist: let _process_entry know that.
3306
root_dir_info = None
3308
# some other random error: hand it up.
3311
root_dir_info = ('', current_root,
3312
osutils.file_kind_from_stat_mode(root_stat.st_mode), root_stat,
3314
if root_dir_info[2] == 'directory':
3315
if self.tree._directory_is_tree_reference(
3316
current_root.decode('utf8')):
3317
root_dir_info = root_dir_info[:2] + \
3318
('tree-reference',) + root_dir_info[3:]
3320
if not root_entries and not root_dir_info:
3321
# this specified path is not present at all, skip it.
3323
path_handled = False
3324
for entry in root_entries:
3325
result = _process_entry(entry, root_dir_info)
3326
if result is not None:
3328
if result is not uninteresting:
3330
if self.want_unversioned and not path_handled and root_dir_info:
3331
new_executable = bool(
3332
stat.S_ISREG(root_dir_info[3].st_mode)
3333
and stat.S_IEXEC & root_dir_info[3].st_mode)
3335
(None, current_root_unicode),
3339
(None, splitpath(current_root_unicode)[-1]),
3340
(None, root_dir_info[2]),
3341
(None, new_executable)
3343
initial_key = (current_root, '', '')
3344
block_index, _ = self.state._find_block_index_from_key(initial_key)
3345
if block_index == 0:
3346
# we have processed the total root already, but because the
3347
# initial key matched it we should skip it here.
3349
if root_dir_info and root_dir_info[2] == 'tree-reference':
3350
current_dir_info = None
3352
dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
3354
current_dir_info = dir_iterator.next()
3356
# on win32, python2.4 has e.errno == ERROR_DIRECTORY, but
3357
# python 2.5 has e.errno == EINVAL,
3358
# and e.winerror == ERROR_DIRECTORY
3359
e_winerror = getattr(e, 'winerror', None)
3360
win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
3361
# there may be directories in the inventory even though
3362
# this path is not a file on disk: so mark it as end of
3364
if e.errno in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
3365
current_dir_info = None
3366
elif (sys.platform == 'win32'
3367
and (e.errno in win_errors
3368
or e_winerror in win_errors)):
3369
current_dir_info = None
3373
if current_dir_info[0][0] == '':
3374
# remove .bzr from iteration
3375
bzr_index = bisect.bisect_left(current_dir_info[1], ('.bzr',))
3376
if current_dir_info[1][bzr_index][0] != '.bzr':
3377
raise AssertionError()
3378
del current_dir_info[1][bzr_index]
3379
# walk until both the directory listing and the versioned metadata
3381
if (block_index < len(self.state._dirblocks) and
3382
osutils.is_inside(current_root, self.state._dirblocks[block_index][0])):
3383
current_block = self.state._dirblocks[block_index]
3385
current_block = None
3386
while (current_dir_info is not None or
3387
current_block is not None):
3388
if (current_dir_info and current_block
3389
and current_dir_info[0][0] != current_block[0]):
3390
if _cmp_by_dirs(current_dir_info[0][0], current_block[0]) < 0:
3391
# filesystem data refers to paths not covered by the dirblock.
3392
# this has two possibilities:
3393
# A) it is versioned but empty, so there is no block for it
3394
# B) it is not versioned.
3396
# if (A) then we need to recurse into it to check for
3397
# new unknown files or directories.
3398
# if (B) then we should ignore it, because we don't
3399
# recurse into unknown directories.
3401
while path_index < len(current_dir_info[1]):
3402
current_path_info = current_dir_info[1][path_index]
3403
if self.want_unversioned:
3404
if current_path_info[2] == 'directory':
3405
if self.tree._directory_is_tree_reference(
3406
current_path_info[0].decode('utf8')):
3407
current_path_info = current_path_info[:2] + \
3408
('tree-reference',) + current_path_info[3:]
3409
new_executable = bool(
3410
stat.S_ISREG(current_path_info[3].st_mode)
3411
and stat.S_IEXEC & current_path_info[3].st_mode)
3413
(None, utf8_decode(current_path_info[0])[0]),
3417
(None, utf8_decode(current_path_info[1])[0]),
3418
(None, current_path_info[2]),
3419
(None, new_executable))
3420
# dont descend into this unversioned path if it is
3422
if current_path_info[2] in ('directory',
3424
del current_dir_info[1][path_index]
3428
# This dir info has been handled, go to the next
3430
current_dir_info = dir_iterator.next()
3431
except StopIteration:
3432
current_dir_info = None
3434
# We have a dirblock entry for this location, but there
3435
# is no filesystem path for this. This is most likely
3436
# because a directory was removed from the disk.
3437
# We don't have to report the missing directory,
3438
# because that should have already been handled, but we
3439
# need to handle all of the files that are contained
3441
for current_entry in current_block[1]:
3442
# entry referring to file not present on disk.
3443
# advance the entry only, after processing.
3444
result = _process_entry(current_entry, None)
3445
if result is not None:
3446
if result is not uninteresting:
3449
if (block_index < len(self.state._dirblocks) and
3450
osutils.is_inside(current_root,
3451
self.state._dirblocks[block_index][0])):
3452
current_block = self.state._dirblocks[block_index]
3454
current_block = None
3457
if current_block and entry_index < len(current_block[1]):
3458
current_entry = current_block[1][entry_index]
3460
current_entry = None
3461
advance_entry = True
3463
if current_dir_info and path_index < len(current_dir_info[1]):
3464
current_path_info = current_dir_info[1][path_index]
3465
if current_path_info[2] == 'directory':
3466
if self.tree._directory_is_tree_reference(
3467
current_path_info[0].decode('utf8')):
3468
current_path_info = current_path_info[:2] + \
3469
('tree-reference',) + current_path_info[3:]
3471
current_path_info = None
3473
path_handled = False
3474
while (current_entry is not None or
3475
current_path_info is not None):
3476
if current_entry is None:
3477
# the check for path_handled when the path is advanced
3478
# will yield this path if needed.
3480
elif current_path_info is None:
3481
# no path is fine: the per entry code will handle it.
3482
result = _process_entry(current_entry, current_path_info)
3483
if result is not None:
3484
if result is not uninteresting:
3486
elif (current_entry[0][1] != current_path_info[1]
3487
or current_entry[1][self.target_index][0] in 'ar'):
3488
# The current path on disk doesn't match the dirblock
3489
# record. Either the dirblock is marked as absent, or
3490
# the file on disk is not present at all in the
3491
# dirblock. Either way, report about the dirblock
3492
# entry, and let other code handle the filesystem one.
3494
# Compare the basename for these files to determine
3496
if current_path_info[1] < current_entry[0][1]:
3497
# extra file on disk: pass for now, but only
3498
# increment the path, not the entry
3499
advance_entry = False
3501
# entry referring to file not present on disk.
3502
# advance the entry only, after processing.
3503
result = _process_entry(current_entry, None)
3504
if result is not None:
3505
if result is not uninteresting:
3507
advance_path = False
3509
result = _process_entry(current_entry, current_path_info)
3510
if result is not None:
3512
if result is not uninteresting:
3514
if advance_entry and current_entry is not None:
3516
if entry_index < len(current_block[1]):
3517
current_entry = current_block[1][entry_index]
3519
current_entry = None
3521
advance_entry = True # reset the advance flaga
3522
if advance_path and current_path_info is not None:
3523
if not path_handled:
3524
# unversioned in all regards
3525
if self.want_unversioned:
3526
new_executable = bool(
3527
stat.S_ISREG(current_path_info[3].st_mode)
3528
and stat.S_IEXEC & current_path_info[3].st_mode)
3530
relpath_unicode = utf8_decode(current_path_info[0])[0]
3531
except UnicodeDecodeError:
3532
raise errors.BadFilenameEncoding(
3533
current_path_info[0], osutils._fs_enc)
3535
(None, relpath_unicode),
3539
(None, utf8_decode(current_path_info[1])[0]),
3540
(None, current_path_info[2]),
3541
(None, new_executable))
3542
# dont descend into this unversioned path if it is
3544
if current_path_info[2] in ('directory'):
3545
del current_dir_info[1][path_index]
3547
# dont descend the disk iterator into any tree
3549
if current_path_info[2] == 'tree-reference':
3550
del current_dir_info[1][path_index]
3553
if path_index < len(current_dir_info[1]):
3554
current_path_info = current_dir_info[1][path_index]
3555
if current_path_info[2] == 'directory':
3556
if self.tree._directory_is_tree_reference(
3557
current_path_info[0].decode('utf8')):
3558
current_path_info = current_path_info[:2] + \
3559
('tree-reference',) + current_path_info[3:]
3561
current_path_info = None
3562
path_handled = False
3564
advance_path = True # reset the advance flagg.
3565
if current_block is not None:
3567
if (block_index < len(self.state._dirblocks) and
3568
osutils.is_inside(current_root, self.state._dirblocks[block_index][0])):
3569
current_block = self.state._dirblocks[block_index]
3571
current_block = None
3572
if current_dir_info is not None:
3574
current_dir_info = dir_iterator.next()
3575
except StopIteration:
3576
current_dir_info = None
3579
# Try to load the compiled form if possible
3581
from bzrlib._dirstate_helpers_pyx import (
3587
ProcessEntryC as _process_entry,
3588
update_entry as update_entry,
3591
from bzrlib._dirstate_helpers_py import (
3598
# FIXME: It would be nice to be able to track moved lines so that the
3599
# corresponding python code can be moved to the _dirstate_helpers_py
3600
# module. I don't want to break the history for this important piece of
3601
# code so I left the code here -- vila 20090622
3602
update_entry = py_update_entry
3603
_process_entry = ProcessEntryPython