Skip to content

Commit

Permalink
Add mutex protection for commit log access
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jun 23, 2024
1 parent 6cb263a commit 4972c7c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/CommitDetailGetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ CommitDetailGetter::~CommitDetailGetter()
void CommitDetailGetter::start(GitPtr git)
{
stop();
interrupted_ = false;

git_ = git;

threads_.clear();
threads_.resize(4);
for (size_t i = 0; i < threads_.size(); i++) {
std::thread th([&](){
threads_[i] = std::thread([&](){
while (1) {
Request item;
{
Expand Down Expand Up @@ -72,7 +75,6 @@ void CommitDetailGetter::start(GitPtr git)
}
}
});
threads_[i] = std::move(th);
}
}

Expand All @@ -96,7 +98,6 @@ void CommitDetailGetter::stop()
}
}
threads_.clear();
interrupted_ = false;
}

/**
Expand Down
45 changes: 27 additions & 18 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2001,18 +2001,22 @@ void MainWindow::commit(RepositoryWrapperFrame *frame, bool amend)

QString message;
QString previousMessage;

if (amend) {
message = getCommitLog(frame)[0].message;
} else {
QString id = g->getCherryPicking();
if (Git::isValidID(id)) {
message = g->getMessage(id);

{
std::lock_guard lock(frame->commit_log_mutex);

if (amend) {
message = getCommitLog(frame)[0].message;
} else {
for (Git::CommitItem const &item : getCommitLog(frame).list) {
if (item.commit_id.isValid()) {
previousMessage = item.message;
break;
QString id = g->getCherryPicking();
if (Git::isValidID(id)) {
message = g->getMessage(id);
} else {
for (Git::CommitItem const &item : getCommitLog(frame).list) {
if (item.commit_id.isValid()) {
previousMessage = item.message;
break;
}
}
}
}
Expand Down Expand Up @@ -4341,16 +4345,21 @@ void MainWindow::makeCommitLog(RepositoryWrapperFrame *frame, int scroll_pos, in
bool block = logtablewidget->blockSignals(true);
{
frame->prepareLogTableWidget();

auto const &logs = getCommitLog(frame);
const int count = (int)logs.size();

Git::CommitItemList commit_log;
{
std::lock_guard lock(frame->commit_log_mutex);
commit_log = frame->commit_log;
}

const int count = (int)commit_log.size();

logtablewidget->setRowCount(count);

int selrow = 0;

for (int row = 0; row < count; row++) {
Git::CommitItem const *commit = &logs[row];
Git::CommitItem const *commit = &commit_log[row];
{
auto *item = new QTableWidgetItem;
item->setData(IndexRole, row);
Expand Down Expand Up @@ -4396,7 +4405,7 @@ void MainWindow::makeCommitLog(RepositoryWrapperFrame *frame, int scroll_pos, in
datetime = misc::makeDateTimeString(commit->commit_date);
author = commit->author;
message = commit->message;
message_ex = makeCommitInfoText(frame, row, &(*getLabelMap(frame))[row], true);
message_ex = makeCommitInfoText(frame, row, &(*getLabelMap(frame))[row], false);
}
AddColumn(commit_id, false, QString());
AddColumn(datetime, false, QString());
Expand Down Expand Up @@ -4682,7 +4691,7 @@ void MainWindow::updateStatusBarText(RepositoryWrapperFrame *frame)
;
}
} else if (w == frame->logtablewidget()) {
QTableWidgetItem *item = frame->logtablewidget()->item(selectedLogIndex(frame), 0);
QTableWidgetItem *item = frame->logtablewidget()->item(selectedLogIndex(frame, false), 0);
if (item) {
std::lock_guard lock(frame->commit_log_mutex);
auto const &logs = getCommitLog(frame);
Expand Down Expand Up @@ -5985,7 +5994,7 @@ void MainWindow::onLogCurrentItemChanged(RepositoryWrapperFrame *frame)

Git::CommitItem const selected_commit = selectedCommitItem(frame);

m->commit_detail_getter.query(selected_commit.commit_id, true, true); // 詳細情報の更新要求
// m->commit_detail_getter.query(selected_commit.commit_id, true, true); // 詳細情報の更新要求

// ステータスバー更新
updateStatusBarText(frame);
Expand Down

0 comments on commit 4972c7c

Please sign in to comment.