userdiff.c: remove implicit dependency on the_index
[jc: squashed in missing forward decl in userdiff.h found by Ramsay] Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
		
				
					committed by
					
						
						Junio C Hamano
					
				
			
			
				
	
			
			
			
						parent
						
							35843b1123
						
					
				
				
					commit
					acd00ea049
				
			
							
								
								
									
										40
									
								
								diff.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								diff.c
									
									
									
									
									
								
							@ -2093,23 +2093,25 @@ static void diff_words_flush(struct emit_callback *ecbdata)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void diff_filespec_load_driver(struct diff_filespec *one)
 | 
			
		||||
static void diff_filespec_load_driver(struct diff_filespec *one,
 | 
			
		||||
				      struct index_state *istate)
 | 
			
		||||
{
 | 
			
		||||
	/* Use already-loaded driver */
 | 
			
		||||
	if (one->driver)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	if (S_ISREG(one->mode))
 | 
			
		||||
		one->driver = userdiff_find_by_path(one->path);
 | 
			
		||||
		one->driver = userdiff_find_by_path(istate, one->path);
 | 
			
		||||
 | 
			
		||||
	/* Fallback to default settings */
 | 
			
		||||
	if (!one->driver)
 | 
			
		||||
		one->driver = userdiff_find_by_name("default");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const char *userdiff_word_regex(struct diff_filespec *one)
 | 
			
		||||
static const char *userdiff_word_regex(struct diff_filespec *one,
 | 
			
		||||
				       struct index_state *istate)
 | 
			
		||||
{
 | 
			
		||||
	diff_filespec_load_driver(one);
 | 
			
		||||
	diff_filespec_load_driver(one, istate);
 | 
			
		||||
	return one->driver->word_regex;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2132,9 +2134,9 @@ static void init_diff_words_data(struct emit_callback *ecbdata,
 | 
			
		||||
			xcalloc(1, sizeof(struct emitted_diff_symbols));
 | 
			
		||||
 | 
			
		||||
	if (!o->word_regex)
 | 
			
		||||
		o->word_regex = userdiff_word_regex(one);
 | 
			
		||||
		o->word_regex = userdiff_word_regex(one, o->repo->index);
 | 
			
		||||
	if (!o->word_regex)
 | 
			
		||||
		o->word_regex = userdiff_word_regex(two);
 | 
			
		||||
		o->word_regex = userdiff_word_regex(two, o->repo->index);
 | 
			
		||||
	if (!o->word_regex)
 | 
			
		||||
		o->word_regex = diff_word_regex_cfg;
 | 
			
		||||
	if (o->word_regex) {
 | 
			
		||||
@ -3257,7 +3259,7 @@ int diff_filespec_is_binary(struct repository *r,
 | 
			
		||||
			    struct diff_filespec *one)
 | 
			
		||||
{
 | 
			
		||||
	if (one->is_binary == -1) {
 | 
			
		||||
		diff_filespec_load_driver(one);
 | 
			
		||||
		diff_filespec_load_driver(one, r->index);
 | 
			
		||||
		if (one->driver->binary != -1)
 | 
			
		||||
			one->is_binary = one->driver->binary;
 | 
			
		||||
		else {
 | 
			
		||||
@ -3273,9 +3275,10 @@ int diff_filespec_is_binary(struct repository *r,
 | 
			
		||||
	return one->is_binary;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct userdiff_funcname *diff_funcname_pattern(struct diff_filespec *one)
 | 
			
		||||
static const struct userdiff_funcname *
 | 
			
		||||
diff_funcname_pattern(struct diff_options *o, struct diff_filespec *one)
 | 
			
		||||
{
 | 
			
		||||
	diff_filespec_load_driver(one);
 | 
			
		||||
	diff_filespec_load_driver(one, o->repo->index);
 | 
			
		||||
	return one->driver->funcname.pattern ? &one->driver->funcname : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3287,12 +3290,13 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
 | 
			
		||||
		options->b_prefix = b;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct userdiff_driver *get_textconv(struct diff_filespec *one)
 | 
			
		||||
struct userdiff_driver *get_textconv(struct index_state *istate,
 | 
			
		||||
				     struct diff_filespec *one)
 | 
			
		||||
{
 | 
			
		||||
	if (!DIFF_FILE_VALID(one))
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	diff_filespec_load_driver(one);
 | 
			
		||||
	diff_filespec_load_driver(one, istate);
 | 
			
		||||
	return userdiff_get_textconv(one->driver);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3342,8 +3346,8 @@ static void builtin_diff(const char *name_a,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (o->flags.allow_textconv) {
 | 
			
		||||
		textconv_one = get_textconv(one);
 | 
			
		||||
		textconv_two = get_textconv(two);
 | 
			
		||||
		textconv_one = get_textconv(o->repo->index, one);
 | 
			
		||||
		textconv_two = get_textconv(o->repo->index, two);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Never use a non-valid filename anywhere if at all possible */
 | 
			
		||||
@ -3465,9 +3469,9 @@ static void builtin_diff(const char *name_a,
 | 
			
		||||
		mf1.size = fill_textconv(o->repo, textconv_one, one, &mf1.ptr);
 | 
			
		||||
		mf2.size = fill_textconv(o->repo, textconv_two, two, &mf2.ptr);
 | 
			
		||||
 | 
			
		||||
		pe = diff_funcname_pattern(one);
 | 
			
		||||
		pe = diff_funcname_pattern(o, one);
 | 
			
		||||
		if (!pe)
 | 
			
		||||
			pe = diff_funcname_pattern(two);
 | 
			
		||||
			pe = diff_funcname_pattern(o, two);
 | 
			
		||||
 | 
			
		||||
		memset(&xpp, 0, sizeof(xpp));
 | 
			
		||||
		memset(&xecfg, 0, sizeof(xecfg));
 | 
			
		||||
@ -4223,7 +4227,9 @@ static void run_diff_cmd(const char *pgm,
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	if (o->flags.allow_external) {
 | 
			
		||||
		struct userdiff_driver *drv = userdiff_find_by_path(attr_path);
 | 
			
		||||
		struct userdiff_driver *drv;
 | 
			
		||||
 | 
			
		||||
		drv = userdiff_find_by_path(o->repo->index, attr_path);
 | 
			
		||||
		if (drv && drv->external)
 | 
			
		||||
			pgm = drv->external;
 | 
			
		||||
	}
 | 
			
		||||
@ -6399,7 +6405,7 @@ int textconv_object(struct repository *r,
 | 
			
		||||
 | 
			
		||||
	df = alloc_filespec(path);
 | 
			
		||||
	fill_filespec(df, oid, oid_valid, mode);
 | 
			
		||||
	textconv = get_textconv(df);
 | 
			
		||||
	textconv = get_textconv(r->index, df);
 | 
			
		||||
	if (!textconv) {
 | 
			
		||||
		free_filespec(df);
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user