diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-10-25 18:18:15 +0200 |
---|---|---|
committer | lunaphied <lunaphied@lunaphied.me> | 2024-03-25 15:30:36 +0000 |
commit | b525d0f20c4fd94b89d6d34d8acd0ca4c579a5fc (patch) | |
tree | 89f2259054c2afec58c56993b70c2ed45efe5529 /src/libfetchers/mercurial.cc | |
parent | 3d065192c08b3dcb76b9cf70cd0104974106ae8f (diff) |
Input: Replace markFileChanged() by putFile()
Committing a lock file using markFileChanged() required the input to
be writable by the caller in the local filesystem (using the path
returned by getSourcePath()). putFile() abstracts over this.
(cherry picked from commit 95d657c8b3ae4282e24628ba7426edb90c8f3942)
Change-Id: Ie081c5d9eb4e923b229191c5e23ece85145557ff
Diffstat (limited to 'src/libfetchers/mercurial.cc')
-rw-r--r-- | src/libfetchers/mercurial.cc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index a70403660..87fecfca3 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -116,7 +116,7 @@ struct MercurialInputScheme : InputScheme return res; } - std::optional<Path> getSourcePath(const Input & input) override + std::optional<Path> getSourcePath(const Input & input) const override { auto url = parseURL(getStrAttr(input.attrs, "url")); if (url.scheme == "file" && !input.getRef() && !input.getRev()) @@ -124,18 +124,27 @@ struct MercurialInputScheme : InputScheme return {}; } - void markChangedFile(const Input & input, std::string_view file, std::optional<std::string> commitMsg) override + void putFile( + const Input & input, + const CanonPath & path, + std::string_view contents, + std::optional<std::string> commitMsg) const override { - auto sourcePath = getSourcePath(input); - assert(sourcePath); + auto [isLocal, repoPath] = getActualUrl(input); + if (!isLocal) + throw Error("cannot commit '%s' to Mercurial repository '%s' because it's not a working tree", path, input.to_string()); + + auto absPath = CanonPath(repoPath) + path; + + writeFile(absPath.abs(), contents); // FIXME: shut up if file is already tracked. runHg( - { "add", *sourcePath + "/" + std::string(file) }); + { "add", absPath.abs() }); if (commitMsg) runHg( - { "commit", *sourcePath + "/" + std::string(file), "-m", *commitMsg }); + { "commit", absPath.abs(), "-m", *commitMsg }); } std::pair<bool, std::string> getActualUrl(const Input & input) const |