~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
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
12
12
#
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Helper functions for adding files to working trees."""
18
18
 
19
 
import errno
20
 
import os
21
19
import sys
22
20
 
23
 
import bzrlib.bzrdir
24
 
import bzrlib.errors as errors
25
 
import bzrlib.osutils
26
 
from bzrlib.symbol_versioning import *
27
 
from bzrlib.workingtree import WorkingTree
 
21
from bzrlib import (
 
22
    osutils,
 
23
    )
28
24
 
29
25
 
30
26
class AddAction(object):
35
31
 
36
32
        :param to_file: The stream to write into. This is expected to take
37
33
            Unicode paths. If not supplied, it will default to ``sys.stdout``.
38
 
        :param should_print: If False, printing will be supressed.
 
34
        :param should_print: If False, printing will be suppressed.
39
35
        """
40
36
        self._to_file = to_file
41
37
        if to_file is None:
44
40
        if should_print is not None:
45
41
            self.should_print = should_print
46
42
 
47
 
    def __call__(self, inv, parent_ie, path, kind, _quote=bzrlib.osutils.quotefn):
 
43
    def __call__(self, inv, parent_ie, path, kind, _quote=osutils.quotefn):
48
44
        """Add path to inventory.
49
45
 
50
46
        The default action does nothing.
54
50
        :param kind: The kind of the object being added.
55
51
        """
56
52
        if self.should_print:
57
 
            self._to_file.write('added %s\n' % _quote(path.raw_path))
 
53
            self._to_file.write('adding %s\n' % _quote(path))
58
54
        return None
59
55
 
60
56
 
73
69
        file_id, base_path = self._get_base_file_id(path, parent_ie)
74
70
        if file_id is not None:
75
71
            if self.should_print:
76
 
                self._to_file.write('added %s w/ file id from %s\n'
77
 
                                    % (path.raw_path, base_path))
 
72
                self._to_file.write('adding %s w/ file id from %s\n'
 
73
                                    % (path, base_path))
78
74
        else:
79
75
            # we aren't doing anything special, so let the default
80
76
            # reporter happen
90
86
        Else, we look for an entry in the base tree with the same path.
91
87
        """
92
88
 
93
 
        if (parent_ie.file_id in self.base_tree):
 
89
        if self.base_tree.has_id(parent_ie.file_id):
94
90
            base_parent_ie = self.base_tree.inventory[parent_ie.file_id]
95
 
            base_child_ie = base_parent_ie.children.get(path.base_path)
 
91
            base_child_ie = base_parent_ie.children.get(
 
92
                osutils.basename(path))
96
93
            if base_child_ie is not None:
97
94
                return (base_child_ie.file_id,
98
95
                        self.base_tree.id2path(base_child_ie.file_id))
99
 
        full_base_path = bzrlib.osutils.pathjoin(self.base_path, path.raw_path)
 
96
        full_base_path = osutils.pathjoin(self.base_path, path)
100
97
        # This may return None, but it is our last attempt
101
98
        return self.base_tree.path2id(full_base_path), full_base_path
102
 
 
103
 
 
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.
108
 
# deprecated
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