Пример #1
0
 def record_iter_changes(self, workingtree, basis_revid, iter_changes):
     seen_root = False
     for (file_id, path, changed_content, versioned, parent, name, kind,
          executable) in iter_changes:
         if kind[1] in ("directory", ):
             self._inv_delta.append(
                 (path[0], path[1], file_id,
                  entry_factory[kind[1]](file_id, name[1], parent[1])))
             if kind[0] in ("file", "symlink"):
                 self._blobs[path[0].encode("utf-8")] = None
                 self._any_changes = True
             if path[1] == "":
                 seen_root = True
             continue
         self._any_changes = True
         if path[1] is None:
             self._inv_delta.append((path[0], path[1], file_id, None))
             self._blobs[path[0].encode("utf-8")] = None
             continue
         try:
             entry_kls = entry_factory[kind[1]]
         except KeyError:
             raise KeyError("unknown kind %s" % kind[1])
         entry = entry_kls(file_id, name[1], parent[1])
         if kind[1] == "file":
             entry.executable = executable[1]
             blob = Blob()
             f, st = workingtree.get_file_with_stat(path[1])
             try:
                 blob.data = f.read()
             finally:
                 f.close()
             entry.text_size = len(blob.data)
             entry.text_sha1 = osutils.sha_string(blob.data)
             self.store.add_object(blob)
             sha = blob.id
         elif kind[1] == "symlink":
             symlink_target = workingtree.get_symlink_target(path[1])
             blob = Blob()
             blob.data = symlink_target.encode("utf-8")
             self.store.add_object(blob)
             sha = blob.id
             entry.symlink_target = symlink_target
             st = None
         elif kind[1] == "tree-reference":
             sha = read_submodule_head(workingtree.abspath(path[1]))
             reference_revision = workingtree.get_reference_revision(
                 path[1])
             entry.reference_revision = reference_revision
             st = None
         else:
             raise AssertionError("Unknown kind %r" % kind[1])
         mode = object_mode(kind[1], executable[1])
         self._inv_delta.append((path[0], path[1], file_id, entry))
         encoded_new_path = path[1].encode("utf-8")
         self._blobs[encoded_new_path] = (mode, sha)
         if st is not None:
             yield file_id, path[1], (entry.text_sha1, st)
         if self._mapping.generate_file_id(encoded_new_path) != file_id:
             self._override_fileids[encoded_new_path] = file_id
         else:
             self._override_fileids[encoded_new_path] = None
     if not seen_root and len(self.parents) == 0:
         raise RootMissing()
     if getattr(workingtree, "basis_tree", False):
         basis_tree = workingtree.basis_tree()
     else:
         if len(self.parents) == 0:
             basis_revid = _mod_revision.NULL_REVISION
         else:
             basis_revid = self.parents[0]
         basis_tree = self.repository.revision_tree(basis_revid)
     # Fill in entries that were not changed
     for entry in basis_tree._iter_tree_contents(include_trees=False):
         if entry.path in self._blobs:
             continue
         self._blobs[entry.path] = (entry.mode, entry.sha)
     if not self._lossy:
         try:
             fileid_map = dict(basis_tree._fileid_map.file_ids)
         except AttributeError:
             fileid_map = {}
         for path, file_id in viewitems(self._override_fileids):
             if not isinstance(path, bytes):
                 raise TypeError(path)
             if file_id is None:
                 if path in fileid_map:
                     del fileid_map[path]
             else:
                 if not isinstance(file_id, bytes):
                     raise TypeError(file_id)
                 fileid_map[path] = file_id
         if fileid_map:
             fileid_blob = self._mapping.export_fileid_map(fileid_map)
         else:
             fileid_blob = None
         if fileid_blob is not None:
             if self._mapping.BZR_FILE_IDS_FILE is None:
                 raise SettingCustomFileIdsUnsupported(fileid_map)
             self.store.add_object(fileid_blob)
             self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (stat.S_IFREG
                                                             | 0o644,
                                                             fileid_blob.id)
         else:
             self._blobs[self._mapping.BZR_FILE_IDS_FILE] = None
     self.new_inventory = None
Пример #2
0
 def record_iter_changes(self, workingtree, basis_revid, iter_changes):
     seen_root = False
     for change in iter_changes:
         if change.kind == (None, None):
             # Ephemeral
             continue
         if change.versioned[0] and not change.copied:
             file_id = self._mapping.generate_file_id(change.path[0])
         elif change.versioned[1]:
             file_id = self._mapping.generate_file_id(change.path[1])
         else:
             file_id = None
         if change.path[1]:
             parent_id_new = self._mapping.generate_file_id(osutils.dirname(change.path[1]))
         else:
             parent_id_new = None
         if change.kind[1] in ("directory",):
             self._inv_delta.append(
                 (change.path[0], change.path[1], file_id,
                  entry_factory[change.kind[1]](
                      file_id, change.name[1], parent_id_new)))
             if change.kind[0] in ("file", "symlink"):
                 self._blobs[encode_git_path(change.path[0])] = None
                 self._any_changes = True
             if change.path[1] == "":
                 seen_root = True
             continue
         self._any_changes = True
         if change.path[1] is None:
             self._inv_delta.append((change.path[0], change.path[1], file_id, None))
             self._deleted_paths.add(encode_git_path(change.path[0]))
             continue
         try:
             entry_kls = entry_factory[change.kind[1]]
         except KeyError:
             raise KeyError("unknown kind %s" % change.kind[1])
         entry = entry_kls(file_id, change.name[1], parent_id_new)
         if change.kind[1] == "file":
             entry.executable = change.executable[1]
             blob = Blob()
             f, st = workingtree.get_file_with_stat(change.path[1])
             try:
                 blob.data = f.read()
             finally:
                 f.close()
             sha = blob.id
             if st is not None:
                 entry.text_size = st.st_size
             else:
                 entry.text_size = len(blob.data)
             entry.git_sha1 = sha
             self.store.add_object(blob)
         elif change.kind[1] == "symlink":
             symlink_target = workingtree.get_symlink_target(change.path[1])
             blob = Blob()
             blob.data = encode_git_path(symlink_target)
             self.store.add_object(blob)
             sha = blob.id
             entry.symlink_target = symlink_target
             st = None
         elif change.kind[1] == "tree-reference":
             sha = read_submodule_head(workingtree.abspath(change.path[1]))
             reference_revision = workingtree.get_reference_revision(change.path[1])
             entry.reference_revision = reference_revision
             st = None
         else:
             raise AssertionError("Unknown kind %r" % change.kind[1])
         mode = object_mode(change.kind[1], change.executable[1])
         self._inv_delta.append((change.path[0], change.path[1], file_id, entry))
         if change.path[0] is not None:
             self._deleted_paths.add(encode_git_path(change.path[0]))
         self._blobs[encode_git_path(change.path[1])] = (mode, sha)
         if st is not None:
             yield change.path[1], (entry.git_sha1, st)
     if not seen_root and len(self.parents) == 0:
         raise RootMissing()
     if getattr(workingtree, "basis_tree", False):
         basis_tree = workingtree.basis_tree()
     else:
         if len(self.parents) == 0:
             basis_revid = _mod_revision.NULL_REVISION
         else:
             basis_revid = self.parents[0]
         basis_tree = self.repository.revision_tree(basis_revid)
     # Fill in entries that were not changed
     for entry in basis_tree._iter_tree_contents(include_trees=False):
         if entry.path in self._blobs:
             continue
         if entry.path in self._deleted_paths:
             continue
         self._blobs[entry.path] = (entry.mode, entry.sha)
     self.new_inventory = None