git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] rebase --abort: cleanup refs/rewritten
@ 2019-04-26 10:32 Phillip Wood
  2019-04-29 16:07 ` Johannes Schindelin
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Phillip Wood @ 2019-04-26 10:32 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Johannes Schindelin, Junio C Hamano, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

When `rebase -r` finishes it removes any refs under refs/rewritten
that it has created. However if the rebase is aborted these refs are
not removed. This can cause problems for future rebases. For example I
recently wanted to merge a updated version of a topic branch into an
integration branch so ran `rebase -ir` and removed the picks and label
for the topic branch from the todo list so that
    merge -C <old-merge> topic
would pick up the new version of topic. Unfortunately
refs/rewritten/topic already existed from a previous rebase that had
been aborted so the rebase just used the old topic, not the new one.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---

Notes:
    This is based on pw/rebase-i-internal, it would be nicer to base it on
    maint but there are function name clashes adding sequencer.h to rebase.c
    an maint. Those clashes are fixed in pw/rebase-i-internal

 builtin/rebase.c         | 13 ++++++++++---
 t/t3430-rebase-merges.sh |  8 ++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 82bd50a1b4..e2e49c8239 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -761,9 +761,16 @@ static int finish_rebase(struct rebase_options *opts)
 	 * user should see them.
 	 */
 	run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
-	strbuf_addstr(&dir, opts->state_dir);
-	remove_dir_recursively(&dir, 0);
-	strbuf_release(&dir);
+	if (opts->type == REBASE_INTERACTIVE) {
+		struct replay_opts replay = REPLAY_OPTS_INIT;
+
+		replay.action = REPLAY_INTERACTIVE_REBASE;
+		sequencer_remove_state(&replay);
+	} else {
+		strbuf_addstr(&dir, opts->state_dir);
+		remove_dir_recursively(&dir, 0);
+		strbuf_release(&dir);
+	}
 
 	return 0;
 }
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 4c69255ee6..6ebebf7098 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -224,6 +224,14 @@ test_expect_success 'refs/rewritten/* is worktree-local' '
 	test_cmp_rev HEAD "$(cat wt/b)"
 '
 
+test_expect_success '--abort cleans up refs/rewritten' '
+	git checkout -b abort-cleans-refs-rewritten H &&
+	GIT_SEQUENCE_EDITOR="echo break >>" git rebase -ir @^ &&
+	git rev-parse --verify refs/rewritten/onto &&
+	git rebase --abort &&
+	test_must_fail git rev-parse --verify refs/rewritten/onto
+'
+
 test_expect_success 'post-rewrite hook and fixups work for merges' '
 	git checkout -b post-rewrite &&
 	test_commit same1 &&
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-04-26 10:32 [PATCH] rebase --abort: cleanup refs/rewritten Phillip Wood
@ 2019-04-29 16:07 ` Johannes Schindelin
  2019-04-30  8:54   ` Phillip Wood
  2019-05-07 15:15 ` SZEDER Gábor
  2019-05-14 18:03 ` [PATCH v2 0/4] rebase --abort/--quit: " Phillip Wood
  2 siblings, 1 reply; 15+ messages in thread
From: Johannes Schindelin @ 2019-04-29 16:07 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Phillip,

On Fri, 26 Apr 2019, Phillip Wood wrote:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> When `rebase -r` finishes it removes any refs under refs/rewritten
> that it has created. However if the rebase is aborted these refs are
> not removed. This can cause problems for future rebases. For example I
> recently wanted to merge a updated version of a topic branch into an
> integration branch so ran `rebase -ir` and removed the picks and label
> for the topic branch from the todo list so that
>     merge -C <old-merge> topic
> would pick up the new version of topic. Unfortunately
> refs/rewritten/topic already existed from a previous rebase that had
> been aborted so the rebase just used the old topic, not the new one.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---

Makes a ton of sense, and I feel a bit embarrassed that I forgot about
that item on my TODO list. The patch looks obviously correct!

Thanks,
Dscho

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-04-29 16:07 ` Johannes Schindelin
@ 2019-04-30  8:54   ` Phillip Wood
  2019-04-30 22:49     ` Johannes Schindelin
  0 siblings, 1 reply; 15+ messages in thread
From: Phillip Wood @ 2019-04-30  8:54 UTC (permalink / raw)
  To: Johannes Schindelin, Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Dscho

