diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-07-16 11:05:59 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-07-16 11:05:59 +0000 |
commit | b9ecadee6e32eddac07d09a228f0dda2b340c7ac (patch) | |
tree | 0d4c3c1279801332235202dcab52ba757ed0c82a | |
parent | c11bbcfd26e554ca044c1cce293097e4e87ef31e (diff) | |
download | guix-b9ecadee6e32eddac07d09a228f0dda2b340c7ac.tar.gz |
* Fix the -qr query.
-rw-r--r-- | src/fstate.cc | 36 | ||||
-rw-r--r-- | src/fstate.hh | 7 | ||||
-rw-r--r-- | src/nix.cc | 12 |
3 files changed, 40 insertions, 15 deletions
diff --git a/src/fstate.cc b/src/fstate.cc index 60a8d475c9..cdd620cf10 100644 --- a/src/fstate.cc +++ b/src/fstate.cc @@ -186,9 +186,10 @@ void registerSuccessor(const FSId & id1, const FSId & id2) } -static FSId storeSuccessor(const FSId & id1, FState sc) +static FSId storeSuccessor(const FSId & id1, FState sc, + string * p) { - FSId id2 = writeTerm(sc, "-s-" + (string) id1, 0); + FSId id2 = writeTerm(sc, "-s-" + (string) id1, p); registerSuccessor(id1, id2); return id2; } @@ -267,7 +268,7 @@ static FState unparseSlice(const Slice & slice) typedef set<FSId> FSIdSet; -Slice normaliseFState(FSId id) +static Slice normaliseFState2(FSId id, StringSet & usedPaths) { debug(format("normalising fstate")); Nest nest(true); @@ -281,12 +282,16 @@ Slice normaliseFState(FSId id) } /* Get the fstate expression. */ - FState fs = termFromId(id); + string fsPath; + FState fs = termFromId(id, &fsPath); /* Already in normal form (i.e., a slice)? */ if (ATgetType(fs) == AT_APPL && (string) ATgetName(ATgetAFun(fs)) == "Slice") + { + usedPaths.insert(fsPath); return parseSlice(fs); + } /* Then we it's a Derive node. */ ATermList outs, ins, bnds; @@ -402,12 +407,20 @@ Slice normaliseFState(FSId id) FState nf = unparseSlice(slice); debug(printTerm(nf)); - storeSuccessor(id, nf); + storeSuccessor(id, nf, &fsPath); + usedPaths.insert(fsPath); return slice; } +Slice normaliseFState(FSId id) +{ + StringSet dummy; + return normaliseFState2(id, dummy); +} + + static void checkSlice(const Slice & slice) { if (slice.elems.size() == 0) @@ -475,7 +488,7 @@ void realiseSlice(const Slice & slice) } -Strings fstatePaths(FSId id, bool normalise) +Strings fstatePaths(const FSId & id, bool normalise) { Strings paths; @@ -520,3 +533,14 @@ Strings fstatePaths(FSId id, bool normalise) return paths; } + + +StringSet fstateRefs(const FSId & id) +{ + StringSet paths; + Slice slice = normaliseFState2(id, paths); + for (SliceElems::const_iterator i = slice.elems.begin(); + i != slice.elems.end(); i++) + paths.insert(i->path); + return paths; +} diff --git a/src/fstate.hh b/src/fstate.hh index 72fc528052..2ae876b7cd 100644 --- a/src/fstate.hh +++ b/src/fstate.hh @@ -101,7 +101,12 @@ Slice normaliseFState(FSId id); /* Realise a Slice in the file system. */ void realiseSlice(const Slice & slice); -Strings fstatePaths(FSId id, bool normalise); +/* Get the list of root (output) paths of the given + fstate-expression. */ +Strings fstatePaths(const FSId & id, bool normalise); + +/* Get the list of paths referenced by the given fstate-expression. */ +StringSet fstateRefs(const FSId & id); #endif /* !__FSTATE_H */ diff --git a/src/nix.cc b/src/nix.cc index 22928880f9..ae016824d1 100644 --- a/src/nix.cc +++ b/src/nix.cc @@ -159,23 +159,19 @@ static void opQuery(Strings opFlags, Strings opArgs) case qPath: { Strings paths = fstatePaths(id, true); - for (Strings::iterator i = paths.begin(); - i != paths.end(); i++) - cout << format("%s\n") % *i; + for (Strings::iterator j = paths.begin(); + j != paths.end(); j++) + cout << format("%s\n") % *j; break; } -#if 0 case qRefs: { - StringSet refs; - FState fs = hash2fstate(hash); - fstateRefs(realiseFState(fs, refs), refs); + StringSet refs = fstateRefs(id); for (StringSet::iterator j = refs.begin(); j != refs.end(); j++) cout << format("%s\n") % *j; break; } -#endif default: abort(); |