Skip to content

Commit bd10b85

Browse files
committed
GitRepo::fetch(): Cleanup
1 parent 2975c2c commit bd10b85

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/libfetchers/git-utils.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ static git_packbuilder_progress PACKBUILDER_PROGRESS_CHECK_INTERRUPT = &packBuil
206206

207207
} // extern "C"
208208

209-
static void initRepoAtomically(std::filesystem::path &path, bool bare) {
209+
static void initRepoAtomically(std::filesystem::path &path, bool bare)
210+
{
210211
if (pathExists(path.string())) return;
211212

212213
Path tmpDir = createTempDir(os_string_to_string(PathViewNG { std::filesystem::path(path).parent_path() }));
@@ -544,13 +545,10 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
544545
// then use code that was removed in this commit (see blame)
545546

546547
auto dir = this->path;
547-
Strings gitArgs;
548-
if (shallow) {
549-
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec };
550-
}
551-
else {
552-
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--", url, refspec };
553-
}
548+
Strings gitArgs{"-C", dir.string(), "fetch", "--quiet", "--force"};
549+
if (shallow)
550+
append(gitArgs, {"--depth", "1"});
551+
append(gitArgs, {std::string("--"), url, refspec});
554552

555553
runProgram(RunOptions {
556554
.program = "git",

src/libutil/util.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ std::optional<typename T::value_type> pop(T & c)
274274
}
275275

276276

277+
/**
278+
* Append items to a container. TODO: remove this once we can use
279+
* C++23's `append_range()`.
280+
*/
281+
template<class C, typename T>
282+
void append(C & c, std::initializer_list<T> l)
283+
{
284+
c.insert(c.end(), l.begin(), l.end());
285+
}
286+
287+
277288
template<typename T>
278289
class Callback;
279290

0 commit comments

Comments
 (0)