1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Helper functions for adding files to working trees."""
24
import bzrlib.errors as errors
21
25
import bzrlib.osutils
26
from bzrlib.symbol_versioning import *
27
from bzrlib.workingtree import WorkingTree
24
30
class AddAction(object):
30
36
:param to_file: The stream to write into. This is expected to take
31
37
Unicode paths. If not supplied, it will default to ``sys.stdout``.
32
:param should_print: If False, printing will be suppressed.
38
:param should_print: If False, printing will be supressed.
34
40
self._to_file = to_file
35
41
if to_file is None:
67
73
file_id, base_path = self._get_base_file_id(path, parent_ie)
68
74
if file_id is not None:
69
75
if self.should_print:
70
self._to_file.write('adding %s w/ file id from %s\n'
76
self._to_file.write('added %s w/ file id from %s\n'
71
77
% (path.raw_path, base_path))
73
79
# we aren't doing anything special, so let the default
93
99
full_base_path = bzrlib.osutils.pathjoin(self.base_path, path.raw_path)
94
100
# This may return None, but it is our last attempt
95
101
return self.base_tree.path2id(full_base_path), full_base_path
104
# TODO: jam 20050105 These could be used for compatibility
105
# however, they bind against the current stdout, not the
106
# one which exists at the time they are called, so they
107
# don't work for the test suite.
109
add_action_add = AddAction()
110
add_action_null = add_action_add
111
add_action_add_and_print = AddAction(should_print=True)
112
add_action_print = add_action_add_and_print
115
@deprecated_function(zero_eighteen)
116
def smart_add(file_list, recurse=True, action=None, save=True):
117
"""Add files to version, optionally recursing into directories.
119
This is designed more towards DWIM for humans than API simplicity.
120
For the specific behaviour see the help for cmd_add().
122
Returns the number of files added.
123
Deprecated in 0.18. Please use MutableTree.smart_add.
125
tree = WorkingTree.open_containing(file_list[0])[0]
126
return smart_add_tree(tree, file_list, recurse, action=action, save=save)
129
@deprecated_function(zero_eighteen)
130
def smart_add_tree(tree, file_list, recurse=True, action=None, save=True):
131
"""Deprecated in 0.18. Please use MutableTree.smart_add."""
132
return tree.smart_add(file_list, recurse, action, save)