forked from lix-project/lix
diffLockFiles(): Show 'follows' changes
This commit is contained in:
parent
0c62b4ad0f
commit
d15c20efd5
1 changed files with 29 additions and 11 deletions
|
@ -242,25 +242,43 @@ static void flattenLockFile(
|
||||||
std::shared_ptr<const Node> node,
|
std::shared_ptr<const Node> node,
|
||||||
const InputPath & prefix,
|
const InputPath & prefix,
|
||||||
std::unordered_set<std::shared_ptr<const Node>> & done,
|
std::unordered_set<std::shared_ptr<const Node>> & done,
|
||||||
std::map<InputPath, std::shared_ptr<const LockedNode>> & res)
|
std::map<InputPath, Node::Edge> & res)
|
||||||
{
|
{
|
||||||
if (!done.insert(node).second) return;
|
if (!done.insert(node).second) return;
|
||||||
|
|
||||||
for (auto &[id, input] : node->inputs) {
|
for (auto &[id, input] : node->inputs) {
|
||||||
auto inputPath(prefix);
|
auto inputPath(prefix);
|
||||||
inputPath.push_back(id);
|
inputPath.push_back(id);
|
||||||
if (auto child = std::get_if<0>(&input)) {
|
res.emplace(inputPath, input);
|
||||||
if (auto lockedInput = std::dynamic_pointer_cast<const LockedNode>(*child))
|
if (auto child = std::get_if<0>(&input))
|
||||||
res.emplace(inputPath, lockedInput);
|
|
||||||
flattenLockFile(*child, inputPath, done, res);
|
flattenLockFile(*child, inputPath, done, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream & operator <<(std::ostream & stream, const Node::Edge & edge)
|
||||||
|
{
|
||||||
|
if (auto node = std::get_if<0>(&edge))
|
||||||
|
stream << "'" << (*node)->lockedRef << "'";
|
||||||
|
else if (auto follows = std::get_if<1>(&edge))
|
||||||
|
stream << fmt("follows '%s'", printInputPath(*follows));
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool equals(const Node::Edge & e1, const Node::Edge & e2)
|
||||||
|
{
|
||||||
|
if (auto n1 = std::get_if<0>(&e1))
|
||||||
|
if (auto n2 = std::get_if<0>(&e2))
|
||||||
|
return (*n1)->lockedRef == (*n2)->lockedRef;
|
||||||
|
if (auto f1 = std::get_if<1>(&e1))
|
||||||
|
if (auto f2 = std::get_if<1>(&e2))
|
||||||
|
return *f1 == *f2;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string diffLockFiles(const LockFile & oldLocks, const LockFile & newLocks)
|
std::string diffLockFiles(const LockFile & oldLocks, const LockFile & newLocks)
|
||||||
{
|
{
|
||||||
std::unordered_set<std::shared_ptr<const Node>> done;
|
std::unordered_set<std::shared_ptr<const Node>> done;
|
||||||
std::map<InputPath, std::shared_ptr<const LockedNode>> oldFlat, newFlat;
|
std::map<InputPath, Node::Edge> oldFlat, newFlat;
|
||||||
flattenLockFile(oldLocks.root, {}, done, oldFlat);
|
flattenLockFile(oldLocks.root, {}, done, oldFlat);
|
||||||
done.clear();
|
done.clear();
|
||||||
flattenLockFile(newLocks.root, {}, done, newFlat);
|
flattenLockFile(newLocks.root, {}, done, newFlat);
|
||||||
|
@ -271,17 +289,17 @@ std::string diffLockFiles(const LockFile & oldLocks, const LockFile & newLocks)
|
||||||
|
|
||||||
while (i != oldFlat.end() || j != newFlat.end()) {
|
while (i != oldFlat.end() || j != newFlat.end()) {
|
||||||
if (j != newFlat.end() && (i == oldFlat.end() || i->first > j->first)) {
|
if (j != newFlat.end() && (i == oldFlat.end() || i->first > j->first)) {
|
||||||
res += fmt("* Added '%s': '%s'\n", printInputPath(j->first), j->second->lockedRef);
|
res += fmt("* Added '%s': %s\n", printInputPath(j->first), j->second);
|
||||||
++j;
|
++j;
|
||||||
} else if (i != oldFlat.end() && (j == newFlat.end() || i->first < j->first)) {
|
} else if (i != oldFlat.end() && (j == newFlat.end() || i->first < j->first)) {
|
||||||
res += fmt("* Removed '%s'\n", printInputPath(i->first));
|
res += fmt("* Removed '%s'\n", printInputPath(i->first));
|
||||||
++i;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
if (!(i->second->lockedRef == j->second->lockedRef)) {
|
if (!equals(i->second, j->second)) {
|
||||||
res += fmt("* Updated '%s': '%s' -> '%s'\n",
|
res += fmt("* Updated '%s': %s -> %s\n",
|
||||||
printInputPath(i->first),
|
printInputPath(i->first),
|
||||||
i->second->lockedRef,
|
i->second,
|
||||||
j->second->lockedRef);
|
j->second);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
++j;
|
++j;
|
||||||
|
|
Loading…
Reference in a new issue