From fa82b5c1ebbe56555065d6a3dad121ccbc22f0d4 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Sat, 7 Jun 2025 18:32:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=84=D0=BB=D0=B0=D0=B3=20--snapshot=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20diff=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D1=81=D0=BC=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D0=BA=D1=80=D0=B5=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=20=D1=81=D0=BD=D0=B8=D0=BC=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/app.d | 14 ++++++++++++-- source/snag/core/core.d | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/source/app.d b/source/app.d index d952688..8289191 100644 --- a/source/app.d +++ b/source/app.d @@ -39,7 +39,15 @@ int main(string[] args) ) ) .add(new Command("status", "Checking the status of tracked files")) - .add(new Command("diff", "Show changed data")) + .add(new Command("diff", "Show changed data") + .add(new Option("s", "snapshot", "Specify snapshot hash") + .optional + .validateEachWith( + opt => opt.isValidHash, + "must contain snapshot hash provided" + ) + ) + ) .add(new Command("size", "Size of snapshots")) .add(new Command("import", "Import snapshot from a tar.gz archive") .add(new Argument("archive", "The path to the tar.gz archive file").required) @@ -167,7 +175,9 @@ int main(string[] args) snag.initialize(init.flag("force")) ) .on("diff", diff => - snag.diff() + snag.diff( + diff.option("snapshot", "") + ) ) .on("size", size => snag.size() diff --git a/source/snag/core/core.d b/source/snag/core/core.d index 4196481..0f97fbe 100644 --- a/source/snag/core/core.d +++ b/source/snag/core/core.d @@ -292,16 +292,41 @@ class Snag { writeln("Backup was restored successfully: ", hash); } - void diff() { - auto result = git( - ["diff"], - "Failed to retrieve changes" - ); - if (result.output.length) { - result.output.write; + void diff(string hash) { + string[] result; + if (hash.length) { + git( + ["rev-parse", hash], + "This snapshot is not available in the archive" + ); + result = git( + ["show", hash, "--name-only", "--pretty="], + "Failed to retrieve snapshot information" + ).output.split('\n').filter!(p => !p.empty).array; + } else { + result = git( + ["diff", "--name-only"], + "Failed to retrieve changes" + ).output.split('\n').filter!(p => !p.empty).array; + } + if (!result.length) { + writeln("No changes at the moment"); return; } - writeln("No changes at the moment"); + if (hash.length) + result.each!(e => + git( + ["show", "--pretty=", hash, "--", e], + "Failed to retrieve file information" + ).output.write + ); + else + result.each!(e => + git( + ["diff", e], + "Failed to retrieve file information" + ).output.write + ); } void exportSnapshot(string path, string hash) {