1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-21 10:26:08 +02:00

tag: libify parse_opt_points_at()

Rename 'parse_opt_points_at()' to 'parse_opt_object_name()' and
move it from 'tag.c' to 'parse-options'. This now acts as a common
parse_opt function which accepts an objectname and stores it into
a sha1_array.

Based-on-patch-by: Jeff King <peff@peff.net>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Karthik Nayak 2015-07-07 21:36:08 +05:30 committed by Junio C Hamano
parent af83bafa48
commit b2172fdf70
3 changed files with 20 additions and 19 deletions

View File

@ -546,23 +546,6 @@ static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
return check_refname_format(sb->buf, 0);
}
static int parse_opt_points_at(const struct option *opt __attribute__((unused)),
const char *arg, int unset)
{
unsigned char sha1[20];
if (unset) {
sha1_array_clear(&points_at);
return 0;
}
if (!arg)
return error(_("switch 'points-at' requires an object"));
if (get_sha1(arg, sha1))
return error(_("malformed object name '%s'"), arg);
sha1_array_append(&points_at, sha1);
return 0;
}
static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
{
int *sort = opt->value;
@ -625,8 +608,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
parse_opt_with_commit, (intptr_t)"HEAD",
},
{
OPTION_CALLBACK, 0, "points-at", NULL, N_("object"),
N_("print only tags of the object"), 0, parse_opt_points_at
OPTION_CALLBACK, 0, "points-at", &points_at, N_("object"),
N_("print only tags of the object"), 0, parse_opt_object_name
},
OPT_END()
};

View File

@ -4,6 +4,7 @@
#include "commit.h"
#include "color.h"
#include "string-list.h"
#include "sha1-array.h"
/*----- some often used options -----*/
@ -92,6 +93,22 @@ int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
return 0;
}
int parse_opt_object_name(const struct option *opt, const char *arg, int unset)
{
unsigned char sha1[20];
if (unset) {
sha1_array_clear(opt->value);
return 0;
}
if (!arg)
return -1;
if (get_sha1(arg, sha1))
return error(_("malformed object name '%s'"), arg);
sha1_array_append(opt->value, sha1);
return 0;
}
int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
{
int *target = opt->value;

View File

@ -220,6 +220,7 @@ extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
extern int parse_opt_expiry_date_cb(const struct option *, const char *, int);
extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
extern int parse_opt_object_name(const struct option *, const char *, int);
extern int parse_opt_with_commit(const struct option *, const char *, int);
extern int parse_opt_tertiary(const struct option *, const char *, int);
extern int parse_opt_string_list(const struct option *, const char *, int);