Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/FileHistory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void FileHistory::clear(bool complete) {
rowData.clear();

if (testFlag(REL_DATE_F)) {
#if QT_VERSION >= 0x06000
#if QT_VERSION >= 0x060000
secs = QDateTime::currentDateTime().toSecsSinceEpoch();
#else
secs = QDateTime::currentDateTime().toTime_t();
Expand Down
5 changes: 5 additions & 0 deletions src/commitimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#include <QTextCodec>
#include <QSettings>
#include <QMenu>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QRegExp>
#define QRegularExpression QRegExp
#else
#include <QRegularExpression>
#endif
#include <QDir>
#include <QMessageBox>
#include <QInputDialog>
Expand Down
4 changes: 4 additions & 0 deletions src/fileview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

#define MAX_LINE_NUM 5

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#define QRegularExpression QRegExp
#endif

FileView::FileView(MainImpl* mi, Git* g) : Domain(mi, g, false) {

fileTab = new Ui_TabFile();
Expand Down
78 changes: 72 additions & 6 deletions src/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <QFile>
#include <QImageReader>
#include <QPalette>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QRegExp>
#else
#include <QRegularExpression>
#endif
//#include <QSet> //CT TODO remove
#include <QSettings>
#include <QTextCodec>
Expand Down Expand Up @@ -425,9 +429,11 @@ const QString Git::getTagMsg(SCRef sha) {

if (!rf.tagMsg.isEmpty())
return rf.tagMsg;

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QRegExp pgp("-----BEGIN PGP SIGNATURE*END PGP SIGNATURE-----", Qt::CaseSensitive, QRegExp::Wildcard);
#else
QRegularExpression pgp("-----BEGIN PGP SIGNATURE.*END PGP SIGNATURE-----", QRegularExpression::DotMatchesEverythingOption);

#endif
if (!rf.tagObj.isEmpty()) {
QString ro;
if (run("git cat-file tag " + rf.tagObj, &ro))
Expand Down Expand Up @@ -1006,8 +1012,11 @@ const QString Git::getNewCommitMsg() {
return "";
}
QString status = c->longLog();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
status.prepend('\n').replace(QRegExp("\\n([^#\\n]?)"), "\n#\\1"); // comment all the lines
#else
status.prepend('\n').replace(QRegularExpression("\\n([^#\\n]?)"), "\n#\\1"); // comment all the lines

#endif
if (isMergeHead) {
QFile file(QDir(gitDir).absoluteFilePath("MERGE_MSG"));
if (file.open(QIODevice::ReadOnly)) {
Expand All @@ -1023,6 +1032,27 @@ const QString Git::getNewCommitMsg() {
}

//CT TODO utility function; can go elsewhere
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
const QString Git::colorMatch(SCRef txt, QRegExp& regExp) {

QString text = qt4and5escaping(txt);

if (regExp.isEmpty())
return text;

SCRef startCol(QString::fromLatin1("<b><font color=\"red\">"));
SCRef endCol(QString::fromLatin1("</font></b>"));
int pos = 0;
while ((pos = text.indexOf(regExp, pos)) != -1) {

SCRef match(regExp.cap(0));
const QString coloredText(startCol + match + endCol);
text.replace(pos, match.length(), coloredText);
pos += coloredText.length();
}
return text;
}
#else
const QString Git::colorMatch(SCRef txt, QRegularExpression& regExp) {

QString text = qt4and5escaping(txt);
Expand All @@ -1043,6 +1073,7 @@ const QString Git::colorMatch(SCRef txt, QRegularExpression& regExp) {
}
return text;
}
#endif

//CT TODO utility function; can go elsewhere
const QString Git::formatList(SCList sl, SCRef name, bool inOneLine) {
Expand All @@ -1057,9 +1088,14 @@ const QString Git::formatList(SCList sl, SCRef name, bool inOneLine) {
return ls;
}

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
const QString Git::getDesc(SCRef sha, QRegExp& shortLogRE, QRegExp& longLogRE,
bool showHeader, FileHistory* fh)
#else
const QString Git::getDesc(SCRef sha, QRegularExpression& shortLogRE, QRegularExpression& longLogRE,
bool showHeader, FileHistory* fh) {

bool showHeader, FileHistory* fh)
#endif
{
if (sha.isEmpty())
return "";

Expand Down Expand Up @@ -1122,6 +1158,28 @@ const QString Git::getDesc(SCRef sha, QRegularExpression& shortLogRE, QRegularEx
// sha if there isn't a leading trailing space or an open parenthesis and,
// in that case, before the space must not be a ':' character.
// It's an ugly heuristic, but seems to work in most cases.
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QRegExp reSHA("..[0-9a-f]{21,40}|[^:][\\s(][0-9a-f]{6,20}", Qt::CaseInsensitive);
reSHA.setMinimal(false);
int pos = 0;
while ((pos = text.indexOf(reSHA, pos)) != -1) {

SCRef ref = reSHA.cap(0).mid(2);
const Rev* r = (ref.length() == 40 ? revLookup(ref) : revLookup(getRefSha(ref)));
if (r && r->sha() != ZERO_SHA_RAW) {
QString slog(r->shortLog());
if (slog.isEmpty()) // very rare but possible
slog = r->sha();
if (slog.length() > 60)
slog = slog.left(57).trimmed().append("...");

const QString link("<a href=\"" + r->sha() + "\">" + qt4and5escaping(slog) + "</a>");
text.replace(pos + 2, ref.length(), link);
pos += link.length();
} else
pos += reSHA.cap(0).length();
}
#else
QRegularExpression reSHA("..[0-9a-f]{21,40}|[^:][\\s(][0-9a-f]{6,20}", QRegularExpression::CaseInsensitiveOption);
int pos = 0;
QRegularExpressionMatch match;
Expand All @@ -1142,6 +1200,7 @@ const QString Git::getDesc(SCRef sha, QRegularExpression& shortLogRE, QRegularEx
} else
pos += match.captured(0).length();
}
#endif
return text;
}

Expand Down Expand Up @@ -1673,7 +1732,11 @@ const QString Git::getLocalDate(SCRef gitDate) {
// cache miss
if (localDate.isEmpty()) {
static QDateTime d;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
d.setTime_t(gitDate.toUInt());
#else
d.setSecsSinceEpoch(gitDate.toUInt());
#endif
localDate = QLocale::system().toString(d, QLocale::ShortFormat);

// save to cache
Expand Down Expand Up @@ -1980,8 +2043,11 @@ const Rev* Git::fakeWorkDirRev(SCRef parent, SCRef log, SCRef longLog, int idx,
QString patch;
if (!isMainHistory(fh))
patch = getWorkDirDiff(fh->fileNames().first());

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QString date(QString::number(QDateTime::currentDateTime().toTime_t()));
#else
QString date(QString::number(QDateTime::currentDateTime().toSecsSinceEpoch()));
#endif
QString author("-");
QStringList parents(parent);
Rev* c = fakeRevData(ZERO_SHA, parents, author, date, log, longLog, patch, idx, fh);
Expand Down
13 changes: 13 additions & 0 deletions src/git.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#include "exceptionmanager.h"
#include "common.h"

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
template <class, class> struct QPair;
class QRegExp;
#else
class QRegularExpression;
#endif
class QTextCodec;
class Annotate;
//class DataLoader;
Expand Down Expand Up @@ -97,7 +102,11 @@ Q_OBJECT
bool getTree(SCRef ts, TreeInfo& ti, bool wd, SCRef treePath);
static const QString getLocalDate(SCRef gitDate);
const QString getCurrentBranchName() const {return curBranchName;}
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
const QString getDesc(SCRef sha, QRegExp& slogRE, QRegExp& lLogRE, bool showH, FileHistory* fh);
#else
const QString getDesc(SCRef sha, QRegularExpression& slogRE, QRegularExpression& lLogRE, bool showH, FileHistory* fh);
#endif
const QString getLastCommitMsg();
const QString getNewCommitMsg();
const QString getLaneParent(SCRef fromSHA, int laneNum);
Expand Down Expand Up @@ -246,7 +255,11 @@ private slots:
const QStringList getOthersFiles();
const QStringList getOtherFiles(SCList selFiles, bool onlyInIndex);
const QString getNewestFileName(SCList args, SCRef fileName);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
static const QString colorMatch(SCRef txt, QRegExp& regExp);
#else
static const QString colorMatch(SCRef txt, QRegularExpression& regExp);
#endif
void appendFileName(RevFile& rf, SCRef name, FileNamesLoader& fl);
void flushFileNames(FileNamesLoader& fl);
void populateFileNamesMap();
Expand Down
17 changes: 16 additions & 1 deletion src/inputdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <QListView>
#include <QStringListModel>

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#define QRegularExpression QRegExp
#endif

namespace QGit {

InputDialog::WidgetItem::WidgetItem() : widget(NULL)
Expand Down Expand Up @@ -92,21 +96,32 @@ InputDialog::InputDialog(const QString &cmd, const VariableMap &variables,
QRegularExpression re("%(([a-z_]+)([[]([a-z ,]+)[]])?:)?([^%=]+)(=[^%]+)?%");
int start = 0;
int row = 0;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
while ((start = re.indexIn(cmd, start)) != -1) {
const QString type = re.cap(2);
const QStringList opts = re.cap(4).split(',', QGIT_SPLITBEHAVIOR(SkipEmptyParts));
const QString name = re.cap(5);
const QString value = re.cap(6).mid(1);
#else
QRegularExpressionMatch match;
while ((start = cmd.indexOf(re, start, &match)) != -1) {
const QString type = match.captured(2);
const QStringList opts = match.captured(4).split(',', QGIT_SPLITBEHAVIOR(SkipEmptyParts));
const QString name = match.captured(5);
const QString value = match.captured(6).mid(1);
#endif
if (widgets.count(name)) { // widget already created
if (!type.isEmpty()) dbs("token must not be redefined: " + name);
continue;
}

WidgetItemPtr item (new WidgetItem());
item->start = start;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
item->end = start = start + re.matchedLength();
#else
item->end = start = start + match.capturedLength();

#endif
if (type == "combobox") {
QComboBox *w = new QComboBox(this);
w->addItems(parseStringList(value, variables));
Expand Down
2 changes: 1 addition & 1 deletion src/listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ void ListViewDelegate::addTextPixmap(QPixmap** pp, SCRef txt, const QStyleOption
#if QT_VERSION >= QT_VERSION_CHECK(5,11,0)
unsigned int fmw = fm.horizontalAdvance(txt);
#else
unsigned int fmw = fm.width(txt)
unsigned int fmw = fm.width(txt);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tibirna This is new in 2.13.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, I screwed it when fixing branch tag size, never caught it because of lack of Qt < 5.11 to compile/test with. Sorry. Thanks for catching it.

#endif
unsigned int text_width = fmw + 2 * text_spacing;
unsigned int text_height = fm.height();
Expand Down
4 changes: 4 additions & 0 deletions src/listview.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#include <QTreeView>
#include <QItemDelegate>
#include <QSortFilterProxyModel>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QRegExp>
#else
#include <QRegularExpression>
#endif
#include "common.h"

class Git;
Expand Down
12 changes: 9 additions & 3 deletions src/mainimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ MainImpl::MainImpl(SCRef cd, QWidget* p) : QMainWindow(p) {
setRepositoryBusy = false;

// init filter match highlighters
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
shortLogRE.setMinimal(true);
shortLogRE.setCaseSensitivity(Qt::CaseInsensitive);
longLogRE.setMinimal(true);
longLogRE.setCaseSensitivity(Qt::CaseInsensitive);
#else
shortLogRE.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
longLogRE.setPatternOptions(QRegularExpression::CaseInsensitiveOption);

#endif
// set-up standard revisions and files list font
QSettings settings;
QString font(settings.value(STD_FNT_KEY).toString());
Expand Down Expand Up @@ -1649,7 +1655,7 @@ bool MainImpl::askApplyPatchParameters(bool* workDirOnly, bool* fold) {
"Apply Patch",
"Do you want to commit or just to apply changes to "
"working directory?",
{}, this);
QMessageBox::NoButton, this);
QAbstractButton* cbtn = qmb.addButton("&Cancel", QMessageBox::ButtonRole::RejectRole);
QAbstractButton* wdbtn = qmb.addButton(
"&Working directory", QMessageBox::ButtonRole::AcceptRole);
Expand All @@ -1662,7 +1668,7 @@ bool MainImpl::askApplyPatchParameters(bool* workDirOnly, bool* fold) {
QMessageBox qmb(QMessageBox::Question,
"Apply Patch",
"Do you want to import or fold the patch?",
{}, this);
QMessageBox::NoButton, this);
QAbstractButton* cbtn = qmb.addButton("&Cancel", QMessageBox::ButtonRole::RejectRole);
QAbstractButton* fbtn = qmb.addButton(
"&Fold", QMessageBox::ButtonRole::AcceptRole);
Expand Down
5 changes: 5 additions & 0 deletions src/mainimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#define MAINIMPL_H

#include <QProcess>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QRegExp>
#define QRegularExpression QRegExp
#else
#include <QRegularExpression>
#endif
#include <QDir>
#include "exceptionmanager.h"
#include "common.h"
Expand Down
Loading
Loading