Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More mingw build fixes (backport #12303) #12312

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ struct GitInputScheme : InputScheme

auto result = runProgram(RunOptions {
.program = "git",
<<<<<<< HEAD
.args = {"-C", repoInfo.url, "--git-dir", repoInfo.gitDir, "check-ignore", "--quiet", std::string(path.rel())},
=======
.args = {"-C", repoPath->string(), "--git-dir", repoInfo.gitDir, "check-ignore", "--quiet", std::string(path.rel())},
>>>>>>> a78f55ef9 (GitInputScheme: Fix mingw build)
});
auto exitCode =
#ifndef WIN32 // TODO abstract over exit status handling on Windows
Expand All @@ -344,15 +348,23 @@ struct GitInputScheme : InputScheme
if (exitCode != 0) {
// The path is not `.gitignore`d, we can add the file.
runProgram("git", true,
<<<<<<< HEAD
{ "-C", repoInfo.url, "--git-dir", repoInfo.gitDir, "add", "--intent-to-add", "--", std::string(path.rel()) });
=======
{ "-C", repoPath->string(), "--git-dir", repoInfo.gitDir, "add", "--intent-to-add", "--", std::string(path.rel()) });
>>>>>>> a78f55ef9 (GitInputScheme: Fix mingw build)


if (commitMsg) {
// Pause the logger to allow for user input (such as a gpg passphrase) in `git commit`
logger->pause();
Finally restoreLogger([]() { logger->resume(); });
runProgram("git", true,
<<<<<<< HEAD
{ "-C", repoInfo.url, "--git-dir", repoInfo.gitDir, "commit", std::string(path.rel()), "-F", "-" },
=======
{ "-C", repoPath->string(), "--git-dir", repoInfo.gitDir, "commit", std::string(path.rel()), "-F", "-" },
>>>>>>> a78f55ef9 (GitInputScheme: Fix mingw build)
*commitMsg);
}
}
Expand Down Expand Up @@ -444,7 +456,7 @@ struct GitInputScheme : InputScheme
return repoInfo;
}

uint64_t getLastModified(const RepoInfo & repoInfo, const std::string & repoDir, const Hash & rev) const
uint64_t getLastModified(const RepoInfo & repoInfo, const std::filesystem::path & repoDir, const Hash & rev) const
{
Cache::Key key{"gitLastModified", {{"rev", rev.gitRev()}}};

Expand All @@ -460,7 +472,7 @@ struct GitInputScheme : InputScheme
return lastModified;
}

uint64_t getRevCount(const RepoInfo & repoInfo, const std::string & repoDir, const Hash & rev) const
uint64_t getRevCount(const RepoInfo & repoInfo, const std::filesystem::path & repoDir, const Hash & rev) const
{
Cache::Key key{"gitRevCount", {{"rev", rev.gitRev()}}};

Expand Down Expand Up @@ -529,29 +541,34 @@ struct GitInputScheme : InputScheme
auto ref = originalRef ? *originalRef : getDefaultRef(repoInfo);
input.attrs.insert_or_assign("ref", ref);

Path repoDir;
std::filesystem::path repoDir;

if (repoInfo.isLocal) {
repoDir = repoInfo.url;
if (!input.getRev())
input.attrs.insert_or_assign("rev", GitRepo::openRepo(repoDir)->resolveRef(ref).gitRev());
} else {
<<<<<<< HEAD
Path cacheDir = getCachePath(repoInfo.url, getShallowAttr(input));
=======
auto repoUrl = std::get<ParsedURL>(repoInfo.location);
std::filesystem::path cacheDir = getCachePath(repoUrl.to_string(), getShallowAttr(input));
>>>>>>> a78f55ef9 (GitInputScheme: Fix mingw build)
repoDir = cacheDir;
repoInfo.gitDir = ".";

createDirs(dirOf(cacheDir));
PathLocks cacheDirLock({cacheDir});
std::filesystem::create_directories(cacheDir.parent_path());
PathLocks cacheDirLock({cacheDir.string()});

auto repo = GitRepo::openRepo(cacheDir, true, true);

// We need to set the origin so resolving submodule URLs works
repo->setRemote("origin", repoInfo.url);

Path localRefFile =
auto localRefFile =
ref.compare(0, 5, "refs/") == 0
? cacheDir + "/" + ref
: cacheDir + "/refs/heads/" + ref;
? cacheDir / ref
: cacheDir / "refs/heads" / ref;

bool doFetch;
time_t now = time(0);
Expand All @@ -567,7 +584,7 @@ struct GitInputScheme : InputScheme
/* If the local ref is older than ‘tarball-ttl’ seconds, do a
git fetch to update the local ref to the remote ref. */
struct stat st;
doFetch = stat(localRefFile.c_str(), &st) != 0 ||
doFetch = stat(localRefFile.string().c_str(), &st) != 0 ||
!isCacheFileWithinTtl(now, st);
}
}
Expand All @@ -587,7 +604,7 @@ struct GitInputScheme : InputScheme

