return props[name]
return default
+ def touches_property(self, path, revnum, name):
+ """Check whether a property was modified in a revision."""
+ assert isinstance(path, str)
+ assert isinstance(revnum, int)
+ assert isinstance(name, str)
+ # If the path this property is set on didn't change, then
+ # the property can't have changed.
+ if not self.log.touches_path(path, revnum):
+ return ""
+
+ current = self.get_property(path, revnum, name, None)
+ (prev_path, prev_revnum) = self.log.get_previous(path, revnum)
+ if prev_path is None and prev_revnum == -1:
+ return (current is not None)
+ previous = self.get_property(prev_path.encode("utf-8"),
+ prev_revnum, name, None)
+ return (previous != current)
+
def get_property_diff(self, path, revnum, name):
"""Returns the new lines that were added to a particular property."""
assert isinstance(path, str)
self._svnprops = {}
self._svnprops[SVN_PROP_BZR_REVISION_INFO] = generate_revision_metadata(
timestamp, timezone, committer, revprops)
+ self._svnprops[SVN_PROP_BZR_FILEIDS] = ""
# Gather information about revision on top of which the commit is
# happening
if not (child_ie.kind in ('file', 'symlink')):
continue
+ new_child_path = self.new_inventory.id2path(child_ie.file_id)
# add them if they didn't exist in old_inv
if not child_ie.file_id in self.old_inv:
- mutter('adding %s %r' % (child_ie.kind, self.new_inventory.id2path(child_ie.file_id)))
-
+ mutter('adding %s %r' % (child_ie.kind, new_child_path))
+ self._record_file_id(child_ie, new_child_path)
child_baton = self.editor.add_file(
- urlutils.join(
- self.branch.get_branch_path(),
- self.new_inventory.id2path(child_ie.file_id)),
- baton, None, -1, self.pool)
+ urlutils.join(self.branch.get_branch_path(),
+ new_child_path), baton, None, -1, self.pool)
# copy if they existed at different location
- elif self.old_inv.id2path(child_ie.file_id) != self.new_inventory.id2path(child_ie.file_id):
+ elif self.old_inv.id2path(child_ie.file_id) != new_child_path:
mutter('copy %s %r -> %r' % (child_ie.kind,
self.old_inv.id2path(child_ie.file_id),
- self.new_inventory.id2path(child_ie.file_id)))
-
+ new_child_path))
+ self._record_file_id(child_ie, new_child_path)
child_baton = self.editor.add_file(
- urlutils.join(self.branch.get_branch_path(), self.new_inventory.id2path(child_ie.file_id)), baton,
+ urlutils.join(self.branch.get_branch_path(), new_child_path), baton,
urlutils.join(self.repository.transport.svn_url, self.base_path, self.old_inv.id2path(child_ie.file_id)),
self.base_revnum, self.pool)
# open if they existed at the same location
elif child_ie.revision is None:
- mutter('open %s %r' % (child_ie.kind,
- self.new_inventory.id2path(child_ie.file_id)))
+ mutter('open %s %r' % (child_ie.kind, new_child_path))
child_baton = self.editor.open_file(
- urlutils.join(self.branch.get_branch_path(), self.new_inventory.id2path(child_ie.file_id)),
+ urlutils.join(self.branch.get_branch_path(),
+ new_child_path),
baton, self.base_revnum, self.pool)
else:
if child_ie.kind != 'directory':
continue
+ new_child_path = self.new_inventory.id2path(child_ie.file_id)
# add them if they didn't exist in old_inv
if not child_ie.file_id in self.old_inv:
mutter('adding dir %r' % child_ie.name)
+ self._record_file_id(child_ie, new_child_path)
child_baton = self.editor.add_directory(
- urlutils.join(self.branch.get_branch_path(), self.new_inventory.id2path(child_ie.file_id)),
- baton, None, -1, self.pool)
+ urlutils.join(self.branch.get_branch_path(),
+ new_child_path), baton, None, -1, self.pool)
# copy if they existed at different location
- elif self.old_inv.id2path(child_ie.file_id) != self.new_inventory.id2path(child_ie.file_id):
- mutter('copy dir %r -> %r' % (self.old_inv.id2path(child_ie.file_id),
- self.new_inventory.id2path(child_ie.file_id)))
+ elif self.old_inv.id2path(child_ie.file_id) != new_child_path:
+ old_child_path = self.old_inv.id2path(child_ie.file_id)
+ mutter('copy dir %r -> %r' % (old_child_path, new_child_path))
+ self._record_file_id(child_ie, new_child_path)
child_baton = self.editor.add_directory(
- urlutils.join(self.branch.get_branch_path(), self.new_inventory.id2path(child_ie.file_id)),
- baton,
- urlutils.join(self.repository.transport.svn_url, self.base_path, self.old_inv.id2path(child_ie.file_id)),
- self.base_revnum, self.pool)
+ urlutils.join(self.branch.get_branch_path(), new_child_path),
+ baton,
+ urlutils.join(self.repository.transport.svn_url, self.base_path, old_child_path), self.base_revnum, self.pool)
# open if they existed at the same location and
# the directory was touched
elif self.new_inventory[child_ie.file_id].revision is None:
- mutter('open dir %r' % self.new_inventory.id2path(child_ie.file_id))
+ mutter('open dir %r' % new_child_path)
child_baton = self.editor.open_directory(
- urlutils.join(self.branch.get_branch_path(), self.new_inventory.id2path(child_ie.file_id)),
+ urlutils.join(self.branch.get_branch_path(), new_child_path),
baton, self.base_revnum, self.pool)
else:
assert child_ie.file_id not in self.modified_dirs
# Handle this directory
if child_ie.file_id in self.modified_dirs:
- self._dir_process(self.new_inventory.id2path(child_ie.file_id),
- child_ie.file_id, child_baton)
+ self._dir_process(new_child_path, child_ie.file_id, child_baton)
self.editor.close_directory(child_baton, self.pool)
return revid
def _record_file_id(self, ie, path):
- # Make sure that ie.file_id exists in the map
- if not ie.file_id in self.old_inv:
- if not self._svnprops.has_key(SVN_PROP_BZR_FILEIDS):
- self._svnprops[SVN_PROP_BZR_FILEIDS] = ""
- mutter('adding fileid mapping %s -> %s' % (path, ie.file_id))
- self._svnprops[SVN_PROP_BZR_FILEIDS] += "%s\t%s\n" % (escape_svn_path(path), ie.file_id)
+ mutter('adding fileid mapping %s -> %s' % (path, ie.file_id))
+ self._svnprops[SVN_PROP_BZR_FILEIDS] += "%s\t%s\n" % (escape_svn_path(path), ie.file_id)
def record_entry_contents(self, ie, parent_invs, path, tree):
"""Record the content of ie from tree into the commit if needed.
if ie.revision is not None:
return
- self._record_file_id(ie, path)
-
previous_entries = ie.find_previous_heads(parent_invs,
self.repository.weave_store, self.repository.get_transaction())
def touch_id(id):
ie = builder.new_inventory[id]
path = builder.new_inventory.id2path(id)
- builder._record_file_id(ie, path)
id = ie.file_id
while builder.new_inventory[id].parent_id is not None:
:return: dictionary with paths as keys, file ids as values
"""
(path, revnum, scheme) = self.lookup_revision_id(revid)
+ # Only consider bzr:file-ids if this is a bzr revision
+ if not self.branchprop_list.touches_property(path, revnum,
+ SVN_PROP_BZR_REVISION_INFO):
+ return {}
+ fileids = self.branchprop_list.get_property(path, revnum,
+ SVN_PROP_BZR_FILEIDS)
+ if fileids is None:
+ return {}
ret = {}
- for line in self.branchprop_list.get_property_diff(path, revnum,
- SVN_PROP_BZR_FILEIDS).splitlines():
+ for line in fileids.splitlines():
(path, key) = line.split("\t", 2)
ret[path] = osutils.safe_file_id(key)
return ret
self.client_add("dc/trunk")
self.client_commit("dc", "Add branch")
branch = Branch.open(repos_url+"/trunk")
- self.assertEqual("/trunk", branch.get_branch_path())
+ self.assertEqual("trunk", branch.get_branch_path())
def test_open_nonexistant(self):
repos_url = self.make_client("a", "dc")
bp = BranchPropertyList(logwalk, self.db)
self.assertEqual("data2\n", bp.get_property_diff("", 2, "myprop"))
+ def test_touches_property(self):
+ repos_url = self.make_client('d', 'dc')
+ self.client_set_prop("dc", "myprop", "data\n")
+ self.client_commit("dc", "My Message")
+ self.client_set_prop("dc", "myprop", "data\ndata2\n")
+ self.client_commit("dc", "My Message")
+
+ logwalk = LogWalker(transport=SvnRaTransport(repos_url))
+
+ bp = BranchPropertyList(logwalk, self.db)
+ self.assertTrue(bp.touches_property("", 2, "myprop"))
+ self.assertTrue(bp.touches_property("", 1, "myprop"))
+ self.assertFalse(bp.touches_property("", 1, "nonexistant-property"))
+
def test_get_property_diff_ignore_origchange(self):
repos_url = self.make_client('d', 'dc')
self.client_set_prop("dc", "myprop", "foodata\n")
self.assertEquals(1, paths["/bar"].copyfrom_rev)
self.assertEquals("bar\t%s\n" % oldid,
self.client_get_prop(repos_url, "bzr:file-ids", 2))
-
def test_commit_rename_file_from_directory(self):
repos_url = self.make_client('d', 'dc')
self.build_tree({'b/file': 'data'})
wt.add('file')
oldid = wt.path2id("file")
- revid = wt.commit(message="Commit from Bzr")
+ revid1 = wt.commit(message="Commit from Bzr")
+ wt.rename_one('file', 'file2')
+ revid2 = wt.commit(message="Commit from Bzr")
master_branch = Branch.open(repos_url)
- self.assertEquals(revid, master_branch.last_revision())
self.assertEquals("file\t%s\n" % oldid,
self.client_get_prop(repos_url, "bzr:file-ids", 1))
+ self.assertEquals("file2\t%s\n" % oldid,
+ self.client_get_prop(repos_url, "bzr:file-ids", 2))
+ tree1 = master_branch.repository.revision_tree(revid1)
+ tree2 = master_branch.repository.revision_tree(revid2)
+ delta = tree2.changes_from(tree1)
+ self.assertEquals(1, len(delta.renamed))
self.build_tree({'dc/test': "data"})
self.client_add("dc/test")
self.client_set_prop("dc", "bzr:file-ids", "test\tbla\n")
+ self.client_set_prop("dc", "bzr:revision-info", "")
self.client_commit("dc", "Msg")
oldrepos = Repository.open(repos_url)
repos_url = self.make_client('d', 'dc')
self.build_tree({'dc/foo': "data"})
self.client_add("dc/foo")
+ self.client_set_prop("dc", "bzr:revision-info", "")
self.client_set_prop("dc", "bzr:file-ids", "foo\tsomeid\n")
self.client_commit("dc", "My Message")
repository = Repository.open("svn+%s" % repos_url)
repos_url = self.make_client('d', 'dc')
self.build_tree({'dc/test': "data"})
self.client_add("dc/test")
+ self.client_set_prop("dc", "bzr:revision-info", "")
self.client_set_prop("dc", "bzr:file-ids", "test\tbla\n")
self.client_commit("dc", "Msg")
else:
assert isinstance(id, str)
new_entries[path] = id
- committed = self.branch.repository.branchprop_list.get_property(
- self.branch.get_branch_path(self.base_revnum),
- self.base_revnum,
- SVN_PROP_BZR_FILEIDS, "")
- existing = committed + "".join(map(lambda (path, id): "%s\t%s\n" % (path, id), new_entries.items()))
+ existing = "".join(map(lambda (path, id): "%s\t%s\n" % (path, id), new_entries.items()))
if existing != "":
svn.wc.prop_set(SVN_PROP_BZR_FILEIDS, existing.encode("utf-8"), self.basedir, subwc)
if wc is None:
self.branch.get_branch_path(self.base_revnum), self.base_revnum,
SVN_PROP_BZR_FILEIDS, "")
existing = svn.wc.prop_get(SVN_PROP_BZR_FILEIDS, self.basedir, wc)
- if existing is None:
+ if existing is None or committed == existing:
return {}
- else:
- return dict(map(lambda x: str(x).split("\t"),
- existing[len(committed):].splitlines()))
+ return dict(map(lambda x: str(x).split("\t"),
+ existing.splitlines()))
def _get_bzr_revids(self):
return self.branch.repository.branchprop_list.get_property(