All of lore.kernel.org
 help / color / mirror / Atom feed
From: Neil Horman <nhorman@tuxdriver.com>
To: Clemens Buchacher <drizzd@aon.at>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Phil Hord <phil.hord@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v5 2/4] git-cherry-pick: Add keep-redundant-commits option
Date: Mon, 16 Apr 2012 11:38:27 -0400	[thread overview]
Message-ID: <20120416153827.GC13366@hmsreliant.think-freely.org> (raw)
In-Reply-To: <20120415104212.GC6263@ecki>

On Sun, Apr 15, 2012 at 12:42:12PM +0200, Clemens Buchacher wrote:
> On Fri, Apr 13, 2012 at 02:45:05PM -0400, Neil Horman wrote:
> >
> > +                     OPT_BOOLEAN(0, "keep-redundant-commits", &opts->keep_if_made_empty, "keep redundant, empty commits"),
> 
> For consistency, I'd prefer if the variable name were the same as the
> option. Then I wouldn't have to keep the option<->variable translation
> in mind.
> 
Ok

> >
> > +     if (!empty && !opts->keep_if_made_empty) {
> [...]
> > +                     return 0;
> [...]
> >       if (opts->allow_empty)
> > +             argv_array_push(&array, "--allow-empty");
> > +
> > +     rc = run_command_v_opt(array.argv, RUN_GIT_CMD);
> 
> I find it a bit strange, that if we cherry-pick a commit that was
> already empty, we _do_ call git commit (and error out), but if we find a
> commit that is made empty, we do _not_ call git commit and quietly
> succeed (in not doing anything). But I suppose that is the legacy
> behavior?
> 
Correct, more or less.  The legacy behavior is to call git commit unilaterally.
With this change, we still do that, but we pass --allow-empty to the commit
command, allowing it to preserve the empty commit.  If we specify
keep-redundant-commits, we skip the check to see if the new commit is empty and
create the new (now empty) commit.  The only change is that if we do not specify
keep-redundant-commits, we check to see if the commit is made empty in
git-cherry-pick and skip it if it is.  We could, instead of returning prior to
calling git-commit, use that test to override the keep_empty option below, so
that we don't pass --allow-empty to git-commit instead.  That would preserve the
prior code path, but for no real advatage, as the outcome is the same, and this
way saves us having to fork the git-commit command, which I think is
adventageous.

> > +
> > +		rc = !hashcmp(active_cache_tree->sha1, head_commit->tree->object.sha1);
> > +
> > +		if (rc)
> 
> rc is short for run_command, for which it stores the return value, no?
> Let's not abuse the variable like this and instead use the result
> directly:
> 
No.  rc is short for return code, generically used to represent the value
to be returned from a function. Its used in this fashion in any number of
places, both in git and any other project. 

>  if (!hashcmp(active_cache_tree->sha1, head_commit->tree->object.sha1))
> 
> If you make the entire paragraph leading up to this a separate function,
> say index_is_empty(), then the above would read more naturally like
> this:
> 
>  if (!opts->keep_if_made_empty && !empty && index_is_empty())
> 
> > +			/*
> > +			 * The head tree and the parent tree match
> > +			 * meaning the commit is empty.  Since it wasn't created
> 
> Don't you mean the head tree and the index?
> 
yeah.

> > +			 * empty (based on the previous test), we can conclude
> > +			 * the commit has been made redundant.  Since we don't
> > +			 * want to keep redundant commits, just skip this one
> > +			 */
> > +			return 0;
> > +	}
> > +
> > +	argv_array_init(&array);
> > +	argv_array_push(&array, "commit");
> > +	argv_array_push(&array, "-n");
> >  
> > -	args[i++] = "commit";
> > -	args[i++] = "-n";
> >  	if (opts->signoff)
> > -		args[i++] = "-s";
> > +		argv_array_push(&array, "-s");
> >  	if (!opts->edit) {
> > -		args[i++] = "-F";
> > -		args[i++] = defmsg;
> > +		argv_array_push(&array, "-F");
> > +		argv_array_push(&array, defmsg);
> >  	}
> > +
> >  	if (opts->allow_empty)
> > -		args[i++] = "--allow-empty";
> > +		argv_array_push(&array, "--allow-empty");
> > +
> > +
> 
> Why two newlines?
> 
> > +	rc = run_command_v_opt(array.argv, RUN_GIT_CMD);
> > +	argv_array_clear(&array);
> > +	return rc;
> > +}
> 
> Looks good to me otherwise.
> 

  reply	other threads:[~2012-04-16 15:38 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30 19:48 [PATCH 0/4] Enhance git-rebases flexibiilty in handling empty commits Neil Horman
2012-03-30 19:48 ` [PATCH 1/4] git-cherry-pick: add keep-empty option Neil Horman
2012-03-30 20:34   ` Junio C Hamano
2012-03-30 21:15   ` Jeff King
2012-03-31 12:57   ` Neil Horman
2012-03-30 19:48 ` [PATCH 2/4] git-rebase: add keep_empty flag Neil Horman
2012-03-30 20:43   ` Junio C Hamano
2012-03-31 12:59     ` Neil Horman
2012-03-30 19:48 ` [PATCH 3/4] git-commit-am: Allow automatic rebasing to preserve empty commits Neil Horman
2012-03-30 20:46   ` Junio C Hamano
2012-03-31 13:01     ` Neil Horman
2012-03-30 20:47   ` Junio C Hamano
2012-03-31 13:03     ` Neil Horman
2012-03-30 19:48 ` [PATCH 4/4] git-commit-interactive: Allow " Neil Horman
2012-03-30 20:59   ` Junio C Hamano
2012-03-31 13:11     ` Neil Horman
2012-03-30 20:32 ` [PATCH 0/4] Enhance git-rebases flexibiilty in handling " Junio C Hamano
2012-04-05 19:39 ` [PATCH 0/5] Enhance git-rebases flexibiilty handling empty commits [v2] Neil Horman
2012-04-05 19:39   ` [PATCH 1/5] argv-array: Add argv_array_pop function [v2] Neil Horman
2012-04-05 20:12     ` Junio C Hamano
2012-04-05 23:24       ` Neil Horman
2012-04-06  0:12         ` Neil Horman
2012-04-06  0:19         ` Jeff King
2012-04-06  1:12           ` Neil Horman
2012-04-06  1:20         ` Junio C Hamano
2012-04-06  2:20           ` Jeff King
2012-04-06  4:19             ` Cc tags in the commit message (Re: [PATCH 1/5] argv-array: Add argv_array_pop function [v2]) Jonathan Nieder
2012-04-06  6:55             ` [PATCH 1/5] argv-array: Add argv_array_pop function [v2] Junio C Hamano
2012-04-06  7:33               ` Jeff King
2012-04-06 16:49                 ` Junio C Hamano
2012-04-06 18:02             ` Neil Horman
2012-04-05 19:39   ` [PATCH 2/5] git-cherry-pick: add allow-empty option [v2] Neil Horman
2012-04-05 19:39   ` [PATCH 3/5] git-cherry-pick: Add ignore-if-made-empty " Neil Horman
2012-04-05 21:01     ` Junio C Hamano
2012-04-05 23:45       ` Neil Horman
2012-04-06  1:20         ` Junio C Hamano
2012-04-06 18:06       ` Neil Horman
2012-04-06 18:30     ` Johannes Sixt
2012-04-05 19:39   ` [PATCH 4/5] git-cherry-pick: Add test to validate new options [v2] Neil Horman
2012-04-05 19:39   ` [PATCH 5/5] git-rebase: add keep_empty flag [v2] Neil Horman
2012-04-10 15:47 ` [PATCH v3 0/4] Enhance git-rebases flexibiilty in handling empty commits Neil Horman
2012-04-10 15:47   ` [PATCH v3 1/4] git-cherry-pick: add allow-empty option Neil Horman
2012-04-10 16:45     ` Junio C Hamano
2012-04-10 18:13       ` Neil Horman
2012-04-10 19:32         ` Junio C Hamano
2012-04-10 20:00           ` Neil Horman
2012-04-10 20:32             ` Junio C Hamano
2012-04-10 20:39               ` Neil Horman
2012-04-10 21:09                 ` Junio C Hamano
2012-04-11  0:44                   ` Neil Horman
2012-04-11 16:52                     ` Junio C Hamano
2012-04-11 18:29                       ` Neil Horman
2012-04-11 18:50                         ` Junio C Hamano
2012-04-11 18:56                           ` Neil Horman
2012-04-10 15:47   ` [PATCH v3 2/4] git-cherry-pick: Add keep-redundant-commits option Neil Horman
2012-04-10 17:04     ` Junio C Hamano
2012-04-10 18:25       ` Neil Horman
2012-04-10 15:47   ` [PATCH v3 3/4] git-cherry-pick: Add test to validate new options Neil Horman
2012-04-10 15:47   ` [PATCH v3 4/4] git-rebase: add keep_empty flag Neil Horman
2012-04-13 18:45 ` [PATCH v5 0/4]Enhance git-rebases flexibiilty in handling empty commits Neil Horman
2012-04-13 18:45   ` [PATCH v5 1/4] git-cherry-pick: add allow-empty option Neil Horman
2012-04-13 18:45   ` [PATCH v5 2/4] git-cherry-pick: Add keep-redundant-commits option Neil Horman
2012-04-15 10:42     ` Clemens Buchacher
2012-04-16 15:38       ` Neil Horman [this message]
2012-04-16 22:10         ` Clemens Buchacher
2012-04-17 10:43           ` Neil Horman
2012-04-17 15:42           ` Junio C Hamano
2012-04-17 21:37             ` Clemens Buchacher
2012-04-18 10:41               ` Neil Horman
2012-04-13 18:45   ` [PATCH v5 3/4] git-cherry-pick: Add test to validate new options Neil Horman
2012-04-15  9:39     ` Clemens Buchacher
2012-04-16 11:04       ` Neil Horman
2012-04-16 16:14       ` Neil Horman
2012-04-16 16:35         ` Junio C Hamano
2012-04-16 16:50           ` Neil Horman
2012-04-16 21:42             ` Clemens Buchacher
2012-04-17 10:56               ` Neil Horman
2012-04-17 21:38                 ` Clemens Buchacher
2012-04-18 10:48                   ` Neil Horman
2012-04-18 18:34                     ` Clemens Buchacher
2012-04-13 18:45   ` [PATCH v5 4/4] git-rebase: add keep_empty flag Neil Horman
2012-04-15  9:33     ` Clemens Buchacher
2012-04-16 16:46       ` Neil Horman
2012-04-17 18:20 ` [PATCH v6 0/4] Enhance git-rebases flexibiilty in handling empty commits Neil Horman
2012-04-17 18:20   ` [PATCH v6 1/4] git-cherry-pick: add allow-empty option Neil Horman
2012-04-17 18:20   ` [PATCH v6 2/4] git-cherry-pick: Add keep-redundant-commits option Neil Horman
2012-04-17 21:45     ` Clemens Buchacher
2012-04-18 10:49       ` Neil Horman
2012-04-17 18:20   ` [PATCH v6 3/4] git-cherry-pick: Add test to validate new options Neil Horman
2012-04-17 18:20   ` [PATCH v6 4/4] git-rebase: add keep_empty flag Neil Horman
2012-04-17 21:47     ` Clemens Buchacher
2012-04-18 10:50       ` Neil Horman
2012-04-18 22:58     ` Junio C Hamano
2012-04-19 13:08       ` Neil Horman
2012-04-19 17:53         ` Junio C Hamano
2012-04-18 19:17 ` [PATCH v7 0/4] Enhance git-rebases flexibiilty in handling empty commits Neil Horman
2012-04-18 19:17   ` [PATCH v7 1/4] git-cherry-pick: add allow-empty option Neil Horman
2012-04-18 19:17   ` [PATCH v7 2/4] git-cherry-pick: Add keep-redundant-commits option Neil Horman
2012-04-18 22:59     ` Junio C Hamano
2012-04-18 19:17   ` [PATCH v7 3/4] git-cherry-pick: Add test to validate new options Neil Horman
2012-04-18 19:18   ` [PATCH v7 4/4] git-rebase: add keep_empty flag Neil Horman
2012-04-19 10:02     ` Zbigniew Jędrzejewski-Szmek
2012-04-19 11:49       ` Thomas Rast
2012-04-19 12:19         ` Zbigniew Jędrzejewski-Szmek
2012-04-19 13:12           ` Neil Horman
2012-04-19 18:59         ` Junio C Hamano
2012-04-19 19:05           ` Junio C Hamano
2012-04-20 10:35             ` Neil Horman
2012-04-20 14:36 ` [PATCH v8 0/4] Enhance git-rebases flexibiilty in handling empty commits Neil Horman
2012-04-20 14:36   ` [PATCH v8 1/4] git-cherry-pick: add allow-empty option Neil Horman
2012-04-20 14:36   ` [PATCH v8 2/4] git-cherry-pick: Add keep-redundant-commits option Neil Horman
2012-04-20 19:21     ` Junio C Hamano
2012-04-20 19:56       ` Neil Horman
2012-04-20 14:36   ` [PATCH v8 3/4] git-cherry-pick: Add test to validate new options Neil Horman
2012-04-20 14:36   ` [PATCH v8 4/4] git-rebase: add keep_empty flag Neil Horman
2012-04-25  1:50     ` Junio C Hamano
2012-04-25 10:38       ` Neil Horman
2012-07-18  6:20     ` Martin von Zweigbergk
2012-07-18  7:10       ` Johannes Sixt
2012-07-18  7:16         ` Martin von Zweigbergk
2012-07-18 12:17         ` Neil Horman

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=20120416153827.GC13366@hmsreliant.think-freely.org \
    --to=nhorman@tuxdriver.com \
    --cc=drizzd@aon.at \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=phil.hord@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.
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.