Changeset 1201 in tailor


Ignore:
Timestamp:
06/30/06 06:42:29 (7 years ago)
Author:
Adeodato Simo <dato@…>
Hash name:
20060630044229-d6905-b193f45b29ad58be18cd933f53c7ab320ee5e752
Message:

[bzr] rewrite _addPathnames and _addSubtree using smart_add_tree

BzrWorkingDir?._addPathnames: make 25 lines shorter by making use of
smart_add_tree, which can deal with already added or renamed files.
This fixes ticket #64, since this function also takes care of adding
missing parent directories.

BzrWorkingDir?._addSubtree: reintroduce, but this time paying attention
to the return value, since it includes a list of ignored files: if any,
call self._addPathnames() on them.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/repository/bzr.py

    r1196 r1201  
    2020del version_info 
    2121 
    22 from bzrlib.osutils import normpath 
     22from bzrlib.osutils import normpath, pathjoin 
    2323from bzrlib.bzrdir import BzrDir 
    2424from bzrlib.delta import compare_trees 
     25from bzrlib.add import smart_add_tree 
    2526from bzrlib import errors 
    2627 
     
    155156 
    156157    def _addPathnames(self, names): 
    157         """ 
    158         Add new files to working tree. 
    159  
    160         This method may get invoked several times with the same files. 
    161         Bzrlib complains if you try to add a file which is already 
    162         versioned. This method filters these out. A file might already been 
    163         marked to be added in this changeset, or might be a target in a rename 
    164         operation. Remove those too. 
    165  
    166         This method does not catch any errors from the adding through bzrlib, 
    167         since they are **real** errors. 
    168         """ 
    169         last_revision = self._working_tree.branch.last_revision() 
    170         if last_revision is None: 
    171             # initial revision 
    172             fnames = names 
    173         else: 
    174             fnames = [] 
    175             basis_tree = self._working_tree.branch.basis_tree() 
    176             inv = basis_tree.inventory 
    177             diff = compare_trees(basis_tree, self._working_tree) 
    178             added = ([new[0] for new in diff.added] + 
    179                      [renamed[1] for renamed in diff.renamed]) 
    180  
    181             def parent_was_copied(n): 
    182                 for p in added: 
    183                     if n.startswith(p+'/'): 
    184                         return True 
    185                 return False 
    186  
    187             for fn in names: 
    188                 normfn = normpath(fn) 
    189                 if (not inv.has_filename(fn) 
    190                     and not normfn in added 
    191                     and not parent_was_copied(normfn)): 
    192                     fnames.append(fn) 
    193                 else: 
    194                     self.log.debug('"%s" already in inventory, skipping', fn) 
    195  
    196         if len(fnames): 
    197             self.log.info('Adding %s...', ', '.join(fnames)) 
    198             self._working_tree.add(fnames) 
     158        if len(names): 
     159            names = [ pathjoin(self.basedir, n) for n in names ] 
     160            smart_add_tree(self._working_tree, names, recurse=False) 
     161 
     162    def _addSubtree(self, subdir): 
     163        subdir = pathjoin(self.basedir, subdir) 
     164        added, ignored = smart_add_tree(self._working_tree, [subdir], recurse=True) 
     165 
     166        if len(ignored): 
     167            f = [] 
     168            map(f.extend, ignored.values()) 
     169            self._addPathnames(f) 
    199170 
    200171    def _commit(self, date, author, patchname, changelog=None, entries=None): 
Note: See TracChangeset for help on using the changeset viewer.