Rev 2412: merge workingtree tests in http://sourcefrog.net/bzr/dirstate
Martin Pool
mbp at sourcefrog.net
Mon Feb 26 04:44:25 GMT 2007
At http://sourcefrog.net/bzr/dirstate
------------------------------------------------------------
revno: 2412
revision-id: mbp at sourcefrog.net-20070226044424-lk243iwf37b18t16
parent: mbp at sourcefrog.net-20070226033932-c8fp56jfjksinn2z
parent: mbp at sourcefrog.net-20070226044016-hp3hp0yitdt7krph
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: dirstate
timestamp: Mon 2007-02-26 15:44:24 +1100
message:
merge workingtree tests
modified:
bzrlib/tests/workingtree_implementations/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
------------------------------------------------------------
revno: 2255.1.44
merged: mbp at sourcefrog.net-20070226044016-hp3hp0yitdt7krph
parent: pqm at pqm.ubuntu.com-20070222144505-5f7551602cad9332
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: trivial
timestamp: Mon 2007-02-26 15:40:16 +1100
message:
Add test for merge_modified
=== modified file 'bzrlib/tests/workingtree_implementations/test_workingtree.py'
--- a/bzrlib/tests/workingtree_implementations/test_workingtree.py 2007-02-26 03:39:32 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_workingtree.py 2007-02-26 04:44:24 +0000
@@ -569,6 +569,22 @@
tree._control_files.put('merge-hashes', StringIO('asdfasdf'))
self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified)
+ def test_merge_modified(self):
+ # merge_modified stores a map from file id to hash
+ tree = self.make_branch_and_tree('tree')
+ d = {'file-id': osutils.sha_string('hello')}
+ self.build_tree_contents([('tree/somefile', 'hello')])
+ tree.lock_write()
+ try:
+ tree.add(['somefile'], ['file-id'])
+ tree.set_merge_modified(d)
+ mm = tree.merge_modified()
+ self.assertEquals(mm, d)
+ finally:
+ tree.unlock()
+ mm = tree.merge_modified()
+ self.assertEquals(mm, d)
+
def test_conflicts(self):
from bzrlib.tests.test_conflicts import example_conflicts
tree = self.make_branch_and_tree('master')
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2007-02-26 03:39:32 +0000
+++ b/bzrlib/workingtree.py 2007-02-26 04:44:24 +0000
@@ -794,8 +794,8 @@
yield Stanza(file_id=file_id.decode('utf8'), hash=hash)
self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
- @needs_tree_write_lock
def _put_rio(self, filename, stanzas, header):
+ self._must_be_locked()
my_file = rio_file(stanzas, header)
self._control_files.put(filename, my_file)
@@ -847,6 +847,15 @@
@needs_read_lock
def merge_modified(self):
+ """Return a dictionary of files modified by a merge.
+
+ The list is initialized by WorkingTree.set_merge_modified, which is
+ typically called after we make some automatic updates to the tree
+ because of a merge.
+
+ This returns a map of file_id->sha1, containing only files which are
+ still in the working inventory and have that text hash.
+ """
try:
hashfile = self._control_files.get('merge-hashes')
except errors.NoSuchFile:
@@ -861,9 +870,9 @@
file_id = s.get("file_id")
if file_id not in self.inventory:
continue
- hash = s.get("hash")
- if hash == self.get_file_sha1(file_id):
- merge_hashes[file_id] = hash
+ text_hash = s.get("hash")
+ if text_hash == self.get_file_sha1(file_id):
+ merge_hashes[file_id] = text_hash
return merge_hashes
@needs_write_lock
@@ -1629,6 +1638,10 @@
def is_locked(self):
return self._control_files.is_locked()
+ def _must_be_locked(self):
+ if not self.is_locked():
+ raise errors.ObjectNotLocked(self)
+
def lock_read(self):
"""See Branch.lock_read, and WorkingTree.unlock."""
self.branch.lock_read()
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-02-26 03:22:55 +0000
+++ b/bzrlib/workingtree_4.py 2007-02-26 04:44:24 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
More information about the bazaar-commits
mailing list