def test_commit_with_int_mark(self): # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) properties = { u'greeting': u'hello', u'planet': u'world', } c = commands.CommitCommand(b'refs/heads/master', 123, None, committer, b'release v1.0', b':aaa', None, None, properties=properties) self.assertEqual( b"commit refs/heads/master\n" b"mark :123\n" b"committer Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 12\n" b"release v1.0\n" b"from :aaa\n" b"property greeting 5 hello\n" b"property planet 5 world", bytes(c))
def _export_commit(self, commit, ref, base_tree=None): file_cmds = list(self._iter_files(base_tree, commit.tree)) marker = self._allocate_marker() if commit.parents: from_ = commit.parents[0] merges = commit.parents[1:] else: from_ = None merges = [] author, author_email = split_email(commit.author) committer, committer_email = split_email(commit.committer) cmd = commands.CommitCommand( ref, marker, (author, author_email, commit.author_time, commit.author_timezone), ( committer, committer_email, commit.commit_time, commit.commit_timezone, ), commit.message, from_, merges, file_cmds, ) return (cmd, marker)
def test_commit_with_more_authors(self): # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) author = (b'Sue Wong', b'*****@*****.**', 1234565432, -6 * 3600) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) more_authors = [ (b'Al Smith', b'*****@*****.**', 1234565432, -6 * 3600), (b'Bill Jones', b'*****@*****.**', 1234565432, -6 * 3600), ] c = commands.CommitCommand(b'refs/heads/master', b'bbb', author, committer, b'release v1.0', b':aaa', None, None, more_authors=more_authors) self.assertEqual( b"commit refs/heads/master\n" b"mark :bbb\n" b"author Sue Wong <*****@*****.**> 1234565432 -0600\n" b"author Al Smith <*****@*****.**> 1234565432 -0600\n" b"author Bill Jones <*****@*****.**> 1234565432 -0600\n" b"committer Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 12\n" b"release v1.0\n" b"from :aaa", bytes(c))
def test_commit_no_mark(self): # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) c = commands.CommitCommand(b'refs/heads/master', None, None, committer, b'release v1.0', b':aaa', None, None) self.assertEqual( b"commit refs/heads/master\n" b"committer Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 12\n" b"release v1.0\n" b"from :aaa", bytes(c))
def simple_commit(self): from fastimport import commands cmd = commands.BlobCommand(b"23", b"data") self.processor.blob_handler(cmd) cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr", (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None, [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)]) self.processor.commit_handler(cmd) commit = self.repo[self.processor.last_commit] return commit
def setUp(self): super(TestCommitCopy, self).setUp() file_cmds = iter([ commands.FileDeleteCommand(b'readme.txt'), commands.FileModifyCommand(b'NEWS', 0o100644, None, b'blah blah blah'), ]) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) self.c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer, b'release v1.0', b':aaa', None, file_cmds)
def make_file_commit(self, file_cmds): """Create a trivial commit with the specified file commands. :param file_cmds: File commands to run. :return: The created commit object """ from fastimport import commands cmd = commands.CommitCommand("refs/heads/foo", "mrkr", ("Jelmer", "*****@*****.**", 432432432.0, 3600), ("Jelmer", "*****@*****.**", 432432432.0, 3600), "FOO", None, [], file_cmds) self.processor.commit_handler(cmd) return self.repo[self.processor.last_commit]
def test_file_add(self): from fastimport import commands cmd = commands.BlobCommand(b"23", b"data") self.processor.blob_handler(cmd) cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr", (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None, [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)]) self.processor.commit_handler(cmd) commit = self.repo[self.processor.last_commit] self.assertEqual([ (b'path', 0o100644, b'6320cd248dd8aeaab759d5871f8781b5c0505172')], self.repo[commit.tree].items())
def test_commit_with_merges(self): # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) c = commands.CommitCommand(b"refs/heads/master", b"ddd", None, committer, b'release v1.0', b":aaa", [b':bbb', b':ccc'], None) self.assertEqual( b"commit refs/heads/master\n" b"mark :ddd\n" b"committer Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 12\n" b"release v1.0\n" b"from :aaa\n" b"merge :bbb\n" b"merge :ccc", bytes(c))
def test_commit_with_author(self): # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) author = (b'Sue Wong', b'*****@*****.**', 1234565432, -6 * 3600) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) c = commands.CommitCommand(b'refs/heads/master', b'bbb', author, committer, b'release v1.0', b':aaa', None, None) self.assertEqual( b"commit refs/heads/master\n" b"mark :bbb\n" b"author Sue Wong <*****@*****.**> 1234565432 -0600\n" b"committer Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 12\n" b"release v1.0\n" b"from :aaa", repr_bytes(c))
def test_commit_handler_markers(self): from fastimport import commands [c1, c2, c3] = build_commit_graph(self.repo.object_store, [[1], [2], [3]]) self.processor.markers[b'10'] = c1.id self.processor.markers[b'42'] = c2.id self.processor.markers[b'98'] = c3.id cmd = commands.CommitCommand( b"refs/heads/foo", b"mrkr", (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", b':10', [b':42', b':98'], []) self.processor.commit_handler(cmd) commit = self.repo[self.processor.last_commit] self.assertEqual(c1.id, commit.parents[0]) self.assertEqual(c2.id, commit.parents[1]) self.assertEqual(c3.id, commit.parents[2])
def test_commit_handler(self): from fastimport import commands cmd = commands.CommitCommand("refs/heads/foo", "mrkr", ("Jelmer", "*****@*****.**", 432432432.0, 3600), ("Jelmer", "*****@*****.**", 432432432.0, 3600), "FOO", None, [], []) self.processor.commit_handler(cmd) commit = self.repo[self.processor.last_commit] self.assertEquals("Jelmer <*****@*****.**>", commit.author) self.assertEquals("Jelmer <*****@*****.**>", commit.committer) self.assertEquals("FOO", commit.message) self.assertEquals([], commit.parents) self.assertEquals(432432432.0, commit.commit_time) self.assertEquals(432432432.0, commit.author_time) self.assertEquals(3600, commit.commit_timezone) self.assertEquals(3600, commit.author_timezone) self.assertEquals(commit, self.repo["refs/heads/foo"])
def _parse_commit(self, ref): """Parse a commit command.""" lineno = self.lineno mark = self._get_mark_if_any() author = self._get_user_info(b'commit', b'author', False) more_authors = [] while True: another_author = self._get_user_info(b'commit', b'author', False) if another_author is not None: more_authors.append(another_author) else: break committer = self._get_user_info(b'commit', b'committer') message = self._get_data(b'commit', b'message') from_ = self._get_from() merges = [] while True: merge = self._get_merge() if merge is not None: # while the spec suggests it's illegal, git-fast-export # outputs multiple merges on the one line, e.g. # merge :x :y :z these_merges = merge.split(b' ') merges.extend(these_merges) else: break properties = {} while True: name_value = self._get_property() if name_value is not None: name, value = name_value properties[name] = value else: break return commands.CommitCommand(ref, mark, author, committer, message, from_, merges, list(self.iter_file_commands()), lineno=lineno, more_authors=more_authors, properties=properties)
def test_commit_unicode_committer(self): # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam' commit_utf8 = utf8_bytes_string( u"commit refs/heads/master\n" u"mark :bbb\n" u"committer %s <*****@*****.**> 1234567890 -0600\n" u"data 12\n" u"release v1.0\n" u"from :aaa" % (name, )) committer = (name, b'*****@*****.**', 1234567890, -6 * 3600) c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer, b'release v1.0', b':aaa', None, None) self.assertEqual(commit_utf8, bytes(c))
def test_commit_with_filecommands(self): file_cmds = iter([ commands.FileDeleteCommand(b'readme.txt'), commands.FileModifyCommand(b'NEWS', 0o100644, None, b'blah blah blah'), ]) # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer, b'release v1.0', b':aaa', None, file_cmds) self.assertEqual( b"commit refs/heads/master\n" b"mark :bbb\n" b"committer Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 12\n" b"release v1.0\n" b"from :aaa\n" b"D readme.txt\n" b"M 644 inline NEWS\n" b"data 14\n" b"blah blah blah", bytes(c))
def test_notecommit(self): committer = (b'Ed Mund', b'*****@*****.**', 1234565432, 0) commits = [ commands.CommitCommand(ref=b'refs/heads/master', mark=b'1', author=committer, committer=committer, message=b'test\n', from_=None, merges=[], file_iter=[ commands.FileModifyCommand( b'bar', 0o100644, None, b'') ]), commands.CommitCommand( ref=b'refs/notes/commits', mark=None, author=None, committer=committer, message=b"Notes added by 'git notes add'\n", from_=None, merges=[], file_iter=[commands.NoteModifyCommand(b'1', b'Test note\n')]), commands.CommitCommand( ref=b'refs/notes/test', mark=None, author=None, committer=committer, message=b"Notes added by 'git notes add'\n", from_=None, merges=[], file_iter=[commands.NoteModifyCommand(b'1', b'Test test\n')]) ] self.assertEqual( b"""commit refs/heads/master mark :1 author Ed Mund <*****@*****.**> 1234565432 +0000 committer Ed Mund <*****@*****.**> 1234565432 +0000 data 5 test M 644 inline bar data 0 commit refs/notes/commits committer Ed Mund <*****@*****.**> 1234565432 +0000 data 31 Notes added by 'git notes add' N inline :1 data 10 Test note commit refs/notes/test committer Ed Mund <*****@*****.**> 1234565432 +0000 data 31 Notes added by 'git notes add' N inline :1 data 10 Test test """, b''.join([bytes(s) for s in commits]))