From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Pranit Bauva <pranit.bauva@gmail.com>,
Git List <git@vger.kernel.org>,
Christian Couder <christian.couder@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>,
Lars Schneider <larsxschneider@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v6 3/3] bisect--helper: `write_terms` shell function in C
Date: Mon, 16 May 2016 18:45:42 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.20.1605161830200.3303@virtualbox> (raw)
In-Reply-To: <CAPig+cQ=Gche_uO840wF6qE4WD-ZNZj1HFzNNgaBi_UjG1sjEg@mail.gmail.com>
Hi Eric,
On Mon, 16 May 2016, Eric Sunshine wrote:
> On Mon, May 16, 2016 at 9:16 AM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > On Mon, 16 May 2016, Eric Sunshine wrote:
> >> On Thu, May 12, 2016 at 1:32 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
> >> > + fp = fopen(".git/BISECT_TERMS", "w");
> >>
> >> Hardcoding ".git/" is wrong for a variety of reasons: It won't be correct
> >> with linked worktrees, or when GIT_DIR is pointing elsewhere, or when ".git"
> >> is a symbolic link, etc. Check out the get_git_dir(), get_git_common_dir(),
> >> etc. functions in cache.h instead.
> >
> > Maybe in this case, `git_path("BISECT_TERMS")` would be a good idea. Or even
> > better: follow the example of bisect.c and use
> > `GIT_PATH_FUNC(bisect_terms_path, "BISECT_TERMS")`.
>
> Thanks for pointing this out. My review time is severely limited these
> days so I didn't go the distance of re-studying and re-digesting which
> function was the correct one to use.
I am constantly amazed how much you manage to review, and how helpful your
comments are. I am glad if I could contribute a little.
> >> > + strbuf_release(&content);
> >> > + die_errno(_("could not open the file to read terms"));
> >>
> >> Is dying here correct? I thought we established previously that you
> >> should be reporting failure via normal -1 return value rather than
> >> dying. Indeed, you're doing so below when strbuf_write() fails.
> >
> > The rule of thumb seems to be that die()ing is okay in builtin/*.c, but not
> > in *.c. So technically, it would be okay here, too. However, I think that
> > this code should be written with libification in mind, so I would also
> > prefer it to error() and return, to give the caller a chance to do other
> > things after an error occurred.
>
> Agreed. Specific to the "established previously" I wrote above, I was
> referring to [1] from just a few days ago which explained why 'return
> -1' was preferable to die() in a similar case that had an odd mix of
> 'return -1' and die() in the same function.
>
> [1]: http://thread.gmane.org/gmane.comp.version-control.git/289476/focus=293556
Yes, this is an excellent link. Maybe we would want something like this,
too?
-- snipsnap --
(From: Eric Sunshine <sunshine@sunshineco.com>)
CodingGuidelines: mention that die() is for fatal errors only
Let's formalize the rule when to use die() and when to use error().
diff --git a/Documentation/CodingGuidelines
b/Documentation/CodingGuidelines
index 0ddd368..5d2d65f 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -333,6 +333,10 @@ For C programs:
- When you come up with an API, document it.
+ - Use die() only to signal an exceptional conditions which should
+ abort the program. All other error conditions should instead
+ return e.g. using "return error(...)".
+
- The first #include in C files, except in platform specific compat/
implementations, must be either "git-compat-util.h", "cache.h" or
"builtin.h". You do not have to include more than one of these.
next prev parent reply other threads:[~2016-05-16 16:47 UTC|newest]
Thread overview: 114+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-21 19:00 [PATCH] bisect--helper: convert a function in shell to C Pranit Bauva
2016-03-22 0:28 ` Stefan Beller
2016-03-22 6:10 ` Christian Couder
2016-03-22 6:13 ` Pranit Bauva
2016-03-22 6:13 ` Pranit Bauva
2016-03-22 8:01 ` [PATCH v2] " Pranit Bauva
2016-03-22 15:09 ` Johannes Schindelin
2016-03-22 15:11 ` Johannes Schindelin
2016-03-22 17:46 ` Pranit Bauva
2016-03-23 11:23 ` Johannes Schindelin
2016-03-22 16:03 ` Junio C Hamano
2016-03-22 16:49 ` Johannes Schindelin
2016-03-22 17:52 ` Pranit Bauva
2016-03-22 17:59 ` Stefan Beller
2016-03-23 11:24 ` Johannes Schindelin
2016-03-22 17:45 ` Pranit Bauva
2016-03-23 11:22 ` Johannes Schindelin
2016-03-23 13:53 ` Pranit Bauva
2016-03-23 7:16 ` [PATCH v3] " Pranit Bauva
2016-03-23 11:57 ` Johannes Schindelin
2016-03-23 13:16 ` Pranit Bauva
2016-03-23 16:24 ` Junio C Hamano
2016-03-23 18:38 ` Pranit Bauva
2016-03-23 16:15 ` Junio C Hamano
2016-03-23 18:46 ` Pranit Bauva
2016-05-04 5:07 ` [PATCH 0/2] bisect--helper: rewrite of check_term_format() Pranit Bauva
2016-05-04 5:07 ` [PATCH 1/2] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-04 5:34 ` Pranit Bauva
2016-05-04 6:07 ` Eric Sunshine
2016-05-04 6:50 ` Christian Couder
2016-05-04 11:05 ` Johannes Schindelin
2016-05-04 12:04 ` Pranit Bauva
2016-05-04 12:05 ` Christian Couder
2016-05-04 12:21 ` Johannes Schindelin
2016-05-04 12:41 ` Christian Couder
2016-05-04 14:56 ` Johannes Schindelin
2016-05-04 19:07 ` Christian Couder
2016-05-08 6:54 ` Johannes Schindelin
2016-05-04 7:28 ` Junio C Hamano
2016-05-04 11:02 ` Johannes Schindelin
2016-05-04 5:07 ` [PATCH 2/2] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-04 6:52 ` Eric Sunshine
2016-05-04 7:36 ` Pranit Bauva
2016-05-04 7:40 ` Pranit Bauva
2016-05-04 8:28 ` Eric Sunshine
2016-05-04 8:54 ` Christian Couder
2016-05-04 11:58 ` Pranit Bauva
2016-05-04 17:49 ` Eric Sunshine
2016-05-04 18:08 ` Pranit Bauva
2016-05-04 11:13 ` Johannes Schindelin
2016-05-04 12:00 ` Pranit Bauva
2016-05-04 12:21 ` Christian Couder
2016-05-04 19:10 ` Junio C Hamano
2016-05-04 5:22 ` [PATCH 0/2] bisect--helper: rewrite of check_term_format() Christian Couder
2016-05-04 5:25 ` Pranit Bauva
2016-05-06 14:49 ` [PATCH v5 0/2] bisect--helper: rewrite of check-term-format() Pranit Bauva
2016-05-06 14:49 ` [PATCH v5 1/2] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-08 7:04 ` Johannes Schindelin
2016-05-08 7:17 ` Pranit Bauva
2016-05-08 15:30 ` Christian Couder
2016-05-08 15:33 ` Pranit Bauva
2016-05-09 14:59 ` Johannes Schindelin
2016-05-09 15:33 ` Pranit Bauva
2016-05-06 14:49 ` [PATCH v5 2/2] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-07 0:05 ` Eric Sunshine
2016-05-06 22:15 ` [PATCH v5 0/2] bisect--helper: rewrite of check-term-format() Junio C Hamano
2016-05-07 13:07 ` Pranit Bauva
2016-05-08 2:25 ` Junio C Hamano
2016-05-08 6:23 ` Pranit Bauva
2016-05-08 13:34 ` Pranit Bauva
2016-05-16 0:35 ` Eric Sunshine
2016-05-16 17:07 ` Christian Couder
2016-05-20 6:59 ` Pranit Bauva
2016-05-12 5:32 ` [PATCH v6 0/3] bisect--helper: check_term_format() & write_terms() Pranit Bauva
2016-05-12 5:32 ` [PATCH v6 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-16 7:07 ` Eric Sunshine
2016-05-20 7:17 ` Pranit Bauva
2016-05-12 5:32 ` [PATCH v6 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-12 22:36 ` Junio C Hamano
2016-05-13 6:59 ` Pranit Bauva
2016-05-13 18:01 ` Junio C Hamano
2016-05-12 5:32 ` [PATCH v6 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-16 7:28 ` Eric Sunshine
2016-05-16 13:16 ` Johannes Schindelin
2016-05-16 15:42 ` Eric Sunshine
2016-05-16 16:45 ` Johannes Schindelin [this message]
2016-05-16 16:59 ` Eric Sunshine
2016-05-20 7:45 ` Pranit Bauva
2016-05-23 11:07 ` Johannes Schindelin
2016-05-23 13:58 ` Christian Couder
2016-05-23 15:10 ` Johannes Schindelin
2016-05-23 14:33 ` Pranit Bauva
2016-05-20 7:42 ` Pranit Bauva
2016-05-23 14:48 ` [PATCH v7 0/3] bisect--helper: check_term_format() & write_terms() Pranit Bauva
2016-05-23 14:48 ` [PATCH v7 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-23 14:48 ` [PATCH v7 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-23 14:48 ` [PATCH v7 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-23 16:01 ` Eric Sunshine
2016-05-23 17:59 ` Pranit Bauva
2016-05-24 7:21 ` [PATCH v8 0/3] bisect--helper: check-term-format() & write_terms() Pranit Bauva
2016-05-24 18:42 ` [PATCH v9 0/3] bisect--helper: check_term_format() and write_terms() Pranit Bauva
2016-05-24 18:42 ` [PATCH v9 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-24 18:42 ` [PATCH v9 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-24 18:42 ` [PATCH v9 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-24 7:21 ` [PATCH v8 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-24 7:21 ` [PATCH v8 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-25 5:04 ` Johannes Schindelin
2016-05-25 5:13 ` Pranit Bauva
2016-06-16 7:10 ` Lars Schneider
2016-06-17 12:48 ` Pranit Bauva
2016-05-24 7:21 ` [PATCH v8 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-24 7:33 ` Christian Couder
2016-05-24 17:39 ` Junio C Hamano
2016-05-24 18:31 ` Pranit Bauva
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1605161830200.3303@virtualbox \
--to=johannes.schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=larsxschneider@gmail.com \
--cc=pranit.bauva@gmail.com \
--cc=sunshine@sunshineco.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).