~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
        :param path: The FastPath being added
75
75
        :param kind: The kind of the object being added.
76
76
        """
77
 
        if self.should_print:
78
 
            self._to_file.write('added %s\n' % _quote(path.raw_path))
79
 
        return None
80
 
 
81
 
 
82
 
class AddFromBaseAction(AddAction):
83
 
    """This class will try to extract file ids from another tree."""
84
 
 
85
 
    def __init__(self, base_tree, base_path, to_file=None, should_print=None):
86
 
        super(AddFromBaseAction, self).__init__(to_file=to_file,
87
 
                                                should_print=should_print)
88
 
        self.base_tree = base_tree
89
 
        self.base_path = base_path
90
 
 
91
 
    def __call__(self, inv, parent_ie, path, kind):
92
 
        # Place the parent call
93
 
        # Now check to see if we can extract an id for this file
94
 
        file_id, base_path = self._get_base_file_id(path, parent_ie)
95
 
        if file_id is not None:
96
 
            if self.should_print:
97
 
                self._to_file.write('added %s w/ file id from %s\n'
98
 
                                    % (path.raw_path, base_path))
99
 
        else:
100
 
            # we aren't doing anything special, so let the default
101
 
            # reporter happen
102
 
            file_id = super(AddFromBaseAction, self).__call__(
103
 
                        inv, parent_ie, path, kind)
104
 
        return file_id
105
 
 
106
 
    def _get_base_file_id(self, path, parent_ie):
107
 
        """Look for a file id in the base branch.
108
 
 
109
 
        First, if the base tree has the parent directory,
110
 
        we look for a file with the same name in that directory.
111
 
        Else, we look for an entry in the base tree with the same path.
112
 
        """
113
 
 
114
 
        if (parent_ie.file_id in self.base_tree):
115
 
            base_parent_ie = self.base_tree.inventory[parent_ie.file_id]
116
 
            base_child_ie = base_parent_ie.children.get(path.base_path)
117
 
            if base_child_ie is not None:
118
 
                return (base_child_ie.file_id,
119
 
                        self.base_tree.id2path(base_child_ie.file_id))
120
 
        full_base_path = bzrlib.osutils.pathjoin(self.base_path, path.raw_path)
121
 
        # This may return None, but it is our last attempt
122
 
        return self.base_tree.path2id(full_base_path), full_base_path
 
77
        if not self.should_print:
 
78
            return
 
79
        self._to_file.write('added %s\n' % _quote(path.raw_path))
123
80
 
124
81
 
125
82
# TODO: jam 20050105 These could be used for compatibility
144
101
    """
145
102
    file_list = _prepare_file_list(file_list)
146
103
    tree = WorkingTree.open_containing(file_list[0])[0]
147
 
    return smart_add_tree(tree, file_list, recurse, action=action, save=save)
 
104
    return smart_add_tree(tree, file_list, recurse, action=action)
148
105
 
149
106
 
150
107
class FastPath(object):
364
321
    :param inv: Inventory which will receive the new entry.
365
322
    :param parent_ie: Parent inventory entry.
366
323
    :param kind: Kind of new entry (file, directory, etc)
367
 
    :param action: callback(inv, parent_ie, path, kind); return a file_id 
368
 
        or None to generate a new file id
 
324
    :param action: callback(inv, parent_ie, path, kind); return ignored.
369
325
    :returns: None
370
326
    """
371
 
    file_id = action(inv, parent_ie, path, kind)
372
 
    entry = bzrlib.inventory.make_entry(kind, path.base_path, parent_ie.file_id,
373
 
                                        file_id=file_id)
 
327
    action(inv, parent_ie, path, kind)
 
328
    entry = bzrlib.inventory.make_entry(kind, path.base_path, parent_ie.file_id)
374
329
    inv.add(entry)