|
| 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 | +} } |
0 commit comments