Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jan 16, 2024
1 parent eb5261d commit 3710422
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1853,3 +1853,4 @@ void parseGitSubModules(const QByteArray &ba, QList<Git::SubmoduleItem> *out)
}



53 changes: 53 additions & 0 deletions src/GitObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QDirIterator>
#include <QFile>
#include <memory>
#include <set>

GitObjectManager::GitObjectManager()
{
Expand Down Expand Up @@ -448,3 +449,55 @@ bool parseGitTreeObject(GitObjectCache *objcache, const QString &commit_id, cons
}
return false;
}

/**
* @brief GitObjectManager::findObject
* @param id
* @param repo_local_dir
*/
QStringList GitObjectManager::findObject(const QString &id, QString const &repo_local_dir)
{
QStringList list;
std::set<QString> set;
if (Git::isValidID(id)) {
{
QString a = id.mid(0, 2);
QString b = id.mid(2);
QString dir = repo_local_dir / ".git/objects" / a;
QDirIterator it(dir);
while (it.hasNext()) {
it.next();
QFileInfo info = it.fileInfo();
if (info.isFile()) {
QString c = info.fileName();
if (c.startsWith(b)) {
set.insert(set.end(), a + c);
}
}
}
}
{
QString dir = repo_local_dir / ".git/objects/pack";
QDirIterator it(dir);
while (it.hasNext()) {
it.next();
QFileInfo info = it.fileInfo();
if (info.isFile() && info.fileName().startsWith("pack-") && info.fileName().endsWith(".idx")) {
GitPackIdxV2 idx;
idx.parse(info.absoluteFilePath(), false);
idx.each([&](GitPackIdxItem const *item){
QString item_id = GitPackIdxItem::qid(*item);
if (item_id.startsWith(id)) {
set.insert(item_id);
}
return true;
});
}
}
}
for (QString const &s : set) {
list.push_back(s);
}
}
return list;
}
2 changes: 2 additions & 0 deletions src/GitObjectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class GitObjectManager {
void setup(GitPtr g);
bool catFile(const Git::CommitID &id, QByteArray *out, Git::Object::Type *type);
void clearIndexes();

static QStringList findObject(const QString &id, const QString &repo_local_dir);
};

class GitObjectCache {
Expand Down
1 change: 0 additions & 1 deletion src/GitPackIdxV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct GitPackIdxItem {

class GitPackIdxV2 {
friend class GitObjectManager;
friend class MainWindow; // for debug
private:
QString pack_idx_path; // e.g. "/path/to/pack-56430ed038c968ded87eb3756dcde85bfafc10ce.idx"

Expand Down
60 changes: 16 additions & 44 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,13 @@ QStringList MainWindow::remotes() const
return m->remotes;
}

/**
* @brief MainWindow::findBranch
* @param frame
* @param id
*
* コミットIDからブランチを検索する
*/
QList<Git::Branch> MainWindow::findBranch(RepositoryWrapperFrame *frame, Git::CommitID const &id)
{
auto it = commitToBranchMapRef(frame).find(id);
Expand All @@ -1981,6 +1988,11 @@ QString MainWindow::tempfileHeader() const
return name.arg(QApplication::applicationPid());
}

/**
* @brief MainWindow::deleteTempFiles
*
* 一時ファイルを削除する
*/
void MainWindow::deleteTempFiles()
{
QString dir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
Expand Down Expand Up @@ -2373,8 +2385,10 @@ const Git::CommitItem *MainWindow::getLog(RepositoryWrapperFrame const *frame, i
}

/**
* @brief 樹形図情報を構築する
* @brief MainWindow::updateCommitGraph
* @param frame
*
* 樹形図情報を構築する
*/
void MainWindow::updateCommitGraph(RepositoryWrapperFrame *frame)
{
Expand Down Expand Up @@ -3220,49 +3234,7 @@ QPixmap MainWindow::getTransparentPixmap() const

QStringList MainWindow::findGitObject(const QString &id) const
{
QStringList list;
std::set<QString> set;
if (Git::isValidID(id)) {
{
QString a = id.mid(0, 2);
QString b = id.mid(2);
QString dir = m->current_repo.local_dir / ".git/objects" / a;
QDirIterator it(dir);
while (it.hasNext()) {
it.next();
QFileInfo info = it.fileInfo();
if (info.isFile()) {
QString c = info.fileName();
if (c.startsWith(b)) {
set.insert(set.end(), a + c);
}
}
}
}
{
QString dir = m->current_repo.local_dir / ".git/objects/pack";
QDirIterator it(dir);
while (it.hasNext()) {
it.next();
QFileInfo info = it.fileInfo();
if (info.isFile() && info.fileName().startsWith("pack-") && info.fileName().endsWith(".idx")) {
GitPackIdxV2 idx;
idx.parse(info.absoluteFilePath(), false);
idx.each([&](GitPackIdxItem const *item){
QString item_id = GitPackIdxItem::qid(*item);
if (item_id.startsWith(id)) {
set.insert(item_id);
}
return true;
});
}
}
}
for (QString const &s : set) {
list.push_back(s);
}
}
return list;
return GitObjectManager::findObject(id, m->current_repo.local_dir);
}

void MainWindow::writeLog(const char *ptr, int len, bool record)
Expand Down

0 comments on commit 3710422

Please sign in to comment.