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: 090960b72547
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d58ab591d4f1
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Jul 22, 2020

  1. Separate concerns in scanForReferences with TeeSink

    This also will make it easier to use a `HashModuloSink` instead for CA
    derivations.
    Ericson2314 committed Jul 22, 2020
    Copy the full SHA
    c56356b View commit details

Commits on Jul 23, 2020

  1. Merge pull request #3850 from obsidiansystems/references-scan-cleanup

    Separate concerns in `scanForReferences` with TeeSink
    edolstra authored Jul 23, 2020
    Copy the full SHA
    d58ab59 View commit details
Showing with 7 additions and 8 deletions.
  1. +7 −8 src/libstore/references.cc
15 changes: 7 additions & 8 deletions src/libstore/references.cc
Original file line number Diff line number Diff line change
@@ -48,22 +48,19 @@ static void search(const unsigned char * s, size_t len,

struct RefScanSink : Sink
{
HashSink hashSink;
StringSet hashes;
StringSet seen;

string tail;

RefScanSink() : hashSink(htSHA256) { }
RefScanSink() { }

void operator () (const unsigned char * data, size_t len);
};


void RefScanSink::operator () (const unsigned char * data, size_t len)
{
hashSink(data, len);

/* It's possible that a reference spans the previous and current
fragment, so search in the concatenation of the tail of the
previous fragment and the start of the current fragment. */
@@ -82,7 +79,9 @@ void RefScanSink::operator () (const unsigned char * data, size_t len)
PathSet scanForReferences(const string & path,
const PathSet & refs, HashResult & hash)
{
RefScanSink sink;
RefScanSink refsSink;
HashSink hashSink { htSHA256 };
TeeSink sink { refsSink, hashSink };
std::map<string, Path> backMap;

/* For efficiency (and a higher hit rate), just search for the
@@ -97,7 +96,7 @@ PathSet scanForReferences(const string & path,
assert(s.size() == refLength);
assert(backMap.find(s) == backMap.end());
// parseHash(htSHA256, s);
sink.hashes.insert(s);
refsSink.hashes.insert(s);
backMap[s] = i;
}

@@ -106,13 +105,13 @@ PathSet scanForReferences(const string & path,

/* Map the hashes found back to their store paths. */
PathSet found;
for (auto & i : sink.seen) {
for (auto & i : refsSink.seen) {
std::map<string, Path>::iterator j;
if ((j = backMap.find(i)) == backMap.end()) abort();
found.insert(j->second);
}

hash = sink.hashSink.finish();
hash = hashSink.finish();

return found;
}