Re: [PATCH] revert: actually check for a dirty index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeff King, Sun, Mar 02, 2008 08:22:52 +0100:
> +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.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux