Rev 2570: * New method ``_glob_expand_file_list_if_needed`` on the ``Command`` class in sftp://rookery/~/public_html/baz2.0/add
Robert Collins
robertc at robertcollins.net
Mon Jul 2 23:36:50 BST 2007
At sftp://rookery/~/public_html/baz2.0/add
------------------------------------------------------------
revno: 2570
revision-id: robertc at robertcollins.net-20070702223611-50tnzmbeoryqid75
parent: robertc at robertcollins.net-20070702220543-bbal5fjb73rsl1s5
committer: Robert Collins <robertc at robertcollins.net>
branch nick: add
timestamp: Tue 2007-07-03 08:36:11 +1000
message:
* New method ``_glob_expand_file_list_if_needed`` on the ``Command`` class
for dealing with unexpanded glob lists - e.g. on the win32 platform. This
was moved from ``bzrlib.add._prepare_file_list``. (Robert Collins)
* ``bzrlib.add.smart_add_tree`` will no longer perform glob expansion on
win32. Callers of the function should do this. (Robert Collins)
* ``bzrlib.add.glob_expand_for_win32`` is now
``bzrlib.win32utils.glob_expand``. (Robert Collins)
* ``bzrlib.smart_add`` is deprecated. (Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/add.py add.py-20050323030017-3a77d63feda58e33
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/generate_ids.py generate_ids.py-20061102205935-z3do15ipw6m7v26u-1
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
=== modified file 'NEWS'
--- a/NEWS 2007-07-02 06:11:47 +0000
+++ b/NEWS 2007-07-02 22:36:11 +0000
@@ -82,6 +82,14 @@
These changes are an API break in the testing infrastructure only.
(Robert Collins)
+ * ``bzrlib.add.smart_add_tree`` will no longer perform glob expansion on
+ win32. Callers of the function should do this. (Robert Collins)
+
+ * ``bzrlib.add.glob_expand_for_win32`` is now
+ ``bzrlib.win32utils.glob_expand``. (Robert Collins)
+
+ * ``bzrlib.smart_add`` is deprecated. (Robert Collins)
+
INTERNALS:
* New SMTPConnection class to unify email handling. (Adeodato Simó)
@@ -90,6 +98,10 @@
allows a nicer UI when hooks are running as the current hook can
be displayed. (Robert Collins)
+ * New method ``_glob_expand_file_list_if_needed`` on the ``Command`` class
+ for dealing with unexpanded glob lists - e.g. on the win32 platform. This
+ was moved from ``bzrlib.add._prepare_file_list``. (Robert Collins)
+
TESTING:
* Removed the ``--keep-output`` option from selftest and clean up test
=== modified file 'bzrlib/add.py'
--- a/bzrlib/add.py 2007-04-09 21:06:31 +0000
+++ b/bzrlib/add.py 2007-07-02 22:36:11 +0000
@@ -23,48 +23,14 @@
import bzrlib.bzrdir
import bzrlib.errors as errors
+from bzrlib.errors import NotBranchError
from bzrlib.inventory import InventoryEntry
+import bzrlib.osutils
+from bzrlib.symbol_versioning import *
from bzrlib.trace import mutter, note, warning
-from bzrlib.errors import NotBranchError
-import bzrlib.osutils
from bzrlib.workingtree import WorkingTree
-def glob_expand_for_win32(file_list):
- """Replacement for glob expansion by the shell.
-
- Win32's cmd.exe does not do glob expansion (eg ``*.py``), so we do our own
- here.
-
- :param file_list: A list of filenames which may include shell globs.
- :return: An expanded list of filenames.
- """
- if not file_list:
- return
- import glob
- expanded_file_list = []
- for possible_glob in file_list:
- glob_files = glob.glob(possible_glob)
-
- if glob_files == []:
- # special case to let the normal code path handle
- # files that do not exists
- expanded_file_list.append(possible_glob)
- else:
- expanded_file_list += glob_files
- return expanded_file_list
-
-
-def _prepare_file_list(file_list):
- """Prepare a file list for use by smart_add_*."""
- if sys.platform == 'win32':
- file_list = glob_expand_for_win32(file_list)
- if not file_list:
- file_list = [u'.']
- file_list = list(file_list)
- return file_list
-
-
class AddAction(object):
"""A class which defines what action to take when adding a file."""
@@ -150,6 +116,7 @@
add_action_print = add_action_add_and_print
+ at deprecated_function(zero_eighteen)
def smart_add(file_list, recurse=True, action=None, save=True):
"""Add files to version, optionally recursing into directories.
@@ -159,7 +126,6 @@
Returns the number of files added.
Please see smart_add_tree for more detail.
"""
- file_list = _prepare_file_list(file_list)
tree = WorkingTree.open_containing(file_list[0])[0]
return smart_add_tree(tree, file_list, recurse, action=action, save=save)
@@ -218,8 +184,10 @@
if action is None:
action = AddAction()
- prepared_list = _prepare_file_list(file_list)
- mutter("smart add of %r, originally %r", prepared_list, file_list)
+ if not file_list:
+ # no paths supplied: add the entire tree.
+ file_list = [u'.']
+ mutter("smart add of %r")
inv = tree.read_working_inventory()
added = []
ignored = {}
@@ -229,7 +197,7 @@
# validate user file paths and convert all paths to tree
# relative : its cheaper to make a tree relative path an abspath
# than to convert an abspath to tree relative.
- for filepath in prepared_list:
+ for filepath in file_list:
rf = FastPath(tree.relpath(filepath))
# validate user parameters. Our recursive code avoids adding new files
# that need such validation
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-06-28 20:50:14 +0000
+++ b/bzrlib/builtins.py 2007-07-02 22:36:11 +0000
@@ -384,8 +384,13 @@
if base_tree:
base_tree.lock_read()
try:
- added, ignored = bzrlib.add.smart_add(file_list, not no_recurse,
- action=action, save=not dry_run)
+ file_list = self._glob_expand_file_list_if_needed(file_list)
+ if file_list:
+ tree = WorkingTree.open_containing(file_list[0])[0]
+ else:
+ tree = WorkingTree.open_containing(u'.')[0]
+ added, ignored = bzrlib.add.smart_add_tree(tree, file_list, not
+ no_recurse, action=action, save=not dry_run)
finally:
if base_tree is not None:
base_tree.unlock()
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2007-06-25 14:27:08 +0000
+++ b/bzrlib/commands.py 2007-07-02 22:36:11 +0000
@@ -44,6 +44,7 @@
option,
osutils,
trace,
+ win32utils,
)
""")
@@ -240,6 +241,19 @@
if self.__doc__ == Command.__doc__:
warn("No help message set for %r" % self)
+ def _glob_expand_file_list_if_needed(self, file_list):
+ """Glob expand file_list if the platform does not do that itself.
+
+ :return: A possibly empty list of unicode paths.
+
+ Introduced in bzrlib 0.18.
+ """
+ if not file_list:
+ file_list = []
+ if sys.platform == 'win32':
+ file_list = win32utils.glob_expand(file_list)
+ return list(file_list)
+
def _usage(self):
"""Return single-line grammar for this command.
=== modified file 'bzrlib/generate_ids.py'
--- a/bzrlib/generate_ids.py 2007-02-18 00:22:24 +0000
+++ b/bzrlib/generate_ids.py 2007-07-02 22:36:11 +0000
@@ -47,7 +47,7 @@
give a highly probably globally unique number. Then each call in the same
process adds 1 to a serial number we append to that unique value.
"""
- # XXX TODO: change bzrlib.add.smart_add to call workingtree.add() rather
+ # XXX TODO: change bzrlib.add.smart_add_tree to call workingtree.add() rather
# than having to move the id randomness out of the inner loop like this.
# XXX TODO: for the global randomness this uses we should add the thread-id
# before the serial #.
=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py 2007-02-03 15:02:06 +0000
+++ b/bzrlib/win32utils.py 2007-07-02 22:36:11 +0000
@@ -238,3 +238,32 @@
def get_host_name_unicode():
return _ensure_unicode(get_host_name())
+
+
+def glob_expand_for_win32(file_list):
+ """Replacement for glob expansion by the shell.
+
+ Win32's cmd.exe does not do glob expansion (eg ``*.py``), so we do our own
+ here.
+
+ :param file_list: A list of filenames which may include shell globs.
+ :return: An expanded list of filenames.
+
+ Introduced in bzrlib 0.18.
+ """
+ if not file_list:
+ return []
+ import glob
+ expanded_file_list = []
+ for possible_glob in file_list:
+ glob_files = glob.glob(possible_glob)
+
+ if glob_files == []:
+ # special case to let the normal code path handle
+ # files that do not exists
+ expanded_file_list.append(possible_glob)
+ else:
+ expanded_file_list += glob_files
+ return expanded_file_list
+
+
More information about the bazaar-commits
mailing list