Skip to content

Commit 269defd

Browse files
Jake Gouldinggitster
authored andcommitted
Make opt_parse_with_commit() non-static
Moving opt_parse_with_commit() from branch to a common location, in preparation for using it in tag. Rename it to match naming convention of other option parsing functions. Signed-off-by: Jake Goulding <goulding@vivisimo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 98ef23b commit 269defd

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

builtin-branch.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -466,22 +466,6 @@ static void rename_branch(const char *oldname, const char *newname, int force)
466466
strbuf_release(&newsection);
467467
}
468468

469-
static int opt_parse_with_commit(const struct option *opt, const char *arg, int unset)
470-
{
471-
unsigned char sha1[20];
472-
struct commit *commit;
473-
474-
if (!arg)
475-
return -1;
476-
if (get_sha1(arg, sha1))
477-
die("malformed object name %s", arg);
478-
commit = lookup_commit_reference(sha1);
479-
if (!commit)
480-
die("no such commit %s", arg);
481-
commit_list_insert(commit, opt->value);
482-
return 0;
483-
}
484-
485469
static int opt_parse_merge_filter(const struct option *opt, const char *arg, int unset)
486470
{
487471
merge_filter = ((opt->long_name[0] == 'n')
@@ -517,13 +501,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
517501
OPTION_CALLBACK, 0, "contains", &with_commit, "commit",
518502
"print only branches that contain the commit",
519503
PARSE_OPT_LASTARG_DEFAULT,
520-
opt_parse_with_commit, (intptr_t)"HEAD",
504+
parse_opt_with_commit, (intptr_t)"HEAD",
521505
},
522506
{
523507
OPTION_CALLBACK, 0, "with", &with_commit, "commit",
524508
"print only branches that contain the commit",
525509
PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT,
526-
opt_parse_with_commit, (intptr_t) "HEAD",
510+
parse_opt_with_commit, (intptr_t) "HEAD",
527511
},
528512
OPT__ABBREV(&abbrev),
529513

parse-options.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "git-compat-util.h"
22
#include "parse-options.h"
33
#include "cache.h"
4+
#include "commit.h"
45

56
#define OPT_SHORT 1
67
#define OPT_UNSET 2
@@ -506,6 +507,22 @@ int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
506507
return 0;
507508
}
508509

510+
int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
511+
{
512+
unsigned char sha1[20];
513+
struct commit *commit;
514+
515+
if (!arg)
516+
return -1;
517+
if (get_sha1(arg, sha1))
518+
return error("malformed object name %s", arg);
519+
commit = lookup_commit_reference(sha1);
520+
if (!commit)
521+
return error("no such commit %s", arg);
522+
commit_list_insert(commit, opt->value);
523+
return 0;
524+
}
525+
509526
/*
510527
* This should really be OPTION_FILENAME type as a part of
511528
* parse_options that take prefix to do this while parsing.

parse-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ extern int parse_options_end(struct parse_opt_ctx_t *ctx);
151151
extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
152152
extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
153153
extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
154+
extern int parse_opt_with_commit(const struct option *, const char *, int);
154155

155156
#define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")
156157
#define OPT__QUIET(var) OPT_BOOLEAN('q', "quiet", (var), "be quiet")

0 commit comments

Comments
 (0)