Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit c36ac2d

Browse files
committed
Add: RefreshRepository Service
1 parent 302c1c5 commit c36ac2d

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

Libs/libRepoMan/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SET( SRC_FILES
4848
Backend/RepoMan.cpp
4949

5050
Services/OpenRepository.cpp
51+
Services/RefreshRepository.cpp
5152
)
5253

5354
SET( PUB_HDR_FILES
@@ -99,6 +100,7 @@ SET( PRI_HDR_FILES
99100
Backend/RepoLocker.hpp
100101

101102
Services/OpenRepository.hpp
103+
Services/RefreshRepository.hpp
102104
)
103105

104106
SET( HID_FILES
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* MacGitver
3+
* Copyright (C) 2012-2015 The MacGitver-Developers <[email protected]>
4+
*
5+
* (C) Sascha Cunz <[email protected]>
6+
* (C) Cunz RaD Ltd.
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the terms of the
9+
* GNU General Public License (Version 2) as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along with this program; if
16+
* not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
#include "libRepoMan/Backend/RepoMan.hpp"
21+
22+
#include "libRepoMan/Backend/RepoLocker.hpp"
23+
#include "libRepoMan/Services/RefreshRepository.hpp"
24+
25+
#include "libGitWrap/Submodule.hpp"
26+
27+
#include <QDebug>
28+
29+
namespace RM { namespace Services {
30+
31+
RefreshRepository::RefreshRepository(const Frontend::Repo& repo)
32+
: mRepo()
33+
{
34+
35+
}
36+
37+
RefreshRepository::RefreshRepository(const Data::Repo::SPtr& repo)
38+
: mRepo(repo)
39+
{
40+
}
41+
42+
void RefreshRepository::run()
43+
{
44+
Backend::RepoLocker lock(mRepo);
45+
46+
mGitRepo = mRepo->gitRepo(false);
47+
if (!mGitRepo.isValid()) {
48+
return;
49+
}
50+
51+
scanSubmodules();
52+
}
53+
54+
55+
void RefreshRepository::scanSubmodules()
56+
{
57+
Git::Result r;
58+
Git::Submodule::List subs = mGitRepo.submodules(r);
59+
if (!r) {
60+
return;
61+
}
62+
63+
Data::Repo::SList oldSubmodules = Data::sharedFromWeakList<Data::Repo>(mRepo->submodules());
64+
65+
foreach (Git::Submodule sub, subs) {
66+
Git::Result child;
67+
68+
Git::Repository subRepo = sub.subRepository(child);
69+
if (!child) {
70+
// If we cannot load the repository, keep it in list of submodules to remove.
71+
continue;
72+
}
73+
Q_ASSERT(subRepo.isValid());
74+
75+
QString path = subRepo.workTreePath();
76+
77+
if (path.endsWith(L'/')) {
78+
path = path.left(path.length() - 1);
79+
}
80+
81+
auto it = std::find(oldSubmodules.begin(), oldSubmodules.end(),
82+
mRepo->repoByPath(path, true));
83+
if (it != oldSubmodules.end()) {
84+
oldSubmodules.erase(it);
85+
}
86+
else {
87+
// ###REPOMAN
88+
qDebug() << "Existing Submodule does not exist in data structure";
89+
// subInfo = new Submodule(subRepo, p);
90+
}
91+
}
92+
93+
foreach (Data::Repo::WPtr repo, oldSubmodules) {
94+
// ###REPOMAN
95+
Q_UNUSED(repo);
96+
// dataOf<Repo>(repo)->terminateObject();
97+
}
98+
}
99+
100+
} }
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* MacGitver
3+
* Copyright (C) 2012-2015 The MacGitver-Developers <[email protected]>
4+
*
5+
* (C) Sascha Cunz <[email protected]>
6+
* (C) Cunz RaD Ltd.
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the terms of the
9+
* GNU General Public License (Version 2) as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along with this program; if
16+
* not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
#pragma once
21+
22+
#include "libRepoMan/Backend/AbstractService.hpp"
23+
#include "libRepoMan/Data/Repo.hpp"
24+
25+
namespace RM { namespace Services {
26+
27+
class RefreshRepository
28+
: public Backend::AbstractService
29+
{
30+
Q_OBJECT
31+
public:
32+
RefreshRepository(const Frontend::Repo& repo);
33+
RefreshRepository(const Data::Repo::SPtr& repo);
34+
35+
private:
36+
void run();
37+
38+
private:
39+
void scanSubmodules();
40+
41+
private:
42+
Data::Repo::SPtr mRepo;
43+
Git::Repository mGitRepo;
44+
};
45+
46+
} }

0 commit comments

Comments
 (0)