1
# Copyright (C) 2006, 2007 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
321
321
# modified states.
322
322
self._header_state = DirState.NOT_IN_MEMORY
323
323
self._dirblock_state = DirState.NOT_IN_MEMORY
324
# If true, an error has been detected while updating the dirstate, and
325
# for safety we're not going to commit to disk.
326
self._changes_aborted = False
324
327
self._dirblocks = []
325
328
self._ghosts = []
326
329
self._parents = []
1292
1295
assert old_path is None
1293
1296
# the entry for this file_id must be in tree 0.
1294
1297
entry = self._get_entry(0, file_id, new_path)
1295
if entry[0][2] != file_id:
1296
raise errors.BzrError('dirstate: cannot apply delta, working'
1297
' tree does not contain new entry %r %r' %
1298
(new_path, file_id))
1298
if entry[0] is None or entry[0][2] != file_id:
1299
self._changes_aborted = True
1300
raise errors.InconsistentDelta(new_path, file_id,
1301
'working tree does not contain new entry')
1299
1302
if real_add and entry[1][1][0] not in absent:
1300
raise errors.BzrError('dirstate: inconsistent delta, with '
1301
'tree 0. %r %r' % (new_path, file_id))
1303
self._changes_aborted = True
1304
raise errors.InconsistentDelta(new_path, file_id,
1305
'The entry was considered to be a genuinely new record,'
1306
' but there was already an old record for it.')
1302
1307
# We don't need to update the target of an 'r' because the handling
1303
1308
# of renames turns all 'r' situations into a delete at the original
1315
1320
assert old_path == new_path
1316
1321
# the entry for this file_id must be in tree 0.
1317
1322
entry = self._get_entry(0, file_id, new_path)
1318
if entry[0][2] != file_id:
1319
raise errors.BzrError('dirstate: cannot apply delta, working'
1320
' tree does not contain new entry %r %r' %
1321
(new_path, file_id))
1323
if entry[0] is None or entry[0][2] != file_id:
1324
self._changes_aborted = True
1325
raise errors.InconsistentDelta(new_path, file_id,
1326
'working tree does not contain new entry')
1322
1327
if (entry[1][0][0] in absent or
1323
1328
entry[1][1][0] in absent):
1324
raise errors.BzrError('dirstate: inconsistent delta, with '
1325
'tree 0. %r %r' % (new_path, file_id))
1329
self._changes_aborted = True
1330
raise errors.InconsistentDelta(new_path, file_id,
1331
'changed considered absent')
1326
1332
entry[1][1] = new_details
1328
1334
def _update_basis_apply_deletes(self, deletes):
1348
1354
block_index, entry_index, dir_present, file_present = \
1349
1355
self._get_block_entry_index(dirname, basename, 1)
1350
1356
if not file_present:
1351
raise errors.BzrError('dirstate: cannot apply delta, basis'
1352
' tree does not contain new entry %r %r' %
1353
(old_path, file_id))
1357
self._changes_aborted = True
1358
raise errors.InconsistentDelta(old_path, file_id,
1359
'basis tree does not contain removed entry')
1354
1360
entry = self._dirblocks[block_index][1][entry_index]
1355
1361
if entry[0][2] != file_id:
1356
raise errors.BzrError('mismatched file_id in tree 1 %r %r' %
1357
(old_path, file_id))
1362
self._changes_aborted = True
1363
raise errors.InconsistentDelta(old_path, file_id,
1364
'mismatched file_id in tree 1')
1358
1365
if real_delete:
1359
1366
if entry[1][0][0] != 'a':
1360
raise errors.BzrError('dirstate: inconsistent delta, with '
1361
'tree 0. %r %r' % (old_path, file_id))
1367
self._changes_aborted = True
1368
raise errors.InconsistentDelta(old_path, file_id,
1369
'This was marked as a real delete, but the WT state'
1370
' claims that it still exists and is versioned.')
1362
1371
del self._dirblocks[block_index][1][entry_index]
1364
1373
if entry[1][0][0] == 'a':
1365
raise errors.BzrError('dirstate: inconsistent delta, with '
1366
'tree 0. %r %r' % (old_path, file_id))
1374
self._changes_aborted = True
1375
raise errors.InconsistentDelta(old_path, file_id,
1376
'The entry was considered a rename, but the source path'
1377
' is marked as absent.')
1378
# For whatever reason, we were asked to rename an entry
1379
# that was originally marked as deleted. This could be
1380
# because we are renaming the parent directory, and the WT
1381
# current state has the file marked as deleted.
1367
1382
elif entry[1][0][0] == 'r':
1368
1383
# implement the rename
1369
1384
del self._dirblocks[block_index][1][entry_index]
1666
1681
assert entry[0][2] and entry[1][tree_index][0] not in ('a', 'r'), 'unversioned entry?!?!'
1667
1682
if fileid_utf8:
1668
1683
if entry[0][2] != fileid_utf8:
1684
self._changes_aborted = True
1669
1685
raise errors.BzrError('integrity error ? : mismatching'
1670
1686
' tree_index, file_id and path')
1954
1970
start over, to allow for fine grained read lock duration, so 'status'
1955
1971
wont block 'commit' - for example.
1973
if self._changes_aborted:
1974
# Should this be a warning? For now, I'm expecting that places that
1975
# mark it inconsistent will warn, making a warning here redundant.
1976
trace.mutter('Not saving DirState because '
1977
'_changes_aborted is set.')
1957
1979
if (self._header_state == DirState.IN_MEMORY_MODIFIED or
1958
1980
self._dirblock_state == DirState.IN_MEMORY_MODIFIED):