filter-repo: micro performance win in Commit.dump()

Commit.dump() showed up in a profile.  Reorganize the code slightly to
build up much of the string into one big chunk before calling
file_.write(); this shaves a few percent off the total runtime.  (Where
total runtime is again measured in terms of the
  cat fast-export.original | git filter-repo --stdin --dry-run ...
trick mentioned a few commits back.)  Trying to make a [c]StringIO
object in order to build more of the string up into a single place
to reduce the number of file_.write() calls was apparently
counter-productive, so only the header before the parents is combined
into a single string.

Signed-off-by: Elijah Newren <newren@gmail.com>
pull/13/head
Elijah Newren 5 years ago
parent 7c680dced9
commit 3df8dee662

@ -589,18 +589,18 @@ class Commit(_GitElementWithId):
_EXTRA_CHANGES[self.id] = parent_extra_changes
# End workaround
file_.write('commit %s\n' % self.branch)
file_.write('mark :%d\n' % self.id)
file_.write('author %s <%s> ' % (self.author_name, self.author_email))
file_.write(self.author_date)
file_.write('\n')
file_.write('committer %s <%s> ' % \
(self.committer_name, self.committer_email))
file_.write(self.committer_date)
file_.write('\n')
file_.write('data %d\n%s' % (len(self.message), self.message))
if not self.message.endswith("\n"):
file_.write('\n')
file_.write(('commit {}\n'
'mark :{}\n'
'author {} <{}> {}\n'
'committer {} <{}> {}\n'
'data {}\n{}{}'
).format(
self.branch, self.id,
self.author_name, self.author_email, self.author_date,
self.committer_name, self.committer_email, self.committer_date,
len(self.message), self.message,
'' if self.message.endswith('\n') else '\n')
)
if self.from_commit:
mark = ':' if isinstance(self.from_commit, int) else ''
file_.write('from {}{}\n'.format(mark, self.from_commit))

Loading…
Cancel
Save