All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha.warpmail.net>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] update-index: add --swap to swap index and worktree content
Date: Tue, 16 Aug 2011 15:01:55 +0200	[thread overview]
Message-ID: <4E4A6A43.7040706@drmicha.warpmail.net> (raw)
In-Reply-To: <1313158058-7684-1-git-send-email-pclouds@gmail.com>

Nguyễn Thái Ngọc Duy venit, vidit, dixit 12.08.2011 16:07:
> Sometimes "git add -p" with "e" to edit the patch does not satisfy me.
> What I want is a quick way to modify index content without changing
> worktree, then I can continue adding more hunks to the index.
> 
> With this option, I can swap index out for a quick edit, then swap it in
> again.

I had to think about that explanation for a while (partly because "git
add" does not alter the wt either). So, your patch would support the
following workflow:

git add foo # have index == wt
hack foo # change foo in wt
git update-index --swap foo # add foo and reset to previous state

Am I understanding you right? The option could trickle down to "add".

I share the pov that "add -p with e" sometimes doesn't cut it. But
similarly, the fact that "add -p" can't be used to undo a previous "add
-p" is suboptimal. Both issues could be solved with a 3way stage tool. I
have this on my todo/wish list, and I seem to recall that Jeff or Junio
came up with a few lines of (scripting) code for that. That would depend
on the availability of proper tools, though (e.g. vim in diff mode).

--swap might be useful nevertheless.

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  Not sure if anybody has the same needs, enough to polish it and make
>  it to master.
> 
>  builtin/update-index.c |   16 ++++++++++++++++
>  1 files changed, 16 insertions(+), 0 deletions(-)
> 
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index a6a23fa..b96065a 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -22,6 +22,7 @@
>  static int allow_add;
>  static int allow_remove;
>  static int allow_replace;
> +static int swap_entry;
>  static int info_only;
>  static int force_remove;
>  static int verbose;
> @@ -104,6 +105,19 @@ static int add_one_path(struct cache_entry *old, const char *path, int len, stru
>  		free(ce);
>  		return -1;
>  	}
> +	if (swap_entry) {
> +		struct checkout state;
> +		if (allow_add || allow_remove)
> +			die("--add, --replace and --swap do not play together");
> +		memset(&state, 0, sizeof(state));
> +		state.force = 1;
> +		state.not_new = 1;
> +		if (add_cache_entry(ce, 0))
> +			return error("%s: cannot add to the index", path);
> +		if (checkout_entry(old, &state, NULL))
> +			return error("%s: cannot swap", path);
> +		return 0;
> +	}
>  	option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
>  	option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
>  	if (add_cache_entry(ce, option))
> @@ -727,6 +741,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
>  			"let files replace directories and vice-versa", 1),
>  		OPT_SET_INT(0, "remove", &allow_remove,
>  			"notice files missing from worktree", 1),
> +		OPT_SET_INT(0, "swap", &swap_entry,
> +			"swap the content of index and worktree", 1),
>  		OPT_BIT(0, "unmerged", &refresh_args.flags,
>  			"refresh even if index contains unmerged entries",
>  			REFRESH_UNMERGED),

  reply	other threads:[~2011-08-16 13:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-12 14:07 [PATCH] update-index: add --swap to swap index and worktree content Nguyễn Thái Ngọc Duy
2011-08-16 13:01 ` Michael J Gruber [this message]
2011-08-16 14:45   ` Nguyen Thai Ngoc Duy
2011-08-16 20:01 ` Junio C Hamano
2011-08-16 21:01   ` Jeff King
2011-08-16 21:56     ` Junio C Hamano
2011-08-16 22:22       ` Jeff King
2011-08-16 23:01         ` Junio C Hamano
2011-08-16 23:06           ` Jeff King
2011-08-17  2:11             ` Nguyen Thai Ngoc Duy
2011-08-17  2:17               ` Jeff King
2011-08-17 14:13                 ` Martin von Zweigbergk
2011-08-17 14:32                   ` Nguyen Thai Ngoc Duy
2011-08-17 18:26                   ` Junio C Hamano
2011-08-17 19:46                   ` Jeff King
2011-08-18  1:01                     ` Martin von Zweigbergk

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=4E4A6A43.7040706@drmicha.warpmail.net \
    --to=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --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.
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.