Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
83f38e9a
Commit
83f38e9a
authored
Feb 07, 2021
by
Waqar Ahmed
Browse files
Only show local/remote branches, no tags
parent
c590fc4e
Changes
6
Hide whitespace changes
Inline
Side-by-side
addons/project/branchesdialog.cpp
View file @
83f38e9a
...
...
@@ -90,16 +90,16 @@ public:
kfts
::
to_scored_fuzzy_matched_display_string
(
m_filterString
,
name
,
QStringLiteral
(
"<b style=
\"
color:%1;
\"
>"
).
arg
(
nameColor
),
QStringLiteral
(
"</b>"
));
auto
type
=
(
GitUtils
::
RefType
)
index
.
data
(
BranchesDialogModel
::
RefType
).
toInt
();
auto
commit
=
index
.
data
(
BranchesDialogModel
::
Commit
).
toString
();
using
RefType
=
GitUtils
::
RefType
;
const
auto
fontSz
=
option
.
font
.
pointSize
();
if
(
type
==
RefType
::
Head
)
{
name
.
append
(
QStringLiteral
(
" <span style=
\"
color:gray; font-size:%1pt;
\"
>
at %2
</span>"
).
arg
(
fontSz
)
.
arg
(
commit
)
);
name
.
append
(
QStringLiteral
(
" <span style=
\"
color:gray; font-size:%1pt;
\"
>
local
</span>"
).
arg
(
fontSz
));
}
else
if
(
type
==
RefType
::
Remote
)
{
name
.
append
(
QStringLiteral
(
" <span style=
\"
color:gray; font-size:%1pt;
\"
>remote at %2</span>"
).
arg
(
fontSz
).
arg
(
commit
));
}
else
if
(
type
==
RefType
::
Tag
)
{
name
.
append
(
QStringLiteral
(
" <span style=
\"
color:gray; font-size:%1pt;
\"
>tag at %2</span>"
).
arg
(
fontSz
).
arg
(
commit
));
}
else
{
name
.
append
(
QStringLiteral
(
" <span style=
\"
color:gray; font-size:%1pt;
\"
>remote</span>"
).
arg
(
fontSz
));
}
/*else if (type == RefType::Tag) {
name.append(QStringLiteral(" <span style=\"color:gray; font-size:%1pt;\">tag at %2</span>").arg(fontSz));
} */
else
{
Q_ASSERT
(
false
);
}
...
...
addons/project/branchesdialogmodel.cpp
View file @
83f38e9a
...
...
@@ -45,8 +45,6 @@ QVariant BranchesDialogModel::data(const QModelIndex &idx, int role) const
}
else
if
(
role
==
Qt
::
DecorationRole
)
{
static
const
auto
branchIcon
=
QIcon
(
QStringLiteral
(
":/kxmlgui5/kateproject/sc-apps-git.svg"
));
return
branchIcon
;
}
else
if
(
role
==
Role
::
Commit
)
{
return
branch
.
commit
.
mid
(
0
,
7
);
}
else
if
(
role
==
Role
::
CheckoutName
)
{
return
branch
.
type
==
GitUtils
::
RefType
::
Remote
?
branch
.
name
.
mid
(
branch
.
remote
.
size
()
+
1
)
:
branch
.
name
;
}
else
if
(
role
==
Role
::
RefType
)
{
...
...
addons/project/branchesdialogmodel.h
View file @
83f38e9a
...
...
@@ -18,7 +18,7 @@ class BranchesDialogModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum
Role
{
Score
=
Qt
::
UserRole
+
1
,
DisplayName
,
Commit
,
CheckoutName
,
RefType
};
enum
Role
{
Score
=
Qt
::
UserRole
+
1
,
DisplayName
,
CheckoutName
,
RefType
};
explicit
BranchesDialogModel
(
QObject
*
parent
=
nullptr
);
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
)
const
override
;
...
...
addons/project/gitutils.cpp
View file @
83f38e9a
...
...
@@ -36,21 +36,21 @@ int GitUtils::checkoutBranch(const QString &repo, const QString &branch)
return
-
1
;
}
QVector
<
GitUtils
::
Branch
>
GitUtils
::
getAllBranches
(
const
QString
&
repo
,
RefType
ref
)
QVector
<
GitUtils
::
Branch
>
GitUtils
::
getAllBranches
AndTags
(
const
QString
&
repo
,
RefType
ref
)
{
// git for-each-ref --format '%(refname) %(objectname) %(*objectname)'
QProcess
git
;
git
.
setWorkingDirectory
(
repo
);
QStringList
args
{
QStringLiteral
(
"for-each-ref"
),
QStringLiteral
(
"--format"
),
QStringLiteral
(
"%(refname)
%(objectname) %(*objectname)
"
)};
QStringList
args
{
QStringLiteral
(
"for-each-ref"
),
QStringLiteral
(
"--format"
),
QStringLiteral
(
"%(refname)"
)};
git
.
start
(
QStringLiteral
(
"git"
),
args
);
QVector
<
Branch
>
branches
;
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
QString
gitout
=
QString
::
fromUtf8
(
git
.
readAllStandardOutput
());
QVector
<
QStringRef
>
out
=
gitout
.
splitRef
(
QLatin1Char
(
'\n'
));
static
const
QRegularExpression
headRe
(
QStringLiteral
(
"^refs/heads/([^ ]+)
([0-9a-f]{40}) ([0-9a-f]{40})?
$"
));
static
const
QRegularExpression
remoteRe
(
QStringLiteral
(
"^refs/remotes/([^/]+)/([^ ]+)
([0-9a-f]{40}) ([0-9a-f]{40})?$
"
));
static
const
QRegularExpression
tagRe
(
QStringLiteral
(
"^refs/tags/([^ ]+)
([0-9a-f]{40}) ([0-9a-f]{40})?
$"
));
static
const
QRegularExpression
headRe
(
QStringLiteral
(
"^refs/heads/([^ ]+)$"
));
static
const
QRegularExpression
remoteRe
(
QStringLiteral
(
"^refs/remotes/([^/]+)/([^ ]+)"
));
static
const
QRegularExpression
tagRe
(
QStringLiteral
(
"^refs/tags/([^ ]+)$"
));
branches
.
reserve
(
out
.
size
());
QRegularExpressionMatch
m
;
...
...
@@ -59,19 +59,16 @@ QVector<GitUtils::Branch> GitUtils::getAllBranches(const QString &repo, RefType
if
(
ref
&
Head
&&
(
m
=
headRe
.
match
(
o
)).
hasMatch
())
{
branches
.
append
({
m
.
captured
(
1
),
QString
(),
// no remote
m
.
captured
(
2
),
RefType
::
Head
,
-
1
});
}
else
if
(
ref
&
Remote
&&
(
m
=
remoteRe
.
match
(
o
)).
hasMatch
())
{
branches
.
append
({
m
.
captured
(
1
).
append
(
QLatin1Char
(
'/'
)
+
m
.
captured
(
2
)),
m
.
captured
(
1
),
m
.
captured
(
3
),
RefType
::
Remote
,
-
1
});
}
else
if
(
ref
&
Tag
&&
(
m
=
tagRe
.
match
(
o
)).
hasMatch
())
{
branches
.
append
({
m
.
captured
(
1
),
QString
(),
// no remote
m
.
captured
(
3
).
isEmpty
()
?
QString
()
:
m
.
captured
(
2
),
RefType
::
Tag
,
-
1
});
}
...
...
@@ -81,3 +78,8 @@ QVector<GitUtils::Branch> GitUtils::getAllBranches(const QString &repo, RefType
return
branches
;
}
QVector
<
GitUtils
::
Branch
>
GitUtils
::
getAllBranches
(
const
QString
&
repo
)
{
return
getAllBranchesAndTags
(
repo
,
static_cast
<
RefType
>
(
RefType
::
Head
|
RefType
::
Remote
));
}
addons/project/gitutils.h
View file @
83f38e9a
...
...
@@ -9,19 +9,16 @@
namespace
GitUtils
{
// clang-format off
enum
RefType
{
Head
=
0x1
,
Head
=
0x1
,
Remote
=
0x2
,
Tag
=
0x4
,
All
=
0x7
Tag
=
0x4
,
All
=
0x7
,
};
// clang-format on
struct
Branch
{
QString
name
;
QString
remote
;
QString
commit
;
RefType
type
;
int
score
;
// used for scoring when filtering
};
...
...
@@ -32,7 +29,14 @@ QString getCurrentBranchName(const QString &repo);
int
checkoutBranch
(
const
QString
&
repo
,
const
QString
&
branch
);
QVector
<
Branch
>
getAllBranches
(
const
QString
&
repo
,
RefType
ref
=
RefType
::
All
);
/**
* @brief get all local and remote branches
*/
QVector
<
Branch
>
getAllBranches
(
const
QString
&
repo
);
/**
* @brief get all local and remote branches + tags
*/
QVector
<
Branch
>
getAllBranchesAndTags
(
const
QString
&
repo
,
RefType
ref
=
RefType
::
All
);
}
#endif // GITUTILS_H
addons/project/kateprojectview.cpp
View file @
83f38e9a
...
...
@@ -14,9 +14,9 @@
#include <ktexteditor/document.h>
#include <ktexteditor/view.h>
#include <KActionCollection>
#include <KLineEdit>
#include <KLocalizedString>
#include <KActionCollection>
#include <QPushButton>
#include <QSortFilterProxyModel>
...
...
@@ -48,13 +48,12 @@ KateProjectView::KateProjectView(KateProjectPluginView *pluginView, KateProject
setFocusProxy
(
m_treeView
);
// add to actionCollection so that this is available in Kate Command bar
auto
chckbr
=
pluginView
->
actionCollection
()
->
addAction
(
QStringLiteral
(
"checkout_branch"
),
this
,
[
this
]{
auto
chckbr
=
pluginView
->
actionCollection
()
->
addAction
(
QStringLiteral
(
"checkout_branch"
),
this
,
[
this
]
{
m_branchBtn
->
click
();
});
chckbr
->
setText
(
QStringLiteral
(
"Checkout Branch"
));
m_branchesDialog
=
new
BranchesDialog
(
this
,
mainWindow
,
m_project
->
baseDir
());
/**
* setup filter line edit
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment