git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Jeff KingNext: Jeff King
Message 5 of 7 in “bug in git-revert”
  1. Jeff KingMar 2, 2008
  2. Johannes SchindelinMar 2, 2008
  3. Jeff KingMar 2, 2008
  4. revert: actually check for a dirty indexJeff King, Mar 2, 2008
  5. Alex RiesenMar 2, 2008
  6. Jeff KingMar 3, 2008
  7. Junio C HamanoMar 3, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.