From 167e36900420048f93e9f0d81c53231caf1582b1 Mon Sep 17 00:00:00 2001 From: womax Date: Mon, 3 Jun 2024 15:01:52 +0200 Subject: [PATCH] Commit reset --- src/commit.c | 15 ++++++++++----- src/commit.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/commit.c b/src/commit.c index d1f0d9d..8f02a78 100644 --- a/src/commit.c +++ b/src/commit.c @@ -162,16 +162,21 @@ void diff_commit_with_working_tree(struct commit *commit) dump_tree(TMP"/a", &commit_tree); - FILE *p = popen("diff -ruN --exclude-from=.gitignore "TMP"/a ./ > "LOCAL_REPO"/diff", "w"); - pclose(p); - - p = popen("cat "LOCAL_REPO"/diff", "w"); + FILE *p = popen("diff -ru --exclude-from=.gitignore "TMP"/a ./ > "LOCAL_REPO"/last.diff", "w"); pclose(p); free_tree(&commit_tree); free_object(&obj); } +void revert_to(struct commit *commit) +{ + diff_commit_with_working_tree(commit); + + FILE *p = popen("patch -p0 -R < "LOCAL_REPO"/last.diff", "r"); + pclose(p); +} + void diff_commit(struct commit *commit_a, struct commit *commit_b) { struct object tree_obj_a, tree_obj_b; @@ -191,7 +196,7 @@ void diff_commit(struct commit *commit_a, struct commit *commit_b) dump_tree(TMP"/a", &tree_a); dump_tree(TMP"/b", &tree_b); - FILE *f = popen("diff -ruN "TMP"/a "TMP"/b ", "w"); + FILE *f = popen("diff -ruN "TMP"/a "TMP"/b | less", "w"); pclose(f); free_tree(&tree_a); diff --git a/src/commit.h b/src/commit.h index a02b916..3bc1e69 100644 --- a/src/commit.h +++ b/src/commit.h @@ -7,6 +7,7 @@ int commit_from_object(struct commit *commit, struct object *object); void free_commit(struct commit *commit); void diff_commit(struct commit *commit_a, struct commit *commit_b); void diff_commit_with_working_tree(struct commit *commit); +void revert_to(struct commit *commit); int commit(); #endif // COMMIT_H \ No newline at end of file