diff.c: convert -U|--unified
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									cc013c224c
								
							
						
					
					
						commit
						d473e2e0e8
					
				|  | @ -36,7 +36,7 @@ endif::git-format-patch[] | ||||||
| -U<n>:: | -U<n>:: | ||||||
| --unified=<n>:: | --unified=<n>:: | ||||||
| 	Generate diffs with <n> lines of context instead of | 	Generate diffs with <n> lines of context instead of | ||||||
| 	the usual three. | 	the usual three. Implies `--patch`. | ||||||
| ifndef::git-format-patch[] | ifndef::git-format-patch[] | ||||||
| 	Implies `-p`. | 	Implies `-p`. | ||||||
| endif::git-format-patch[] | endif::git-format-patch[] | ||||||
|  |  | ||||||
							
								
								
									
										23
									
								
								diff.c
								
								
								
								
							
							
						
						
									
										23
									
								
								diff.c
								
								
								
								
							|  | @ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg) | ||||||
| 	return 1; | 	return 1; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static int diff_opt_unified(const struct option *opt, | ||||||
|  | 			    const char *arg, int unset) | ||||||
|  | { | ||||||
|  | 	struct diff_options *options = opt->value; | ||||||
|  | 	char *s; | ||||||
|  |  | ||||||
|  | 	BUG_ON_OPT_NEG(unset); | ||||||
|  |  | ||||||
|  | 	options->context = strtol(arg, &s, 10); | ||||||
|  | 	if (*s) | ||||||
|  | 		return error(_("%s expects a numerical value"), "--unified"); | ||||||
|  | 	enable_patch_output(&options->output_format); | ||||||
|  |  | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
| static void prep_parse_options(struct diff_options *options) | static void prep_parse_options(struct diff_options *options) | ||||||
| { | { | ||||||
| 	struct option parseopts[] = { | 	struct option parseopts[] = { | ||||||
|  | @ -4877,6 +4893,9 @@ static void prep_parse_options(struct diff_options *options) | ||||||
| 		OPT_BITOP('u', NULL, &options->output_format, | 		OPT_BITOP('u', NULL, &options->output_format, | ||||||
| 			  N_("generate patch"), | 			  N_("generate patch"), | ||||||
| 			  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), | 			  DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), | ||||||
|  | 		OPT_CALLBACK_F('U', "unified", options, N_("<n>"), | ||||||
|  | 			       N_("generate diffs with <n> lines context"), | ||||||
|  | 			       PARSE_OPT_NONEG, diff_opt_unified), | ||||||
| 		OPT_END() | 		OPT_END() | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | @ -4905,9 +4924,7 @@ int diff_opt_parse(struct diff_options *options, | ||||||
| 		return ac; | 		return ac; | ||||||
|  |  | ||||||
| 	/* Output format options */ | 	/* Output format options */ | ||||||
| 	if (opt_arg(arg, 'U', "unified", &options->context)) | 	if (!strcmp(arg, "--raw")) | ||||||
| 		enable_patch_output(&options->output_format); |  | ||||||
| 	else if (!strcmp(arg, "--raw")) |  | ||||||
| 		options->output_format |= DIFF_FORMAT_RAW; | 		options->output_format |= DIFF_FORMAT_RAW; | ||||||
| 	else if (!strcmp(arg, "--patch-with-raw")) { | 	else if (!strcmp(arg, "--patch-with-raw")) { | ||||||
| 		enable_patch_output(&options->output_format); | 		enable_patch_output(&options->output_format); | ||||||
|  |  | ||||||
|  | @ -134,6 +134,8 @@ struct option { | ||||||
| #define OPT_SET_INT_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \ | #define OPT_SET_INT_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \ | ||||||
| 					  (h), PARSE_OPT_NOARG | (f), NULL, (i) } | 					  (h), PARSE_OPT_NOARG | (f), NULL, (i) } | ||||||
| #define OPT_BOOL_F(s, l, v, h, f)   OPT_SET_INT_F(s, l, v, h, 1, f) | #define OPT_BOOL_F(s, l, v, h, f)   OPT_SET_INT_F(s, l, v, h, 1, f) | ||||||
|  | #define OPT_CALLBACK_F(s, l, v, a, h, f, cb)			\ | ||||||
|  | 	{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) } | ||||||
|  |  | ||||||
| #define OPT_END()                   { OPTION_END } | #define OPT_END()                   { OPTION_END } | ||||||
| #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \ | #define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \ | ||||||
|  | @ -164,8 +166,7 @@ struct option { | ||||||
| #define OPT_EXPIRY_DATE(s, l, v, h) \ | #define OPT_EXPIRY_DATE(s, l, v, h) \ | ||||||
| 	{ OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0,	\ | 	{ OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0,	\ | ||||||
| 	  parse_opt_expiry_date_cb } | 	  parse_opt_expiry_date_cb } | ||||||
| #define OPT_CALLBACK(s, l, v, a, h, f) \ | #define OPT_CALLBACK(s, l, v, a, h, f) OPT_CALLBACK_F(s, l, v, a, h, 0, f) | ||||||
| 	{ OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) } |  | ||||||
| #define OPT_NUMBER_CALLBACK(v, h, f) \ | #define OPT_NUMBER_CALLBACK(v, h, f) \ | ||||||
| 	{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \ | 	{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \ | ||||||
| 	  PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) } | 	  PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Nguyễn Thái Ngọc Duy
						Nguyễn Thái Ngọc Duy