On 29/04/2019 17:07, Johannes Schindelin wrote:
> Hi Phillip,
> 
> On Fri, 26 Apr 2019, Phillip Wood wrote:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> When `rebase -r` finishes it removes any refs under refs/rewritten
>> that it has created. However if the rebase is aborted these refs are
>> not removed. This can cause problems for future rebases. For example I
>> recently wanted to merge a updated version of a topic branch into an
>> integration branch so ran `rebase -ir` and removed the picks and label
>> for the topic branch from the todo list so that
>>      merge -C <old-merge> topic
>> would pick up the new version of topic. Unfortunately
>> refs/rewritten/topic already existed from a previous rebase that had
>> been aborted so the rebase just used the old topic, not the new one.
>>
>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>> ---
> 
> Makes a ton of sense, and I feel a bit embarrassed that I forgot about
> that item on my TODO list. The patch looks obviously correct!

Thanks, after I sent it I realized that --quit should probably clear 
refs/rewritten as well, so I'll re-roll with that added. (One could 
argue that a user might want them after quitting the rebase but there is 
no way to clean them up safely once we've deleted the state files and I 
suspect most users would be suprised if they were left laying around)

Best Wishes

Phillip

> 
> Thanks,
> Dscho
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-04-30  8:54   ` Phillip Wood
@ 2019-04-30 22:49     ` Johannes Schindelin
  2019-05-01 15:36       ` Phillip Wood
  0 siblings, 1 reply; 15+ messages in thread
From: Johannes Schindelin @ 2019-04-30 22:49 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Phillip,

On Tue, 30 Apr 2019, Phillip Wood wrote:

> On 29/04/2019 17:07, Johannes Schindelin wrote:
> >
> > On Fri, 26 Apr 2019, Phillip Wood wrote:
> >
> > > From: Phillip Wood <phillip.wood@dunelm.org.uk>
> > >
> > > When `rebase -r` finishes it removes any refs under refs/rewritten
> > > that it has created. However if the rebase is aborted these refs are
> > > not removed. This can cause problems for future rebases. For example I
> > > recently wanted to merge a updated version of a topic branch into an
> > > integration branch so ran `rebase -ir` and removed the picks and label
> > > for the topic branch from the todo list so that
> > >      merge -C <old-merge> topic
> > > would pick up the new version of topic. Unfortunately
> > > refs/rewritten/topic already existed from a previous rebase that had
> > > been aborted so the rebase just used the old topic, not the new one.
> > >
> > > Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> > > ---
> >
> > Makes a ton of sense, and I feel a bit embarrassed that I forgot about
> > that item on my TODO list. The patch looks obviously correct!
>
> Thanks, after I sent it I realized that --quit should probably clear
> refs/rewritten as well, so I'll re-roll with that added. (One could argue that
> a user might want them after quitting the rebase but there is no way to clean
> them up safely once we've deleted the state files and I suspect most users
> would be suprised if they were left laying around)

I am not so sure. `--quit` is essentially all about "leave the state
as-is, but still abort the rebase".

So if I were you, I would *not* remove the `refs/rewritten/` refs in the
`--quit` case.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-04-30 22:49     ` Johannes Schindelin
@ 2019-05-01 15:36       ` Phillip Wood
  2019-05-03  9:21         ` Johannes Schindelin
  0 siblings, 1 reply; 15+ messages in thread
From: Phillip Wood @ 2019-05-01 15:36 UTC (permalink / raw)
  To: Johannes Schindelin, Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Dscho

On 30/04/2019 23:49, Johannes Schindelin wrote:
> Hi Phillip,
> 
> On Tue, 30 Apr 2019, Phillip Wood wrote:
> 
>> On 29/04/2019 17:07, Johannes Schindelin wrote:
>>>
>>> On Fri, 26 Apr 2019, Phillip Wood wrote:
>>>
>>>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>>>
>>>> When `rebase -r` finishes it removes any refs under refs/rewritten
>>>> that it has created. However if the rebase is aborted these refs are
>>>> not removed. This can cause problems for future rebases. For example I
>>>> recently wanted to merge a updated version of a topic branch into an
>>>> integration branch so ran `rebase -ir` and removed the picks and label
>>>> for the topic branch from the todo list so that
>>>>       merge -C <old-merge> topic
>>>> would pick up the new version of topic. Unfortunately
>>>> refs/rewritten/topic already existed from a previous rebase that had
>>>> been aborted so the rebase just used the old topic, not the new one.
>>>>
>>>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>>>> ---
>>>
>>> Makes a ton of sense, and I feel a bit embarrassed that I forgot about
>>> that item on my TODO list. The patch looks obviously correct!
>>
>> Thanks, after I sent it I realized that --quit should probably clear
>> refs/rewritten as well, so I'll re-roll with that added. (One could argue that
>> a user might want them after quitting the rebase but there is no way to clean
>> them up safely once we've deleted the state files and I suspect most users
>> would be suprised if they were left laying around)
> 
> I am not so sure. `--quit` is essentially all about "leave the state
> as-is, but still abort the rebase".

