git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Fredrik Gustafsson <iveqy@iveqy.com>
To: Jens Lehmann <Jens.Lehmann@web.de>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	Heiko Voigt <hvoigt@hvoigt.net>,
	Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Subject: Re: [PATCH v3 5/5] rm: delete .gitmodules entry of submodules removed from the work tree
Date: Tue, 30 Jul 2013 22:15:11 +0200	[thread overview]
Message-ID: <20130730201511.GC19369@paksenarrion.iveqy.com> (raw)
In-Reply-To: <51F81957.1000709@web.de>

On Tue, Jul 30, 2013 at 09:51:51PM +0200, Jens Lehmann wrote:
> +/*
> + * Try to remove the "submodule.<name>" section from .gitmodules where the given
> + * path is configured. Return 0 only if a .gitmodules file was found, a section
> + * with the correct path=<path> setting was found and we could remove it.
> + */
> +int remove_path_from_gitmodules(const char *path)
> +{
> +	struct strbuf sect = STRBUF_INIT;
> +	struct string_list_item *path_option;
> +
> +	if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */
> +		return -1;
> +
> +	if (gitmodules_is_unmerged)
> +		die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
> +
> +	path_option = unsorted_string_list_lookup(&config_name_for_path, path);
> +	if (!path_option) {
> +		warning(_("Could not find section in .gitmodules where path=%s"), path);
> +		return -1;
> +	}
> +	strbuf_addstr(&sect, "submodule.");
> +	strbuf_addstr(&sect, path_option->util);
> +	if (git_config_rename_section_in_file(".gitmodules", sect.buf, NULL) < 0) {
> +		/* Maybe the user already did that, don't error out here */
> +		warning(_("Could not remove .gitmodules entry for %s"), path);
> +		return -1;
> +	}
> +	strbuf_release(&sect);
> +	return 0;
> +}

This question applies for this function and a few more functions in this
patch that has the same characteristics.

If we're in a state when we need to return non-zero, we don't do any
cleaning (that is strbuf_release()). Since this file is in the part
called libgit AFAIK, shouldn't we always clean after us?

Would it make sense to have different return values for different
errors?

I do like the comments above the function, more functions (at least
non-static ones) should follow this good style IMHO.
-- 
Med vänliga hälsningar
Fredrik Gustafsson

tel: 0733-608274
e-post: iveqy@iveqy.com

  reply	other threads:[~2013-07-30 20:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-30 19:48 [PATCH v3 0/5] Teach mv to move submodules Jens Lehmann
2013-07-30 19:49 ` [PATCH v3 1/5] Teach mv to move submodules together with their work trees Jens Lehmann
2013-07-30 19:50 ` [PATCH v3 2/5] Teach mv to move submodules using a gitfile Jens Lehmann
2013-07-31  9:43   ` Fredrik Gustafsson
2013-07-30 19:50 ` [PATCH v3 3/5] submodule.c: add .gitmodules staging helper functions Jens Lehmann
2013-07-30 21:37   ` Junio C Hamano
2013-07-30 23:13     ` Jens Lehmann
2013-07-30 19:51 ` [PATCH v3 4/5] Teach mv to update the path entry in .gitmodules for moved submodules Jens Lehmann
2013-08-06 19:15   ` [PATCH v4 " Jens Lehmann
2013-07-30 19:51 ` [PATCH v3 5/5] rm: delete .gitmodules entry of submodules removed from the work tree Jens Lehmann
2013-07-30 20:15   ` Fredrik Gustafsson [this message]
2013-07-30 23:06     ` Jens Lehmann
2013-08-06 19:15   ` [PATCH v4 " Jens Lehmann
2013-08-06 21:11     ` Junio C Hamano
2013-08-07 16:51       ` Jens Lehmann
2013-08-07 18:28       ` Fredrik Gustafsson
2013-08-08 17:11         ` Jens Lehmann
2013-08-08 18:55           ` Fredrik Gustafsson

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=20130730201511.GC19369@paksenarrion.iveqy.com \
    --to=iveqy@iveqy.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hvoigt@hvoigt.net \
    --cc=pclouds@gmail.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).