mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
GitRepo::fetch(): Cleanup
(cherry picked from commit bd10b859f7
)
# Conflicts:
# src/libfetchers/git-utils.cc
This commit is contained in:
parent
532092a812
commit
4511c47ab7
2 changed files with 17 additions and 8 deletions
|
@ -159,7 +159,8 @@ static Object peelToTreeOrBlob(git_object * obj)
|
|||
return peelObject<Object>(obj, GIT_OBJECT_TREE);
|
||||
}
|
||||
|
||||
static void initRepoAtomically(std::filesystem::path &path, bool bare) {
|
||||
static void initRepoAtomically(std::filesystem::path &path, bool bare)
|
||||
{
|
||||
if (pathExists(path.string())) return;
|
||||
|
||||
Path tmpDir = createTempDir(std::filesystem::path(path).parent_path());
|
||||
|
@ -416,13 +417,10 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
|||
// then use code that was removed in this commit (see blame)
|
||||
|
||||
auto dir = this->path;
|
||||
Strings gitArgs;
|
||||
if (shallow) {
|
||||
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec };
|
||||
}
|
||||
else {
|
||||
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--", url, refspec };
|
||||
}
|
||||
Strings gitArgs{"-C", dir.string(), "fetch", "--quiet", "--force"};
|
||||
if (shallow)
|
||||
append(gitArgs, {"--depth", "1"});
|
||||
append(gitArgs, {std::string("--"), url, refspec});
|
||||
|
||||
runProgram(RunOptions {
|
||||
.program = "git",
|
||||
|
|
|
@ -295,6 +295,17 @@ std::optional<typename T::value_type> pop(T & c)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append items to a container. TODO: remove this once we can use
|
||||
* C++23's `append_range()`.
|
||||
*/
|
||||
template<class C, typename T>
|
||||
void append(C & c, std::initializer_list<T> l)
|
||||
{
|
||||
c.insert(c.end(), l.begin(), l.end());
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
class Callback;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue