@matheusbsbs / matheus-bagliano / commits / 6b61ec0564
Fork 0

revisions: refactor handle_revision_opt into parse_revision_opt.

It seems we're using handle_revision_opt the same way each time, have a wrapper around it that does the 9-liner we copy each time instead. handle_revision_opt can be static in the module for now, it's always possible to make it public again if needed. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pierre Habouzit committed Jul 9, 2008 at 23:38 UTC 6b61ec0564993d2e60f7eb56c0f0fd9c313d5e2c
4 files changed +23 -23
builtin-blame.c
+1 -10
@@ -2305,8 +2305,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2305 parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH |
2306 PARSE_OPT_KEEP_ARGV0);
2307 for (;;) {
2308 - int n;
2309 -
2308 switch (parse_options_step(&ctx, options, blame_opt_usage)) {
2309 case PARSE_OPT_HELP:
2310 exit(129);
@@ -2320,14 +2318,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2318 ctx.argv[0] = "--children";
2319 reverse = 1;
2320 }
2323 - n = handle_revision_opt(&revs, ctx.argc, ctx.argv,
2324 - &ctx.cpidx, ctx.out);
2325 - if (n <= 0) {
2326 - error("unknown option `%s'", ctx.argv[0]);
2327 - usage_with_options(blame_opt_usage, options);
2328 - }
2329 - ctx.argv += n;
2330 - ctx.argc -= n;
2321 + parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
2322 }
2323 parse_done:
2324 argc = parse_options_end(&ctx);
builtin-shortlog.c
+1 -9
@@ -255,21 +255,13 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
255 PARSE_OPT_KEEP_ARGV0);
256
257 for (;;) {
258 - int n;
258 switch (parse_options_step(&ctx, options, shortlog_usage)) {
259 case PARSE_OPT_HELP:
260 exit(129);
261 case PARSE_OPT_DONE:
262 goto parse_done;
263 }
265 - n = handle_revision_opt(&rev, ctx.argc, ctx.argv,
266 - &ctx.cpidx, ctx.out);
267 - if (n <= 0) {
268 - error("unknown option `%s'", ctx.argv[0]);
269 - usage_with_options(shortlog_usage, options);
270 - }
271 - ctx.argv += n;
272 - ctx.argc -= n;
264 + parse_revision_opt(&rev, &ctx, options, shortlog_usage);
265 }
266 parse_done:
267 argc = parse_options_end(&ctx);
revision.c
+16 -2
@@ -957,8 +957,8 @@ static void add_ignore_packed(struct rev_info *revs, const char *name)
957 revs->ignore_packed[num] = NULL;
958 }
959
960 -int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
961 - int *unkc, const char **unkv)
960 +static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
961 + int *unkc, const char **unkv)
962 {
963 const char *arg = argv[0];
964
@@ -1163,6 +1163,20 @@ int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
1163 return 1;
1164 }
1165
1166 +void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
1167 + const struct option *options,
1168 + const char * const usagestr[])
1169 +{
1170 + int n = handle_revision_opt(revs, ctx->argc, ctx->argv,
1171 + &ctx->cpidx, ctx->out);
1172 + if (n <= 0) {
1173 + error("unknown option `%s'", ctx->argv[0]);
1174 + usage_with_options(usagestr, options);
1175 + }
1176 + ctx->argv += n;
1177 + ctx->argc -= n;
1178 +}
1179 +
1180 /*
1181 * Parse revision information, filling in the "rev_info" structure,
1182 * and removing the used arguments from the argument list.
revision.h
+5 -2
@@ -1,6 +1,8 @@
1 #ifndef REVISION_H
2 #define REVISION_H
3
4 +#include "parse-options.h"
5 +
6 #define SEEN (1u<<0)
7 #define UNINTERESTING (1u<<1)
8 #define TREESAME (1u<<2)
@@ -119,8 +121,9 @@ volatile show_early_output_fn_t show_early_output;
121
122 extern void init_revisions(struct rev_info *revs, const char *prefix);
123 extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);
122 -extern int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
123 - int *unkc, const char **unkv);
124 +extern void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
125 + const struct option *options,
126 + const char * const usagestr[]);
127 extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename);
128
129 extern int prepare_revision_walk(struct rev_info *revs);