I think it depends on what you mean by "state" `--quit` is about 
removing state specific to rebases while preserving HEAD, the index and 
worktree. When "rebase --quit" was introduced in 9512177b68 ("rebase: 
add --quit to cleanup rebase, leave everything else untouched", 
2016-11-12) the start of the log message reads

     rebase: add --quit to cleanup rebase, leave everything else untouched

     There are occasions when you decide to abort an in-progress rebase and
     move on to do something else but you forget to do "git rebase --abort"
     first. Or the rebase has been in progress for so long you forgot about
     it. By the time you realize that (e.g. by starting another rebase)
     it's already too late to retrace your steps. The solution is normally

         rm -r .git/<some rebase dir>

     and continue with your life.


So `--quit` is used when the user has forgotten to run "rebase --abort". 
They have moved onto something else and want to remove the rebase state 
without changing the current HEAD, index or worktree, they are not 
looking to use the refs under refs/rewritten. I think the refs rebase 
creates under refs/rewritten is an implementation detail of "rebase -r" 
and should be treated like files under .git/rebase-merge. I'm worried 
that if we leave them lying around after --quit they will cause trouble 
for future rebases in the same way they have after "rebase --abort"

Best Wishes

Phillip

> So if I were you, I would *not* remove the `refs/rewritten/` refs in the
> `--quit` case.
> 
> Ciao,
> Dscho
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-05-01 15:36       ` Phillip Wood
@ 2019-05-03  9:21         ` Johannes Schindelin
  2019-05-03 10:06           ` Phillip Wood
  0 siblings, 1 reply; 15+ messages in thread
From: Johannes Schindelin @ 2019-05-03  9:21 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Phillip,

On Wed, 1 May 2019, Phillip Wood wrote:

> On 30/04/2019 23:49, Johannes Schindelin wrote:
> >
> > On Tue, 30 Apr 2019, Phillip Wood wrote:
> >
> > > On 29/04/2019 17:07, Johannes Schindelin wrote:
> > > >
> > > > On Fri, 26 Apr 2019, Phillip Wood wrote:
> > > >
> > > > > From: Phillip Wood <phillip.wood@dunelm.org.uk>
> > > > >
> > > > > When `rebase -r` finishes it removes any refs under refs/rewritten
> > > > > that it has created. However if the rebase is aborted these refs are
> > > > > not removed. This can cause problems for future rebases. For example I
> > > > > recently wanted to merge a updated version of a topic branch into an
> > > > > integration branch so ran `rebase -ir` and removed the picks and label
> > > > > for the topic branch from the todo list so that
> > > > >       merge -C <old-merge> topic
> > > > > would pick up the new version of topic. Unfortunately
> > > > > refs/rewritten/topic already existed from a previous rebase that had
> > > > > been aborted so the rebase just used the old topic, not the new one.
> > > > >
> > > > > Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> > > > > ---
> > > >
> > > > Makes a ton of sense, and I feel a bit embarrassed that I forgot about
> > > > that item on my TODO list. The patch looks obviously correct!
> > >
> > > Thanks, after I sent it I realized that --quit should probably clear
> > > refs/rewritten as well, so I'll re-roll with that added. (One could argue
> > > that
> > > a user might want them after quitting the rebase but there is no way to
> > > clean
> > > them up safely once we've deleted the state files and I suspect most users
> > > would be suprised if they were left laying around)
> >
> > I am not so sure. `--quit` is essentially all about "leave the state
> > as-is, but still abort the rebase".
>
> I think it depends on what you mean by "state" `--quit` is about removing
> state specific to rebases while preserving HEAD, the index and worktree.

I guess the fault is mine for bleeding out internal rebase state into the
refs namespace.

While I cannot really imagine any harm from this patch in practice, it is
slightly worrisome that deleting refs also deletes their reflogs, which
makes it an unrecoverable problem *iff* any user runs into trouble with
this.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-05-03  9:21         ` Johannes Schindelin
@ 2019-05-03 10:06           ` Phillip Wood
  0 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-05-03 10:06 UTC (permalink / raw)
  To: Johannes Schindelin, Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Dscho

On 03/05/2019 10:21, Johannes Schindelin wrote:
> Hi Phillip,
> 
> On Wed, 1 May 2019, Phillip Wood wrote:
> 
>> On 30/04/2019 23:49, Johannes Schindelin wrote:
>>>
>>> On Tue, 30 Apr 2019, Phillip Wood wrote:
>>>
>>>> On 29/04/2019 17:07, Johannes Schindelin wrote:
>>>>>
>>>>> On Fri, 26 Apr 2019, Phillip Wood wrote:
>>>>>
>>>>>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>>>>>
>>>>>> When `rebase -r` finishes it removes any refs under refs/rewritten
>>>>>> that it has created. However if the rebase is aborted these refs are
>>>>>> not removed. This can cause problems for future rebases. For example I
>>>>>> recently wanted to merge a updated version of a topic branch into an
>>>>>> integration branch so ran `rebase -ir` and removed the picks and label
>>>>>> for the topic branch from the todo list so that
>>>>>>        merge -C <old-merge> topic
>>>>>> would pick up the new version of topic. Unfortunately
>>>>>> refs/rewritten/topic already existed from a previous rebase that had
>>>>>> been aborted so the rebase just used the old topic, not the new one.
>>>>>>
>>>>>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>>>>>> ---
>>>>>
>>>>> Makes a ton of sense, and I feel a bit embarrassed that I forgot about
>>>>> that item on my TODO list. The patch looks obviously correct!
>>>>
>>>> Thanks, after I sent it I realized that --quit should probably clear
>>>> refs/rewritten as well, so I'll re-roll with that added. (One could argue
>>>> that
>>>> a user might want them after quitting the rebase but there is no way to
>>>> clean
>>>> them up safely once we've deleted the state files and I suspect most users
>>>> would be suprised if they were left laying around)
>>>
>>> I am not so sure. `--quit` is essentially all about "leave the state
>>> as-is, but still abort the rebase".
>>
>> I think it depends on what you mean by "state" `--quit` is about removing
>> state specific to rebases while preserving HEAD, the index and worktree.
> 
> I guess the fault is mine for bleeding out internal rebase state into the
> refs namespace.

I wouldn't feel bad about that, I guess it would be possible to get gc 
to read a list of objects not to collect from a file in 
.git/rebase-merge but creating a refs for labels seems like a sensible 
way to stop them from being collect by gc.

> While I cannot really imagine any harm from this patch in practice, it is
> slightly worrisome that deleting refs also deletes their reflogs,

Yes it's a shame there's no way to get a ref back once it's been deleted 
(though I'm not sure how long we'd want to keep any reflog of a deleted 
ref before gc'ing the objects). In any case refs/rewritten only has a 
reflog if the user has explicitly enabled it.

> which
> makes it an unrecoverable problem *iff* any user runs into trouble with
> this.

I guess "rebase --quit" could print a warning listing the refs that are 
being deleted so the user can cut and paste if they need to. I'm not 
sure how likely they are to need that though.

Best Wishes

Phillip

> Ciao,
> Dscho
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-04-26 10:32 [PATCH] rebase --abort: cleanup refs/rewritten Phillip Wood
  2019-04-29 16:07 ` Johannes Schindelin
