forked from lix-project/lix
Merge pull request #5124 from edolstra/lock-file-diff
Improve flake lock file diffs
This commit is contained in:
commit
43856b0d6d
|
@ -19,11 +19,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1624862269,
|
"lastModified": 1628689438,
|
||||||
"narHash": "sha256-JFcsh2+7QtfKdJFoPibLFPLgIW6Ycnv8Bts9a7RYme0=",
|
"narHash": "sha256-YMINW6YmubHZVdliGsAJpnnMYXRrvppv59LgwtnyYhs=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "f77036342e2b690c61c97202bf48f2ce13acc022",
|
"rev": "f6551e1efa261568c82b76c3a582b2c2ceb1f53f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -567,8 +567,8 @@ LockedFlake lockFlake(
|
||||||
topRef.input.markChangedFile(
|
topRef.input.markChangedFile(
|
||||||
(topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock",
|
(topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock",
|
||||||
lockFlags.commitLockFile
|
lockFlags.commitLockFile
|
||||||
? std::optional<std::string>(fmt("%s: %s\n\nFlake input changes:\n\n%s",
|
? std::optional<std::string>(fmt("%s: %s\n\nFlake lock file changes:\n\n%s",
|
||||||
relPath, lockFileExists ? "Update" : "Add", diff))
|
relPath, lockFileExists ? "Update" : "Add", filterANSIEscapes(diff, true)))
|
||||||
: std::nullopt);
|
: std::nullopt);
|
||||||
|
|
||||||
/* Rewriting the lockfile changed the top-level
|
/* Rewriting the lockfile changed the top-level
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "url-parts.hh"
|
#include "url-parts.hh"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace nix::flake {
|
namespace nix::flake {
|
||||||
|
@ -268,10 +270,20 @@ std::map<InputPath, Node::Edge> LockFile::getAllInputs() const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string describe(const FlakeRef & flakeRef)
|
||||||
|
{
|
||||||
|
auto s = fmt("'%s'", flakeRef.to_string());
|
||||||
|
|
||||||
|
if (auto lastModified = flakeRef.input.getLastModified())
|
||||||
|
s += fmt(" (%s)", std::put_time(std::gmtime(&*lastModified), "%Y-%m-%d"));
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream & operator <<(std::ostream & stream, const Node::Edge & edge)
|
std::ostream & operator <<(std::ostream & stream, const Node::Edge & edge)
|
||||||
{
|
{
|
||||||
if (auto node = std::get_if<0>(&edge))
|
if (auto node = std::get_if<0>(&edge))
|
||||||
stream << "'" << (*node)->lockedRef << "'";
|
stream << describe((*node)->lockedRef);
|
||||||
else if (auto follows = std::get_if<1>(&edge))
|
else if (auto follows = std::get_if<1>(&edge))
|
||||||
stream << fmt("follows '%s'", printInputPath(*follows));
|
stream << fmt("follows '%s'", printInputPath(*follows));
|
||||||
return stream;
|
return stream;
|
||||||
|
@ -299,14 +311,15 @@ std::string LockFile::diff(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);
|
res += fmt("• " ANSI_GREEN "Added input '%s':" ANSI_NORMAL "\n %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("• " ANSI_RED "Removed input '%s'" ANSI_NORMAL "\n", printInputPath(i->first));
|
||||||
++i;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
if (!equals(i->second, j->second)) {
|
if (!equals(i->second, j->second)) {
|
||||||
res += fmt("* Updated '%s': %s -> %s\n",
|
res += fmt("• " ANSI_BOLD "Updated input '%s':" ANSI_NORMAL "\n %s\n → %s\n",
|
||||||
printInputPath(i->first),
|
printInputPath(i->first),
|
||||||
i->second,
|
i->second,
|
||||||
j->second);
|
j->second);
|
||||||
|
|
Loading…
Reference in a new issue