Ejemplo n.º 1
0
    def iter_file_commands(self):
        """Iterator returning FileCommand objects.

        If an invalid file command is found, the line is silently
        pushed back and iteration ends.
        """
        while True:
            line = self.next_line()
            if line is None:
                break
            elif len(line) == 0 or line.startswith(b'#'):
                continue
            # Search for file commands in order of likelihood
            elif line.startswith(b'M '):
                yield self._parse_file_modify(line[2:])
            elif line.startswith(b'D '):
                path = self._path(line[2:])
                yield commands.FileDeleteCommand(path)
            elif line.startswith(b'R '):
                old, new = self._path_pair(line[2:])
                yield commands.FileRenameCommand(old, new)
            elif line.startswith(b'C '):
                src, dest = self._path_pair(line[2:])
                yield commands.FileCopyCommand(src, dest)
            elif line.startswith(b'deleteall'):
                yield commands.FileDeleteAllCommand()
            else:
                self.push_line(line)
                break
Ejemplo n.º 2
0
 def test_file_copy(self):
     from fastimport import commands
     self.simple_commit()
     commit = self.make_file_commit([commands.FileCopyCommand("path", "new_path")])
     self.assertEquals([
         ('new_path', 0100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
         ('path', 0100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
         ], self.repo[commit.tree].items())
Ejemplo n.º 3
0
    def test_file_copy(self):
        from fastimport import commands

        self.simple_commit()
        commit = self.make_file_commit([commands.FileCopyCommand(b"path", b"new_path")])
        self.assertEqual(
            [
                (
                    b"new_path",
                    0o100644,
                    b"6320cd248dd8aeaab759d5871f8781b5c0505172",
                ),
                (
                    b"path",
                    0o100644,
                    b"6320cd248dd8aeaab759d5871f8781b5c0505172",
                ),
            ],
            self.repo[commit.tree].items(),
        )
Ejemplo n.º 4
0
 def test_filecopy_quoted(self):
     # Check the first path is quoted if it contains spaces
     c = commands.FileCopyCommand(b'foo/b a r', b'foo/b a z')
     self.assertEqual(b'C "foo/b a r" foo/b a z', bytes(c))
Ejemplo n.º 5
0
 def test_filecopy(self):
     c = commands.FileCopyCommand(b'foo/bar', b'foo/baz')
     self.assertEqual(b'C foo/bar foo/baz', bytes(c))