diff --git a/src/FileDiffWidget.cpp b/src/FileDiffWidget.cpp index ae5c9265..5c160370 100644 --- a/src/FileDiffWidget.cpp +++ b/src/FileDiffWidget.cpp @@ -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 @@ -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; } @@ -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); } /** @@ -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)) { @@ -665,7 +664,7 @@ 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; @@ -673,14 +672,14 @@ void FileDiffWidget::updateDiffView(Git::Diff const &info, bool uncommited) 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); } } @@ -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); diff --git a/src/FileDiffWidget.h b/src/FileDiffWidget.h index bc999909..ffe81f8d 100644 --- a/src/FileDiffWidget.h +++ b/src/FileDiffWidget.h @@ -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; @@ -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: diff --git a/src/Git.cpp b/src/Git.cpp index 01e1045c..cf48b9a6 100644 --- a/src/Git.cpp +++ b/src/Git.cpp @@ -448,10 +448,10 @@ QList 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); } @@ -798,12 +798,12 @@ std::optional 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(); @@ -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); } diff --git a/src/Git.h b/src/Git.h index ff169df4..ba18699d 100644 --- a/src/Git.h +++ b/src/Git.h @@ -77,7 +77,7 @@ class Git : QObject { OFS_DELTA = 6, REF_DELTA = 7, }; - Type type = Type::UNKNOWN; + Type type = Type::NONE; QByteArray content; }; @@ -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 log_signature(CommitID const &id); CommitItemList log(int maxcount); std::optional queryCommit(const CommitID &id); @@ -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 *out); void createBranch(QString const &name); @@ -463,7 +463,7 @@ class Git : QObject { CommitID rev_parse(QString const &name); QList tags(); QList 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); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 4c6a43cd..0d7a1ae6 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -146,8 +146,6 @@ struct MainWindow::Private { QString repository_filter_text; bool uncommited_changes = false; -// bool remote_changed = false; - GitHubRepositoryInfo github; Git::CommitID head_id; @@ -625,20 +623,15 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) if (watched == frame()->unstagedFileslistwidget()) { m->last_focused_file_list = watched; updateStatusBarText(frame()); -// updateUnstagedFileCurrentItem(frame()); -// SelectItem(frame()->unstagedFileslistwidget()); return true; } if (watched == frame()->stagedFileslistwidget()) { m->last_focused_file_list = watched; updateStatusBarText(frame()); -// updateStagedFileCurrentItem(frame()); -// SelectItem(frame()->stagedFileslistwidget()); return true; } if (watched == frame()->fileslistwidget()) { m->last_focused_file_list = watched; -// SelectItem(frame()->fileslistwidget()); return true; } } @@ -759,9 +752,7 @@ std::vector MainWindow::getLogHistoryLines() void MainWindow::clearLogHistory() { -// if (m->log_history_bytes.empty()) return; m->log_history_bytes.clear(); -// qDebug() << "---"; } void MainWindow::internalWriteLog(char const *ptr, int len, bool record) @@ -846,11 +837,6 @@ QString MainWindow::defaultWorkingDir() const return appsettings()->default_working_dir; } -//WebContext *MainWindow::webContext() -//{ -// return &m->webcx; -//} - QIcon MainWindow::verifiedIcon(char s) const { Git::SignatureGrade g = Git::evaluateSignature(s); @@ -1003,7 +989,7 @@ bool MainWindow::addExistingLocalRepository(QString dir, QString name, QString s if (open) { setCurrentRepository(item, true); GitPtr g = git(item.local_dir, {}, sshkey); - openRepository_(g); + internalOpenRepository(g); } return true; @@ -1132,7 +1118,7 @@ bool MainWindow::checkGitCommand() bool MainWindow::saveBlobAs(RepositoryWrapperFrame *frame, const QString &id, const QString &dstpath) { - Git::Object obj = cat_file(frame, id); + Git::Object obj = internalCatFile(frame, id); if (!obj.content.isEmpty()) { if (saveByteArrayAs(obj.content, dstpath)) { return true; @@ -1219,14 +1205,12 @@ bool MainWindow::checkExecutable(const QString &path) void MainWindow::internalSaveCommandPath(const QString &path, bool save, const QString &name) { -// if (checkExecutable(path)) { - if (save) { - MySettings s; - s.beginGroup("Global"); - s.setValue(name, path); - s.endGroup(); - } -// } + if (save) { + MySettings s; + s.beginGroup("Global"); + s.setValue(name, path); + s.endGroup(); + } } void MainWindow::logGitVersion() @@ -1288,7 +1272,7 @@ void MainWindow::openRepository(bool validate, bool waitcursor, bool keep_select qDebug() << "Guitar: git pointer is null"; return; } - openRepository_(g, keep_selection); + internalOpenRepository(g, keep_selection); } void MainWindow::updateRepository() @@ -1297,7 +1281,7 @@ void MainWindow::updateRepository() if (!isValidWorkingCopy(g)) return; OverrideWaitCursor; - openRepository_(g); + internalOpenRepository(g); } void MainWindow::reopenRepository(bool log, const std::function &callback) @@ -1318,7 +1302,7 @@ void MainWindow::reopenRepository(bool log, const std::function } else { callback(g); } - openRepository_(g); + internalOpenRepository(g); } void MainWindow::setCurrentRepository(const RepositoryData &repo, bool clear_authentication) @@ -1544,7 +1528,7 @@ void MainWindow::submodule_add(QString url, QString const &local_dir) } setLogEnabled(g, false); } - openRepository_(g); + internalOpenRepository(g); } return; // done @@ -3626,28 +3610,7 @@ void MainWindow::clearLog(RepositoryWrapperFrame *frame) frame->clearLogContents(); } -void MainWindow::openRepository_(GitPtr g, bool keep_selection) -{ - openRepository_(frame(), g, keep_selection); -} - -MainWindow::GitFile MainWindow::catFile(Git::CommitID const &id, GitPtr g) -{ - GitFile file; - if (0) { //@TODO:いつか消す - auto ba = g->cat_file(id); - if (ba) { - file.data = *ba; - } - } else { - Git::Object::Type type; - GitObjectManager om(g); - om.catFile(id, &file.data, &file.type); - } - return file; -} - -Git::Object MainWindow::cat_file_(RepositoryWrapperFrame *frame, GitPtr g, const QString &id) //@TODO: +Git::Object MainWindow::internalCatFile(RepositoryWrapperFrame *frame, GitPtr g, const QString &id) //@TODO: { if (isValidWorkingCopy(g)) { QString path_prefix = PATH_PREFIX; @@ -3664,15 +3627,25 @@ Git::Object MainWindow::cat_file_(RepositoryWrapperFrame *frame, GitPtr g, const return getObjCache(frame)->catFile(id);; } } - return Git::Object(); + return {}; +} + +Git::Object MainWindow::internalCatFile(RepositoryWrapperFrame *frame, const QString &id) //@TODO: +{ + return internalCatFile(frame, git(), id); } -Git::Object MainWindow::cat_file(RepositoryWrapperFrame *frame, const QString &id) //@TODO: +Git::Object MainWindow::catFile(QString const &id) { - return cat_file_(frame, git(), id); + return internalCatFile(frame(), git(), id); } -void MainWindow::openRepository_(RepositoryWrapperFrame *frame, GitPtr g, bool keep_selection) +void MainWindow::internalOpenRepository(GitPtr g, bool keep_selection) +{ + openRepositoryWithFrame(frame(), g, keep_selection); +} + +void MainWindow::openRepositoryWithFrame(RepositoryWrapperFrame *frame, GitPtr g, bool keep_selection) { getObjCache(frame)->setup(g); @@ -4660,24 +4633,11 @@ void MainWindow::showObjectProperty(QListWidgetItem *item) if (item) { QString submodpath = getSubmodulePath(item); if (!submodpath.isEmpty()) { -#if 0 - // サブモジュールウィンドウを表示する - Git::SubmoduleItem submod; - submod.path = submodpath; - submod.id = getObjectID(item); - if (submod) { - OverrideWaitCursor; - GitPtr g = git(submod); - SubmoduleMainWindow *w = new SubmoduleMainWindow(this, g); - w->show(); - w->reset(); - } -#else + // サブモジュールのときは新しいプロセスを起動する QString commit_id = getSubmoduleCommitId(item); QString path = currentWorkingCopyDir() / submodpath; qDebug() << path << commit_id; QProcess::execute(global->this_executive_program, {path, "--commit-id", commit_id}); -#endif } else { // ファイルプロパティダイアログを表示する QString path = getFilePath(item); diff --git a/src/MainWindow.h b/src/MainWindow.h index 9ec45230..6f9a8860 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -160,8 +160,8 @@ class MainWindow : public QMainWindow { void updateFilesList(RepositoryWrapperFrame *frame, Git::CommitItem const &commit, bool wait); void updateRepositoriesList(); - void openRepository_(GitPtr g, bool keep_selection = false); - void openRepository_(RepositoryWrapperFrame *frame, GitPtr g, bool keep_selection = false); + void internalOpenRepository(GitPtr g, bool keep_selection = false); + void openRepositoryWithFrame(RepositoryWrapperFrame *frame, GitPtr g, bool keep_selection = false); QStringList selectedFiles_(QListWidget *listwidget) const; QStringList selectedFiles() const; @@ -282,7 +282,7 @@ class MainWindow : public QMainWindow { Git::CommitID idFromTag(RepositoryWrapperFrame *frame, const QString &tag); QString newTempFilePath(); int limitLogCount() const; - Git::Object cat_file_(RepositoryWrapperFrame *frame, GitPtr g, const QString &id); + Git::Object internalCatFile(RepositoryWrapperFrame *frame, GitPtr g, const QString &id); bool isThereUncommitedChanges() const; static void addDiffItems(const QList *diff_list, const std::function &add_item); Git::CommitItemList retrieveCommitLog(GitPtr g); @@ -392,7 +392,7 @@ class MainWindow : public QMainWindow { class GitFile { public: Git::Object::Type type = Git::Object::Type::NONE; - QByteArray data; + QByteArray content; operator bool () const { return type != Git::Object::Type::NONE; @@ -452,13 +452,13 @@ class MainWindow : public QMainWindow { GitPtr git(const QString &dir, const QString &submodpath, const QString &sshkey) const; GitPtr git(); GitPtr git(Git::SubmoduleItem const &submod); - GitFile catFile(const Git::CommitID &id, GitPtr g); void autoOpenRepository(QString dir, const QString &commit_id = {}); std::optional queryCommit(const QString &id); void checkout(RepositoryWrapperFrame *frame, QWidget *parent, const Git::CommitItem *commit, std::function accepted_callback = {}); void checkout(RepositoryWrapperFrame *frame); void jumpToCommit(RepositoryWrapperFrame *frame, QString id); - Git::Object cat_file(RepositoryWrapperFrame *frame, const QString &id); + Git::Object internalCatFile(RepositoryWrapperFrame *frame, const QString &id); + Git::Object catFile(const QString &id); bool addExistingLocalRepository(const QString &dir, bool open); bool saveAs(RepositoryWrapperFrame *frame, const QString &id, const QString &dstpath); QString determinFileType(QByteArray in); diff --git a/src/SubmoduleMainWindow.cpp b/src/SubmoduleMainWindow.cpp index af785a50..d1757fb7 100644 --- a/src/SubmoduleMainWindow.cpp +++ b/src/SubmoduleMainWindow.cpp @@ -47,6 +47,6 @@ RepositoryWrapperFrame *SubmoduleMainWindow::frame() void SubmoduleMainWindow::reset() { GitPtr g = git(); - mainwindow()->openRepository_(ui->frame_repository_wrapper2, g); + mainwindow()->openRepositoryWithFrame(ui->frame_repository_wrapper2, g); }