Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ebeea068d52a
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4aee93d5ce6c
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Aug 17, 2018

  1. fetchGit: use a better caching scheme

    The current usage technically works by putting multiple different
    repos in to the same git directory. However, it is very slow as
    Git tries very hard to find common commits between the two
    repositories. If the two repositories are large (like Nixpkgs and
    another long-running project,) it is maddeningly slow.
    
    This change busts the cache for existing deployments, but users
    will be promptly repaid in per-repository performance.
    graham-at-target committed Aug 17, 2018
    Copy the full SHA
    02098d2 View commit details

Commits on Nov 20, 2018

  1. 1
    Copy the full SHA
    3f4de91 View commit details
  2. Copy the full SHA
    4aee93d View commit details
Showing with 9 additions and 7 deletions.
  1. +7 −5 src/libexpr/primops/fetchGit.cc
  2. +2 −2 tests/fetchGit.sh
12 changes: 7 additions & 5 deletions src/libexpr/primops/fetchGit.cc
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
#include "download.hh"
#include "store-api.hh"
#include "pathlocks.hh"
#include "hash.hh"

#include <sys/time.h>

@@ -84,15 +85,16 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
if (rev != "" && !std::regex_match(rev, revRegex))
throw Error("invalid Git revision '%s'", rev);

Path cacheDir = getCacheDir() + "/nix/git";
deletePath(getCacheDir() + "/nix/git");

Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(htSHA256, uri).to_string(Base32, false);

if (!pathExists(cacheDir)) {
createDirs(dirOf(cacheDir));
runProgram("git", true, { "init", "--bare", cacheDir });
}

std::string localRef = hashString(htSHA256, fmt("%s-%s", uri, *ref)).to_string(Base32, false);

Path localRefFile = cacheDir + "/refs/heads/" + localRef;
Path localRefFile = cacheDir + "/refs/heads/" + *ref;

bool doFetch;
time_t now = time(0);
@@ -122,7 +124,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,

// FIXME: git stderr messes up our progress indicator, so
// we're using --quiet for now. Should process its stderr.
runProgram("git", true, { "-C", cacheDir, "fetch", "--quiet", "--force", "--", uri, *ref + ":" + localRef });
runProgram("git", true, { "-C", cacheDir, "fetch", "--quiet", "--force", "--", uri, fmt("%s:%s", *ref, *ref) });

struct timeval times[2];
times[0].tv_sec = now;
4 changes: 2 additions & 2 deletions tests/fetchGit.sh
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ clearStore

repo=$TEST_ROOT/git

rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix/git
rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix/gitv2

git init $repo
git -C $repo config user.email "foobar@example.com"
@@ -129,7 +129,7 @@ path5=$(nix eval --raw "(builtins.fetchGit { url = $repo; ref = \"dev\"; }).outP


# Nuke the cache
rm -rf $TEST_HOME/.cache/nix/git
rm -rf $TEST_HOME/.cache/nix/gitv2

# Try again, but without 'git' on PATH
NIX=$(command -v nix)