Tue, 25 Feb 2025 18:22:55 +0100
add dist target
fixes #607
3 | 1 | /* Copyright 2025 Mike Becker. All rights reserved. |
2 | * | |
3 | * Redistribution and use in source and binary forms, with or without | |
4 | * modification, are permitted provided that the following conditions are met: | |
5 | * | |
6 | * 1. Redistributions of source code must retain the above copyright | |
7 | * notice, this list of conditions and the following disclaimer. | |
8 | * | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
20 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
21 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
22 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
23 | */ | |
24 | ||
25 | #include "repositories.h" | |
26 | ||
27 | #include <utility> | |
28 | #include <filesystem> | |
29 | ||
30 | using namespace fm; | |
31 | namespace fs = std::filesystem; | |
32 | ||
37
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
33 | repository::repository(repository_type type, std::string path) noexcept |
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
34 | : path(std::move(path)), |
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
35 | name(fs::path(this->path).filename()), |
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
36 | type(type) { |
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
37 | } |
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
38 | |
3 | 39 | void repositories::scan(std::string path, unsigned depth) { |
40 | // check the base path | |
41 | { | |
42 | auto p = fs::path{path}; | |
43 | if (is_directory(p / ".hg")) { | |
37
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
44 | m_repositories.emplace_back(HG, canonical(p)); |
3 | 45 | return; |
46 | } else if (is_directory(p / ".git")) { | |
37
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
47 | m_repositories.emplace_back(GIT, canonical(p)); |
3 | 48 | return; |
49 | } else if (depth == 0) { | |
50 | return; | |
51 | } | |
52 | } | |
53 | ||
54 | // if depth is non-zero, scan subdirs recursively | |
55 | --depth; | |
56 | for (auto i = fs::recursive_directory_iterator( | |
57 | std::move(path), | |
58 | fs::directory_options::skip_permission_denied); | |
59 | i != fs::recursive_directory_iterator(); ++i) { | |
60 | if (!i->is_directory()) continue; | |
61 | auto p = i->path(); | |
62 | if (is_directory(p / ".hg")) { | |
37
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
63 | m_repositories.emplace_back(HG, canonical(p)); |
3 | 64 | i.disable_recursion_pending(); |
65 | } else if (is_directory(p / ".git")) { | |
37
d7e9a1200e21
improve headings in separate repository view
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
66 | m_repositories.emplace_back(GIT, canonical(p)); |
3 | 67 | i.disable_recursion_pending(); |
68 | } else if (i.depth() == depth) { | |
69 | i.disable_recursion_pending(); | |
70 | } | |
71 | } | |
72 | } |