@ 2019-05-07 15:15 ` SZEDER Gábor
  2019-05-07 16:07   ` Junio C Hamano
  2019-05-14 18:03 ` [PATCH v2 0/4] rebase --abort/--quit: " Phillip Wood
  2 siblings, 1 reply; 15+ messages in thread
From: SZEDER Gábor @ 2019-05-07 15:15 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List, Johannes Schindelin, Junio C Hamano

On Fri, Apr 26, 2019 at 11:32:12AM +0100, Phillip Wood wrote:
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
> 
> When `rebase -r` finishes it removes any refs under refs/rewritten
> that it has created. However if the rebase is aborted these refs are
> not removed. This can cause problems for future rebases. For example I
> recently wanted to merge a updated version of a topic branch into an
> integration branch so ran `rebase -ir` and removed the picks and label
> for the topic branch from the todo list so that
>     merge -C <old-merge> topic
> would pick up the new version of topic. Unfortunately
> refs/rewritten/topic already existed from a previous rebase that had
> been aborted so the rebase just used the old topic, not the new one.
> 
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
> 
> Notes:
>     This is based on pw/rebase-i-internal, it would be nicer to base it on
>     maint but there are function name clashes adding sequencer.h to rebase.c
>     an maint. Those clashes are fixed in pw/rebase-i-internal
> 
>  builtin/rebase.c         | 13 ++++++++++---
>  t/t3430-rebase-merges.sh |  8 ++++++++
>  2 files changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index 82bd50a1b4..e2e49c8239 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -761,9 +761,16 @@ static int finish_rebase(struct rebase_options *opts)
>  	 * user should see them.
>  	 */
>  	run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
> -	strbuf_addstr(&dir, opts->state_dir);
> -	remove_dir_recursively(&dir, 0);
> -	strbuf_release(&dir);
> +	if (opts->type == REBASE_INTERACTIVE) {
> +		struct replay_opts replay = REPLAY_OPTS_INIT;

This patch and the topic 'pw/rebase-abort-clean-rewritten' can't be
compiled on its own, because it starts using 'struct replay_opts'
here, which is defined in 'sequencer.h', but 'builtin/rebase.c'
doesn't include that header yet.  (Though 'pu' already builds fine,
because commit 0609b741a4 (rebase -i: combine rebase--interactive.c
with rebase.c, 2019-04-17) in the parallel topic
'pw/rebase-i-internal' adds the necessary #include.)

So, to keep future bisects from potentially tipping over the compiler
error, this patch should either #include "sequencer.h", or be applied
on top of 'pw/rebase-i-internal'.

> +
> +		replay.action = REPLAY_INTERACTIVE_REBASE;
> +		sequencer_remove_state(&replay);
> +	} else {
> +		strbuf_addstr(&dir, opts->state_dir);
> +		remove_dir_recursively(&dir, 0);
> +		strbuf_release(&dir);
> +	}
>  
>  	return 0;
>  }
> diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
> index 4c69255ee6..6ebebf7098 100755
> --- a/t/t3430-rebase-merges.sh
> +++ b/t/t3430-rebase-merges.sh
> @@ -224,6 +224,14 @@ test_expect_success 'refs/rewritten/* is worktree-local' '
>  	test_cmp_rev HEAD "$(cat wt/b)"
>  '
>  
> +test_expect_success '--abort cleans up refs/rewritten' '
> +	git checkout -b abort-cleans-refs-rewritten H &&
> +	GIT_SEQUENCE_EDITOR="echo break >>" git rebase -ir @^ &&
> +	git rev-parse --verify refs/rewritten/onto &&
> +	git rebase --abort &&
> +	test_must_fail git rev-parse --verify refs/rewritten/onto
> +'
> +
>  test_expect_success 'post-rewrite hook and fixups work for merges' '
>  	git checkout -b post-rewrite &&
>  	test_commit same1 &&
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-05-07 15:15 ` SZEDER Gábor
@ 2019-05-07 16:07   ` Junio C Hamano
  2019-05-07 20:06     ` Phillip Wood
  0 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2019-05-07 16:07 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Phillip Wood, Git Mailing List, Johannes Schindelin

