Fix assertion failure in FlakeRef::to_string()

Fixes

  $ nix build
  nix: src/libexpr/primops/flakeref.cc:169: std::__cxx11::string nix::FlakeRef::to_string() const: Assertion `!rev' failed.
  Aborted

e.g. when flake.nix doesn't exist.

Also use gitRev().
This commit is contained in:
Eelco Dolstra 2019-05-08 22:08:38 +02:00
parent 455aa8d9ea
commit 8fc1c3f413
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -161,13 +161,13 @@ std::string FlakeRef::to_string() const
if (auto refData = std::get_if<FlakeRef::IsAlias>(&data)) { if (auto refData = std::get_if<FlakeRef::IsAlias>(&data)) {
string = refData->alias; string = refData->alias;
if (ref) string += '/' + *ref; if (ref) string += '/' + *ref;
if (rev) string += '/' + rev->to_string(Base16, false); if (rev) string += '/' + rev->gitRev();
} }
else if (auto refData = std::get_if<FlakeRef::IsPath>(&data)) { else if (auto refData = std::get_if<FlakeRef::IsPath>(&data)) {
assert(subdir == ""); assert(subdir == "");
assert(!rev); if (ref) addParam("ref", *ref);
assert(!ref); if (rev) addParam("rev", rev->gitRev());
return refData->path; return refData->path;
} }
@ -175,7 +175,7 @@ std::string FlakeRef::to_string() const
assert(!(ref && rev)); assert(!(ref && rev));
string = "github:" + refData->owner + "/" + refData->repo; string = "github:" + refData->owner + "/" + refData->repo;
if (ref) { string += '/'; string += *ref; } if (ref) { string += '/'; string += *ref; }
if (rev) { string += '/'; string += rev->to_string(Base16, false); } if (rev) { string += '/'; string += rev->gitRev(); }
if (subdir != "") addParam("dir", subdir); if (subdir != "") addParam("dir", subdir);
} }
@ -186,7 +186,7 @@ std::string FlakeRef::to_string() const
if (ref) { if (ref) {
addParam("ref", *ref); addParam("ref", *ref);
if (rev) if (rev)
addParam("rev", rev->to_string(Base16, false)); addParam("rev", rev->gitRev());
} }
if (subdir != "") addParam("dir", subdir); if (subdir != "") addParam("dir", subdir);