Skip to content

Commit b424ccd

Browse files
DaElftnyblom
authored andcommitted
Add a Q&D log filter (#13)
This will just open a process to filter optionally filter the log message inline. This is much faster than having to do it after the fact with git filter-branch. Also allows for incremental imports vs using git filter-branch post processing.
1 parent 3c2f294 commit b424ccd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static const CommandLineOption options[] = {
130130
{"--identity-domain DOMAIN", "provide user domain if no map was given"},
131131
{"--revisions-file FILENAME", "provide a file with revision number that should be processed"},
132132
{"--rules FILENAME[,FILENAME]", "the rules file(s) that determines what goes where"},
133+
{"--msg-filter FILENAME", "External program / script to modify svn log message"},
133134
{"--add-metadata", "if passed, each git commit will have svn commit info"},
134135
{"--add-metadata-notes", "if passed, each git commit will have notes with svn commit info"},
135136
{"--resume-from revision", "start importing at svn revision number"},

src/repository.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ class FastImportRepository : public Repository
120120
QByteArray deletedBranches;
121121
QByteArray resetBranches;
122122

123+
/* Optional filter to fix up log messages */
124+
QProcess filterMsg;
125+
QByteArray msgFilter(QByteArray);
126+
123127
/* starts at 0, and counts up. */
124128
mark_t last_commit_mark;
125129

@@ -729,6 +733,29 @@ void FastImportRepository::finalizeTags()
729733
printf("\n");
730734
}
731735

736+
737+
QByteArray
738+
FastImportRepository::msgFilter(QByteArray msg)
739+
{
740+
QByteArray output = msg;
741+
742+
if (CommandLineParser::instance()->contains("msg-filter")) {
743+
if (filterMsg.state() == QProcess::Running)
744+
qFatal("filter process already running?");
745+
746+
filterMsg.start(CommandLineParser::instance()->optionArgument("msg-filter"));
747+
748+
if(!(filterMsg.waitForStarted(-1)))
749+
qFatal("Failed to Start Filter %d %s", __LINE__, qPrintable(filterMsg.errorString()));
750+
751+
filterMsg.write(msg);
752+
filterMsg.closeWriteChannel();
753+
filterMsg.waitForFinished();
754+
output = filterMsg.readAllStandardOutput();
755+
}
756+
return output;
757+
}
758+
732759
void FastImportRepository::startFastImport()
733760
{
734761
processCache.touch(this);
@@ -936,6 +963,9 @@ void FastImportRepository::Transaction::commit()
936963
if (CommandLineParser::instance()->contains("add-metadata"))
937964
message += "\n" + Repository::formatMetadataMessage(svnprefix, revnum);
938965

966+
// Call external message filter if provided
967+
message = repository->msgFilter(message);
968+
939969
mark_t parentmark = 0;
940970
Branch &br = repository->branches[branch];
941971
if (br.created && !br.marks.isEmpty() && br.marks.last()) {

0 commit comments

Comments
 (0)