SZEDER Gábor <szeder.dev@gmail.com> writes:

> This patch and the topic 'pw/rebase-abort-clean-rewritten' can't be
> compiled on its own, because it starts using 'struct replay_opts'
> here, which is defined in 'sequencer.h', but 'builtin/rebase.c'
> doesn't include that header yet.  (Though 'pu' already builds fine,
> because commit 0609b741a4 (rebase -i: combine rebase--interactive.c
> with rebase.c, 2019-04-17) in the parallel topic
> 'pw/rebase-i-internal' adds the necessary #include.)

Thanks; that's entirely my fault.  I needed to find a good fork
point and failed to do so.  FTR, when there are too many topics
I need to queue on a given day, I may not have time to compile
check individual topic branches before merging them to the
integration branches, testing the integration branches and pushing
them out.  That was what happened here.

> So, to keep future bisects from potentially tipping over the compiler
> error, this patch should either #include "sequencer.h", or be applied
> on top of 'pw/rebase-i-internal'.

I suspect that the latter was how the patch originally was
developed.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] rebase --abort: cleanup refs/rewritten
  2019-05-07 16:07   ` Junio C Hamano
@ 2019-05-07 20:06     ` Phillip Wood
  0 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-05-07 20:06 UTC (permalink / raw)
  To: Junio C Hamano, SZEDER Gábor
  Cc: Phillip Wood, Git Mailing List, Johannes Schindelin

