From: Tobias Klauser <tklauser@distanz.ch>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Tobias Klauser <tobias.klauser@zhinst.com>,
Junio C Hamano <gitster@pobox.com>,
Christian Couder <chriscool@tuxfamily.org>,
Git List <git@vger.kernel.org>
Subject: Re: [PATCH] interpret-trailers: add option for in-place editing
Date: Thu, 7 Jan 2016 13:42:17 +0100 [thread overview]
Message-ID: <20160107124216.GK29125@distanz.ch> (raw)
In-Reply-To: <CAPig+cSvD-TAd6365wxycUcTBehL-81a0WWosz4mVr1-HKCqGQ@mail.gmail.com>
On 2016-01-06 at 20:02:23 +0100, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Wed, Jan 6, 2016 at 8:34 AM, Tobias Klauser
> <tobias.klauser@zhinst.com> wrote:
> > Add a command line option --in-place to support in-place editing akin to
> > sed -i. This allows to write commands like the following:
> >
> > git interpret-trailers --trailer "X: Y" a.txt > b.txt && mv b.txt a.txt
> >
> > in a more concise way:
> >
> > git interpret-trailers --trailer "X: Y" --in-place a.txt
> >
> > Also add the corresponding documentation and tests.
>
> In addition to Matthieu's comments...
>
> > Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> > ---
> > diff --git a/trailer.c b/trailer.c
> > @@ -856,19 +858,28 @@ void process_trailers(const char *file, int trim_empty, struct string_list *trai
> >
> > lines = read_input_file(file);
> >
> > + if (in_place) {
> > + fp = fopen(file, "w");
> > + if (!fp)
> > + die_errno(_("could not open file '%s' for writing"), file);
> > + }
>
> The input file should be considered precious, but this implementation
> plays too loosely with it. If the user interrupts the program or a
> die() somewhere within the "trailers" code aborts the program before
> the output file is written, then the original file will be
> irrecoverably lost. Users won't be happy about that.
Indeed, I didn't consider this. Thanks a lot for pointing this out.
> Instead, this code should go through the standard dance of writing the
> output to a new file (with some unique temporary name) and then, only
> once the output has been successfully written in full, rename the new
> file atop the old.
Ok, will do this for v2. I guess with the help of the functions from
tempfile.h it should be fairly easy to implement...
Thanks for your review!
prev parent reply other threads:[~2016-01-07 12:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-06 13:34 [PATCH] interpret-trailers: add option for in-place editing Tobias Klauser
2016-01-06 14:19 ` Matthieu Moy
2016-01-06 14:36 ` Tobias Klauser
2016-01-06 19:02 ` Eric Sunshine
2016-01-07 12:42 ` Tobias Klauser [this message]
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=20160107124216.GK29125@distanz.ch \
--to=tklauser@distanz.ch \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
--cc=tobias.klauser@zhinst.com \
/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).