Skip to content

Commit

Permalink
rafactor
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jan 17, 2024
1 parent 5796f72 commit 73a14a8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 102 deletions.
29 changes: 14 additions & 15 deletions src/FileDiffWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ GitPtr FileDiffWidget::git()
return mainwindow()->git();
}

Git::Object FileDiffWidget::cat_file(GitPtr g, QString const &id)
Git::Object FileDiffWidget::catFile(QString const &id)
{
(void)g;
return mainwindow()->cat_file(mainwindow()->frame(), id);
return mainwindow()->catFile(id);
}

int FileDiffWidget::totalTextLines() const
Expand Down Expand Up @@ -599,11 +598,11 @@ void FileDiffWidget::setSideBySide_(Git::Diff const &diff, QByteArray const &ba_
}
}

QString FileDiffWidget::diffObjects(GitPtr g, QString const &a_id, QString const &b_id)
QString FileDiffWidget::diffObjects(QString const &a_id, QString const &b_id)
{
if (m->text_codec) {
Git::Object obj_a = mainwindow()->cat_file_(mainwindow()->frame(), g, a_id);
Git::Object obj_b = mainwindow()->cat_file_(mainwindow()->frame(), g, b_id);
Git::Object obj_a = mainwindow()->catFile(a_id);
Git::Object obj_b = mainwindow()->catFile(b_id);
if (obj_b.type == Git::Object::Type::UNKNOWN) {
obj_b.type = Git::Object::Type::BLOB;
}
Expand All @@ -617,14 +616,14 @@ QString FileDiffWidget::diffObjects(GitPtr g, QString const &a_id, QString const
file_b.write(m->text_codec->toUnicode(obj_b.content).toUtf8());
file_a.close();
file_b.close();
QString s = g->diff_file(path_a, path_b);
QString s = git()->diff_file(path_a, path_b);
file_a.remove();
file_b.remove();
return s;
}
}
}
return GitDiff::diffObjects(g, a_id, b_id);
return GitDiff::diffObjects(git(), a_id, b_id);
}

