Rev 4241: (abentley) Change guess-renames to mv --auto, add --dry-run in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Apr 2 17:35:07 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4241
revision-id: pqm at pqm.ubuntu.com-20090402163502-ryn8zr2giilw5bki
parent: pqm at pqm.ubuntu.com-20090402154740-0h1xz7luyp8mb2lz
parent: aaron at aaronbentley.com-20090401215909-zysl5d9v78tg9ehd
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-04-02 17:35:02 +0100
message:
(abentley) Change guess-renames to mv --auto, add --dry-run
removed:
bzrlib/tests/blackbox/test_guess_renames.py test_guess_renames.p-20090312063936-bqdtxr0r3md3jc00-1
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/rename_map.py rename_map.py-20090312140439-xexkkmjlg2enbohc-1
bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
bzrlib/tests/blackbox/test_mv.py test_mv.py-20060705114902-33tkxz0o9cdshemo-1
bzrlib/tests/test_rename_map.py test_rename_map.py-20090312140439-xexkkmjlg2enbohc-2
------------------------------------------------------------
revno: 3193.8.39
revision-id: aaron at aaronbentley.com-20090401215909-zysl5d9v78tg9ehd
parent: aaron at aaronbentley.com-20090401203316-si0w1d1wbc8bapay
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: guess-renames
timestamp: Wed 2009-04-01 17:59:09 -0400
message:
Remove guess-renames command
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
------------------------------------------------------------
revno: 3193.8.38
revision-id: aaron at aaronbentley.com-20090401203316-si0w1d1wbc8bapay
parent: aaron at aaronbentley.com-20090401203051-d69lplsnxovk6nxi
parent: pqm at pqm.ubuntu.com-20090401151438-hqulqoazddtacbls
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: guess-renames
timestamp: Wed 2009-04-01 16:33:16 -0400
message:
Merge bzr.dev into guess-renames
added:
doc/developers/improved_chk_index.txt improved_chk_index.t-20090320211430-odgus43a7wgoi0ik-1
modified:
.bzrignore bzrignore-20050311232317-81f7b71efa2db11a
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/__init__.py __init__.py-20050309040759-33e65acf91bbcd5d
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/btree_index.py index.py-20080624222253-p0x5f92uyh5hw734-7
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bundle/serializer/v4.py v10.py-20070611062757-5ggj7k18s9dej0fr-1
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/counted_lock.py counted_lock.py-20070502135927-7dk86io3ok7ctx6k-1
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/filters/__init__.py __init__.py-20080416080515-mkxl29amuwrf6uir-2
bzrlib/graph.py graph_walker.py-20070525030359-y852guab65d4wtn0-1
bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/lockable_files.py control_files.py-20051111201905-bb88546e799d669f
bzrlib/log.py log.py-20050505065812-c40ce11702fe5fb1
bzrlib/lru_cache.py lru_cache.py-20070119165515-tlw203kuwh0id5gv-1
bzrlib/memorytree.py memorytree.py-20060906023413-4wlkalbdpsxi2r4y-1
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/repofmt/pack_repo.py pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
bzrlib/repofmt/weaverepo.py presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/revisiontree.py revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
bzrlib/smart/repository.py repository.py-20061128022038-vr5wy5bubyb8xttk-1
bzrlib/smart/request.py request.py-20061108095550-gunadhxmzkdjfeek-1
bzrlib/smtp_connection.py smtp_connection.py-20070618204456-nu6wag1ste4biuk2-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/test_add.py test_add.py-20060518072250-857e4f86f54a30b2
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
bzrlib/tests/blackbox/test_filtered_view_ops.py test_filtered_view_o-20081110012645-5t7ogtola0l33lkg-1
bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/blackbox/test_view.py test_view.py-20080731135100-66o8o32heop7augi-1
bzrlib/tests/per_repository/test_commit_builder.py test_commit_builder.py-20060606110838-76e3ra5slucqus81-1
bzrlib/tests/test_bundle.py test.py-20050630184834-092aa401ab9f039c
bzrlib/tests/test_commit.py test_commit.py-20050914060732-279f057f8c295434
bzrlib/tests/test_counted_lock.py test_counted_lock.py-20070502135927-7dk86io3ok7ctx6k-2
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
bzrlib/tests/test_filters.py test_filters.py-20080417120614-tc3zok0vvvprsc99-1
bzrlib/tests/test_graph.py test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/tests/test_info.py test_info.py-20070320150933-m0xxm1g7xi9v6noe-1
bzrlib/tests/test_log.py testlog.py-20050728115707-1a514809d7d49309
bzrlib/tests/test_lru_cache.py test_lru_cache.py-20070119165535-hph6rk4h9rzy4180-1
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
bzrlib/tests/test_smart_request.py test_smart_request.p-20090211070731-o38wayv3asm25d6a-1
bzrlib/tests/test_smtp_connection.py test_smtp_connection-20070618204509-wuyxc0r0ztrecv7e-1
bzrlib/tests/test_source.py test_source.py-20051207061333-a58dea6abecc030d
bzrlib/tests/test_upgrade.py test_upgrade.py-20051004040251-555fe1d2bae1bc71
bzrlib/tests/workingtree_implementations/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
bzrlib/upgrade.py history2weaves.py-20050818063535-e7d319791c19a8b2
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
doc/developers/index.txt index.txt-20070508041241-qznziunkg0nffhiw-1
doc/developers/performance-contributing.txt performancecontribut-20070621063612-ac4zhhagjzkr21qp-1
doc/developers/planned-change-integration.txt plannedchangeintegra-20070619004702-i1b3ccamjtfaoq6w-1
doc/developers/releasing.txt releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
doc/developers/revision-properties.txt revisionproperties.t-20070807133526-w57m8zv5o7t5kugm-1
doc/en/user-guide/browsing_history.txt browsing_history.txt-20071121073725-0corxykv5irjal00-2
doc/en/user-guide/filtered_views.txt filtered_views.txt-20090226100856-a16ba1v97v91ru58-1
------------------------------------------------------------
revno: 3193.8.37
revision-id: aaron at aaronbentley.com-20090401203051-d69lplsnxovk6nxi
parent: aaron at aaronbentley.com-20090401200852-fk0duxmcy6sbxfuz
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: guess-renames
timestamp: Wed 2009-04-01 16:30:51 -0400
message:
Finish up conversion to mv --auto.
removed:
bzrlib/tests/blackbox/test_guess_renames.py test_guess_renames.p-20090312063936-bqdtxr0r3md3jc00-1
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
bzrlib/tests/blackbox/test_mv.py test_mv.py-20060705114902-33tkxz0o9cdshemo-1
------------------------------------------------------------
revno: 3193.8.36
revision-id: aaron at aaronbentley.com-20090401200852-fk0duxmcy6sbxfuz
parent: aaron at aaronbentley.com-20090401195927-chkayyap0yl8wmnb
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: guess-renames
timestamp: Wed 2009-04-01 16:08:52 -0400
message:
Get remaining behaviour under test.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_mv.py test_mv.py-20060705114902-33tkxz0o9cdshemo-1
------------------------------------------------------------
revno: 3193.8.35
revision-id: aaron at aaronbentley.com-20090401195927-chkayyap0yl8wmnb
parent: aaron at aaronbentley.com-20090330205942-irvhmm42k6d4kfdd
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: guess-renames
timestamp: Wed 2009-04-01 15:59:27 -0400
message:
Implement mv --auto.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_mv.py test_mv.py-20060705114902-33tkxz0o9cdshemo-1
------------------------------------------------------------
revno: 3193.8.34
revision-id: aaron at aaronbentley.com-20090330205942-irvhmm42k6d4kfdd
parent: aaron at aaronbentley.com-20090324154732-bwkvi4dx3o90a7dq
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: guess-renames
timestamp: Mon 2009-03-30 16:59:42 -0400
message:
Add tests of guess_renames output.
modified:
bzrlib/tests/test_rename_map.py test_rename_map.py-20090312140439-xexkkmjlg2enbohc-2
------------------------------------------------------------
revno: 3193.8.33
revision-id: aaron at aaronbentley.com-20090324154732-bwkvi4dx3o90a7dq
parent: aaron at aaronbentley.com-20090324125405-dz57ar35gw5m19y5
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: guess-renames
timestamp: Tue 2009-03-24 11:47:32 -0400
message:
Add output, emit minimal inventory delta.
modified:
bzrlib/rename_map.py rename_map.py-20090312140439-xexkkmjlg2enbohc-1
=== modified file 'NEWS'
--- a/NEWS 2009-04-02 06:19:45 +0000
+++ b/NEWS 2009-04-02 16:35:02 +0000
@@ -38,7 +38,7 @@
respectively, but have support for filtered views disabled.
(Ian Clatworthy)
-* New ``guess-renames`` command recognizes renames after they occur.
+* New ``mv --auto`` option recognizes renames after they occur.
(Aaron Bentley)
* ``bzr log`` now supports filtering of multiple files and directories
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2009-03-31 11:33:02 +0000
+++ b/bzrlib/builtins.py 2009-04-01 21:59:09 +0000
@@ -722,14 +722,19 @@
takes_args = ['names*']
takes_options = [Option("after", help="Move only the bzr identifier"
" of the file, because the file has already been moved."),
+ Option('auto', help='Automatically guess renames.'),
+ Option('dry-run', help='Avoid making changes when guessing renames.'),
]
aliases = ['move', 'rename']
encoding_type = 'replace'
- def run(self, names_list, after=False):
+ def run(self, names_list, after=False, auto=False, dry_run=False):
+ if auto:
+ return self.run_auto(names_list, after, dry_run)
+ elif dry_run:
+ raise errors.BzrCommandError('--dry-run requires --auto.')
if names_list is None:
names_list = []
-
if len(names_list) < 2:
raise errors.BzrCommandError("missing file argument")
tree, rel_names = tree_files(names_list, canonicalize=False)
@@ -739,6 +744,20 @@
finally:
tree.unlock()
+ def run_auto(self, names_list, after, dry_run):
+ if names_list is not None and len(names_list) > 1:
+ raise errors.BzrCommandError('Only one path may be specified to'
+ ' --auto.')
+ if after:
+ raise errors.BzrCommandError('--after cannot be specified with'
+ ' --auto.')
+ work_tree, file_list = tree_files(names_list, default_branch='.')
+ work_tree.lock_write()
+ try:
+ rename_map.RenameMap.guess_renames(work_tree, dry_run)
+ finally:
+ work_tree.unlock()
+
def _run(self, tree, names_list, rel_names, after):
into_existing = osutils.isdir(names_list[-1])
if into_existing and len(names_list) == 2:
@@ -5268,22 +5287,6 @@
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
-class cmd_guess_renames(Command):
- """Guess which files have been have been renamed, based on their content.
-
- Only versioned files which have been deleted are candidates for rename
- detection, and renames to ignored files will not be detected.
- """
-
- def run(self):
- work_tree, file_list = tree_files(None, default_branch='.')
- work_tree.lock_write()
- try:
- rename_map.RenameMap.guess_renames(work_tree)
- finally:
- work_tree.unlock()
-
-
class cmd_view(Command):
"""Manage filtered views.
=== modified file 'bzrlib/rename_map.py'
--- a/bzrlib/rename_map.py 2009-03-24 12:54:05 +0000
+++ b/bzrlib/rename_map.py 2009-03-24 15:47:32 +0000
@@ -20,6 +20,7 @@
from bzrlib import (
osutils,
progress,
+ trace,
)
from bzrlib.ui import ui_factory
@@ -202,7 +203,7 @@
return missing_files, missing_parents, candidate_files
@classmethod
- def guess_renames(klass, tree):
+ def guess_renames(klass, tree, dry_run=False):
"""Guess which files to rename, and perform the rename.
We assume that unversioned files and missing files indicate that
@@ -235,12 +236,16 @@
missing_parents)
matches.update(parents_matches)
pp.next_phase()
- rn._update_tree(required_parents, matches)
+ delta = rn._make_inventory_delta(matches)
+ for old, new, file_id, entry in delta:
+ trace.note("%s => %s", old, new)
+ if not dry_run:
+ tree.add(required_parents)
+ tree.apply_inventory_delta(delta)
finally:
task.finished()
- def _update_tree(self, required_parents, matches):
- self.tree.add(required_parents)
+ def _make_inventory_delta(self, matches):
delta = []
file_id_matches = dict((f, p) for p, f in matches.items())
for old_path, entry in self.tree.iter_entries_by_dir(matches.values()):
@@ -249,8 +254,10 @@
parent_id = matches.get(parent_path)
if parent_id is None:
parent_id = self.tree.path2id(parent_path)
+ if entry.name == new_name and entry.parent_id == parent_id:
+ continue
new_entry = entry.copy()
new_entry.parent_id = parent_id
new_entry.name = new_name
delta.append((old_path, new_path, new_entry.file_id, new_entry))
- self.tree.apply_inventory_delta(delta)
+ return delta
=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py 2009-03-24 12:15:01 +0000
+++ b/bzrlib/tests/blackbox/__init__.py 2009-04-01 20:30:51 +0000
@@ -59,7 +59,6 @@
'bzrlib.tests.blackbox.test_filesystem_cicp',
'bzrlib.tests.blackbox.test_filtered_view_ops',
'bzrlib.tests.blackbox.test_find_merge_base',
- 'bzrlib.tests.blackbox.test_guess_renames',
'bzrlib.tests.blackbox.test_help',
'bzrlib.tests.blackbox.test_hooks',
'bzrlib.tests.blackbox.test_ignore',
=== removed file 'bzrlib/tests/blackbox/test_guess_renames.py'
--- a/bzrlib/tests/blackbox/test_guess_renames.py 2009-03-24 12:54:05 +0000
+++ b/bzrlib/tests/blackbox/test_guess_renames.py 1970-01-01 00:00:00 +0000
@@ -1,24 +0,0 @@
-# Copyright (C) 2008 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
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-from bzrlib import tests
-
-
-class TestGuessRenames(tests.TestCaseWithTransport):
-
- def test_guess_renames(self):
- self.run_bzr('guess-renames')
=== modified file 'bzrlib/tests/blackbox/test_mv.py'
--- a/bzrlib/tests/blackbox/test_mv.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_mv.py 2009-04-01 20:30:51 +0000
@@ -430,3 +430,58 @@
self.assertNotInWorkingTree('c')
self.failUnlessExists('d')
self.assertInWorkingTree('d')
+
+ def make_abcd_tree(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/a', 'tree/c'])
+ tree.add(['a', 'c'])
+ tree.commit('record old names')
+ osutils.rename('tree/a', 'tree/b')
+ osutils.rename('tree/c', 'tree/d')
+ return tree
+
+ def test_mv_auto(self):
+ self.make_abcd_tree()
+ out, err = self.run_bzr('mv --auto', working_dir='tree')
+ self.assertEqual(out, '')
+ self.assertEqual(err, 'a => b\nc => d\n')
+ tree = workingtree.WorkingTree.open('tree')
+ self.assertIsNot(None, tree.path2id('b'))
+ self.assertIsNot(None, tree.path2id('d'))
+
+ def test_mv_auto_one_path(self):
+ self.make_abcd_tree()
+ out, err = self.run_bzr('mv --auto tree')
+ self.assertEqual(out, '')
+ self.assertEqual(err, 'a => b\nc => d\n')
+ tree = workingtree.WorkingTree.open('tree')
+ self.assertIsNot(None, tree.path2id('b'))
+ self.assertIsNot(None, tree.path2id('d'))
+
+ def test_mv_auto_two_paths(self):
+ self.make_abcd_tree()
+ out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
+ self.assertEqual('bzr: ERROR: Only one path may be specified to'
+ ' --auto.\n', err)
+
+ def test_mv_auto_dry_run(self):
+ self.make_abcd_tree()
+ out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
+ self.assertEqual(out, '')
+ self.assertEqual(err, 'a => b\nc => d\n')
+ tree = workingtree.WorkingTree.open('tree')
+ self.assertIsNot(None, tree.path2id('a'))
+ self.assertIsNot(None, tree.path2id('c'))
+
+ def test_mv_no_auto_dry_run(self):
+ self.make_abcd_tree()
+ out, err = self.run_bzr('mv c d --dry-run',
+ working_dir='tree', retcode=3)
+ self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
+
+ def test_mv_auto_after(self):
+ self.make_abcd_tree()
+ out, err = self.run_bzr('mv --auto --after', working_dir='tree',
+ retcode=3)
+ self.assertEqual('bzr: ERROR: --after cannot be specified with'
+ ' --auto.\n', err)
=== modified file 'bzrlib/tests/test_rename_map.py'
--- a/bzrlib/tests/test_rename_map.py 2009-03-24 12:54:05 +0000
+++ b/bzrlib/tests/test_rename_map.py 2009-03-30 20:59:42 +0000
@@ -17,6 +17,7 @@
import os
+from bzrlib import trace
from bzrlib.rename_map import RenameMap
from bzrlib.tests import TestCaseWithTransport
@@ -158,3 +159,43 @@
os.rename('tree/foo', 'tree/baz')
RenameMap.guess_renames(tree)
self.assertEqual('baz/empty', tree.id2path('empty-id'))
+
+ def test_guess_renames_dry_run(self):
+ tree = self.make_branch_and_tree('tree')
+ tree.lock_write()
+ self.addCleanup(tree.unlock)
+ self.build_tree(['tree/file'])
+ tree.add('file', 'file-id')
+ tree.commit('Added file')
+ os.rename('tree/file', 'tree/file2')
+ RenameMap.guess_renames(tree, dry_run=True)
+ self.assertEqual('file', tree.id2path('file-id'))
+
+ @staticmethod
+ def captureNotes(cmd, *args, **kwargs):
+ notes = []
+ def my_note(fmt, *args):
+ notes.append(fmt % args)
+ old_note = trace.note
+ trace.note = my_note
+ try:
+ result = cmd(*args, **kwargs)
+ finally:
+ trace.note = old_note
+ return notes, result
+
+ def test_guess_renames_output(self):
+ """guess_renames emits output whether dry_run is True or False."""
+ tree = self.make_branch_and_tree('tree')
+ tree.lock_write()
+ self.addCleanup(tree.unlock)
+ self.build_tree(['tree/file'])
+ tree.add('file', 'file-id')
+ tree.commit('Added file')
+ os.rename('tree/file', 'tree/file2')
+ notes = self.captureNotes(RenameMap.guess_renames, tree,
+ dry_run=True)[0]
+ self.assertEqual('file => file2', ''.join(notes))
+ notes = self.captureNotes(RenameMap.guess_renames, tree,
+ dry_run=False)[0]
+ self.assertEqual('file => file2', ''.join(notes))
More information about the bazaar-commits
mailing list