summaryrefslogtreecommitdiff
path: root/builtin-commit.c
diff options
context:
space:
mode:
authorStephan Beyer <s-beyer@gmx.net>2009-02-10 14:30:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-02-11 06:25:39 (GMT)
commit75f3ff2eeaba820b37016f464b6d1078cb6260e2 (patch)
tree0401f9c7b3904977dc50afc8081e780405113bf1 /builtin-commit.c
parentfcb6c0760d14cd8ee284a0acf9f7424878cba5a0 (diff)
downloadgit-75f3ff2eeaba820b37016f464b6d1078cb6260e2.zip
git-75f3ff2eeaba820b37016f464b6d1078cb6260e2.tar.gz
git-75f3ff2eeaba820b37016f464b6d1078cb6260e2.tar.bz2
Generalize and libify index_is_dirty() to index_differs_from(...)
index_is_dirty() in builtin-revert.c checks if the index is dirty. This patch generalizes this function to check if the index differs from a revision, i.e. the former index_is_dirty() behavior can now be achieved by index_differs_from("HEAD", 0). The second argument "diff_flags" allows to set further diff option flags like DIFF_OPT_IGNORE_SUBMODULES. See DIFF_OPT_* macros in diff.h for a list. index_differs_from() seems to be useful for more than builtin-revert.c, so it is moved into diff-lib.c and also used in builtin-commit.c. Yet to mention: - "rev.abbrev = 0;" can be safely removed. This has no impact on performance or functioning of neither setup_revisions() nor run_diff_index(). - rev.pending.objects is free()d because this fixes a leak. (Also see 295dd2ad "Fix memory leak in traverse_commit_list") Mentored-by: Daniel Barkalow <barkalow@iabervon.org> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-commit.c')
-rw-r--r--builtin-commit.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/builtin-commit.c b/builtin-commit.c
index d6a3a62..46e649c 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -561,7 +561,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
commitable = run_status(fp, index_file, prefix, 1);
wt_status_use_color = saved_color_setting;
} else {
- struct rev_info rev;
unsigned char sha1[20];
const char *parent = "HEAD";
@@ -573,16 +572,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
if (get_sha1(parent, sha1))
commitable = !!active_nr;
- else {
- init_revisions(&rev, "");
- rev.abbrev = 0;
- setup_revisions(0, NULL, &rev, parent);
- DIFF_OPT_SET(&rev.diffopt, QUIET);
- DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
- run_diff_index(&rev, 1 /* cached */);
-
- commitable = !!DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES);
- }
+ else
+ commitable = index_differs_from(parent, 0);
}
fclose(fp);