From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: "Carlos Rica" <jasampler@gmail.com>, "Santi Béjar" <santi@agolina.net>
Subject: [PATCH 3/5] Expose verify_tag()
Date: Sat, 20 Mar 2010 00:13:28 -0500 [thread overview]
Message-ID: <20100320051327.GC24791@progeny.tock> (raw)
In-Reply-To: <20100320050953.GA24746@progeny.tock>
Expose the verify_tag() function so ‘git tag -v’ can use it directly
in the future. verify_tag() already frees all the memory it allocates
and does not call any functions that can exit, so this should be safe.
The function is renamed to verify_tag_signature() for clarity and to
avoid conflicting with builtin/tag.c and builtin/mktag.c’s unrelated
verify_tag().
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Makefile | 1 +
builtin/verify-tag.c | 85 +---------------------------------
tag.h | 1 +
builtin/verify-tag.c => verify-tag.c | 34 +-------------
4 files changed, 4 insertions(+), 117 deletions(-)
copy builtin/verify-tag.c => verify-tag.c (71%)
diff --git a/Makefile b/Makefile
index 7c616f8..ed58261 100644
--- a/Makefile
+++ b/Makefile
@@ -616,6 +616,7 @@ LIB_OBJS += unpack-trees.o
LIB_OBJS += usage.o
LIB_OBJS += userdiff.o
LIB_OBJS += utf8.o
+LIB_OBJS += verify-tag.o
LIB_OBJS += walker.o
LIB_OBJS += wrapper.o
LIB_OBJS += write_or_die.o
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 91dd1c1..ca075bd 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -5,12 +5,8 @@
*
* Based on git-verify-tag.sh
*/
-#include "cache.h"
#include "builtin.h"
#include "tag.h"
-#include "run-command.h"
-#include <signal.h>
-#include "sigchain.h"
#include "parse-options.h"
static const char * const verify_tag_usage[] = {
@@ -18,85 +14,6 @@ static const char * const verify_tag_usage[] = {
NULL
};
-#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
-
-static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
-{
- struct child_process gpg;
- const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL};
- char path[PATH_MAX], *eol;
- size_t len;
- int fd, ret;
-
- fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX");
- if (fd < 0)
- return error("could not create temporary file '%s': %s",
- path, strerror(errno));
- if (write_in_full(fd, buf, size) < 0)
- return error("failed writing temporary file '%s': %s",
- path, strerror(errno));
- close(fd);
-
- /* find the length without signature */
- len = 0;
- while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) {
- eol = memchr(buf + len, '\n', size - len);
- len += eol ? eol - (buf + len) + 1 : size - len;
- }
- if (verbose)
- write_in_full(1, buf, len);
-
- memset(&gpg, 0, sizeof(gpg));
- gpg.argv = args_gpg;
- gpg.in = -1;
- args_gpg[2] = path;
- if (start_command(&gpg)) {
- unlink(path);
- return error("could not run gpg.");
- }
-
- /*
- * gpg will stop as soon as it knows the signature is bad,
- * which can result in SIGPIPE.
- */
- sigchain_push(SIGPIPE, SIG_IGN);
- write_in_full(gpg.in, buf, len);
- close(gpg.in);
- sigchain_pop(SIGPIPE);
-
- ret = finish_command(&gpg);
-
- unlink_or_warn(path);
-
- return ret;
-}
-
-static int verify_tag(const char *name, int verbose)
-{
- enum object_type type;
- unsigned char sha1[20];
- char *buf;
- unsigned long size;
- int ret;
-
- if (get_sha1(name, sha1))
- return error("tag '%s' not found.", name);
-
- type = sha1_object_info(sha1, NULL);
- if (type != OBJ_TAG)
- return error("%s: cannot verify a non-tag object of type %s.",
- name, typename(type));
-
- buf = read_sha1_file(sha1, &type, &size);
- if (!buf)
- return error("%s: unable to read file.", name);
-
- ret = run_gpg_verify(buf, size, verbose);
-
- free(buf);
- return ret;
-}
-
int cmd_verify_tag(int argc, const char **argv, const char *prefix)
{
int i = 1, verbose = 0, had_error = 0;
@@ -113,7 +30,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
usage_with_options(verify_tag_usage, verify_tag_options);
while (i < argc)
- if (verify_tag(argv[i++], verbose))
+ if (verify_tag_signature(argv[i++], verbose))
had_error = 1;
return had_error;
}
diff --git a/tag.h b/tag.h
index 7a0cb00..1034109 100644
--- a/tag.h
+++ b/tag.h
@@ -16,5 +16,6 @@ extern struct tag *lookup_tag(const unsigned char *sha1);
extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size);
extern int parse_tag(struct tag *item);
extern struct object *deref_tag(struct object *, const char *, int);
+extern int verify_tag_signature(const char *name, int verbose);
#endif /* TAG_H */
diff --git a/builtin/verify-tag.c b/verify-tag.c
similarity index 71%
copy from builtin/verify-tag.c
copy to verify-tag.c
index 91dd1c1..7152e99 100644
--- a/builtin/verify-tag.c
+++ b/verify-tag.c
@@ -1,22 +1,11 @@
/*
- * Builtin "git verify-tag"
- *
* Copyright (c) 2007 Carlos Rica <jasampler@gmail.com>
- *
- * Based on git-verify-tag.sh
*/
#include "cache.h"
-#include "builtin.h"
#include "tag.h"
#include "run-command.h"
#include <signal.h>
#include "sigchain.h"
-#include "parse-options.h"
-
-static const char * const verify_tag_usage[] = {
- "git verify-tag [-v|--verbose] <tag>...",
- NULL
-};
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
@@ -71,7 +60,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
return ret;
}
-static int verify_tag(const char *name, int verbose)
+int verify_tag_signature(const char *name, int verbose)
{
enum object_type type;
unsigned char sha1[20];
@@ -96,24 +85,3 @@ static int verify_tag(const char *name, int verbose)
free(buf);
return ret;
}
-
-int cmd_verify_tag(int argc, const char **argv, const char *prefix)
-{
- int i = 1, verbose = 0, had_error = 0;
- const struct option verify_tag_options[] = {
- OPT__VERBOSE(&verbose),
- OPT_END()
- };
-
- git_config(git_default_config, NULL);
-
- argc = parse_options(argc, argv, prefix, verify_tag_options,
- verify_tag_usage, PARSE_OPT_KEEP_ARGV0);
- if (argc <= i)
- usage_with_options(verify_tag_usage, verify_tag_options);
-
- while (i < argc)
- if (verify_tag(argv[i++], verbose))
- had_error = 1;
- return had_error;
-}
--
1.7.0.2
next prev parent reply other threads:[~2010-03-20 5:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-20 5:09 [PATCH/RFC 0/5] libify verify_tag() Jonathan Nieder
2010-03-20 5:11 ` [PATCH 1/5] tag -v: use ‘git verify-tag’ without dash Jonathan Nieder
2010-03-20 16:01 ` Johannes Sixt
2010-03-20 21:29 ` Jonathan Nieder
2010-03-20 5:12 ` [PATCH 2/5] verify-tag: use sigchain library to block SIGPIPE Jonathan Nieder
2010-03-20 5:13 ` Jonathan Nieder [this message]
2010-03-20 5:14 ` [PATCH 4/5] tag -v: Do not spawn a separate process for verify-tag Jonathan Nieder
2010-03-20 22:14 ` [PATCH 4/5 v2] " Jonathan Nieder
2010-03-20 5:14 ` [PATCH 5/5] verify_tag_signature(): let caller look up tag object sha1 Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100320051327.GC24791@progeny.tock \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=jasampler@gmail.com \
--cc=santi@agolina.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).