mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
* New query `nix --query --predecessors' to print the predecessors of
a Nix expression.
This commit is contained in:
parent
0abe185688
commit
1d61e473c8
5 changed files with 29 additions and 2 deletions
|
@ -35,7 +35,8 @@ extern TableId dbSuccessors;
|
|||
|
||||
/* dbSuccessorsRev :: Path -> [Path]
|
||||
|
||||
The reverse mapping of dbSuccessors.
|
||||
The reverse mapping of dbSuccessors (i.e., it stores the
|
||||
predecessors of a Nix expression).
|
||||
*/
|
||||
extern TableId dbSuccessorsRev;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ Query flags:
|
|||
--list / -l: query the output paths (roots) of a Nix expression (default)
|
||||
--requisites / -r: print all paths necessary to realise expression
|
||||
--generators / -g: find expressions producing a subset of given ids
|
||||
--predecessors: print predecessors of a Nix expression
|
||||
--graph: print a dot graph rooted at given ids
|
||||
|
||||
Options:
|
||||
|
|
15
src/nix.cc
15
src/nix.cc
|
@ -73,7 +73,7 @@ Path maybeNormalise(const Path & ne, bool normalise)
|
|||
/* Perform various sorts of queries. */
|
||||
static void opQuery(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
enum { qList, qRequisites, qGenerators, qGraph
|
||||
enum { qList, qRequisites, qGenerators, qPredecessors, qGraph
|
||||
} query = qList;
|
||||
bool normalise = false;
|
||||
bool includeExprs = true;
|
||||
|
@ -84,6 +84,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
|||
if (*i == "--list" || *i == "-l") query = qList;
|
||||
else if (*i == "--requisites" || *i == "-r") query = qRequisites;
|
||||
else if (*i == "--generators" || *i == "-g") query = qGenerators;
|
||||
else if (*i == "--predecessors") query = qPredecessors;
|
||||
else if (*i == "--graph") query = qGraph;
|
||||
else if (*i == "--normalise" || *i == "-n") normalise = true;
|
||||
else if (*i == "--exclude-exprs") includeExprs = false;
|
||||
|
@ -139,6 +140,18 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
|||
}
|
||||
#endif
|
||||
|
||||
case qPredecessors: {
|
||||
for (Strings::iterator i = opArgs.begin();
|
||||
i != opArgs.end(); i++)
|
||||
{
|
||||
Paths preds = queryPredecessors(checkPath(*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();
|
||||
|
|
|
@ -104,6 +104,14 @@ void registerSuccessor(const Transaction & txn,
|
|||
}
|
||||
|
||||
|
||||
Paths queryPredecessors(const Path & sucPath)
|
||||
{
|
||||
Paths revs;
|
||||
nixDB.queryStrings(noTxn, dbSuccessorsRev, sucPath, revs);
|
||||
return revs;
|
||||
}
|
||||
|
||||
|
||||
void registerSubstitute(const Path & srcPath, const Path & subPath)
|
||||
{
|
||||
Transaction txn(nixDB);
|
||||
|
|
|
@ -22,6 +22,10 @@ void copyPath(const Path & src, const Path & dst);
|
|||
void registerSuccessor(const Transaction & txn,
|
||||
const Path & srcPath, const Path & sucPath);
|
||||
|
||||
/* Return the predecessors of the Nix expression stored at the given
|
||||
path. */
|
||||
Paths queryPredecessors(const Path & sucPath);
|
||||
|
||||
/* Register a substitute. */
|
||||
void registerSubstitute(const Path & srcPath, const Path & subPath);
|
||||
|
||||
|
|
Loading…
Reference in a new issue