コード例 #1
0
    def _ensure_directory(self, path, inv):
        """Ensure that the containing directory exists for 'path'"""
        dirname, basename = osutils.split(path)
        if dirname == '':
            # the root node doesn't get updated
            return basename, self.inventory_root_id
        try:
            ie = self._get_directory_entry(inv, dirname)
        except KeyError:
            # We will create this entry, since it doesn't exist
            pass
        else:
            return basename, ie.file_id

        # No directory existed, we will just create one, first, make sure
        # the parent exists
        dir_basename, parent_id = self._ensure_directory(dirname, inv)
        dir_file_id = self.bzr_file_id(dirname)
        ie = inventory.entry_factory['directory'](dir_file_id,
            dir_basename, parent_id)
        ie.revision = self.revision_id
        self.directory_entries[dirname] = ie
        # There are no lines stored for a directory so
        # make sure the cache used by get_lines knows that
        self.data_for_commit[dir_file_id] = ''

        # It's possible that a file or symlink with that file-id
        # already exists. If it does, we need to delete it.
        if inv.has_id(dir_file_id):
            self.record_delete(dirname, ie)
        self.record_new(dirname, ie)
        return basename, ie.file_id
コード例 #2
0
    def bzr_file_id_and_new(self, path):
        """Get a Bazaar file identifier and new flag for a path.
        
        :return: file_id, is_new where
          is_new = True if the file_id is newly created
        """
        if path not in self._paths_deleted_this_commit:
            # Try file-ids renamed in this commit
            id = self._modified_file_ids.get(path)
            if id is not None:
                return id, False

            # Try the basis inventory
            id = self.basis_inventory.path2id(path)
            if id is not None:
                return id, False
            
            # Try the other inventories
            if len(self.parents) > 1:
                for inv in self.parent_invs[1:]:
                    id = self.basis_inventory.path2id(path)
                    if id is not None:
                        return id, False

        # Doesn't exist yet so create it
        dirname, basename = osutils.split(path)
        id = generate_ids.gen_file_id(basename)
        self.debug("Generated new file id %s for '%s' in revision-id '%s'",
            id, path, self.revision_id)
        self._new_file_ids[path] = id
        return id, True
コード例 #3
0
 def _probe(self):
     fileno, name = tempfile.mkstemp(prefix='MixedCase')
     try:
         # first check truly case-preserving for created files, then check
         # case insensitive when opening existing files.
         name = osutils.normpath(name)
         base, rel = osutils.split(name)
         found_rel = osutils.canonical_relpath(base, name)
         return (found_rel == rel
                 and os.path.isfile(name.upper())
                 and os.path.isfile(name.lower()))
     finally:
         os.close(fileno)
         os.remove(name)
コード例 #4
0
ファイル: anvtransport.py プロジェクト: Etenil/anvil
    def _abspath(self, relative_reference):
        """Return a path for use in os calls.

        Several assumptions are made:
         - relative_reference does not contain '..'
         - relative_reference is url escaped.
        """
        relative_reference = self._anvilise_path(relative_reference)
        if relative_reference in ('.', ''):
            # _local_base normally has a trailing slash; strip it so that stat
            # on a transport pointing to a symlink reads the link not the
            # referent but be careful of / and c:\
            return osutils.split(self._local_base)[0]
        #return self._local_base + urlutils.unescape(relative_reference)
        return urlutils.unescape(relative_reference)
コード例 #5
0
 def _make_inventory_delta(self, matches):
     delta = []
     file_id_matches = dict((f, p) for p, f in matches.items())
     for old_path, entry in self.tree.iter_entries_by_dir(matches.values()):
         new_path = file_id_matches[entry.file_id]
         parent_path, new_name = osutils.split(new_path)
         parent_id = matches.get(parent_path)
         if parent_id is None:
             parent_id = self.tree.path2id(parent_path)
         if entry.name == new_name and entry.parent_id == parent_id:
             continue
         new_entry = entry.copy()
         new_entry.parent_id = parent_id
         new_entry.name = new_name
         delta.append((old_path, new_path, new_entry.file_id, new_entry))
     return delta
コード例 #6
0
ファイル: rename_map.py プロジェクト: pombreda/dist-packages
 def _make_inventory_delta(self, matches):
     delta = []
     file_id_matches = dict((f, p) for p, f in matches.items())
     for old_path, entry in self.tree.iter_entries_by_dir(matches.values()):
         new_path = file_id_matches[entry.file_id]
         parent_path, new_name = osutils.split(new_path)
         parent_id = matches.get(parent_path)
         if parent_id is None:
             parent_id = self.tree.path2id(parent_path)
         if entry.name == new_name and entry.parent_id == parent_id:
             continue
         new_entry = entry.copy()
         new_entry.parent_id = parent_id
         new_entry.name = new_name
         delta.append((old_path, new_path, new_entry.file_id, new_entry))
     return delta
コード例 #7
0
    def _fix_other_tree(self, this_tree, other_tree):
        """We need to pretend that other_tree's root is actually not at ''."""
        parent_dir, name = osutils.split(self._target_subdir)
        parent_id = this_tree.path2id(parent_dir)

        root_ie = other_tree.inventory.root
        root_ie.parent_id = parent_id
        root_ie.name = name

        new_file_id = generate_ids.gen_file_id(name)
        trace.mutter('munging root_ie.file_id: %s => %s', root_ie.file_id,
                     new_file_id)
        del other_tree.inventory._byid[root_ie.file_id]
        root_ie.file_id = new_file_id
        other_tree.inventory._byid[new_file_id] = root_ie
        # We need to fake a new id for root_ie
        for child_ie in root_ie.children.itervalues():
            child_ie.parent_id = new_file_id
コード例 #8
0
ファイル: tree.py プロジェクト: c0ns0le/cygwin
 def _path_to_key(path):
     dirname, basename = osutils.split(path)
     return (dirname.split(u'/'), basename)