Ejemplo n.º 1
0
 def test_simple_bytesio(self):
     f = BytesIO()
     c = Commit()
     c.committer = c.author = b"Jelmer <*****@*****.**>"
     c.commit_time = c.author_time = 1271350201
     c.commit_timezone = c.author_timezone = 0
     c.message = b"This is the first line\nAnd this is the second line.\n"
     c.tree = Tree().id
     write_commit_patch(f, c, b"CONTENTS", (1, 1), version="custom")
     f.seek(0)
     lines = f.readlines()
     self.assertTrue(lines[0].startswith(
                 b"From 0b0d34d1b5b596c928adc9a727a4b9e03d025298"))
     self.assertEqual(lines[1], b"From: Jelmer <*****@*****.**>\n")
     self.assertTrue(lines[2].startswith(b"Date: "))
     self.assertEqual([
         b"Subject: [PATCH 1/1] This is the first line\n",
         b"And this is the second line.\n",
         b"\n",
         b"\n",
         b"---\n"], lines[3:8])
     self.assertEqual([
         b"CONTENTS-- \n",
         b"custom\n"], lines[-2:])
     if len(lines) >= 12:
         # diffstat may not be present
         self.assertEqual(lines[8], b" 0 files changed\n")
Ejemplo n.º 2
0
 def test_simple_bytesio(self):
     f = BytesIO()
     c = Commit()
     c.committer = c.author = b"Jelmer <*****@*****.**>"
     c.commit_time = c.author_time = 1271350201
     c.commit_timezone = c.author_timezone = 0
     c.message = b"This is the first line\nAnd this is the second line.\n"
     c.tree = Tree().id
     write_commit_patch(f, c, b"CONTENTS", (1, 1), version="custom")
     f.seek(0)
     lines = f.readlines()
     self.assertTrue(lines[0].startswith(b"From 0b0d34d1b5b596c928adc9a727a4b9e03d025298"))
     self.assertEqual(lines[1], b"From: Jelmer <*****@*****.**>\n")
     self.assertTrue(lines[2].startswith(b"Date: "))
     self.assertEqual(
         [
             b"Subject: [PATCH 1/1] This is the first line\n",
             b"And this is the second line.\n",
             b"\n",
             b"\n",
             b"---\n",
         ],
         lines[3:8],
     )
     self.assertEqual([b"CONTENTS-- \n", b"custom\n"], lines[-2:])
     if len(lines) >= 12:
         # diffstat may not be present
         self.assertEqual(lines[8], b" 0 files changed\n")
Ejemplo n.º 3
0
 def _generate_commit(cls,
                      repository,
                      revision_id,
                      num,
                      total,
                      context=_mod_diff.DEFAULT_CONTEXT_AMOUNT):
     s = BytesIO()
     store = get_object_store(repository)
     with store.lock_read():
         commit = store[repository.lookup_bzr_revision_id(revision_id)[0]]
     from dulwich.patch import write_commit_patch, get_summary
     try:
         lhs_parent = repository.get_revision(revision_id).parent_ids[0]
     except IndexError:
         lhs_parent = _mod_revision.NULL_REVISION
     tree_1 = repository.revision_tree(lhs_parent)
     tree_2 = repository.revision_tree(revision_id)
     contents = BytesIO()
     differ = GitDiffTree.from_trees_options(tree_1,
                                             tree_2,
                                             contents,
                                             'utf8',
                                             None,
                                             'a/',
                                             'b/',
                                             None,
                                             context_lines=context)
     differ.show_diff(None, None)
     write_commit_patch(s, commit, contents.getvalue(), (num, total),
                        version_tail)
     summary = generate_patch_filename(num, get_summary(commit))
     return summary, s.getvalue()