git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 02/11] tag: libify parse_opt_points_at()

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jun 16, 2015, 14:20 UTC
Message-ID
<1434464457-10749-2-git-send-email-karthik.188@gmail.com>
In-Reply-To
<1434464457-10749-1-git-send-email-karthik.188@gmail.com>

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>
---
 builtin/tag.c      | 21 ++-------------------
 parse-options-cb.c | 17 +++++++++++++++++
 parse-options.h    |  1 +
 3 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index 5f6cdc5..e36c43e 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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()
 	};
diff --git a/parse-options-cb.c b/parse-options-cb.c
index be8c413..de75411 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -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;
diff --git a/parse-options.h b/parse-options.h
index c71e9da..36c71fe 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -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);
-- 
2.4.3.436.g722e2ce.dirty
Previous: Karthik NayakNext: Karthik Nayak
Message 3 of 23 in “add options to for-each-ref”
  1. 00/11 add options to for-each-refkarthik nayak, Jun 16, 2015
  2. 01/11 t6301: for-each-ref tests for ref-filter APIsKarthik Nayak, Jun 16, 2015
  3. 02/11 tag: libify parse_opt_points_at()Karthik Nayak, Jun 16, 2015
  4. 03/11 ref-filter: implement '--points-at' optionKarthik Nayak, Jun 16, 2015
  5. 04/11 for-each-ref: add '--points-at' optionKarthik Nayak, Jun 16, 2015
  6. Matthieu MoyJun 16, 2015
  7. karthik nayakJun 16, 2015
  8. 05/11 ref-filter: add parse_opt_merge_filter()Karthik Nayak, Jun 16, 2015
  9. Matthieu MoyJun 16, 2015
  10. karthik nayakJun 16, 2015
  11. Matthieu MoyJun 17, 2015
  12. karthik nayakJun 17, 2015
  13. 06/11 ref-filter: implement '--merged' and '--no-merged' optionsKarthik Nayak, Jun 16, 2015
  14. Matthieu MoyJun 17, 2015
  15. karthik nayakJun 17, 2015
  16. 07/11 for-each-ref: add '--merged' and '--no-merged' optionsKarthik Nayak, Jun 16, 2015
  17. 08/11 parse-option: rename parse_opt_with_commit()Karthik Nayak, Jun 16, 2015
  18. 09/11 parse-options.h: add macros for '--contains' optionKarthik Nayak, Jun 16, 2015
  19. 10/11 ref-filter: implement '--contains' optionKarthik Nayak, Jun 16, 2015
  20. 11/11 for-each-ref: add '--contains' optionKarthik Nayak, Jun 16, 2015
  21. Matthieu MoyJun 17, 2015
  22. Matthieu MoyJun 16, 2015
  23. karthik nayakJun 16, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.