git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* diff machinery cleanup
@ 2006-08-10  8:24 Jeff King
  2006-08-10  9:36 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2006-08-10  8:24 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-08-10 21:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-10  8:24 diff machinery cleanup Jeff King
2006-08-10  9:36 ` Junio C Hamano
2006-08-10 10:38   ` Jeff King
2006-08-10 17:06     ` Junio C Hamano
2006-08-10 20:10       ` Jeff King
2006-08-10 21:02         ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).