* New query `nix --query --predecessors' to print the predecessors of

a Nix expression.
This commit is contained in:
Eelco Dolstra 2003-10-10 15:25:21 +00:00
parent 0abe185688
commit 1d61e473c8
5 changed files with 29 additions and 2 deletions

View File

@ -35,7 +35,8 @@ extern TableId dbSuccessors;
/* dbSuccessorsRev :: Path -> [Path] /* 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; extern TableId dbSuccessorsRev;

View File

@ -24,6 +24,7 @@ Query flags:
--list / -l: query the output paths (roots) of a Nix expression (default) --list / -l: query the output paths (roots) of a Nix expression (default)
--requisites / -r: print all paths necessary to realise expression --requisites / -r: print all paths necessary to realise expression
--generators / -g: find expressions producing a subset of given ids --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 --graph: print a dot graph rooted at given ids
Options: Options:

View File

@ -73,7 +73,7 @@ Path maybeNormalise(const Path & ne, bool normalise)
/* Perform various sorts of queries. */ /* Perform various sorts of queries. */
static void opQuery(Strings opFlags, Strings opArgs) static void opQuery(Strings opFlags, Strings opArgs)
{ {
enum { qList, qRequisites, qGenerators, qGraph enum { qList, qRequisites, qGenerators, qPredecessors, qGraph
} query = qList; } query = qList;
bool normalise = false; bool normalise = false;
bool includeExprs = true; bool includeExprs = true;
@ -84,6 +84,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
if (*i == "--list" || *i == "-l") query = qList; if (*i == "--list" || *i == "-l") query = qList;
else if (*i == "--requisites" || *i == "-r") query = qRequisites; else if (*i == "--requisites" || *i == "-r") query = qRequisites;
else if (*i == "--generators" || *i == "-g") query = qGenerators; else if (*i == "--generators" || *i == "-g") query = qGenerators;
else if (*i == "--predecessors") query = qPredecessors;
else if (*i == "--graph") query = qGraph; else if (*i == "--graph") query = qGraph;
else if (*i == "--normalise" || *i == "-n") normalise = true; else if (*i == "--normalise" || *i == "-n") normalise = true;
else if (*i == "--exclude-exprs") includeExprs = false; else if (*i == "--exclude-exprs") includeExprs = false;
@ -139,6 +140,18 @@ static void opQuery(Strings opFlags, Strings opArgs)
} }
#endif #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: { case qGraph: {
PathSet roots; PathSet roots;
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();

View File

@ -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) void registerSubstitute(const Path & srcPath, const Path & subPath)
{ {
Transaction txn(nixDB); Transaction txn(nixDB);

View File

@ -22,6 +22,10 @@ void copyPath(const Path & src, const Path & dst);
void registerSuccessor(const Transaction & txn, void registerSuccessor(const Transaction & txn,
const Path & srcPath, const Path & sucPath); 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. */ /* Register a substitute. */
void registerSubstitute(const Path & srcPath, const Path & subPath); void registerSubstitute(const Path & srcPath, const Path & subPath);