On 07/05/2019 17:07, Junio C Hamano wrote:
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
>> This patch and the topic 'pw/rebase-abort-clean-rewritten' can't be
>> compiled on its own, because it starts using 'struct replay_opts'
>> here, which is defined in 'sequencer.h', but 'builtin/rebase.c'
>> doesn't include that header yet.  (Though 'pu' already builds fine,
>> because commit 0609b741a4 (rebase -i: combine rebase--interactive.c
>> with rebase.c, 2019-04-17) in the parallel topic
>> 'pw/rebase-i-internal' adds the necessary #include.)
> 
> Thanks; that's entirely my fault.  I needed to find a good fork
> point and failed to do so.  FTR, when there are too many topics
> I need to queue on a given day, I may not have time to compile
> check individual topic branches before merging them to the
> integration branches, testing the integration branches and pushing
> them out.  That was what happened here.
> 
>> So, to keep future bisects from potentially tipping over the compiler
>> error, this patch should either #include "sequencer.h", or be applied
>> on top of 'pw/rebase-i-internal'.
> 
> I suspect that the latter was how the patch originally was
> developed.

Yes that's right, there is a note on the original patch [1] explaining 
why - you cannot just add '#include "sequencer.h"' as there are function 
name conflicts between a static function in builtin/rebase.c and a 
global function in sequencer.c which are fixed in pw/rebase-i-internal

Best Wishes

Phillip

[1] 
https://public-inbox.org/git/xmqqpnoujlj4.fsf@gitster-ct.c.googlers.com/T/#mb431b81731798388e12f3852747c560f8ce7c6ec


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2 0/4] rebase --abort/--quit: cleanup refs/rewritten
  2019-04-26 10:32 [PATCH] rebase --abort: cleanup refs/rewritten Phillip Wood
  2019-04-29 16:07 ` Johannes Schindelin
  2019-05-07 15:15 ` SZEDER Gábor
@ 2019-05-14 18:03 ` Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 1/4] rebase: fix a memory leak Phillip Wood
                     ` (3 more replies)
  2 siblings, 4 replies; 15+ messages in thread
From: Phillip Wood @ 2019-05-14 18:03 UTC (permalink / raw)
  To: Git Mailing List, Johannes Schindelin, Junio C Hamano; +Cc: Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

refs/rewritten/ is now cleaned up on --quit as well as --abort. I've
also added a patch to make sequencer_remove_state() to return any
errors, so rebase now always reports any errors that occur when
cleaning up the state directory.

These patches are still based on pw/rebase-i-internal, the first 3
could probably be applied to maint if required.

I'm going to be off line for ten days or so from Thursday so there's
no hurry to look at these (also we're in an rc phase at the moment)

Best Wishes

Phillip


Phillip Wood (4):
  rebase: fix a memory leak
  rebase: warn if state directory cannot be removed
  sequencer: return errors from sequencer_remove_state()
  rebase --abort/--quit: cleanup refs/rewritten

 builtin/rebase.c         | 39 +++++++++++++++++++++++++++++----------
 sequencer.c              | 11 +++++++----
 t/t3430-rebase-merges.sh | 18 +++++++++++++++++-
 3 files changed, 53 insertions(+), 15 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2 1/4] rebase: fix a memory leak
  2019-05-14 18:03 ` [PATCH v2 0/4] rebase --abort/--quit: " Phillip Wood
@ 2019-05-14 18:03   ` Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 2/4] rebase: warn if state directory cannot be removed Phillip Wood
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-05-14 18:03 UTC (permalink / raw)
  To: Git Mailing List, Johannes Schindelin, Junio C Hamano; +Cc: Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

buf was never freed.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/rebase.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 82bd50a1b4..90037c9c45 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -2168,6 +2168,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	ret = !!run_specific_rebase(&options, action);
 
 cleanup:
+	strbuf_release(&buf);
 	strbuf_release(&revisions);
 	free(options.head_name);
 	free(options.gpg_sign_opt);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 2/4] rebase: warn if state directory cannot be removed
  2019-05-14 18:03 ` [PATCH v2 0/4] rebase --abort/--quit: " Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 1/4] rebase: fix a memory leak Phillip Wood
@ 2019-05-14 18:03   ` Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 3/4] sequencer: return errors from sequencer_remove_state() Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 4/4] rebase --abort/--quit: cleanup refs/rewritten Phillip Wood
  3 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-05-14 18:03 UTC (permalink / raw)
  To: Git Mailing List, Johannes Schindelin, Junio C Hamano; +Cc: Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

If rebase --quit cannot remove the state directory then it dies. However
when rebase finishes normally or the user runs rebase --abort any errors
that occur when removing the state directory are ignored. That is fixed
by this commit.

