Merge branch 'jk/diff-no-index-initialize'
"git diff --no-index" may still want to access Git goodies like --ext-diff and --textconv, but so far these have been ignored, which has been corrected. * jk/diff-no-index-initialize: diff: reuse diff setup for --no-index case
This commit is contained in:
		@ -338,21 +338,23 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 | 
				
			|||||||
		       "--no-index" : "[--no-index]");
 | 
							       "--no-index" : "[--no-index]");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (no_index)
 | 
					 | 
				
			||||||
		/* If this is a no-index diff, just run it and exit there. */
 | 
					 | 
				
			||||||
		diff_no_index(the_repository, &rev, argc, argv);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Otherwise, we are doing the usual "git" diff */
 | 
						/* Set up defaults that will apply to both no-index and regular diffs. */
 | 
				
			||||||
	rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Scale to real terminal size and respect statGraphWidth config */
 | 
					 | 
				
			||||||
	rev.diffopt.stat_width = -1;
 | 
						rev.diffopt.stat_width = -1;
 | 
				
			||||||
	rev.diffopt.stat_graph_width = -1;
 | 
						rev.diffopt.stat_graph_width = -1;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Default to let external and textconv be used */
 | 
					 | 
				
			||||||
	rev.diffopt.flags.allow_external = 1;
 | 
						rev.diffopt.flags.allow_external = 1;
 | 
				
			||||||
	rev.diffopt.flags.allow_textconv = 1;
 | 
						rev.diffopt.flags.allow_textconv = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* If this is a no-index diff, just run it and exit there. */
 | 
				
			||||||
 | 
						if (no_index)
 | 
				
			||||||
 | 
							diff_no_index(&rev, argc, argv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Otherwise, we are doing the usual "git" diff; set up any
 | 
				
			||||||
 | 
						 * further defaults that apply to regular diffs.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Default to intent-to-add entries invisible in the
 | 
						 * Default to intent-to-add entries invisible in the
 | 
				
			||||||
	 * index. This makes them show up as new files in diff-files
 | 
						 * index. This makes them show up as new files in diff-files
 | 
				
			||||||
 | 
				
			|||||||
@ -233,8 +233,7 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void diff_no_index(struct repository *r,
 | 
					void diff_no_index(struct rev_info *revs,
 | 
				
			||||||
		   struct rev_info *revs,
 | 
					 | 
				
			||||||
		   int argc, const char **argv)
 | 
							   int argc, const char **argv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
@ -242,11 +241,6 @@ void diff_no_index(struct repository *r,
 | 
				
			|||||||
	struct strbuf replacement = STRBUF_INIT;
 | 
						struct strbuf replacement = STRBUF_INIT;
 | 
				
			||||||
	const char *prefix = revs->prefix;
 | 
						const char *prefix = revs->prefix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	 * FIXME: --no-index should not look at index and we should be
 | 
					 | 
				
			||||||
	 * able to pass NULL repo. Maybe later.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	repo_diff_setup(r, &revs->diffopt);
 | 
					 | 
				
			||||||
	for (i = 1; i < argc - 2; ) {
 | 
						for (i = 1; i < argc - 2; ) {
 | 
				
			||||||
		int j;
 | 
							int j;
 | 
				
			||||||
		if (!strcmp(argv[i], "--no-index"))
 | 
							if (!strcmp(argv[i], "--no-index"))
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								diff.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								diff.h
									
									
									
									
									
								
							@ -438,7 +438,7 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int diff_result_code(struct diff_options *, int);
 | 
					int diff_result_code(struct diff_options *, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void diff_no_index(struct repository *, struct rev_info *, int, const char **);
 | 
					void diff_no_index(struct rev_info *, int, const char **);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int index_differs_from(struct repository *r, const char *def,
 | 
					int index_differs_from(struct repository *r, const char *def,
 | 
				
			||||||
		       const struct diff_flags *flags,
 | 
							       const struct diff_flags *flags,
 | 
				
			||||||
 | 
				
			|||||||
@ -137,4 +137,12 @@ test_expect_success 'diff --no-index from repo subdir with absolute paths' '
 | 
				
			|||||||
	test_cmp expect actual
 | 
						test_cmp expect actual
 | 
				
			||||||
'
 | 
					'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test_expect_success 'diff --no-index allows external diff' '
 | 
				
			||||||
 | 
						test_expect_code 1 \
 | 
				
			||||||
 | 
							env GIT_EXTERNAL_DIFF="echo external ;:" \
 | 
				
			||||||
 | 
							git diff --no-index non/git/a non/git/b >actual &&
 | 
				
			||||||
 | 
						echo external >expect &&
 | 
				
			||||||
 | 
						test_cmp expect actual
 | 
				
			||||||
 | 
					'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test_done
 | 
					test_done
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user