/**
Expand Down Expand Up @@ -652,8 +651,8 @@ void FileDiffWidget::updateDiffView(Git::Diff const &info, bool uncommited)
if (!g->isValidWorkingCopy()) return;

if (isValidID_(info.blob.a_id_or_path) && isValidID_(info.blob.b_id_or_path)) {
Git::Object obj_a = cat_file(g, info.blob.a_id_or_path);
Git::Object obj_b = cat_file(g, info.blob.b_id_or_path);
Git::Object obj_a = catFile(info.blob.a_id_or_path);
Git::Object obj_b = catFile(info.blob.b_id_or_path);
QString mime_a = mainwindow()->determinFileType(obj_a.content);
QString mime_b = mainwindow()->determinFileType(obj_b.content);
if (misc::isImage(mime_a) && misc::isImage(mime_b)) {
Expand All @@ -665,22 +664,22 @@ void FileDiffWidget::updateDiffView(Git::Diff const &info, bool uncommited)
{
Git::Diff diff;
if (isValidID_(info.blob.a_id_or_path) && isValidID_(info.blob.b_id_or_path)) {
std::string text = diffObjects(g, info.blob.a_id_or_path, info.blob.b_id_or_path).toStdString();
std::string text = diffObjects(info.blob.a_id_or_path, info.blob.b_id_or_path).toStdString();
GitDiff::parseDiff(text, &info, &diff);
} else {
diff = info;
}

Git::Object obj;
if (isValidID_(diff.blob.a_id_or_path)) { // 左が有効
obj = cat_file(g, diff.blob.a_id_or_path);
obj = catFile(diff.blob.a_id_or_path);
if (isValidID_(diff.blob.b_id_or_path)) { // 右が有効
setSideBySide(diff, obj.content, uncommited, g->workingDir()); // 通常のdiff表示
} else {
setLeftOnly(diff, obj.content); // 右が無効の時は、削除されたファイル
}
} else if (isValidID_(diff.blob.b_id_or_path)) { // 左が無効で右が有効の時は、追加されたファイル
obj = cat_file(g, diff.blob.b_id_or_path);
obj = catFile(diff.blob.b_id_or_path);
setRightOnly(diff, obj.content);
}
}
Expand All @@ -703,10 +702,10 @@ void FileDiffWidget::updateDiffView(QString const &id_left, QString const &id_ri
diff.blob.a_id_or_path = id_left;
diff.blob.b_id_or_path = id_right;
diff.mode = "0";
std::string text = diffObjects(g, diff.blob.a_id_or_path, diff.blob.b_id_or_path).toStdString();
std::string text = diffObjects(diff.blob.a_id_or_path, diff.blob.b_id_or_path).toStdString();
GitDiff::parseDiff(text, &diff, &diff);

Git::Object obj = cat_file(g, diff.blob.a_id_or_path);
Git::Object obj = catFile(diff.blob.a_id_or_path);
setSideBySide(diff, obj.content, false, g->workingDir());

ui->widget_diff_slider->clear(false);
Expand Down
4 changes: 2 additions & 2 deletions src/FileDiffWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class FileDiffWidget : public QWidget {
ViewStyle viewstyle() const;

GitPtr git();
Git::Object cat_file(GitPtr g, QString const &id);
Git::Object catFile(QString const &id);

int totalTextLines() const;

Expand All @@ -124,7 +124,7 @@ class FileDiffWidget : public QWidget {
void refrectScrollBarV();
void refrectScrollBarH();
void setOriginalLines_(QByteArray const &ba, const Git::SubmoduleItem *submodule, const Git::CommitItem *submodule_commit);
QString diffObjects(GitPtr g, QString const &a_id, QString const &b_id);
QString diffObjects(QString const &a_id, QString const &b_id);
MainWindow *mainwindow();
bool setSubmodule(const Git::Diff &diff);
protected:
Expand Down
12 changes: 6 additions & 6 deletions src/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ QList<Git::Tag> Git::tags2()
return list;
}

bool Git::tag(QString const &name, QString const &id)
bool Git::tag(QString const &name, CommitID const &id)
{
QString cmd = "tag \"%1\" %2";
cmd = cmd.arg(name).arg(id);
cmd = cmd.arg(name).arg(id.toQString());
return git(cmd);
}

Expand Down Expand Up @@ -798,12 +798,12 @@ std::optional<Git::CommitItem> Git::parseCommitItem(QString const &line)
* @param maxcount 最大アイテム数
* @return
*/
Git::CommitItemList Git::log_all(QString const &id, int maxcount)
Git::CommitItemList Git::log_all(CommitID const &id, int maxcount)
{
CommitItemList items;

QString cmd = "log --pretty=format:\"id:%H#parent:%P#author:%an#mail:%ae#date:%ci##%s\" --all -%1 %2";
cmd = cmd.arg(maxcount).arg(id);
cmd = cmd.arg(maxcount).arg(id.toQString());
git(cmd);
if (getProcessExitCode() == 0) {
QString text = resultQString().trimmed();
Expand Down Expand Up @@ -1117,10 +1117,10 @@ bool Git::commit_amend_m(QString const &text, bool sign, AbstractPtyProcess *pty
return commit_(text, true, sign, pty);
}

bool Git::revert(QString const &id)
bool Git::revert(CommitID const &id)
{
QString cmd = "revert %1";
cmd = cmd.arg(id);
cmd = cmd.arg(id.toQString());
return git(cmd);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Git.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Git : QObject {
OFS_DELTA = 6,
REF_DELTA = 7,
};
Type type = Type::UNKNOWN;
Type type = Type::NONE;
QByteArray content;
};

Expand Down Expand Up @@ -382,7 +382,7 @@ class Git : QObject {
QString version();
bool init();
QStringList getUntrackedFiles();
CommitItemList log_all(QString const &id, int maxcount);
CommitItemList log_all(CommitID const &id, int maxcount);
std::optional<CommitItem> log_signature(CommitID const &id);
CommitItemList log(int maxcount);
std::optional<CommitItem> queryCommit(const CommitID &id);
Expand Down Expand Up @@ -448,7 +448,7 @@ class Git : QObject {
QString status();
bool commit(QString const &text, bool sign, AbstractPtyProcess *pty);
bool commit_amend_m(QString const &text, bool sign, AbstractPtyProcess *pty);
bool revert(QString const &id);
bool revert(const CommitID &id);
bool push_tags(AbstractPtyProcess *pty = nullptr);
void getRemoteURLs(QList<Remote> *out);
void createBranch(QString const &name);
Expand All @@ -463,7 +463,7 @@ class Git : QObject {
CommitID rev_parse(QString const &name);
QList<Tag> tags();
QList<Tag> tags2();
bool tag(QString const &name, QString const &id = QString());
bool tag(QString const &name, const CommitID &id = QString());
void delete_tag(QString const &name, bool remote);
void setRemoteURL(const Remote &remote);
void addRemoteURL(const Remote &remote);
Expand Down
Loading

0 comments on commit 73a14a8

Please sign in to comment.