All of the callers of finish_rebase() except the code
that handles --abort are careful to make sure they get a postive return
value, do the same for --abort.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/rebase.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 90037c9c45..199cb5b81d 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -752,6 +752,7 @@ static int finish_rebase(struct rebase_options *opts)
 {
 	struct strbuf dir = STRBUF_INIT;
 	const char *argv_gc_auto[] = { "gc", "--auto", NULL };
+	int ret = 0;
 
 	delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
 	apply_autostash(opts);
@@ -762,10 +763,11 @@ static int finish_rebase(struct rebase_options *opts)
 	 */
 	run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
 	strbuf_addstr(&dir, opts->state_dir);
-	remove_dir_recursively(&dir, 0);
+	if (remove_dir_recursively(&dir, 0))
+		ret = error(_("could not remove '%s'"), opts->state_dir);
 	strbuf_release(&dir);
 
-	return 0;
+	return ret;
 }
 
 static struct commit *peel_committish(const char *name)
@@ -1648,7 +1650,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			die(_("could not move back to %s"),
 			    oid_to_hex(&options.orig_head));
 		remove_branch_state(the_repository);
-		ret = finish_rebase(&options);
+		ret = !!finish_rebase(&options);
 		goto cleanup;
 	}
 	case ACTION_QUIT: {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 3/4] sequencer: return errors from sequencer_remove_state()
  2019-05-14 18:03 ` [PATCH v2 0/4] rebase --abort/--quit: " Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 1/4] rebase: fix a memory leak Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 2/4] rebase: warn if state directory cannot be removed Phillip Wood
@ 2019-05-14 18:03   ` Phillip Wood
  2019-05-14 18:03   ` [PATCH v2 4/4] rebase --abort/--quit: cleanup refs/rewritten Phillip Wood
  3 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-05-14 18:03 UTC (permalink / raw)
  To: Git Mailing List, Johannes Schindelin, Junio C Hamano; +Cc: Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

If there is an error when removing the state directory then we should
report it. This matches what the non-interactive rebase does.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 610b7ece14..258e583156 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -274,7 +274,7 @@ static const char *gpg_sign_opt_quoted(struct replay_opts *opts)
 int sequencer_remove_state(struct replay_opts *opts)
 {
 	struct strbuf buf = STRBUF_INIT;
-	int i;
+	int i, ret = 0;
 
 	if (is_rebase_i(opts) &&
 	    strbuf_read_file(&buf, rebase_path_refs_to_delete(), 0) > 0) {
@@ -283,8 +283,10 @@ int sequencer_remove_state(struct replay_opts *opts)
 			char *eol = strchr(p, '\n');
 			if (eol)
 				*eol = '\0';
-			if (delete_ref("(rebase -i) cleanup", p, NULL, 0) < 0)
+			if (delete_ref("(rebase -i) cleanup", p, NULL, 0) < 0) {
 				warning(_("could not delete '%s'"), p);
+				ret = -1;
+			}
 			if (!eol)
 				break;
 			p = eol + 1;
@@ -300,10 +302,11 @@ int sequencer_remove_state(struct replay_opts *opts)
 
 	strbuf_reset(&buf);
 	strbuf_addstr(&buf, get_dir(opts));
-	remove_dir_recursively(&buf, 0);
+	if (remove_dir_recursively(&buf, 0))
+		ret = error(_("could not remove '%s'"), buf.buf);
 	strbuf_release(&buf);
 
-	return 0;
+	return ret;
 }
 
 static const char *action_name(const struct replay_opts *opts)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 4/4] rebase --abort/--quit: cleanup refs/rewritten
  2019-05-14 18:03 ` [PATCH v2 0/4] rebase --abort/--quit: " Phillip Wood
                     ` (2 preceding siblings ...)
  2019-05-14 18:03   ` [PATCH v2 3/4] sequencer: return errors from sequencer_remove_state() Phillip Wood