repo->fetch(repoInfo.url, fmt("%s:%s", fetchRef, fetchRef), getShallowAttr(input));
} catch (Error & e) {
if (!pathExists(localRefFile)) throw;
if (!std::filesystem::exists(localRefFile)) throw;
logError(e.info());
warn("could not update local clone of Git repository '%s'; continuing with the most recent version", repoInfo.url);
}
Expand Down Expand Up @@ -805,8 +822,30 @@ struct GitInputScheme : InputScheme
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
{
if (auto rev = input.getRev())
<<<<<<< HEAD
return rev->gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "");
else
=======
return makeFingerprint(*rev);
else {
auto repoInfo = getRepoInfo(input);
if (auto repoPath = repoInfo.getPath(); repoPath && repoInfo.workdirInfo.headRev && repoInfo.workdirInfo.submodules.empty()) {
/* Calculate a fingerprint that takes into account the
deleted and modified/added files. */
HashSink hashSink{HashAlgorithm::SHA512};
for (auto & file : repoInfo.workdirInfo.dirtyFiles) {
writeString("modified:", hashSink);
writeString(file.abs(), hashSink);
dumpPath((*repoPath / file.rel()).string(), hashSink);
}
for (auto & file : repoInfo.workdirInfo.deletedFiles) {
writeString("deleted:", hashSink);
writeString(file.abs(), hashSink);
}
return makeFingerprint(*repoInfo.workdirInfo.headRev)
+ ";d=" + hashSink.finish().first.to_string(HashFormat::Base16, false);
}
>>>>>>> a78f55ef9 (GitInputScheme: Fix mingw build)
return std::nullopt;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libflake/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ LockedFlake lockFlake(
auto relPath = (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock";
auto outputLockFilePath = *sourcePath + "/" + relPath;

bool lockFileExists = pathExists(outputLockFilePath);
bool lockFileExists = fs::symlink_exists(outputLockFilePath);

auto s = chomp(diff);
if (lockFileExists) {
Expand Down
4 changes: 2 additions & 2 deletions src/nix/upgrade-nix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand

// FIXME: don't call an external process.
runProgram(getNixBin("nix-env").string(), false,
{"--profile", profileDir, "-i", store->printStorePath(storePath), "--no-sandbox"});
{"--profile", profileDir.string(), "-i", store->printStorePath(storePath), "--no-sandbox"});
}

printInfo(ANSI_GREEN "upgrade to version %s done" ANSI_NORMAL, version);
Expand All @@ -120,7 +120,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand

// Resolve profile to /nix/var/nix/profiles/<name> link.
while (canonPath(profileDir.string()).find("/profiles/") == std::string::npos && std::filesystem::is_symlink(profileDir))
profileDir = readLink(profileDir);
profileDir = readLink(profileDir.string());

printInfo("found profile %s", profileDir);

Expand Down
Loading