All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: "René Scharfe" <l.s.r@web.de>, "Git List" <git@vger.kernel.org>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH 0/8] write_file cleanups
Date: Fri, 8 Jul 2016 05:04:01 -0400	[thread overview]
Message-ID: <20160708090400.GA26594@sigill.intra.peff.net> (raw)
In-Reply-To: <20160708065650.GA10664@sigill.intra.peff.net>

On Fri, Jul 08, 2016 at 02:56:50AM -0400, Jeff King wrote:

> > This is more an illustration of unnecessarily duplicated code, isn't it?
> > There are *tons* of instances in Git's code where writing to a file is
> > implemented separately (and differently).
> > 
> > It would make tons of sense to consolidate all of these instances,
> > methinks. The diffstat should look *very* pleasing.
> 
> I grepped for O_WRONLY, and there are fewer instances than I would have
> thought. Most of the obvious write_file() candidates are in the merge
> code, which is probably why you saw so many of them. :)
> 
> I started at converting a few sites, but it's actually a little awkward
> because they all have strbufs (with a ptr/len combo that _could_ contain
> NULs, but probably doesn't), and write_file() wants to take a format
> string.
> 
> I think we can clean that up, though. I'll hopefully have a series in a
> few minutes.

Here it is. There actually weren't that many spots to clean up, as quite
a few of them have a "twist" where they want to do something clever,
like open the file and feed the descriptor to a sub-function, or open
with funny things like O_EXCL.

But still, the diffstat is pleasing:

 builtin/am.c     | 25 +++++++----------
 builtin/branch.c |  5 +---
 builtin/config.c |  2 +-
 builtin/merge.c  | 45 ++++--------------------------
 cache.h          | 17 ++++++++++--
 wrapper.c        | 52 ++++++++---------------------------
 6 files changed, 44 insertions(+), 102 deletions(-)

and that even includes adding some function documentation.

The most interesting thing is that I also found a real bug, albeit a
fairly minor one. I floated that up to the front of the series.

  [1/8]: config: fix bogus fd check when setting up default config
  [2/8]: am: ignore return value of write_file()
  [3/8]: branch: use non-gentle write_file for branch description
  [4/8]: write_file: drop "gently" form
  [5/8]: write_file: use xopen
  [6/8]: write_file: add pointer+len variant
  [7/8]: write_file: add format attribute
  [8/8]: use write_file_buf where applicable

-Peff

  reply	other threads:[~2016-07-08  9:04 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-07 20:02 [PATCH] am: ignore return value of write_file() René Scharfe
2016-07-07 20:31 ` Jeff King
2016-07-08  6:37   ` Johannes Schindelin
2016-07-08  6:56     ` Jeff King
2016-07-08  9:04       ` Jeff King [this message]
2016-07-08  9:06         ` [PATCH 1/8] config: fix bogus fd check when setting up default config Jeff King
2016-07-08  9:08         ` [PATCH 2/8] am: ignore return value of write_file() Jeff King
2016-07-08  9:08         ` [PATCH 3/8] branch: use non-gentle write_file for branch description Jeff King
2016-07-08  9:09         ` [PATCH 4/8] write_file: drop "gently" form Jeff King
2016-07-08  9:10         ` [PATCH 5/8] write_file: use xopen Jeff King
2016-07-08  9:12         ` [PATCH 6/8] write_file: add pointer+len variant Jeff King
2016-07-08  9:12         ` [PATCH 7/8] write_file: add format attribute Jeff King
2016-07-08  9:25           ` Jeff King
2016-07-08  9:25             ` [PATCH 1/2] walker: let walker_say take arbitrary formats Jeff King
2016-07-08  9:25             ` [PATCH 2/2] avoid using sha1_to_hex output as printf format Jeff King
2016-07-08 10:35               ` Jeff King
2016-07-08 17:02                 ` Junio C Hamano
2016-07-08 17:09                   ` Junio C Hamano
2016-07-08 21:41                     ` Jeff King
2016-07-08  9:12         ` [PATCH 8/8] use write_file_buf where applicable Jeff King
2016-07-08  9:16         ` [PATCH 9/8] branch: use write_file_buf instead of write_file Jeff King
2016-07-08 18:44         ` [PATCH 0/8] write_file cleanups René Scharfe
2016-07-09 14:24       ` [PATCH] am: ignore return value of write_file() Johannes Schindelin
2016-07-10 10:53         ` Johannes Schindelin
2016-07-08  6:33 ` Johannes Schindelin
2016-07-08 18:44   ` René Scharfe
2016-07-08 21:51     ` Jeff King

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=20160708090400.GA26594@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.