Re: [PATCH] revert: actually check for a dirty index
- From
Alex Riesen <raa.lkml@gmail.com>
- Date
- Mar 2, 2008, 10:37 UTC
- Message-ID
- <20080302103753.GB2973@steel.home>
- In-Reply-To
- <20080302072252.GA14214@coredump.intra.peff.net>
Jeff King, Sun, Mar 02, 2008 08:22:52 +0100:
Show 14 quoted lines
> +static int index_is_dirty(void)
> +{
> + struct rev_info rev;
> + int is_dirty = 0;
> +
> + init_revisions(&rev, NULL);
> + setup_revisions(0, NULL, &rev, "HEAD");
> + rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
> + rev.diffopt.format_callback = index_is_dirty_cb;
> + rev.diffopt.format_callback_data = &is_dirty;
> + run_diff_index(&rev, 1);
> +
> + return is_dirty;
> +}Wouldn't something like what built-commit does more effective? It does:
struct rev_info rev; unsigned char sha1[20]; const char *parent = "HEAD";
if (!active_nr && read_cache() < 0)
die("Cannot read index");if (amend) parent = "HEAD^1";
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); }
Diff-index in this case will stop as soon as the first difference found, while just using the output method will enforce finding all the differences, which is just a waste of time, if all you need is just to know if index is different to HEAD.