Rev 2368: 545ms, 600ms: Switch memory model from storing kind to using minikind in http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
John Arbash Meinel
john at arbash-meinel.com
Thu Feb 22 18:43:38 GMT 2007
At http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
------------------------------------------------------------
revno: 2368
revision-id: john at arbash-meinel.com-20070222184235-2q0gcimvw3qqudx4
parent: john at arbash-meinel.com-20070222181111-kbu6t6vc4e9u5yin
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate
timestamp: Thu 2007-02-22 12:42:35 -0600
message:
545ms, 600ms: Switch memory model from storing kind to using minikind
Need to profile effect on _generate_inventory, but makes a significant improvement for
both fast path and slow path, and should have minimal effect elsewhere.
modified:
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
bzrlib/tests/test_dirstate.py test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2007-02-22 18:11:11 +0000
+++ b/bzrlib/dirstate.py 2007-02-22 18:42:35 +0000
@@ -57,7 +57,7 @@
entry[1][1]: The second tree
For an entry for a tree, we have (using tree 0 - current tree) to demonstrate:
-entry[1][0][0]: kind
+entry[1][0][0]: minikind
entry[1][0][1]: fingerprint
entry[1][0][2]: size
entry[1][0][3]: executable
@@ -240,7 +240,7 @@
# A pack_stat (the x's) that is just noise and will never match the output
# of base64 encode.
NULLSTAT = 'x' * 32
- NULL_PARENT_DETAILS = ('absent', '', 0, False, '')
+ NULL_PARENT_DETAILS = ('a', '', 0, False, '')
def __init__(self):
"""Create a DirState object.
@@ -325,17 +325,18 @@
size = stat.st_size
packed_stat = pack_stat(stat)
parent_info = self._empty_parent_info()
+ minikind = DirState._kind_to_minikind[kind]
if kind == 'file':
entry_data = entry_key, [
- (kind, link_or_sha1, size, False, packed_stat),
+ (minikind, link_or_sha1, size, False, packed_stat),
] + parent_info
elif kind == 'directory':
entry_data = entry_key, [
- (kind, '', 0, False, packed_stat),
+ (minikind, '', 0, False, packed_stat),
] + parent_info
elif kind == 'symlink':
entry_data = entry_key, [
- (kind, link_or_sha1, size, False, packed_stat),
+ (minikind, link_or_sha1, size, False, packed_stat),
] + parent_info
else:
raise errors.BzrError('unknown kind %r' % kind)
@@ -442,12 +443,12 @@
"""
entire_entry = list(entry[0])
for tree_number, tree_data in enumerate(entry[1]):
- # (kind, fingerprint, size, executable, tree_specific_string)
+ # (minikind, fingerprint, size, executable, tree_specific_string)
entire_entry.extend(tree_data)
# 3 for the key, 5 for the fields per tree.
tree_offset = 3 + tree_number * 5
- # kind
- entire_entry[tree_offset + 0] = DirState._kind_to_minikind[tree_data[0]]
+ # minikind
+ entire_entry[tree_offset + 0] = tree_data[0]
# size
entire_entry[tree_offset + 2] = str(tree_data[2])
# executable
@@ -570,7 +571,7 @@
def _get_fields_to_entry(self):
"""Get a function which converts entry fields into a entry record.
- This handles kind, size, and executable, as well as parent records.
+ This handles size and executable, as well as parent records.
:return: A function which takes a list of fields, and returns an
appropriate record for storing in memory.
@@ -578,12 +579,11 @@
# This is intentionally unrolled for performance
num_present_parents = self._num_present_parents()
if num_present_parents == 0:
- def fields_to_entry_0_parents(fields, _int=int, _tuple=tuple,
- _mini_to_kind=self._minikind_to_kind):
+ def fields_to_entry_0_parents(fields, _int=int):
path_name_file_id_key = (fields[0], fields[1], fields[2])
return (path_name_file_id_key, [
( # Current tree
- _mini_to_kind[fields[3]], # kind
+ fields[3], # minikind
fields[4], # fingerprint
_int(fields[5]), # size
fields[6] == 'y', # executable
@@ -591,19 +591,18 @@
)])
return fields_to_entry_0_parents
elif num_present_parents == 1:
- def fields_to_entry_1_parent(fields, _int=int, _tuple=tuple,
- _mini_to_kind=self._minikind_to_kind):
+ def fields_to_entry_1_parent(fields, _int=int):
path_name_file_id_key = (fields[0], fields[1], fields[2])
return (path_name_file_id_key, [
( # Current tree
- _mini_to_kind[fields[3]], # kind
+ fields[3], # minikind
fields[4], # fingerprint
_int(fields[5]), # size
fields[6] == 'y', # executable
fields[7], # packed_stat or revision_id
),
( # Parent 1
- _mini_to_kind[fields[8]], # kind
+ fields[8], # minikind
fields[9], # fingerprint
_int(fields[10]), # size
fields[11] == 'y', # executable
@@ -612,26 +611,25 @@
])
return fields_to_entry_1_parent
elif num_present_parents == 2:
- def fields_to_entry_2_parents(fields, _int=int, _tuple=tuple,
- _mini_to_kind=self._minikind_to_kind):
+ def fields_to_entry_2_parents(fields, _int=int):
path_name_file_id_key = (fields[0], fields[1], fields[2])
return (path_name_file_id_key, [
( # Current tree
- _mini_to_kind[fields[3]], # kind
+ fields[3], # minikind
fields[4], # fingerprint
_int(fields[5]), # size
fields[6] == 'y', # executable
fields[7], # packed_stat or revision_id
),
( # Parent 1
- _mini_to_kind[fields[8]], # kind
+ fields[8], # minikind
fields[9], # fingerprint
_int(fields[10]), # size
fields[11] == 'y', # executable
fields[12], # packed_stat or revision_id
),
( # Parent 2
- _mini_to_kind[fields[13]],# kind
+ fields[13], # minikind
fields[14], # fingerprint
_int(fields[15]), # size
fields[16] == 'y', # executable
@@ -640,10 +638,9 @@
])
return fields_to_entry_2_parents
else:
- def fields_to_entry_n_parents(fields, _int=int, _tuple=tuple,
- _mini_to_kind=self._minikind_to_kind):
+ def fields_to_entry_n_parents(fields, _int=int):
path_name_file_id_key = (fields[0], fields[1], fields[2])
- trees = [(_mini_to_kind[fields[cur]], # kind
+ trees = [(fields[cur], # minikind
fields[cur+1], # fingerprint
_int(fields[cur+2]), # size
fields[cur+3] == 'y', # executable
@@ -689,7 +686,7 @@
# requested.
while entry_index < len(block) and block[entry_index][0][1] == basename:
if block[entry_index][1][tree_index][0] not in \
- ('absent', 'relocated'):
+ ('a', 'r'): # absent, relocated
return block_index, entry_index, True, True
entry_index += 1
return block_index, entry_index, True, False
@@ -718,7 +715,7 @@
if not file_present:
return None, None
entry = self._dirblocks[block_index][1][entry_index]
- assert entry[0][2] and entry[1][tree_index][0] not in ('absent', 'relocated'), 'unversioned entry?!?!'
+ assert entry[0][2] and entry[1][tree_index][0] not in ('a', 'r'), 'unversioned entry?!?!'
if fileid_utf8:
if entry[0][2] != fileid_utf8:
raise BzrError('integrity error ? : mismatching tree_index, file_id and path')
@@ -726,12 +723,12 @@
else:
for entry in self._iter_entries():
if entry[0][2] == fileid_utf8:
- if entry[1][tree_index][0] == 'relocated':
+ if entry[1][tree_index][0] == 'r': # relocated
# look up the real location directly by path
return self._get_entry(tree_index,
fileid_utf8=fileid_utf8,
path_utf8=entry[1][tree_index][1])
- if entry[1][tree_index][0] == 'absent':
+ if entry[1][tree_index][0] == 'a': # absent
# not in the tree at all.
return None, None
return entry
@@ -759,7 +756,7 @@
# a new root directory, with a NULLSTAT.
empty_tree_dirblocks[0][1].append(
(('', '', bzrlib.inventory.ROOT_ID), [
- ('directory', '', 0, False, DirState.NULLSTAT),
+ ('d', '', 0, False, DirState.NULLSTAT),
]))
result._set_data([], empty_tree_dirblocks)
try:
@@ -778,6 +775,7 @@
id.
"""
kind = inv_entry.kind
+ minikind = DirState._kind_to_minikind[kind]
tree_data = inv_entry.revision
assert len(tree_data) > 0, 'empty revision for the inv_entry.'
if kind == 'directory':
@@ -794,7 +792,7 @@
executable = inv_entry.executable
else:
raise Exception
- return (kind, fingerprint, size, executable, tree_data)
+ return (minikind, fingerprint, size, executable, tree_data)
def _iter_entries(self):
"""Iterate over all the entries in the dirstate.
@@ -892,7 +890,6 @@
if num_present_parents == 1:
# Bind external functions to local names
- _mini_to_kind = DirState._minikind_to_kind
_int = int
# We access all fields in order, so we can just iterate over
# them. Grab an straight iterator over the fields. (We use an
@@ -922,14 +919,14 @@
# creating new strings
entry = ((current_dirname, name, file_id),
[(# Current Tree
- _mini_to_kind[next()], # kind
+ next(), # minikind
next(), # fingerprint
_int(next()), # size
next() == 'y', # executable
next(), # packed_stat or revision_id
),
( # Parent 1
- _mini_to_kind[next()], # kind
+ next(), # minikind
next(), # fingerprint
_int(next()), # size
next() == 'y', # executable
@@ -1113,7 +1110,7 @@
# one: the current tree
for entry in self._iter_entries():
# skip entries not in the current tree
- if entry[1][0][0] in ('absent', 'relocated'):
+ if entry[1][0][0] in ('a', 'r'): # absent, relocated
continue
by_path[entry[0]] = [entry[1][0]] + \
[DirState.NULL_PARENT_DETAILS] * parent_count
@@ -1154,7 +1151,7 @@
# other trees, so put absent pointers there
# This is the vertical axis in the matrix, all pointing
# tot he real path.
- by_path[entry_key][tree_index] = ('relocated', path_utf8, 0, False, '')
+ by_path[entry_key][tree_index] = ('r', path_utf8, 0, False, '')
# by path consistency: Insert into an existing path record (trivial), or
# add a new one with relocation pointers for the other tree indexes.
if new_entry_key in id_index[file_id]:
@@ -1178,13 +1175,13 @@
# fragmented situations by reusing the relocation
# records.
a_key = iter(id_index[file_id]).next()
- if by_path[a_key][lookup_index][0] in ('relocated', 'absent'):
+ if by_path[a_key][lookup_index][0] in ('r', 'a'):
# its a pointer or missing statement, use it as is.
new_details.append(by_path[a_key][lookup_index])
else:
# we have the right key, make a pointer to it.
real_path = ('/'.join(a_key[0:2])).strip('/')
- new_details.append(('relocated', real_path, 0, False, ''))
+ new_details.append(('r', real_path, 0, False, ''))
new_details.append(self._inv_entry_to_details(entry))
new_details.extend(new_location_suffix)
by_path[new_entry_key] = new_details
@@ -1230,7 +1227,8 @@
return None
while current_new or current_old:
# skip entries in old that are not really there
- if current_old and current_old[1][0][0] in ('relocated', 'absent'):
+ if current_old and current_old[1][0][0] in ('r', 'a'):
+ # relocated or absent
current_old = advance(old_iterator)
continue
if current_new:
@@ -1259,8 +1257,9 @@
# TODO: update the record if anything significant has changed.
# the minimal required trigger is if the execute bit or cached
# kind has changed.
+ kind = DirState._minikind_to_kind[current_old[1][0][0]]
if (current_old[1][0][3] != current_new[1].executable or
- current_old[1][0][0] != current_new[1].kind):
+ kind != current_new[1].kind):
self.update_minimal(current_old[0], current_new[1].kind,
num_present_parents,
executable=current_new[1].executable,
@@ -1295,9 +1294,9 @@
all_remaining_keys = set()
# Dont check the working tree, because its going.
for details in current_old[1][1:]:
- if details[0] not in ('absent', 'relocated'):
+ if details[0] not in ('a', 'r'): # absent, relocated
all_remaining_keys.add(current_old[0])
- elif details[0] == 'relocated':
+ elif details[0] == 'r': # relocated
# record the key for the real path.
all_remaining_keys.add(tuple(os.path.split(details[1])) + (current_old[0][2],))
# absent rows are not present at any path.
@@ -1326,7 +1325,7 @@
assert present
update_tree_details = self._dirblocks[update_block_index][1][update_entry_index][1]
# it must not be absent at the moment
- assert update_tree_details[0][0] != 'absent'
+ assert update_tree_details[0][0] != 'a' # absent
update_tree_details[0] = DirState.NULL_PARENT_DETAILS
self._dirblock_state = DirState.IN_MEMORY_MODIFIED
return last_reference
@@ -1339,7 +1338,8 @@
if packed_stat is None:
packed_stat = DirState.NULLSTAT
entry_index, present = self._find_entry_index(key, block)
- new_details = (kind, fingerprint, size, executable, packed_stat)
+ minikind = DirState._kind_to_minikind[kind]
+ new_details = (minikind, fingerprint, size, executable, packed_stat)
assert id_index is not None, 'need an id index to do updates for now !'
if not present:
# new entry, synthesis cross reference here,
@@ -1364,7 +1364,7 @@
assert present
assert path_utf8 is not None
self._dirblocks[other_block_index][1][other_entry_index][1][0] = \
- ('relocated', path_utf8, 0, False, '')
+ ('r', path_utf8, 0, False, '')
for lookup_index in xrange(1, num_present_parents + 1):
# grab any one entry, use it to find the right path.
@@ -1378,14 +1378,14 @@
self._find_entry_index(other_key, self._dirblocks[update_block_index][1])
assert present
update_details = self._dirblocks[update_block_index][1][update_entry_index][1][lookup_index]
- if update_details[0] in ('relocated', 'absent'):
+ if update_details[0] in ('r', 'a'): # relocated, absent
# its a pointer or absent in lookup_index's tree, use
# it as is.
new_entry[1].append(update_details)
else:
# we have the right key, make a pointer to it.
pointer_path = os.path.join(*other_key[0:2])
- new_entry[1].append(('relocated', pointer_path, 0, False, ''))
+ new_entry[1].append(('r', pointer_path, 0, False, ''))
block.insert(entry_index, new_entry)
existing_keys.add(key)
else:
@@ -1415,9 +1415,9 @@
entry_index, present = self._find_entry_index(entry_key, self._dirblocks[block_index][1])
assert present
self._dirblocks[block_index][1][entry_index][1][0] = \
- ('relocated', path_utf8, 0, False, '')
+ ('r', path_utf8, 0, False, '')
# add a containing dirblock if needed.
- if new_details[0] == 'directory':
+ if new_details[0] == 'd':
subdir_key = (os.path.join(*key[0:2]), '', '')
block_index, present = self._find_block_index_from_key(subdir_key)
if not present:
=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py 2007-02-21 11:10:37 +0000
+++ b/bzrlib/tests/test_dirstate.py 2007-02-22 18:42:35 +0000
@@ -62,7 +62,7 @@
state = self.create_empty_dirstate()
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
root_entry_direntry = ('', '', 'a-root-value'), [
- ('directory', '', 0, False, packed_stat),
+ ('d', '', 0, False, packed_stat),
]
dirblocks = []
dirblocks.append(('', [root_entry_direntry]))
@@ -75,7 +75,7 @@
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
dirblocks = list(state._dirblocks)
subdir_entry = ('', 'subdir', 'subdir-id'), [
- ('directory', '', 0, False, packed_stat),
+ ('d', '', 0, False, packed_stat),
]
dirblocks[1][1].append(subdir_entry)
state._set_data([], dirblocks)
@@ -100,31 +100,31 @@
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
null_sha = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
root_entry = ('', '', 'a-root-value'), [
- ('directory', '', 0, False, packed_stat),
+ ('d', '', 0, False, packed_stat),
]
a_entry = ('', 'a', 'a-dir'), [
- ('directory', '', 0, False, packed_stat),
+ ('d', '', 0, False, packed_stat),
]
b_entry = ('', 'b', 'b-dir'), [
- ('directory', '', 0, False, packed_stat),
+ ('d', '', 0, False, packed_stat),
]
c_entry = ('', 'c', 'c-file'), [
- ('file', null_sha, 10, False, packed_stat),
+ ('f', null_sha, 10, False, packed_stat),
]
d_entry = ('', 'd', 'd-file'), [
- ('file', null_sha, 20, False, packed_stat),
+ ('f', null_sha, 20, False, packed_stat),
]
e_entry = ('a', 'e', 'e-dir'), [
- ('directory', '', 0, False, packed_stat),
+ ('d', '', 0, False, packed_stat),
]
f_entry = ('a', 'f', 'f-file'), [
- ('file', null_sha, 30, False, packed_stat),
+ ('f', null_sha, 30, False, packed_stat),
]
g_entry = ('b', 'g', 'g-file'), [
- ('file', null_sha, 30, False, packed_stat),
+ ('f', null_sha, 30, False, packed_stat),
]
h_entry = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file'), [
- ('file', null_sha, 40, False, packed_stat),
+ ('f', null_sha, 40, False, packed_stat),
]
dirblocks = []
dirblocks.append(('', [root_entry]))
@@ -159,7 +159,7 @@
state = dirstate.DirState.from_tree(tree, 'dirstate')
expected_result = ([], [
(('', '', tree.path2id('')), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
])])
self.check_state_with_reopen(expected_result, state)
@@ -171,8 +171,8 @@
root_stat_pack = dirstate.pack_stat(os.stat(tree.basedir))
expected_result = ([rev_id], [
(('', '', tree.path2id('')), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
- ('directory', '', 0, False, rev_id), # first parent details
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, rev_id), # first parent details
])])
self.check_state_with_reopen(expected_result, state)
@@ -186,9 +186,9 @@
state = dirstate.DirState.from_tree(tree, 'dirstate')
expected_result = ([rev_id, rev_id2], [
(('', '', tree.path2id('')), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
- ('directory', '', 0, False, rev_id), # first parent details
- ('directory', '', 0, False, rev_id2), # second parent details
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, rev_id), # first parent details
+ ('d', '', 0, False, rev_id2), # second parent details
])])
self.check_state_with_reopen(expected_result, state)
@@ -200,7 +200,7 @@
state = dirstate.DirState.from_tree(tree, 'dirstate')
expected_result = ([], [
(('', '', tree.path2id('')), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
])])
self.check_state_with_reopen(expected_result, state)
@@ -217,10 +217,10 @@
state = dirstate.DirState.from_tree(tree, 'dirstate')
expected_result = ([], [
(('', '', tree.path2id('')), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
]),
(('', 'a file', 'a file id'), # common
- [('file', '', 0, False, dirstate.DirState.NULLSTAT), # current
+ [('f', '', 0, False, dirstate.DirState.NULLSTAT), # current
]),
])
self.check_state_with_reopen(expected_result, state)
@@ -235,12 +235,12 @@
state = dirstate.DirState.from_tree(tree, 'dirstate')
expected_result = ([rev_id], [
(('', '', tree.path2id('')), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
- ('directory', '', 0, False, rev_id), # first parent details
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, rev_id), # first parent details
]),
(('', 'a file', 'a file id'), # common
- [('file', '', 0, False, dirstate.DirState.NULLSTAT), # current
- ('file', 'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False, rev_id), # first parent
+ [('f', '', 0, False, dirstate.DirState.NULLSTAT), # current
+ ('f', 'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False, rev_id), # first parent
]),
])
self.check_state_with_reopen(expected_result, state)
@@ -261,14 +261,14 @@
state = dirstate.DirState.from_tree(tree, 'dirstate')
expected_result = ([rev_id, rev_id2], [
(('', '', tree.path2id('')), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
- ('directory', '', 0, False, rev_id), # first parent details
- ('directory', '', 0, False, rev_id2), # second parent details
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, rev_id), # first parent details
+ ('d', '', 0, False, rev_id2), # second parent details
]),
(('', 'a file', 'a file id'), # common
- [('file', '', 0, False, dirstate.DirState.NULLSTAT), # current
- ('file', 'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False, rev_id), # first parent
- ('file', '314d796174c9412647c3ce07dfb5d36a94e72958', 14, False, rev_id2), # second parent
+ [('f', '', 0, False, dirstate.DirState.NULLSTAT), # current
+ ('f', 'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False, rev_id), # first parent
+ ('f', '314d796174c9412647c3ce07dfb5d36a94e72958', 14, False, rev_id2), # second parent
]),
])
self.check_state_with_reopen(expected_result, state)
@@ -291,7 +291,7 @@
# current tree details, but new from_tree skips statting, it
# uses set_state_from_inventory, and thus depends on the
# inventory state.
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT),
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT),
])
])
self.check_state_with_reopen(expected_result, state)
@@ -315,7 +315,7 @@
'dirstate')
expected_result = ([], [
(('', '', 'TREE_ROOT'), # common details
- [('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
+ [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
])
])
self.check_state_with_reopen(expected_result, state)
@@ -337,7 +337,7 @@
self.assertEqual(DirState.IN_MEMORY_MODIFIED, state._dirblock_state)
expected_result = [], [
(('', '', root_id), [
- ('directory', '', 0, False, DirState.NULLSTAT)])]
+ ('d', '', 0, False, DirState.NULLSTAT)])]
self.check_state_with_reopen(expected_result, state)
def test_set_path_id_no_parents(self):
@@ -345,11 +345,11 @@
state = dirstate.DirState.initialize('dirstate')
# check precondition to be sure the state does change appropriately.
self.assertEqual(
- [(('', '', 'TREE_ROOT'), [('directory', '', 0, False, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])],
+ [(('', '', 'TREE_ROOT'), [('d', '', 0, False, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])],
list(state._iter_entries()))
state.set_path_id('', 'foobarbaz')
expected_rows = [
- (('', '', 'foobarbaz'), [('directory', '', 0, False, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])]
+ (('', '', 'foobarbaz'), [('d', '', 0, False, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])]
self.assertEqual(expected_rows, list(state._iter_entries()))
# should work across save too
state.save()
@@ -398,9 +398,9 @@
self.assertEqual(['ghost-rev'], state.get_ghosts())
self.assertEqual(
[(('', '', root_id), [
- ('directory', '', 0, False, DirState.NULLSTAT),
- ('directory', '', 0, False, revid1),
- ('directory', '', 0, False, revid2)
+ ('d', '', 0, False, DirState.NULLSTAT),
+ ('d', '', 0, False, revid1),
+ ('d', '', 0, False, revid2)
])],
list(state._iter_entries()))
@@ -432,13 +432,13 @@
# check the layout in memory
expected_result = [revid1.encode('utf8'), revid2.encode('utf8')], [
(('', '', root_id), [
- ('directory', '', 0, False, DirState.NULLSTAT),
- ('directory', '', 0, False, revid1.encode('utf8')),
- ('directory', '', 0, False, revid2.encode('utf8'))]),
+ ('d', '', 0, False, DirState.NULLSTAT),
+ ('d', '', 0, False, revid1.encode('utf8')),
+ ('d', '', 0, False, revid2.encode('utf8'))]),
(('', 'a file', 'file-id'), [
- ('absent', '', 0, False, ''),
- ('file', '2439573625385400f2a669657a7db6ae7515d371', 12, False, revid1.encode('utf8')),
- ('file', '542e57dc1cda4af37cb8e55ec07ce60364bb3c7d', 16, False, revid2.encode('utf8'))])
+ ('a', '', 0, False, ''),
+ ('f', '2439573625385400f2a669657a7db6ae7515d371', 12, False, revid1.encode('utf8')),
+ ('f', '542e57dc1cda4af37cb8e55ec07ce60364bb3c7d', 16, False, revid2.encode('utf8'))])
]
self.check_state_with_reopen(expected_result, state)
@@ -456,10 +456,10 @@
# having added it, it should be in the output of iter_entries.
expected_entries = [
(('', '', 'TREE_ROOT'), [
- ('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
]),
(('', 'a file', 'a file id'), [
- ('file', '1'*20, 19, False, dirstate.pack_stat(stat)), # current tree details
+ ('f', '1'*20, 19, False, dirstate.pack_stat(stat)), # current tree details
]),
]
self.assertEqual(expected_entries, list(state._iter_entries()))
@@ -490,10 +490,10 @@
# having added it, it should be in the output of iter_entries.
expected_entries = [
(('', '', 'TREE_ROOT'), [
- ('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
]),
(('', 'a dir', 'a dir id'), [
- ('directory', '', 0, False, dirstate.pack_stat(stat)), # current tree details
+ ('d', '', 0, False, dirstate.pack_stat(stat)), # current tree details
]),
]
self.assertEqual(expected_entries, list(state._iter_entries()))
@@ -514,10 +514,10 @@
# having added it, it should be in the output of iter_entries.
expected_entries = [
(('', '', 'TREE_ROOT'), [
- ('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
]),
(('', 'a link', 'a link id'), [
- ('symlink', 'target', 6, False, dirstate.pack_stat(stat)), # current tree details
+ ('l', 'target', 6, False, dirstate.pack_stat(stat)), # current tree details
]),
]
self.assertEqual(expected_entries, list(state._iter_entries()))
@@ -537,13 +537,13 @@
# having added it, it should be in the output of iter_entries.
expected_entries = [
(('', '', 'TREE_ROOT'), [
- ('directory', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
+ ('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree details
]),
(('', 'a dir', 'a dir id'), [
- ('directory', '', 0, False, dirstate.pack_stat(stat)), # current tree details
+ ('d', '', 0, False, dirstate.pack_stat(stat)), # current tree details
]),
(('a dir', 'a file', 'a file id'), [
- ('file', '1'*20, 25, False, dirstate.pack_stat(filestat)), # current tree details
+ ('f', '1'*20, 25, False, dirstate.pack_stat(filestat)), # current tree details
]),
]
self.assertEqual(expected_entries, list(state._iter_entries()))
@@ -578,8 +578,8 @@
state = dirstate.DirState.initialize('dirstate')
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
root_entry = ('', '', 'a-root-value'), [
- ('directory', '', 0, False, packed_stat), # current tree details
- ('absent', 'dirname/basename', 0, False, ''), # first: a pointer to the current location
+ ('d', '', 0, False, packed_stat), # current tree details
+ ('a', 'dirname/basename', 0, False, ''), # first: a pointer to the current location
]
self.assertEqual(
'\x00\x00a-root-value\x00'
@@ -592,9 +592,9 @@
state = dirstate.DirState.initialize('dirstate')
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
root_entry = ('', '', 'a-root-value'), [
- ('directory', '', 0, False, packed_stat), # current tree details
- ('directory', '', 0, False, 'rev_id'), # first parent details
- ('absent', 'dirname/basename', 0, False, ''), # second: a pointer to the current location
+ ('d', '', 0, False, packed_stat), # current tree details
+ ('d', '', 0, False, 'rev_id'), # first parent details
+ ('a', 'dirname/basename', 0, False, ''), # second: a pointer to the current location
]
self.assertEqual(
'\x00\x00a-root-value\x00'
@@ -610,20 +610,20 @@
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
dirblocks = []
root_entries = [(('', '', 'a-root-value'), [
- ('directory', '', 0, False, packed_stat), # current tree details
+ ('d', '', 0, False, packed_stat), # current tree details
])]
dirblocks.append(('', root_entries))
# add two files in the root
subdir_entry = ('', 'subdir', 'subdir-id'), [
- ('directory', '', 0, False, packed_stat), # current tree details
+ ('d', '', 0, False, packed_stat), # current tree details
]
afile_entry = ('', 'afile', 'afile-id'), [
- ('file', 'sha1value', 34, False, packed_stat), # current tree details
+ ('f', 'sha1value', 34, False, packed_stat), # current tree details
]
dirblocks.append(('', [subdir_entry, afile_entry]))
# and one in subdir
file_entry2 = ('subdir', '2file', '2file-id'), [
- ('file', 'sha1value', 23, False, packed_stat), # current tree details
+ ('f', 'sha1value', 23, False, packed_stat), # current tree details
]
dirblocks.append(('subdir', [file_entry2]))
state._set_data([], dirblocks)
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-02-22 15:39:23 +0000
+++ b/bzrlib/workingtree_4.py 2007-02-22 18:42:35 +0000
@@ -233,7 +233,7 @@
state._read_dirblocks_if_needed()
root_key, current_entry = self._get_entry(path='')
current_id = root_key[2]
- assert current_entry[0][0] == 'directory'
+ assert current_entry[0][0] == 'd' # directory
inv = Inventory(root_id=current_id)
# we could do this straight out of the dirstate; it might be fast
# and should be profiled - RBC 20070216
@@ -246,13 +246,14 @@
# all the paths in this block are not versioned in this tree
continue
for key, entry in block[1]:
- if entry[0][0] in ('absent', 'relocated'):
+ if entry[0][0] in ('a', 'r'): # absent, relocated
# a parent tree only entry
continue
name = key[1]
name_unicode = name.decode('utf8')
file_id = key[2]
- kind, link_or_sha1, size, executable, stat = entry[0]
+ minikind, link_or_sha1, size, executable, stat = entry[0]
+ kind = dirstate.DirState._minikind_to_kind[minikind]
inv_entry = entry_factory[kind](file_id, name_unicode, parent_id)
if kind == 'file':
# not strictly needed: working tree
@@ -342,7 +343,7 @@
"""
result = []
for key, tree_details in self.current_dirstate()._iter_entries():
- if tree_details[0][0] in ('absent', 'relocated'):
+ if tree_details[0][0] in ('a', 'r'): # absent, relocated
# not relevant to the working tree
continue
path = pathjoin(self.basedir, key[0].decode('utf8'), key[1].decode('utf8'))
@@ -397,7 +398,7 @@
raise errors.BzrMoveFailedError('',to_dir,
errors.NotADirectory(to_abs))
- if to_entry[1][0][0] != 'directory':
+ if to_entry[1][0][0] != 'd':
raise errors.BzrMoveFailedError('',to_dir,
errors.NotADirectory(to_abs))
@@ -494,9 +495,11 @@
from_key = old_block[old_entry_index][0]
to_key = ((to_block[0],) + from_key[1:3])
state._make_absent(old_block[old_entry_index])
+ minikind = old_entry_details[0][0]
+ kind = dirstate.DirState._minikind_to_kind[minikind]
rollbacks.append(
lambda:state.update_minimal(from_key,
- old_entry_details[0][0],
+ kind,
num_present_parents=len(old_entry_details) - 1,
executable=old_entry_details[0][3],
fingerprint=old_entry_details[0][1],
@@ -506,7 +509,7 @@
path_utf8=from_rel.encode('utf8')))
# create new row in current block
state.update_minimal(to_key,
- old_entry_details[0][0],
+ kind,
num_present_parents=len(old_entry_details) - 1,
executable=old_entry_details[0][3],
fingerprint=old_entry_details[0][1],
@@ -517,7 +520,7 @@
added_entry_index, _ = state._find_entry_index(to_key, to_block[1])
new_entry = to_block[added_entry_index]
rollbacks.append(lambda:state._make_absent(new_entry))
- if new_entry[1][0][0] == 'directory':
+ if new_entry[1][0][0] == 'd':
import pdb;pdb.set_trace()
# if a directory, rename all the contents of child blocks
# adding rollbacks as each is inserted to remove them and
@@ -604,12 +607,12 @@
for entry in path_entries:
# for each tree.
for index in search_indexes:
- if entry[1][index][0] != 'absent':
+ if entry[1][index][0] != 'a': # absent
found_versioned = True
# all good: found a versioned cell
break
if not found_versioned:
- # non of the indexes was not 'absent' at all ids for this
+ # none of the indexes was not 'absent' at all ids for this
# path.
all_versioned = False
break
@@ -637,10 +640,10 @@
nothing. Otherwise add the id to found_ids.
"""
for index in search_indexes:
- if entry[1][index][0] == 'relocated':
+ if entry[1][index][0] == 'r': # relocated
if not osutils.is_inside_any(searched_paths, entry[1][index][1]):
search_paths.add(entry[1][index][1])
- elif entry[1][index][0] != 'absent':
+ elif entry[1][index][0] != 'a': # absent
found_ids.add(entry[0][2])
while search_paths:
current_root = search_paths.pop()
@@ -800,7 +803,7 @@
# walk the state marking unversioned things as absent.
# if there are any un-unversioned ids at the end, raise
for key, details in state._dirblocks[0][1]:
- if (details[0][0] not in ('absent', 'relocated') and
+ if (details[0][0] not in ('a', 'r') and # absent or relocated
key[2] in ids_to_unversion):
# I haven't written the code to unversion / yet - it should be
# supported.
@@ -836,13 +839,13 @@
entry_index = 0
while entry_index < len(block[1]):
entry = block[1][entry_index]
- if (entry[1][0][0] in ('absent', 'relocated') or
+ if (entry[1][0][0] in ('a', 'r') or # absent, relocated
# ^ some parent row.
entry[0][2] not in ids_to_unversion):
# ^ not an id to unversion
entry_index += 1
continue
- if entry[1][0][0] == 'directory':
+ if entry[1][0][0] == 'd':
paths_to_unversion.add(os.path.join(*entry[0][0:2]))
if not state._make_absent(entry):
entry_index += 1
@@ -1010,7 +1013,7 @@
# for the tree index use.
root_key, current_entry = self._dirstate._get_entry(parent_index, path_utf8='')
current_id = root_key[2]
- assert current_entry[parent_index][0] == 'directory'
+ assert current_entry[parent_index][0] == 'd'
inv = Inventory(root_id=current_id, revision_id=self._revision_id)
inv.root.revision = current_entry[parent_index][4]
# we could do this straight out of the dirstate; it might be fast
@@ -1024,13 +1027,14 @@
# all the paths in this block are not versioned in this tree
continue
for key, entry in block[1]:
- if entry[parent_index][0] in ('absent', 'relocated'):
+ if entry[parent_index][0] in ('a', 'r'): # absent, relocated
# not this tree
continue
name = key[1]
name_unicode = name.decode('utf8')
file_id = key[2]
- kind, link_or_sha1, size, executable, revid = entry[parent_index]
+ minikind, link_or_sha1, size, executable, revid = entry[parent_index]
+ kind = dirstate.DirState._minikind_to_kind[minikind]
inv_entry = entry_factory[kind](file_id, name_unicode, parent_id)
inv_entry.revision = revid
if kind == 'file':
More information about the bazaar-commits
mailing list