Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void CommandLineParser::Private::parse()
else if (!clp->undefinedOptions.contains(option.option))
clp->undefinedOptions << option.option;
else
clp->errors.append(QLatin1String("Not enough arguments passed for option `")
clp->errors.append(QStringLiteral("Not enough arguments passed for option `")
+ option.option +QLatin1Char('\''));
}
option.option.clear();
Expand Down Expand Up @@ -260,7 +260,7 @@ void CommandLineParser::Private::parse()
processor.next(option);

if (requiredArguments > arguments.count())
errors.append(QLatin1String("Not enough arguments, usage: ") + QString::fromLocal8Bit(argumentStrings[0])
errors.append(QStringLiteral("Not enough arguments, usage: ") + QString::fromLocal8Bit(argumentStrings[0])
+ QLatin1Char(' ') + argumentDefinition);

/*
Expand Down Expand Up @@ -372,6 +372,12 @@ bool CommandLineParser::contains(const QString & key) const
return d->options.contains(key);
}

bool CommandLineParser::contains(const QLatin1String & key) const
{
d->parse();
return d->options.contains(key);
}

QStringList CommandLineParser::arguments() const
{
d->parse();
Expand Down
8 changes: 8 additions & 0 deletions src/CommandLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ class CommandLineParser
*/
bool contains(const QString & key) const;

/**
* returns true if the option was found.
* Consider the following definition "--expert level" The user can type as an argument
* "--expert 10". Calling contains("expert") will return true.
* @see optionArgument()
*/
bool contains(const QLatin1String & key) const;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, either we add a contains with a QLatin1String or we change everywhere to use a QStringLiteral instead of a QLatin1String. From what I understand, as there are overrides for QLatin1String in QListString.contains, it should be faster to have an override instead of using QStringLiteral


/// returns the list of items that are not options, note that the first one is the name of the command called
QStringList arguments() const;

Expand Down
24 changes: 12 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ QSet<int> loadRevisionsFile( const QString &fileName, Svn &svn )
continue;
}
int lastrev = 0;
if(revint.cap(2) == "HEAD") {
if(revint.cap(2) == QLatin1String("HEAD")) {
lastrev = svn.youngestRevision();
ok = true;
} else {
Expand Down Expand Up @@ -170,11 +170,11 @@ int main(int argc, char **argv)
return 0;
}
if (args->contains(QLatin1String("help"))) {
args->usage(QString(), "--rules RULES_FILE SVN_REPO_DIR/");
args->usage(QString(), QStringLiteral("--rules RULES_FILE SVN_REPO_DIR/"));
return 0;
}
if (args->arguments().count() != 1) {
args->usage(QString(), "--rules RULES_FILE SVN_REPO_DIR/");
args->usage(QString(), QStringLiteral("--rules RULES_FILE SVN_REPO_DIR/"));
return 12;
}
if (args->undefinedOptions().count()) {
Expand All @@ -189,23 +189,23 @@ int main(int argc, char **argv)
}
return 10;
}
if (!args->contains("rules")) {
if (!args->contains(QLatin1String("rules"))) {
QTextStream out(stderr);
out << "svn-all-fast-export failed: please specify the rules using the 'rules' argument\n";
return 11;
}
if (!args->contains("identity-map") && !args->contains("identity-domain")) {
if (!args->contains(QLatin1String("identity-map")) && !args->contains(QLatin1String("identity-domain"))) {
QTextStream out(stderr);
out << "WARNING; no identity-map or -domain specified, all commits will use default @localhost email address\n\n";
}

QCoreApplication app(argc, argv);
// Load the configuration
RulesList rulesList(args->optionArgument(QLatin1String("rules")));
RulesList rulesList(args->optionArgument(QStringLiteral("rules")));
rulesList.load();

int resume_from = args->optionArgument(QLatin1String("resume-from")).toInt();
int max_rev = args->optionArgument(QLatin1String("max-rev")).toInt();
int resume_from = args->optionArgument(QStringLiteral("resume-from")).toInt();
int max_rev = args->optionArgument(QStringLiteral("max-rev")).toInt();

// create the repository list
QHash<QString, Repository *> repositories;
Expand Down Expand Up @@ -260,12 +260,12 @@ int main(int argc, char **argv)
min_rev = resume_from;

Svn::initialize();
Svn svn(args->arguments().first());
Svn svn(args->arguments().constFirst());
svn.setMatchRules(rulesList.allMatchRules());
svn.setRepositories(repositories);
svn.setIdentityMap(loadIdentityMapFile(args->optionArgument("identity-map")));
svn.setIdentityMap(loadIdentityMapFile(args->optionArgument(QStringLiteral("identity-map"))));
// Massage user input a little, no guarantees that input makes sense.
QString domain = args->optionArgument("identity-domain").simplified().remove(QChar('@'));
QString domain = args->optionArgument(QStringLiteral("identity-domain")).simplified().remove(QChar('@'));
if (domain.isEmpty())
domain = QString("localhost");
svn.setIdentityDomain(domain);
Expand All @@ -274,7 +274,7 @@ int main(int argc, char **argv)
max_rev = svn.youngestRevision();

bool errors = false;
QSet<int> revisions = loadRevisionsFile(args->optionArgument(QLatin1String("revisions-file")), svn);
QSet<int> revisions = loadRevisionsFile(args->optionArgument(QStringLiteral("revisions-file")), svn);
const bool filerRevisions = !revisions.isEmpty();
for (int i = min_rev; i <= max_rev; ++i) {
if(filerRevisions) {
Expand Down
60 changes: 31 additions & 29 deletions src/repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ FastImportRepository::FastImportRepository(const Rules::Repository &rule)

// create the defaultBranch from the config
QProcess config;
config.start("git", QStringList() << "config" << "init.defaultBranch");
config.start(QStringLiteral("git"), QStringList() << QStringLiteral("config") << QStringLiteral("init.defaultBranch"));
config.waitForFinished(-1);
defaultBranch = QString(config.readAllStandardOutput()).trimmed();

Expand All @@ -340,22 +340,22 @@ FastImportRepository::FastImportRepository(const Rules::Repository &rule)

branches[defaultBranch].created = 1;

if (!CommandLineParser::instance()->contains("dry-run") && !CommandLineParser::instance()->contains("create-dump")) {
if (!CommandLineParser::instance()->contains(QStringLiteral("dry-run")) && !CommandLineParser::instance()->contains(QStringLiteral("create-dump"))) {
fastImport.setWorkingDirectory(name);
if (!QDir(name).exists()) { // repo doesn't exist yet.
qDebug() << "Creating new repository" << name;
QDir::current().mkpath(name);
QProcess init;
init.setWorkingDirectory(name);
init.start("git", QStringList() << "--bare" << "init");
init.start(QStringLiteral("git"), QStringList() << QStringLiteral("--bare") << QStringLiteral("init"));
init.waitForFinished(-1);
QProcess casesensitive;
casesensitive.setWorkingDirectory(name);
casesensitive.start("git", QStringList() << "config" << "core.ignorecase" << "false");
casesensitive.start(QStringLiteral("git"), QStringList() << QStringLiteral("config") << QStringLiteral("core.ignorecase") << QStringLiteral("false"));
casesensitive.waitForFinished(-1);
// Write description
if (!rule.description.isEmpty()) {
QFile fDesc(QDir(name).filePath("description"));
QFile fDesc(QDir(name).filePath(QStringLiteral("description")));
if (fDesc.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
fDesc.write(rule.description.toUtf8());
fDesc.putChar('\n');
Expand All @@ -374,7 +374,7 @@ FastImportRepository::FastImportRepository(const Rules::Repository &rule)
static QString logFileName(QString name)
{
name.replace('/', '_');
if (CommandLineParser::instance()->contains("create-dump"))
if (CommandLineParser::instance()->contains(QStringLiteral("create-dump")))
name.append(".fi");
else
name.prepend("log-");
Expand Down Expand Up @@ -551,7 +551,7 @@ FastImportRepository::~FastImportRepository()
void FastImportRepository::closeFastImport()
{
if (fastImport.state() != QProcess::NotRunning) {
int fastImportTimeout = CommandLineParser::instance()->optionArgument(QLatin1String("fast-import-timeout"), QLatin1String("30")).toInt();
int fastImportTimeout = CommandLineParser::instance()->optionArgument(QStringLiteral("fast-import-timeout"), QStringLiteral("30")).toInt();
if(fastImportTimeout == 0) {
qDebug() << "Waiting forever for fast-import to finish.";
fastImportTimeout = -1;
Expand All @@ -575,8 +575,9 @@ void FastImportRepository::closeFastImport()
void FastImportRepository::reloadBranches()
{
bool reset_notes = false;
foreach (QString branch, branches.keys()) {
Branch &br = branches[branch];
for (auto it = branches.keyValueBegin(); it != branches.keyValueEnd(); ++it) {
const QString &branch = it->first;
Branch &br = it->second;

if (br.marks.isEmpty() || !br.marks.last())
continue;
Expand All @@ -594,7 +595,7 @@ void FastImportRepository::reloadBranches()
}

if (reset_notes &&
CommandLineParser::instance()->contains("add-metadata-notes")) {
CommandLineParser::instance()->contains(QStringLiteral("add-metadata-notes"))) {

startFastImport();
fastImport.write("reset refs/notes/commits\nfrom :" +
Expand All @@ -617,7 +618,7 @@ long long FastImportRepository::markFrom(const QString &branchFrom, int branchRe
}

QVector<int>::const_iterator it = std::upper_bound(brFrom.commits.constBegin(), brFrom.commits.constEnd(), branchRevNum);
if (it == brFrom.commits.begin()) {
if (it == brFrom.commits.constBegin()) {
return 0;
}

Expand Down Expand Up @@ -723,7 +724,7 @@ void FastImportRepository::commit()
QString tagName = *it;
if (resetBranchNames.contains(tagName))
continue;
if (tagName.startsWith("refs/tags/"))
if (tagName.startsWith(QLatin1String("refs/tags/")))
tagName.remove(0, 10);
if (annotatedTags.remove(tagName) > 0) {
qDebug() << "Removing annotated tag" << tagName << "for" << name;
Expand All @@ -748,7 +749,7 @@ Repository::Transaction *FastImportRepository::newTransaction(const QString &bra
txn->datetime = 0;
txn->revnum = revnum;

if ((++commitCount % CommandLineParser::instance()->optionArgument(QLatin1String("commit-interval"), QLatin1String("10000")).toInt()) == 0) {
if ((++commitCount % CommandLineParser::instance()->optionArgument(QStringLiteral("commit-interval"), QStringLiteral("10000")).toInt()) == 0) {
startFastImport();
// write everything to disk every 10000 commits
fastImport.write("checkpoint\n");
Expand All @@ -770,7 +771,7 @@ void FastImportRepository::createAnnotatedTag(const QString &ref, const QString
const QByteArray &log)
{
QString tagName = ref;
if (tagName.startsWith("refs/tags/"))
if (tagName.startsWith(QLatin1String("refs/tags/")))
tagName.remove(0, 10);

if (!annotatedTags.contains(tagName))
Expand Down Expand Up @@ -809,7 +810,7 @@ void FastImportRepository::finalizeTags()
QByteArray message = tag.log;
if (!message.endsWith('\n'))
message += '\n';
if (CommandLineParser::instance()->contains("add-metadata"))
if (CommandLineParser::instance()->contains(QStringLiteral("add-metadata")))
message += "\n" + formatMetadataMessage(tag.svnprefix, tag.revnum, tagName.toUtf8());

{
Expand All @@ -832,7 +833,7 @@ void FastImportRepository::finalizeTags()

// Append note to the tip commit of the supporting ref. There is no
// easy way to attach a note to the tag itself with fast-import.
if (CommandLineParser::instance()->contains("add-metadata-notes")) {
if (CommandLineParser::instance()->contains(QStringLiteral("add-metadata-notes"))) {
Repository::Transaction *txn = newTransaction(tag.supportingRef, tag.svnprefix, tag.revnum);
txn->setAuthor(tag.author);
txn->setDateTime(tag.dt);
Expand All @@ -858,7 +859,7 @@ void FastImportRepository::saveBranchNotes()
if (branchNotes.isEmpty())
return;

QFile branchNotesFile(name + "/" + branchNotesFileName(name));
QFile branchNotesFile(name + QStringLiteral("/") + branchNotesFileName(name));
branchNotesFile.open(QIODevice::WriteOnly);
QDataStream branchNotesStream(&branchNotesFile);
branchNotesStream << branchNotes;
Expand All @@ -874,7 +875,7 @@ FastImportRepository::msgFilter(QByteArray msg)
if (filterMsg.state() == QProcess::Running)
qFatal("filter process already running?");

filterMsg.start(CommandLineParser::instance()->optionArgument("msg-filter"));
filterMsg.start(CommandLineParser::instance()->optionArgument(QStringLiteral("msg-filter")));

if(!(filterMsg.waitForStarted(-1)))
qFatal("Failed to Start Filter %d %s", __LINE__, qPrintable(filterMsg.errorString()));
Expand All @@ -899,17 +900,17 @@ void FastImportRepository::startFastImport()
// start the process
QString marksFile = marksFileName(name);
QStringList marksOptions;
marksOptions << "--import-marks=" + marksFile;
marksOptions << "--export-marks=" + marksFile;
marksOptions << "--force";
marksOptions << QStringLiteral("--import-marks=") + marksFile;
marksOptions << QStringLiteral("--export-marks=") + marksFile;
marksOptions << QStringLiteral("--force");

fastImport.setStandardOutputFile(logFileName(name), QIODevice::Append);
fastImport.setProcessChannelMode(QProcess::MergedChannels);

if (!CommandLineParser::instance()->contains("dry-run") && !CommandLineParser::instance()->contains("create-dump")) {
fastImport.start("git", QStringList() << "fast-import" << marksOptions);
if (!CommandLineParser::instance()->contains(QStringLiteral("dry-run")) && !CommandLineParser::instance()->contains(QStringLiteral("create-dump"))) {
fastImport.start(QStringLiteral("git"), QStringList() << QStringLiteral("fast-import") << marksOptions);
} else {
fastImport.start("cat", QStringList());
fastImport.start(QStringLiteral("cat"), QStringList());
}
fastImport.waitForStarted(-1);

Expand Down Expand Up @@ -1032,7 +1033,7 @@ QIODevice *FastImportRepository::Transaction::addFile(const QString &path, int m

// it is returned for being written to, so start the process in any case
repository->startFastImport();
if (!CommandLineParser::instance()->contains("dry-run")) {
if (!CommandLineParser::instance()->contains(QStringLiteral("dry-run"))) {
repository->fastImport.writeNoLog("blob\nmark :");
repository->fastImport.writeNoLog(QByteArray::number(mark));
repository->fastImport.writeNoLog("\ndata ");
Expand Down Expand Up @@ -1099,8 +1100,9 @@ bool FastImportRepository::Transaction::commitNote(const QByteArray &noteText, b

int FastImportRepository::Transaction::commit()
{
foreach (QString branchName, repository->branches.keys())
for (auto it = repository->branches.keyValueBegin(); it != repository->branches.keyValueEnd(); ++it)
{
const QString &branchName = it->first;
if (branchName.toUtf8().startsWith(branch + "/") || branch.startsWith((branchName + "/").toUtf8()))
{
qCritical() << "Branch" << branch << "conflicts with already existing branch" << branchName;
Expand All @@ -1122,7 +1124,7 @@ int FastImportRepository::Transaction::commit()
QByteArray message = log;
if (!message.endsWith('\n'))
message += '\n';
if (CommandLineParser::instance()->contains("add-metadata"))
if (CommandLineParser::instance()->contains(QStringLiteral("add-metadata")))
message += "\n" + Repository::formatMetadataMessage(svnprefix, revnum);

// Call external message filter if provided
Expand Down Expand Up @@ -1190,7 +1192,7 @@ int FastImportRepository::Transaction::commit()
}
}
// write the file deletions
if (deletedFiles.contains(""))
if (deletedFiles.contains(QLatin1String("")))
repository->fastImport.write("deleteall\n");
else
foreach (QString df, deletedFiles)
Expand All @@ -1208,7 +1210,7 @@ int FastImportRepository::Transaction::commit()
qPrintable(repository->name), branch.data());

// Commit metadata note if requested
if (CommandLineParser::instance()->contains("add-metadata-notes"))
if (CommandLineParser::instance()->contains(QStringLiteral("add-metadata-notes")))
commitNote(Repository::formatMetadataMessage(svnprefix, revnum), false);

while (repository->fastImport.bytesToWrite())
Expand Down
2 changes: 1 addition & 1 deletion src/repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LoggingQProcess : public QProcess
bool logging;
public:
LoggingQProcess(const QString filename) : QProcess(), log() {
if(CommandLineParser::instance()->contains("debug-rules")) {
if(CommandLineParser::instance()->contains(QStringLiteral("debug-rules"))) {
logging = true;
QString name = filename;
name.replace('/', '_');
Expand Down
Loading