@ 2019-05-14 18:03   ` Phillip Wood
  3 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-05-14 18:03 UTC (permalink / raw)
  To: Git Mailing List, Johannes Schindelin, Junio C Hamano; +Cc: Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

When `rebase -r` finishes it removes any refs under refs/rewritten that
it has created. However if the user aborts or quits the rebase refs are
not removed. This can cause problems for future rebases. For example I
recently wanted to merge a updated version of a topic branch into an
integration branch so ran `rebase -ir` and removed the picks and label
for the topic branch from the todo list so that

    merge -C <old-merge> topic

would pick up the new version of topic. Unfortunately
refs/rewritten/topic already existed from a previous rebase that had
been aborted so the rebase just used the old topic, not the new one.

The logic for the non-interactive quit case is changed to ensure
`buf` is always freed.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/rebase.c         | 34 +++++++++++++++++++++++++---------
 t/t3430-rebase-merges.sh | 18 +++++++++++++++++-
 2 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 199cb5b81d..7c4cd1a733 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -762,10 +762,18 @@ static int finish_rebase(struct rebase_options *opts)
 	 * user should see them.
 	 */
 	run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
-	strbuf_addstr(&dir, opts->state_dir);
-	if (remove_dir_recursively(&dir, 0))
-		ret = error(_("could not remove '%s'"), opts->state_dir);
-	strbuf_release(&dir);
+	if (opts->type == REBASE_INTERACTIVE) {
+		struct replay_opts replay = REPLAY_OPTS_INIT;
+
+		replay.action = REPLAY_INTERACTIVE_REBASE;
+		ret = sequencer_remove_state(&replay);
+	} else {
+		strbuf_addstr(&dir, opts->state_dir);
+		if (remove_dir_recursively(&dir, 0))
+			ret = error(_("could not remove '%s'"),
+				    opts->state_dir);
+		strbuf_release(&dir);
+	}
 
 	return ret;
 }
@@ -1654,11 +1662,19 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		goto cleanup;
 	}
 	case ACTION_QUIT: {
-		strbuf_reset(&buf);
-		strbuf_addstr(&buf, options.state_dir);
-		ret = !!remove_dir_recursively(&buf, 0);
-		if (ret)
-			die(_("could not remove '%s'"), options.state_dir);
+		if (options.type == REBASE_INTERACTIVE) {
+			struct replay_opts replay = REPLAY_OPTS_INIT;
+
+			replay.action = REPLAY_INTERACTIVE_REBASE;
+			ret = !!sequencer_remove_state(&replay);
+		} else {
+			strbuf_reset(&buf);
+			strbuf_addstr(&buf, options.state_dir);
+			ret = !!remove_dir_recursively(&buf, 0);
+			if (ret)
+				error(_("could not remove '%s'"),
+				       options.state_dir);
+		}
 		goto cleanup;
 	}
 	case ACTION_EDIT_TODO:
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 4c69255ee6..e63576d334 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -224,8 +224,24 @@ test_expect_success 'refs/rewritten/* is worktree-local' '
 	test_cmp_rev HEAD "$(cat wt/b)"
 '
 
+test_expect_success '--abort cleans up refs/rewritten' '
+	git checkout -b abort-cleans-refs-rewritten H &&
+	GIT_SEQUENCE_EDITOR="echo break >>" git rebase -ir @^ &&
+	git rev-parse --verify refs/rewritten/onto &&
+	git rebase --abort &&
+	test_must_fail git rev-parse --verify refs/rewritten/onto
+'
+
+test_expect_success '--quit cleans up refs/rewritten' '
+	git checkout -b quit-cleans-refs-rewritten H &&
+	GIT_SEQUENCE_EDITOR="echo break >>" git rebase -ir @^ &&
+	git rev-parse --verify refs/rewritten/onto &&
+	git rebase --quit &&
+	test_must_fail git rev-parse --verify refs/rewritten/onto
+'
+
 test_expect_success 'post-rewrite hook and fixups work for merges' '
-	git checkout -b post-rewrite &&
+	git checkout -b post-rewrite H &&
 	test_commit same1 &&
 	git reset --hard HEAD^ &&
 	test_commit same2 &&
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-05-14 18:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 10:32 [PATCH] rebase --abort: cleanup refs/rewritten Phillip Wood
2019-04-29 16:07 ` Johannes Schindelin
2019-04-30  8:54   ` Phillip Wood
2019-04-30 22:49     ` Johannes Schindelin
2019-05-01 15:36       ` Phillip Wood
2019-05-03  9:21         ` Johannes Schindelin
2019-05-03 10:06           ` Phillip Wood
2019-05-07 15:15 ` SZEDER Gábor
2019-05-07 16:07   ` Junio C Hamano
2019-05-07 20:06     ` Phillip Wood
2019-05-14 18:03 ` [PATCH v2 0/4] rebase --abort/--quit: " Phillip Wood
2019-05-14 18:03   ` [PATCH v2 1/4] rebase: fix a memory leak Phillip Wood
2019-05-14 18:03   ` [PATCH v2 2/4] rebase: warn if state directory cannot be removed Phillip Wood
2019-05-14 18:03   ` [PATCH v2 3/4] sequencer: return errors from sequencer_remove_state() Phillip Wood
2019-05-14 18:03   ` [PATCH v2 4/4] rebase --abort/--quit: cleanup refs/rewritten Phillip Wood

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).