forked from lix-project/lix
Merge branch 'fetchGit-fast-revision-update'
This commit is contained in:
commit
11a7f8ce14
|
@ -89,17 +89,29 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
||||||
|
|
||||||
Path localRefFile = cacheDir + "/refs/heads/" + localRef;
|
Path localRefFile = cacheDir + "/refs/heads/" + localRef;
|
||||||
|
|
||||||
/* If the local ref is older than ‘tarball-ttl’ seconds, do a git
|
bool doFetch;
|
||||||
fetch to update the local ref to the remote ref. */
|
|
||||||
time_t now = time(0);
|
time_t now = time(0);
|
||||||
|
/* If a rev was specified, we need to fetch if it's not in the
|
||||||
|
repo. */
|
||||||
|
if (rev != "") {
|
||||||
|
try {
|
||||||
|
runProgram("git", true, { "-C", cacheDir, "cat-file", "-e", rev });
|
||||||
|
doFetch = false;
|
||||||
|
} catch (ExecError & e) {
|
||||||
|
if (WIFEXITED(e.status)) {
|
||||||
|
doFetch = true;
|
||||||
|
} else {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* 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;
|
struct stat st;
|
||||||
if (stat(localRefFile.c_str(), &st) != 0 ||
|
doFetch = stat(localRefFile.c_str(), &st) != 0 ||
|
||||||
st.st_mtime <= now - settings.tarballTtl)
|
st.st_mtime <= now - settings.tarballTtl;
|
||||||
{
|
}
|
||||||
if (rev == "" ||
|
if (doFetch)
|
||||||
chomp(runProgram(
|
|
||||||
RunOptions("git", { "-C", cacheDir, "cat-file", "-t", rev })
|
|
||||||
.killStderr(true)).second) != "commit")
|
|
||||||
{
|
{
|
||||||
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri));
|
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri));
|
||||||
|
|
||||||
|
@ -115,7 +127,6 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
|
||||||
|
|
||||||
utimes(localRefFile.c_str(), times);
|
utimes(localRefFile.c_str(), times);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: check whether rev is an ancestor of ref.
|
// FIXME: check whether rev is an ancestor of ref.
|
||||||
GitInfo gitInfo;
|
GitInfo gitInfo;
|
||||||
|
|
|
@ -21,6 +21,7 @@ export NIX_REMOTE=$NIX_REMOTE_
|
||||||
unset NIX_PATH
|
unset NIX_PATH
|
||||||
export TEST_HOME=$TEST_ROOT/test-home
|
export TEST_HOME=$TEST_ROOT/test-home
|
||||||
export HOME=$TEST_HOME
|
export HOME=$TEST_HOME
|
||||||
|
unset XDG_CACHE_HOME
|
||||||
mkdir -p $TEST_HOME
|
mkdir -p $TEST_HOME
|
||||||
|
|
||||||
export PATH=@bindir@:$PATH
|
export PATH=@bindir@:$PATH
|
||||||
|
|
|
@ -86,3 +86,10 @@ git -C $repo commit -m 'Bla3' -a
|
||||||
|
|
||||||
path4=$(nix eval --tarball-ttl 0 --raw "(builtins.fetchGit file://$repo).outPath")
|
path4=$(nix eval --tarball-ttl 0 --raw "(builtins.fetchGit file://$repo).outPath")
|
||||||
[[ $path2 = $path4 ]]
|
[[ $path2 = $path4 ]]
|
||||||
|
|
||||||
|
# tarball-ttl should be ignored if we specify a rev
|
||||||
|
echo delft > $repo/hello
|
||||||
|
git -C $repo add hello
|
||||||
|
git -C $repo commit -m 'Bla4'
|
||||||
|
rev3=$(git -C $repo rev-parse HEAD)
|
||||||
|
nix eval --tarball-ttl 3600 "(builtins.fetchGit { url = $repo; rev = \"$rev3\"; })" >/dev/null
|
||||||
|
|
Loading…
Reference in a new issue