mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00:59 +01:00
Fixed bugs, cleaned up some code
This commit is contained in:
parent
afb445957d
commit
bc2fbabc12
6 changed files with 74 additions and 57 deletions
|
|
@ -10,6 +10,4 @@ if [ "$#" != 4 ] ; then
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $statepath
|
$svnbin merge -r HEAD:$torevision $repos $statepath
|
||||||
$svnbin merge -r HEAD:$torevision $repos
|
|
||||||
cd -
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,4 @@ if [ "$#" != 4 ] ; then
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $statepath
|
$svnbin merge -r HEAD:$torevision $repos $statepath
|
||||||
$svnbin merge -r HEAD:$torevision $repos
|
|
||||||
cd -
|
|
||||||
|
|
|
||||||
|
|
@ -546,8 +546,16 @@ bool Database::queryStateReferences(const Transaction & txn, TableId table,
|
||||||
Strings keys;
|
Strings keys;
|
||||||
enumTable(txn, table, keys); //get all revisions
|
enumTable(txn, table, keys); //get all revisions
|
||||||
|
|
||||||
string key;
|
//Check if this revision exists key in the table
|
||||||
if(revision == -1){
|
string key = makeStatePathRevision(statePath, revision);
|
||||||
|
bool found = false;
|
||||||
|
for (Strings::const_iterator i = keys.begin(); i != keys.end(); ++i) {
|
||||||
|
if(key == *i)
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
key = ""; //reset
|
||||||
|
if(revision == -1 || (!found)){
|
||||||
bool foundsomething = lookupHighestRevivison(keys, statePath, key);
|
bool foundsomething = lookupHighestRevivison(keys, statePath, key);
|
||||||
if(!foundsomething)
|
if(!foundsomething)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -555,23 +563,18 @@ bool Database::queryStateReferences(const Transaction & txn, TableId table,
|
||||||
else
|
else
|
||||||
key = makeStatePathRevision(statePath, revision);
|
key = makeStatePathRevision(statePath, revision);
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
printMsg(lvlError, format("Warning: References for revision '%1%' not was not found, so taking the highest rev-key possible for statePath '%2%'") % revision % statePath);
|
||||||
|
|
||||||
|
|
||||||
return queryStrings(txn, table, key, references); //now that we have the key, we can query the references
|
return queryStrings(txn, table, key, references); //now that we have the key, we can query the references
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Database::queryStateReferrers(const Transaction & txn, TableId table,
|
bool Database::queryStateReferrers(const Transaction & txn, TableId table,
|
||||||
const Path & statePath, Strings & referrers, int revision)
|
const Path & statePath, Strings & referrers, int revision)
|
||||||
{
|
{
|
||||||
//PathSet referrers;
|
//Exactly the same as queryStateReferences
|
||||||
Strings keys;
|
return queryStateReferences(txn, table, statePath, referrers, revision);
|
||||||
Path revisionedStatePath = makeStatePathRevision(statePath, revision);
|
|
||||||
|
|
||||||
enumTable(txn, table, keys, revisionedStatePath + string(1, (char) 0));
|
|
||||||
|
|
||||||
for (Strings::iterator i = keys.begin(); i != keys.end(); ++i)
|
|
||||||
printMsg(lvlError, format("queryStateReferrers %1%") % *i);
|
|
||||||
//referrers.insert(stripPrefix(storePath, *i));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -591,10 +594,8 @@ void Database::setStateRevisions(const Transaction & txn, TableId table,
|
||||||
sorted_revisions.push_back(revisions.at(*i));
|
sorted_revisions.push_back(revisions.at(*i));
|
||||||
|
|
||||||
//////////////////
|
//////////////////
|
||||||
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i){
|
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i)
|
||||||
printMsg(lvlError, format("Insert: %1% into %2%") % int2String(revisions.at(*i)) % *i);
|
printMsg(lvlError, format("Insert: %1% into %2%") % int2String(revisions.at(*i)) % *i);
|
||||||
|
|
||||||
}
|
|
||||||
//////////////////
|
//////////////////
|
||||||
|
|
||||||
//Convert the int's into Strings
|
//Convert the int's into Strings
|
||||||
|
|
@ -639,6 +640,9 @@ bool Database::queryStateRevisions(const Transaction & txn, TableId table,
|
||||||
revisions.push_back(getRevision);
|
revisions.push_back(getRevision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!succeed)
|
||||||
|
throw Error(format("Revision '%1%' not found of statePath '%2%'") % int2String(revision) % statePath);
|
||||||
|
|
||||||
return succeed;
|
return succeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,7 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath,
|
||||||
if (references.size() > 0 && !isRealisableComponentOrStatePath(txn, store_or_statePath))
|
if (references.size() > 0 && !isRealisableComponentOrStatePath(txn, store_or_statePath))
|
||||||
throw Error(format("cannot set references for path `%1%' which is invalid and has no substitutes") % store_or_statePath);
|
throw Error(format("cannot set references for path `%1%' which is invalid and has no substitutes") % store_or_statePath);
|
||||||
|
|
||||||
printMsg(lvlError, format("Setting references for %1%") % store_or_statePath);
|
printMsg(lvlError, format("Setting references for %1% (revision:%2%)") % store_or_statePath % int2String(revision));
|
||||||
for (PathSet::iterator i = references.begin(); i != references.end(); ++i)
|
for (PathSet::iterator i = references.begin(); i != references.end(); ++i)
|
||||||
printMsg(lvlError, format("'%2%' has references: %1%") % *i % store_or_statePath);
|
printMsg(lvlError, format("'%2%' has references: %1%") % *i % store_or_statePath);
|
||||||
for (PathSet::iterator i = stateReferences.begin(); i != stateReferences.end(); ++i)
|
for (PathSet::iterator i = stateReferences.begin(); i != stateReferences.end(); ++i)
|
||||||
|
|
@ -1598,8 +1598,6 @@ PathSet mergeNewDerivationIntoList(const Path & storepath, const Path & newdrv,
|
||||||
*/
|
*/
|
||||||
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision)
|
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision)
|
||||||
{
|
{
|
||||||
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
computeFSClosure(storeOrstatePath, paths, withComponents, withState, revision);
|
computeFSClosure(storeOrstatePath, paths, withComponents, withState, revision);
|
||||||
|
|
||||||
if (includeOutputs) {
|
if (includeOutputs) {
|
||||||
|
|
@ -1752,9 +1750,6 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Register Valid again if neccesary
|
Register Valid again if neccesary
|
||||||
update the extra references in a new table??? why???
|
|
||||||
(remember we need to keep the old as the basis, and things can change, the db is not consistent anymore then ....)
|
|
||||||
But we also dont want useless refereces ......
|
|
||||||
|
|
||||||
Update the 2 references tables: all state paths get: Path statepath --> List(int revnumber, List(References))
|
Update the 2 references tables: all state paths get: Path statepath --> List(int revnumber, List(References))
|
||||||
TODO EDIT TABLES references,references_state,referrers,referrers_state
|
TODO EDIT TABLES references,references_state,referrers,referrers_state
|
||||||
|
|
@ -1783,9 +1778,9 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
|
||||||
Hash(), //emtpy hash
|
Hash(), //emtpy hash
|
||||||
state_references,
|
state_references,
|
||||||
state_stateReferences,
|
state_stateReferences,
|
||||||
drvPath);
|
drvPath
|
||||||
}
|
);
|
||||||
*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalStore::scanAndUpdateAllReferences(const Path & statePath)
|
void LocalStore::scanAndUpdateAllReferences(const Path & statePath)
|
||||||
|
|
|
||||||
|
|
@ -260,14 +260,19 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
|
||||||
|
|
||||||
bool recursive = true; //TODO !!!!!!!!!!!!!!!!!
|
bool recursive = true; //TODO !!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
//Insert the direct statePath or all recursive statePaths into the list
|
|
||||||
PathSet drvs;
|
PathSet drvs;
|
||||||
if(recursive)
|
if(recursive)
|
||||||
drvs = getAllStateDerivationsRecursively(componentPath, revision_arg); //get dependecies (if neccecary | recusively) of all state components that need to be updated
|
drvs = getAllStateDerivationsRecursively(componentPath, revision_arg); //get dependecies (if neccecary | recusively) of all state components that need to be updated
|
||||||
else
|
else
|
||||||
drvs.insert(derivationPath);
|
drvs.insert(derivationPath); //Insert direct state path
|
||||||
|
|
||||||
//Revert each statePath in the list
|
//Get the revisions recursively to also roll them back
|
||||||
|
RevisionNumbers getRivisions;
|
||||||
|
bool b = store->queryStateRevisions(statePath, getRivisions, revision_arg);
|
||||||
|
|
||||||
|
//Sort the statePaths from all drvs
|
||||||
|
map<Path, string> state_repos;
|
||||||
|
vector<Path> sorted_paths;
|
||||||
for (PathSet::iterator d = drvs.begin(); d != drvs.end(); ++d)
|
for (PathSet::iterator d = drvs.begin(); d != drvs.end(); ++d)
|
||||||
{
|
{
|
||||||
Path drvPath = *d;
|
Path drvPath = *d;
|
||||||
|
|
@ -275,20 +280,30 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
|
||||||
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
||||||
Path statePath = stateOutputs.find("state")->second.statepath;
|
Path statePath = stateOutputs.find("state")->second.statepath;
|
||||||
string drvName = drv.env.find("name")->second;
|
string drvName = drv.env.find("name")->second;
|
||||||
|
|
||||||
RevisionNumbers getRivisions;
|
|
||||||
bool b = store->queryStateRevisions(statePath, getRivisions, revision_arg);
|
|
||||||
|
|
||||||
string repos = getStateReposPath("stateOutput:staterepospath", statePath, drvName, stateIdentifier); //this is a copy from store-state.cc
|
string repos = getStateReposPath("stateOutput:staterepospath", statePath, drvName, stateIdentifier); //this is a copy from store-state.cc
|
||||||
|
|
||||||
|
state_repos[statePath] = repos;
|
||||||
|
sorted_paths.push_back(statePath);
|
||||||
|
}
|
||||||
|
sort(sorted_paths.begin(), sorted_paths.end());
|
||||||
|
|
||||||
|
//Revert each statePath in the list
|
||||||
|
for (vector<Path>::iterator i = sorted_paths.begin(); i != sorted_paths.end(); ++i){
|
||||||
|
Path statePath = *i;
|
||||||
|
string repos = state_repos[statePath];
|
||||||
|
int revision = getRivisions.front();
|
||||||
|
getRivisions.pop_front();
|
||||||
|
|
||||||
|
printMsg(lvlError, format("Reverting statePath '%1%' to revision: %2%") % statePath % int2String(revision));
|
||||||
Strings p_args;
|
Strings p_args;
|
||||||
p_args.push_back(nixSVNPath + "/svn");
|
p_args.push_back(nixSVNPath + "/svn");
|
||||||
p_args.push_back(int2String(revision_arg));
|
p_args.push_back(int2String(revision));
|
||||||
p_args.push_back("file://" + repos);
|
p_args.push_back("file://" + repos);
|
||||||
p_args.push_back(statePath);
|
p_args.push_back(statePath);
|
||||||
string output = runProgram(nixLibexecDir + "/nix/nix-restorerevision.sh", true, p_args); //run
|
runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-restorerevision.sh", true, p_args, "svn"); //run
|
||||||
|
|
||||||
printMsg(lvlError, format("Reverted statePath '%1%' to revision: %2%") % statePath % int2String(revision_arg));
|
//TODO !!!!!!!!!!!!!!!!!!!!! do a commit
|
||||||
|
//TODO !!!!!!!!!!!!!!!!!!!!! check if statePath is a working copy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,6 +330,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
|
||||||
|
|
||||||
//get all current dependecies (if neccecary | recusively) of all state components that need to be updated
|
//get all current dependecies (if neccecary | recusively) of all state components that need to be updated
|
||||||
PathSet root_drvs = getAllStateDerivationsRecursively(root_componentPath, -1);
|
PathSet root_drvs = getAllStateDerivationsRecursively(root_componentPath, -1);
|
||||||
|
//TODO WHAT ABOUT YOURSELF??????????
|
||||||
|
|
||||||
//TODO maybe also scan the parameters for state or component hashes?
|
//TODO maybe also scan the parameters for state or component hashes?
|
||||||
//program_args
|
//program_args
|
||||||
|
|
@ -430,10 +446,10 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
|
||||||
runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-statecommit.sh", true, p_args, "svn");
|
runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-statecommit.sh", true, p_args, "svn");
|
||||||
|
|
||||||
//Update the intervals again
|
//Update the intervals again
|
||||||
//store->setStatePathsInterval(intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!!
|
//store->setStatePathsInterval(intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!! uncomment
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
//Scan if needed
|
//Scan if needed //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! needs a new revision number
|
||||||
if(false)
|
if(false)
|
||||||
store->scanAndUpdateAllReferencesRecusively(statePath);
|
store->scanAndUpdateAllReferencesRecusively(statePath);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
bool includeOutputs = false;
|
bool includeOutputs = false;
|
||||||
bool forceRealise = false;
|
bool forceRealise = false;
|
||||||
string bindingName;
|
string bindingName;
|
||||||
|
int revision = -1; //last revision
|
||||||
|
|
||||||
for (Strings::iterator i = opFlags.begin();
|
for (Strings::iterator i = opFlags.begin();
|
||||||
i != opFlags.end(); ++i)
|
i != opFlags.end(); ++i)
|
||||||
|
|
@ -274,6 +275,11 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
else if (*i == "--use-output" || *i == "-u") useOutput = true;
|
else if (*i == "--use-output" || *i == "-u") useOutput = true;
|
||||||
else if (*i == "--force-realise" || *i == "-f") forceRealise = true;
|
else if (*i == "--force-realise" || *i == "-f") forceRealise = true;
|
||||||
else if (*i == "--include-outputs") includeOutputs = true;
|
else if (*i == "--include-outputs") includeOutputs = true;
|
||||||
|
else if ((*i).substr(0,11) == "--revision="){
|
||||||
|
bool succeed = string2Int((*i).substr(11,(*i).length()), revision);
|
||||||
|
if(!succeed)
|
||||||
|
throw UsageError("The given revision is not a valid number");
|
||||||
|
}
|
||||||
else throw UsageError(format("unknown flag `%1%'") % *i);
|
else throw UsageError(format("unknown flag `%1%'") % *i);
|
||||||
|
|
||||||
switch (query) {
|
switch (query) {
|
||||||
|
|
@ -304,15 +310,15 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
i != opArgs.end(); ++i)
|
i != opArgs.end(); ++i)
|
||||||
{
|
{
|
||||||
Path path = maybeUseOutput(fixStoreOrStatePath(*i), useOutput, forceRealise);
|
Path path = maybeUseOutput(fixStoreOrStatePath(*i), useOutput, forceRealise);
|
||||||
if (query == qRequisites) store->storePathRequisites(path, includeOutputs, paths, true, false, -1);
|
if (query == qRequisites) store->storePathRequisites(path, includeOutputs, paths, true, false, revision);
|
||||||
else if (query == qRequisitesState) store->storePathRequisites(path, includeOutputs, paths, false, true, -1);
|
else if (query == qRequisitesState) store->storePathRequisites(path, includeOutputs, paths, false, true, revision);
|
||||||
else if (query == qRequisitesFull) store->storePathRequisites(path, includeOutputs, paths, true, true, -1);
|
else if (query == qRequisitesFull) store->storePathRequisites(path, includeOutputs, paths, true, true, revision);
|
||||||
else if (query == qReferences) store->queryReferences(path, paths, -1);
|
else if (query == qReferences) store->queryReferences(path, paths, revision);
|
||||||
else if (query == qStateReferences) store->queryStateReferences(path, paths, -1); //latest revision
|
else if (query == qStateReferences) store->queryStateReferences(path, paths, revision);
|
||||||
else if (query == qReferrers) store->queryReferrers(path, paths, -1);
|
else if (query == qReferrers) store->queryReferrers(path, paths, revision);
|
||||||
else if (query == qStateReferrers) store->queryStateReferrers(path, paths, -1); //latest revision
|
else if (query == qStateReferrers) store->queryStateReferrers(path, paths, revision);
|
||||||
else if (query == qReferrersClosure) computeFSClosure(path, paths, true, false, -1, true);
|
else if (query == qReferrersClosure) computeFSClosure(path, paths, true, false, revision, true);
|
||||||
else if (query == qReferrersClosureWithState) computeFSClosure(path, paths, true, true, -1, true);
|
else if (query == qReferrersClosureWithState) computeFSClosure(path, paths, true, true, revision, true);
|
||||||
}
|
}
|
||||||
Paths sorted = topoSortPaths(paths);
|
Paths sorted = topoSortPaths(paths);
|
||||||
for (Paths::reverse_iterator i = sorted.rbegin();
|
for (Paths::reverse_iterator i = sorted.rbegin();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue