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", repr_bytes(c))
def main(spec, rootpath, outfile): with open(spec, 'r') as f: y = yaml.safe_load(f) versions = [Version("..", v) for v in y['versions']] lastset = FileSet(None) files = {} cmds = [] hfiles = HistoricalFiles(".") mk = COMMIT_BASE_MARK for i, v in enumerate(versions): if v.fileset is not None: hfiles.apply_files(v.fileset, versions[:i + 1]) cmds.extend(apply_changes(v, lastset, files, mk)) mk += 1 lastset = v.fileset # Write it out with open(outfile, 'wb') as f: for c in cmds: f.write(repr_bytes(c)) f.write(b'\n') return True
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", repr_bytes(c))
def to_string(self, use_features=True, include_file_contents=False): """ @todo the name to_string is ambiguous since the method actually returns bytes. """ if self.mark is None: mark_line = b'' else: if isinstance(self.mark, (int)): mark_line = b'\nmark :' + str(self.mark).encode('utf-8') else: mark_line = b'\nmark :' + self.mark if self.author is None: author_section = b'' else: author_section = b'\nauthor ' + format_who_when(self.author) if use_features and self.more_authors: for author in self.more_authors: author_section += b'\nauthor ' + format_who_when(author) committer = b'committer ' + format_who_when(self.committer) if self.message is None: msg_section = b'' else: msg = self.message msg_section = ('\ndata %d\n' % len(msg)).encode('ascii') + msg if self.from_ is None: from_line = b'' else: from_line = b'\nfrom ' + self.from_ if self.merges is None: merge_lines = b'' else: merge_lines = b''.join([b'\nmerge ' + m for m in self.merges]) if use_features and self.properties: property_lines = [] for name in sorted(self.properties): value = self.properties[name] property_lines.append(b'\n' + format_property(name, value)) properties_section = b''.join(property_lines) else: properties_section = b'' if self.file_iter is None: filecommands = b'' else: if include_file_contents: filecommands = b''.join( [b'\n' + repr_bytes(c) for c in self.iter_files()]) else: filecommands = b''.join( [b'\n' + str(c) for c in self.iter_files()]) return b''.join([ b'commit ', self.ref, mark_line, author_section + b'\n', committer, msg_section, from_line, merge_lines, properties_section, filecommands ])
def test_tag_no_from(self): tagger = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) c = commands.TagCommand(b'refs/tags/v1.0', None, tagger, b'create v1.0') self.assertEqual( b"tag refs/tags/v1.0\n" b"tagger Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 11\n" b"create v1.0", repr_bytes(c))
def main(hgin, hgout): with open(hgin, 'rb') as f: p = ImportParser(f) l = list(p.iter_commands()) cutoff = 6 t = util.Tracker() for c in l[:cutoff + 1]: t.feed(c) # Cobble together a new commit. last = l[cutoff] commit = CommitCommand(ref=last.ref, mark=last.mark, author=last.author, committer=last.committer, message=last.message, from_=None, merges=None, file_iter=[ FileModifyCommand(p, f.mode, f.modify.dataref, f.modify.data) for p, f in t.last.files.items() ]) # Still need to make annotated tags + fix authors. with open(hgout, 'wb') as f: f.write(repr_bytes(commit)) f.write(b'\n') for c in l[cutoff + 1:]: if c.name == b'reset': c = fix_tag(c, t) if c.name == b'commit': fix_authors(c) if c is not None: t.feed(c) f.write(repr_bytes(c)) f.write(b'\n') return True
def test_tag(self): # tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc) tagger = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) c = commands.TagCommand(b'refs/tags/v1.0', b':xxx', tagger, b'create v1.0') self.assertEqual( b"tag refs/tags/v1.0\n" b"from :xxx\n" b"tagger Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 11\n" b"create v1.0", repr_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", repr_bytes(c))
def test_commit_no_from(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"bbb", None, committer, b"release v1.0", None, None, None) 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", repr_bytes(c))
def main(*flist): infiles = flist[:-1] outfile = flist[-1] # Global tracker gt = util.Tracker() output = [] for infile in infiles: # Local tracker lt = util.Tracker() print("Processing {} ...".format(infile)) with open(infile, 'rb') as f: p = ImportParser(f) for cmd in p.iter_commands(): if cmd.name == b'commit': # Stitch together if this is the first commit to an # existing branch. if cmd.ref in gt.branches and cmd.ref not in lt.branches: prev = gt.branches[cmd.ref] lt.feed(cmd) c = util.rebase_branch(prev, lt.last, cmd) if c is None: print("OOPS - Not implemented!") return False if c.from_ is not None: if c.merges is not None: c.merges.append(c.from_) else: c.merges = [c.from_] c.from_ = None gt.feed(c) output.append(c) else: lt.feed(cmd) gt.feed(cmd) output.append(cmd) else: lt.feed(cmd) gt.feed(cmd) output.append(cmd) with open(outfile, 'wb') as f: for c in output: f.write(repr_bytes(c)) f.write(b'\n') return True
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_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", repr_bytes(c))
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, repr_bytes(c))
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, repr_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", repr_bytes(c))
def test_filecopy(self): c = commands.FileCopyCommand(b'foo/bar', b'foo/baz') self.assertEqual(b'C foo/bar foo/baz', repr_bytes(c))
def test_filemodify_treeref(self): c = commands.FileModifyCommand(b'tree-info', 0o160000, b'revision-id-info', None) self.assertEqual(b'M 160000 revision-id-info tree-info', repr_bytes(c))
def test_filemodify_file_internal(self): c = commands.FileModifyCommand(b'foo/bar', 0o100644, None, b'hello world') self.assertEqual(b'M 644 inline foo/bar\ndata 11\nhello world', repr_bytes(c))
def test_blob_no_mark(self): c = commands.BlobCommand(None, b"hello world") self.assertEqual(b"blob\ndata 11\nhello world", repr_bytes(c))
def test_replace_attr(self): c2 = self.c.copy(mark=b'ccc') self.assertEqual( repr_bytes(self.c).replace(b'mark :bbb', b'mark :ccc'), repr_bytes(c2) )
def test_reset_no_from(self): c = commands.ResetCommand(b'refs/remotes/origin/master', None) self.assertEqual(b'reset refs/remotes/origin/master', repr_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([repr_bytes(s) for s in commits]))
def test_checkpoint(self): c = commands.CheckpointCommand() self.assertEqual(b'checkpoint', repr_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([repr_bytes(s) for s in commits]))
def test_noteonly(self): c = commands.NoteModifyCommand(b'foo', b'A basic note') self.assertEqual(b'N inline :foo\ndata 12\nA basic note', repr_bytes(c))
def test_filedeleteall(self): c = commands.FileDeleteAllCommand() self.assertEqual(b'deleteall', repr_bytes(c))
def test_filerename_quoted(self): # Check the first path is quoted if it contains spaces c = commands.FileRenameCommand(b'foo/b a r', b'foo/b a z') self.assertEqual(b'R "foo/b a r" foo/b a z', repr_bytes(c))
def test_filerename(self): c = commands.FileRenameCommand(b'foo/bar', b'foo/baz') self.assertEqual(b'R foo/bar foo/baz', repr_bytes(c))
def test_filedelete(self): c = commands.FileDeleteCommand(b'foo/bar') self.assertEqual(b'D foo/bar', repr_bytes(c))
def test_blob(self): c = commands.BlobCommand(b"1", b"hello world") self.assertEqual(b"blob\nmark :1\ndata 11\nhello world", repr_bytes(c))
def test_feature(self): c = commands.FeatureCommand(b"dwim") self.assertEqual(b"feature dwim", repr_bytes(c))
def test_filemodify_file(self): c = commands.FileModifyCommand(b'foo/bar', 0o100644, b':23', None) self.assertEqual(b'M 644 :23 foo/bar', repr_bytes(c))
def test_filemodify_file_executable(self): c = commands.FileModifyCommand(b'foo/bar', 0o100755, b':23', None) self.assertEqual(b'M 755 :23 foo/bar', repr_bytes(c))
def test_reset(self): c = commands.ResetCommand(b"refs/tags/v1.0", b":xxx") self.assertEqual(b"reset refs/tags/v1.0\nfrom :xxx\n", repr_bytes(c))
def test_filemodify_symlink(self): c = commands.FileModifyCommand(b'foo/bar', 0o120000, None, b'baz') self.assertEqual(b'M 120000 inline foo/bar\ndata 3\nbaz', repr_bytes(c))
def main(blobs, cmds, outfile): t = util.Tracker() out = [] cmk = BASE_MARK with open(blobs, 'rb') as f: p = ImportParser(f) for c in p.iter_commands(): fix_blobmark(c) t.feed(c) out.append(c) with open(cmds, 'rb') as f: p = ImportParser(f) l = list(p.iter_commands()) # Ignore the first 3 commands (false start) i = 2 for c in l[3:]: i += 1 fix_blobmark(c) if c.name == b'commit': fix_person(c) # Track everything until we hit the coroutines commit. if c.name == b'commit' and c.message == b'semiautomatic variables\n': break t.feed(c) # Look for untagged releases if c.name == b'commit': out.append(c) tag = find_release_tag(c) if tag is not None: out.append(tag) elif c.name == b'reset': tag = fix_tag(c, t) if tag is not None: out.append(tag) else: out.append(c) # Branch coroutine/ bc = l[i] #fix_blobmark(bc) - this already happened above! #fix_person(bc) bc.ref = b'refs/heads/coroutine' bc.from_ = b':' + t.last.commit.mark t.feed(bc) out.append(bc) # Here begins the madness. We need to fork commits to master and coroutine. for c in l[i+1:]: fix_blobmark(c) if c.name == b'commit': fix_person(c) coro, mstr = fork_commit(c) if mstr is not None: mstr = util.rebase(t, mstr) if mstr is not None: mstr.mark = str(cmk).encode('utf-8') cmk += 1 t.feed(mstr) out.append(mstr) # Look for untagged releases tag = find_release_tag(mstr) if tag is not None: out.append(tag) if coro is not None: coro = util.rebase(t, coro) if coro is not None: coro.mark = str(cmk).encode('utf-8') cmk += 1 t.feed(coro) out.append(coro) elif c.name == b'reset': tag = fix_tag(c, t) if tag is not None: out.append(tag) else: out.append(c) with open(outfile, 'wb') as f: for c in out: f.write(repr_bytes(c)) f.write(b'\n') return True
def test_progress(self): c = commands.ProgressCommand(b"doing foo") self.assertEqual(b"progress doing foo", repr_bytes(c))
def test_feature_with_value(self): c = commands.FeatureCommand(b"dwim", b"please") self.assertEqual(b"feature dwim=please", repr_bytes(c))
def _print_command(self, cmd): """Wrapper to avoid adding unnecessary blank lines.""" text = helpers.repr_bytes(cmd) self.outf.write(text) if not text.endswith(b'\n'): self.outf.write(b'\n')