* Nix-store queries --references' and
referers' to query the pointer
graph. That is, `nix-store --query --references PATH' shows the set of paths referenced by PATH, and `nix-store --query --referers PATH' shows the set of paths referencing PATH.
This commit is contained in:
parent
96de272b48
commit
e0f4e587c3
|
@ -272,6 +272,16 @@ void queryReferences(const Path & storePath, PathSet & references)
|
|||
}
|
||||
|
||||
|
||||
void queryReferers(const Path & storePath, PathSet & referers)
|
||||
{
|
||||
Paths referers2;
|
||||
if (!isValidPath(storePath))
|
||||
throw Error(format("path `%1%' is not valid") % storePath);
|
||||
nixDB.queryStrings(noTxn, dbReferers, storePath, referers2);
|
||||
referers.insert(referers2.begin(), referers2.end());
|
||||
}
|
||||
|
||||
|
||||
static Substitutes readSubstitutes(const Transaction & txn,
|
||||
const Path & srcPath)
|
||||
{
|
||||
|
|
|
@ -84,6 +84,10 @@ void setReferences(const Transaction & txn, const Path & storePath,
|
|||
result is not cleared. */
|
||||
void queryReferences(const Path & storePath, PathSet & references);
|
||||
|
||||
/* Queries the set of incoming FS references for a store path. The
|
||||
result is not cleared. */
|
||||
void queryReferers(const Path & storePath, PathSet & referers);
|
||||
|
||||
/* Constructs a unique store path name. */
|
||||
Path makeStorePath(const string & type,
|
||||
const Hash & hash, const string & suffix);
|
||||
|
|
|
@ -64,10 +64,18 @@ static Path maybeUseOutput(const Path & storePath, bool useOutput)
|
|||
}
|
||||
|
||||
|
||||
static void printPathSet(const PathSet & paths)
|
||||
{
|
||||
for (PathSet::iterator i = paths.begin();
|
||||
i != paths.end(); i++)
|
||||
cout << format("%s\n") % *i;
|
||||
}
|
||||
|
||||
|
||||
/* Perform various sorts of queries. */
|
||||
static void opQuery(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
enum { qOutputs, qRequisites, qPredecessors, qGraph } query = qOutputs;
|
||||
enum { qOutputs, qRequisites, qReferences, qReferers, qGraph } query = qOutputs;
|
||||
bool useOutput = false;
|
||||
bool includeOutputs = false;
|
||||
|
||||
|
@ -75,6 +83,8 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
|||
i != opFlags.end(); i++)
|
||||
if (*i == "--outputs") query = qOutputs;
|
||||
else if (*i == "--requisites" || *i == "-R") query = qRequisites;
|
||||
else if (*i == "--references") query = qReferences;
|
||||
else if (*i == "--referers") query = qReferers;
|
||||
else if (*i == "--graph") query = qGraph;
|
||||
else if (*i == "--use-output" || *i == "-u") useOutput = true;
|
||||
else if (*i == "--include-outputs") includeOutputs = true;
|
||||
|
@ -92,33 +102,24 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
|||
break;
|
||||
}
|
||||
|
||||
case qRequisites: {
|
||||
case qRequisites:
|
||||
case qReferences:
|
||||
case qReferers: {
|
||||
PathSet paths;
|
||||
for (Strings::iterator i = opArgs.begin();
|
||||
i != opArgs.end(); i++)
|
||||
{
|
||||
Path path = maybeUseOutput(*i, useOutput);
|
||||
storePathRequisites(path, includeOutputs, paths);
|
||||
if (query == qRequisites)
|
||||
storePathRequisites(path, includeOutputs, paths);
|
||||
else if (query == qReferences) queryReferences(path, paths);
|
||||
else if (query == qReferers) queryReferers(path, paths);
|
||||
}
|
||||
for (PathSet::iterator i = paths.begin();
|
||||
i != paths.end(); i++)
|
||||
cout << format("%s\n") % *i;
|
||||
printPathSet(paths);
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
case qPredecessors: {
|
||||
for (Strings::iterator i = opArgs.begin();
|
||||
i != opArgs.end(); i++)
|
||||
{
|
||||
Paths preds = queryPredecessors(*i);
|
||||
for (Paths::iterator j = preds.begin();
|
||||
j != preds.end(); j++)
|
||||
cout << format("%s\n") % *j;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case qGraph: {
|
||||
PathSet roots;
|
||||
for (Strings::iterator i = opArgs.begin();
|
||||
|
|
Loading…
Reference in a new issue