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

diff machinery cleanup

From
Jeff King <peff@peff.net>
Date
Aug 10, 2006, 08:24 UTC
Message-ID
<20060810082455.GA30739@coredump.intra.peff.net>

I'm trying to run two different 'diffs' in the same C program, and the results of the second diff depend on whether or not the first diff has run. A minimal case is below. When show_updated() is run, show_changed() results in all files listed as "unmerged". If show_updated() is commented out, the output for show_changed() is as expected.

-- >8 -- #include "cache.h" #include "object.h" #include "commit.h" #include "diff.h" #include "revision.h"

void show_updated() {
	struct rev_info rev;
	const char *argv[] = { NULL, "HEAD", NULL };
	init_revisions(&rev, NULL);
	setup_revisions(2, argv, &rev, NULL);
	rev.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
	run_diff_index(&rev, 1);
}
void show_changed() {
	struct rev_info rev;
	const char *argv[] = { NULL, NULL };
	init_revisions(&rev, NULL);
	setup_revisions(1, argv, &rev, NULL);
	rev.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
	run_diff_files(&rev, 0);
}
int main(int argc, char **argv) {
	printf("updated:\n");
	show_updated();
	printf("changed:\n");
	show_changed();
	return 0;
}
-- >8 --

It seems clear that there's some global magic touched by the first diff that impacts the second. I have to give up on finding it for tonight, but I'm hoping somebody who knows more about the code will find it obvious (or can tell me that I'm doing something else horribly wrong in the above, or that these functions were never intended to be called within the same program).

-Peff
Next: Junio C Hamano
Message 1 of 6 in “diff machinery cleanup”
  1. Jeff KingAug 10, 2006
  2. Junio C HamanoAug 10, 2006
  3. Jeff KingAug 10, 2006
  4. Junio C HamanoAug 10, 2006
  5. Jeff KingAug 10, 2006
  6. Junio C HamanoAug 10, 2006

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.