Git: Factor out pattern for invalid branch names

Re-use it in the follow-up commit for remote names also.

Change-Id: Ib88792a1abdc2fa8ac23c99aa7d4861728e36eec
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Andre Hartmann
2017-03-06 22:40:03 +01:00
committed by André Hartmann
parent 93299cb802
commit 57144e28da
3 changed files with 23 additions and 14 deletions

View File

@@ -25,6 +25,7 @@
#include "branchadddialog.h"
#include "ui_branchadddialog.h"
#include "gitplugin.h"
#include <utils/hostosinfo.h>
@@ -47,20 +48,7 @@ class BranchNameValidator : public QValidator
public:
BranchNameValidator(const QStringList &localBranches, QObject *parent = 0) :
QValidator(parent),
m_invalidChars(
"\\s" // no whitespace
"|~" // no "~"
"|\\^" // no "^"
"|\\[" // no "["
"|\\.\\." // no ".."
"|/\\." // no slashdot
"|:" // no ":"
"|@\\{" // no "@{" sequence
"|\\\\" // no backslash
"|//" // no double slash
"|^[/-]" // no leading slash or dash
"|\"" // no quotes
),
m_invalidChars(GitPlugin::invalidBranchAndRemoteNamePattern()),
m_localBranches(localBranches)
{
}

View File

@@ -173,6 +173,26 @@ QString GitPlugin::msgRepositoryLabel(const QString &repository)
tr("Repository: %1").arg(QDir::toNativeSeparators(repository));
}
// Returns a regular expression pattern with characters not allowed
// in branch and remote names.
QString GitPlugin::invalidBranchAndRemoteNamePattern()
{
return QLatin1String(
"\\s" // no whitespace
"|~" // no "~"
"|\\^" // no "^"
"|\\[" // no "["
"|\\.\\." // no ".."
"|/\\." // no slashdot
"|:" // no ":"
"|@\\{" // no "@{" sequence
"|\\\\" // no backslash
"|//" // no double slash
"|^[/-]" // no leading slash or dash
"|\"" // no quotes
);
}
const VcsBaseSubmitEditorParameters submitParameters = {
Git::Constants::SUBMIT_MIMETYPE,
Git::Constants::GITSUBMITEDITOR_ID,

View File

@@ -88,6 +88,7 @@ public:
Gerrit::Internal::GerritPlugin *gerritPlugin() const;
bool isCommitEditorOpen() const;
static QString msgRepositoryLabel(const QString &repository);
static QString invalidBranchAndRemoteNamePattern();
void startCommit();
void updateBranches(const QString &repository);