Skip to content
GitLab
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
0c933b84
Commit
0c933b84
authored
Dec 22, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Dec 26, 2021
Browse files
git: Show last commit in branch delete dialog
Helps to remember what the branch might be related to.
parent
867301eb
Pipeline
#114487
passed with stage
in 4 minutes and 16 seconds
Changes
4
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
addons/project/branchdeletedialog.cpp
View file @
0c933b84
...
...
@@ -22,6 +22,10 @@ BranchDeleteDialog::BranchDeleteDialog(const QString &dotGitPath, QWidget *paren
l
->
addWidget
(
&
m_listView
);
m_model
.
setHorizontalHeaderLabels
({
i18n
(
"Branch"
),
i18n
(
"Last Commit"
)});
m_listView
.
setUniformRowHeights
(
true
);
m_listView
.
setRootIsDecorated
(
false
);
m_listView
.
setModel
(
&
m_model
);
// setup the buttons
...
...
@@ -49,7 +53,10 @@ BranchDeleteDialog::BranchDeleteDialog(const QString &dotGitPath, QWidget *paren
l
->
addWidget
(
dlgBtns
);
resize
(
500
,
500
);
m_listView
.
resizeColumnToContents
(
0
);
m_listView
.
resizeColumnToContents
(
1
);
resize
(
m_listView
.
width
()
*
1.5
,
m_listView
.
height
()
+
l
->
contentsMargins
().
top
()
*
2
);
}
void
BranchDeleteDialog
::
loadBranches
(
const
QString
&
dotGitPath
)
...
...
@@ -61,12 +68,13 @@ void BranchDeleteDialog::loadBranches(const QString &dotGitPath)
#endif
static
const
auto
branchIcon
=
QIcon
::
fromTheme
(
QStringLiteral
(
"vcs-branch"
));
const
auto
branches
=
GitUtils
::
getAllBranches
AndTags
(
dotGitPath
,
GitUtils
::
RefType
::
Head
);
const
auto
branches
=
GitUtils
::
getAll
Local
Branches
WithLastCommitSubject
(
dotGitPath
);
for
(
const
auto
&
branch
:
branches
)
{
auto
item
=
new
QStandardItem
(
branchIcon
,
branch
.
name
);
item
->
setFont
(
f
);
item
->
setCheckable
(
true
);
m_model
.
appendRow
(
item
);
auto
branchName
=
new
QStandardItem
(
branchIcon
,
branch
.
name
);
auto
branchLastCommit
=
new
QStandardItem
(
branch
.
lastCommit
);
branchName
->
setFont
(
f
);
branchName
->
setCheckable
(
true
);
m_model
.
appendRow
({
branchName
,
branchLastCommit
});
}
}
...
...
addons/project/branchdeletedialog.h
View file @
0c933b84
#include
<QDialog>
#include
<QLabel>
#include
<QListView>
#include
<QStandardItemModel>
#include
<QTreeView>
class
BranchDeleteDialog
:
public
QDialog
{
...
...
@@ -14,5 +14,5 @@ private:
void
loadBranches
(
const
QString
&
dotGitPath
);
void
updateLabel
(
QStandardItem
*
item
);
QStandardItemModel
m_model
;
Q
List
View
m_listView
;
Q
Tree
View
m_listView
;
};
addons/project/git/gitutils.cpp
View file @
0c933b84
...
...
@@ -105,14 +105,14 @@ GitUtils::CheckoutResult GitUtils::checkoutNewBranch(const QString &repo, const
static
GitUtils
::
Branch
parseLocalBranch
(
const
QString
&
raw
)
{
static
const
int
len
=
QStringLiteral
(
"refs/heads/"
).
length
();
return
GitUtils
::
Branch
{
raw
.
mid
(
len
),
QString
(),
GitUtils
::
Head
};
return
GitUtils
::
Branch
{
raw
.
mid
(
len
),
QString
(),
GitUtils
::
Head
,
QString
()
};
}
static
GitUtils
::
Branch
parseRemoteBranch
(
const
QString
&
raw
)
{
static
const
int
len
=
QStringLiteral
(
"refs/remotes/"
).
length
();
int
indexofRemote
=
raw
.
indexOf
(
QLatin1Char
(
'/'
),
len
);
return
GitUtils
::
Branch
{
raw
.
mid
(
len
),
raw
.
mid
(
len
,
indexofRemote
-
len
),
GitUtils
::
Remote
};
return
GitUtils
::
Branch
{
raw
.
mid
(
len
),
raw
.
mid
(
len
,
indexofRemote
-
len
),
GitUtils
::
Remote
,
QString
()
};
}
QVector
<
GitUtils
::
Branch
>
GitUtils
::
getAllBranchesAndTags
(
const
QString
&
repo
,
RefType
ref
)
...
...
@@ -148,7 +148,7 @@ QVector<GitUtils::Branch> GitUtils::getAllBranchesAndTags(const QString &repo, R
branches
.
append
(
parseRemoteBranch
(
o
));
}
else
if
(
ref
&
Tag
&&
o
.
startsWith
(
QLatin1String
(
"refs/tags/"
)))
{
static
const
int
len
=
QStringLiteral
(
"refs/tags/"
).
length
();
branches
.
append
({
o
.
mid
(
len
),
{},
RefType
::
Tag
});
branches
.
append
({
o
.
mid
(
len
),
{},
RefType
::
Tag
,
QString
()
});
}
}
// clang-format on
...
...
@@ -157,6 +157,42 @@ QVector<GitUtils::Branch> GitUtils::getAllBranchesAndTags(const QString &repo, R
return
branches
;
}
QVector
<
GitUtils
::
Branch
>
GitUtils
::
getAllLocalBranchesWithLastCommitSubject
(
const
QString
&
repo
)
{
// git for-each-ref --format '%(refname)' --sort=-committerdate ...
QProcess
git
;
QStringList
args
{
QStringLiteral
(
"for-each-ref"
),
QStringLiteral
(
"--format"
),
QStringLiteral
(
"%(refname)[--]%(contents:subject)"
),
QStringLiteral
(
"--sort=-committerdate"
),
QStringLiteral
(
"refs/heads"
)};
setupGitProcess
(
git
,
repo
,
args
);
git
.
start
(
QProcess
::
ReadOnly
);
QVector
<
Branch
>
branches
;
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
QByteArray
gitout
=
git
.
readAllStandardOutput
();
QByteArrayList
rows
=
gitout
.
split
(
'\n'
);
branches
.
reserve
(
rows
.
size
());
constexpr
int
len
=
sizeof
(
"refs/heads/"
)
-
1
;
for
(
const
auto
&
row
:
rows
)
{
int
seperatorIdx
=
row
.
indexOf
(
"[--]"
,
len
);
if
(
seperatorIdx
==
-
1
)
{
continue
;
}
int
commitStart
=
seperatorIdx
+
4
;
branches
<<
GitUtils
::
Branch
{
QString
::
fromUtf8
(
row
.
mid
(
len
,
seperatorIdx
-
len
)),
QString
(),
GitUtils
::
Head
,
QString
::
fromUtf8
(
row
.
mid
(
commitStart
))};
}
}
return
branches
;
}
QVector
<
GitUtils
::
Branch
>
GitUtils
::
getAllBranches
(
const
QString
&
repo
)
{
return
getAllBranchesAndTags
(
repo
,
static_cast
<
RefType
>
(
RefType
::
Head
|
RefType
::
Remote
));
...
...
addons/project/git/gitutils.h
View file @
0c933b84
...
...
@@ -29,6 +29,8 @@ struct Branch {
QString
remote
;
/** Ref type @see RefType */
RefType
type
;
/** last commit on this branch, may be empty **/
QString
lastCommit
;
};
struct
Result
{
...
...
@@ -87,6 +89,11 @@ QVector<Branch> getAllBranches(const QString &repo);
*/
QVector
<
Branch
>
getAllBranchesAndTags
(
const
QString
&
repo
,
RefType
ref
=
RefType
::
All
);
/**
* @brief get all local branches with last commit
*/
QVector
<
Branch
>
getAllLocalBranchesWithLastCommitSubject
(
const
QString
&
repo
);
std
::
pair
<
QString
,
QString
>
getLastCommitMessage
(
const
QString
&
repo
);
Result
deleteBranches
(
const
QStringList
&
branches
,
const
QString
&
repo
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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