28 #include <filesystem> |
28 #include <filesystem> |
29 |
29 |
30 using namespace fm; |
30 using namespace fm; |
31 namespace fs = std::filesystem; |
31 namespace fs = std::filesystem; |
32 |
32 |
|
33 repository::repository(repository_type type, std::string path) noexcept |
|
34 : path(std::move(path)), |
|
35 name(fs::path(this->path).filename()), |
|
36 type(type) { |
|
37 } |
|
38 |
33 void repositories::scan(std::string path, unsigned depth) { |
39 void repositories::scan(std::string path, unsigned depth) { |
34 // check the base path |
40 // check the base path |
35 { |
41 { |
36 auto p = fs::path{path}; |
42 auto p = fs::path{path}; |
37 if (is_directory(p / ".hg")) { |
43 if (is_directory(p / ".hg")) { |
38 m_repositories.emplace_back(repository{canonical(p), HG}); |
44 m_repositories.emplace_back(HG, canonical(p)); |
39 return; |
45 return; |
40 } else if (is_directory(p / ".git")) { |
46 } else if (is_directory(p / ".git")) { |
41 m_repositories.emplace_back(repository{canonical(p), GIT}); |
47 m_repositories.emplace_back(GIT, canonical(p)); |
42 return; |
48 return; |
43 } else if (depth == 0) { |
49 } else if (depth == 0) { |
44 return; |
50 return; |
45 } |
51 } |
46 } |
52 } |
52 fs::directory_options::skip_permission_denied); |
58 fs::directory_options::skip_permission_denied); |
53 i != fs::recursive_directory_iterator(); ++i) { |
59 i != fs::recursive_directory_iterator(); ++i) { |
54 if (!i->is_directory()) continue; |
60 if (!i->is_directory()) continue; |
55 auto p = i->path(); |
61 auto p = i->path(); |
56 if (is_directory(p / ".hg")) { |
62 if (is_directory(p / ".hg")) { |
57 m_repositories.emplace_back(repository{canonical(p), HG}); |
63 m_repositories.emplace_back(HG, canonical(p)); |
58 i.disable_recursion_pending(); |
64 i.disable_recursion_pending(); |
59 } else if (is_directory(p / ".git")) { |
65 } else if (is_directory(p / ".git")) { |
60 m_repositories.emplace_back(repository{canonical(p), GIT}); |
66 m_repositories.emplace_back(GIT, canonical(p)); |
61 i.disable_recursion_pending(); |
67 i.disable_recursion_pending(); |
62 } else if (i.depth() == depth) { |
68 } else if (i.depth() == depth) { |
63 i.disable_recursion_pending(); |
69 i.disable_recursion_pending(); |
64 } |
70 } |
65 } |
71 } |