From: Jeremiah Mahler <jmmahler@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] format-patch --signature-file <file>
Date: Sat, 17 May 2014 01:59:11 -0700 [thread overview]
Message-ID: <20140517085911.GA18862@hudson.localdomain> (raw)
In-Reply-To: <20140517074224.GA16697@sigill.intra.peff.net>
On Sat, May 17, 2014 at 03:42:24AM -0400, Jeff King wrote:
> On Sat, May 17, 2014 at 12:25:48AM -0700, Jeremiah Mahler wrote:
>
> > > We have routines for reading directly into a strbuf, which eliminates
> > > the need for this 1024-byte limit. We even have a wrapper that can make
> > > this much shorter:
> > >
> > > struct strbuf buf = STRBUF_INIT;
> > >
> > > strbuf_read_file(&buf, arg, 128);
> > > *signature = strbuf_detach(&buf, NULL);
> > >
> >
> > Yes, that is much cleaner.
> > The memory returned by strbuf_detach() will have to be freed as well.
>
> In cases like this, we often let the memory leak. It's in a global that
> stays valid through the whole program, so we just let the program's exit
> clean it up.
>
It bugs me but I see your point.
It works just fine in this situation.
> > Having --signature-file override --signature seems simpler to implement.
> > The signature variable has a default value which complicates
> > determining whether it was set or not.
>
> Yeah, the default value complicates it. I think you can handle that just
> by moving the default to the main logic, like:
>
> static const char *signature;
> static const char *signature_file;
>
> ...
>
> if (signature) {
> if (signature_file)
> die("you cannot specify both a signature and a signature-file");
> /* otherwise, we already have the value */
> } else if (signature_file) {
> struct strbuf buf = STRBUF_INIT;
> strbuf_read(&buf, signature_file, 128);
> signature = strbuf_detach(&buf);
> } else
> signature = git_version_string;
>
Before, --no-signature would clear the &signature.
With this code it sees it as not being set and assigns
the default version string.
> and as a bonus, that keeps all of the logic together in one (fairly
> readable) chain.
>
> -Peff
--
Jeremiah Mahler
jmmahler@gmail.com
http://github.com/jmahler
next prev parent reply other threads:[~2014-05-17 8:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 1:31 [PATCH v2] format-patch --signature-file <file> Jeremiah Mahler
2014-05-16 1:31 ` Jeremiah Mahler
2014-05-16 8:14 ` Jeff King
2014-05-17 7:25 ` Jeremiah Mahler
2014-05-17 7:42 ` Jeff King
2014-05-17 8:59 ` Jeremiah Mahler [this message]
2014-05-17 10:00 ` Jeff King
2014-05-17 15:39 ` Jeremiah Mahler
2014-05-19 16:54 ` Junio C Hamano
2014-05-20 5:46 ` Jeremiah Mahler
2014-05-20 6:21 ` Jeff King
2014-05-20 15:06 ` Junio C Hamano
2014-05-21 0:45 ` Jeremiah Mahler
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=20140517085911.GA18862@hudson.localdomain \
--to=jmmahler@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.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).