From patchwork Tue May 14 18:03:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10943505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 774D31390 for ; Tue, 14 May 2019 18:04:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A82F28887 for ; Tue, 14 May 2019 18:04:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E7B72888C; Tue, 14 May 2019 18:04:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 169BA28887 for ; Tue, 14 May 2019 18:04:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbfENSEE (ORCPT ); Tue, 14 May 2019 14:04:04 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55065 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726332AbfENSEE (ORCPT ); Tue, 14 May 2019 14:04:04 -0400 Received: by mail-wm1-f68.google.com with SMTP id i3so29407wml.4 for ; Tue, 14 May 2019 11:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=gnBAG4q5GIs5YWzbla5uHaaJfSjhi0fheUTMEMyPzt4=; b=kop9yz4K92ifiFiEqlarS1lnYvrUS5/4mey6UIEE+7IILKPM5p76Xx2WhgZ5EFs5Q+ yXUOYnKvJCyCmf6Uve10pguYUFSUdFrzbdCmamLdnlkEScj/7e9V8mOoqPdY1QHa4ch9 Sr/FXSbORKOmOv0canGFlP75XZ4GKbdNW4rpDGRg+MxeMwKVYiKOyhcfZJh52IgCmg6c eJnNT4DyPcq08ANAc3ULj6Ga6bFstwwh+XxZqd6/bj5U4qVzx24JcuxOJ3MPmm9jM0yq +xkwY+MD7mAQSUGPI1lGwSd6+rGbHvOsbOs58kWmthUZYCS9JvrZv9H5PD8IBIqKKxA/ c8ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=gnBAG4q5GIs5YWzbla5uHaaJfSjhi0fheUTMEMyPzt4=; b=j8BKLubv2p3lkrAoqnO0Q69xpyQV9IRU5GDy/HQM/R4pTgdCkZ9IQoLAfZ8jcLbeXY sVi/u91KJV2lPEYeKJt2nrUnrTwpKycuz8XOE36qbPa4SVWERHlAtRfRNXLkng3u8K5q CKx6EC4uaeMKCE+yF+4QIwTME0GORCRCKQvJ7OiDofLm/3W7JymRV8Z/AdFDInIf9qnE O34wrbLnfPPEawXEfIROVFP43vgeR80yB9tozQ0cUaSWjnNzB78zLui0SAlRGFZyweO0 uoQgN1H0yaEkc4YHtu8Mkzd8OZ/g9xgJA69dm40ZSzFOkcAc2m83A88+rmErFhfyhK0V GDUw== X-Gm-Message-State: APjAAAWIgfbCShWODdS9OonXhjDWZxlubLtgoqHdIW768fRDog+ApFKm rbv9kkHON5qAVj5unQnkVRqA+Rk9 X-Google-Smtp-Source: APXvYqxgLr6kXWn4dBXZuOKwrB8Ad9B62JMJPoqdlohPbQ9A+ynHpECpA5Lh005lIjL3RwpWGeS0DQ== X-Received: by 2002:a7b:c304:: with SMTP id k4mr21170906wmj.22.1557857041678; Tue, 14 May 2019 11:04:01 -0700 (PDT) Received: from lindisfarne.localdomain (host-89-242-178-164.as13285.net. [89.242.178.164]) by smtp.gmail.com with ESMTPSA id a4sm4528230wmf.45.2019.05.14.11.04.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:04:01 -0700 (PDT) From: Phillip Wood To: Git Mailing List , Johannes Schindelin , Junio C Hamano Cc: Phillip Wood Subject: [PATCH v2 1/4] rebase: fix a memory leak Date: Tue, 14 May 2019 19:03:46 +0100 Message-Id: <20190514180349.17245-2-phillip.wood123@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514180349.17245-1-phillip.wood123@gmail.com> References: <20190426103212.8097-1-phillip.wood123@gmail.com> <20190514180349.17245-1-phillip.wood123@gmail.com> Reply-To: Phillip Wood MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood buf was never freed. Signed-off-by: Phillip Wood --- 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); From patchwork Tue May 14 18:03:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10943509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F123F1390 for ; Tue, 14 May 2019 18:04:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E18DB28885 for ; Tue, 14 May 2019 18:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5AB928894; Tue, 14 May 2019 18:04:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 741C828889 for ; Tue, 14 May 2019 18:04:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727163AbfENSEH (ORCPT ); Tue, 14 May 2019 14:04:07 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33117 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbfENSEE (ORCPT ); Tue, 14 May 2019 14:04:04 -0400 Received: by mail-wr1-f68.google.com with SMTP id d9so11879178wrx.0 for ; Tue, 14 May 2019 11:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=3cdTWHyfF2uZxinSS3hMKsNP913Nsf7W9VTMgEpQqK4=; b=XgzVvYLJ6zrBN7Pk9PEzwssne7aiSOVA4A3A4bu47ak/IePMHF4uf7rSjH1ImzGUm6 JPzwzVv/8c3SuNBqe0MRVtm0wdBj+SaRmbhfsU7RsAMAGoWzy4VYbSjPlrGfHK+y4az3 mf4AoHewBAoFpESUjD1BDR32H6FjWIq5LOJjGwo6y/DtSF/r0Ce5PqENlAmQaHh+54kv gbnsQUJCgGuu6IhPNATt/9UZoGZym25uEY1EKahgOtWUWHXk3xjRW4xlkpD6n5sCHYFK y0zSBj9csBpdYGtDUtGdPlJVpZzxsBiACV00FsY4sVH39WPrJhuwXsgOX98qjzBRfxLK +4Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=3cdTWHyfF2uZxinSS3hMKsNP913Nsf7W9VTMgEpQqK4=; b=lohinG4AzHvn7WlXfyqJofVIvHo9f6chT30khjH2pwLKb+Dk7ofw4cUBmRr97YVV5M 1Jr1jBOwiZ2zcAsgjvQKAbSX0j9B4zKwRmadCeZLqPblAmdzfrmfnePR5qYF9f88mmt0 E8GVUm5mCelKBDbzzy1MDB0T4MyUq+LZQQaucasYDASx7/SdX2KBm4I9PB7QHLvj9wLY G0cgt4R6cMNvgs8tXkmL+wPTubxGk08sE5PgFjPLH7pLoo2LpJqkvwRmvjTToCJ5MS6s zcSFaTgPMFJsBtBq7tL3XInvZFtZgfxmT8RsJZz1I4MMns3gMjA1rR2cEUgoUn7EYMb5 eaLw== X-Gm-Message-State: APjAAAWZ+BOdG/aA6evc4zukDQdkMK7tugjKsXzpfQUo9WlfKJvqTp0X YQvWBzHLzSM/qB3uvfm80mhSVKVQ X-Google-Smtp-Source: APXvYqzKpKxYkZGL5K/u2QlzuW/Dw7iTrD1mRr09PkEs3rY1kqmDlsaK1c1Rk+927CmPK8Nig5ggag== X-Received: by 2002:adf:fb4a:: with SMTP id c10mr21984501wrs.309.1557857042713; Tue, 14 May 2019 11:04:02 -0700 (PDT) Received: from lindisfarne.localdomain (host-89-242-178-164.as13285.net. [89.242.178.164]) by smtp.gmail.com with ESMTPSA id a4sm4528230wmf.45.2019.05.14.11.04.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:04:02 -0700 (PDT) From: Phillip Wood To: Git Mailing List , Johannes Schindelin , Junio C Hamano Cc: Phillip Wood Subject: [PATCH v2 2/4] rebase: warn if state directory cannot be removed Date: Tue, 14 May 2019 19:03:47 +0100 Message-Id: <20190514180349.17245-3-phillip.wood123@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514180349.17245-1-phillip.wood123@gmail.com> References: <20190426103212.8097-1-phillip.wood123@gmail.com> <20190514180349.17245-1-phillip.wood123@gmail.com> Reply-To: Phillip Wood MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood 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 --- 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: { From patchwork Tue May 14 18:03:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10943513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2F0A13AD for ; Tue, 14 May 2019 18:04:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A486A28885 for ; Tue, 14 May 2019 18:04:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98B2628889; Tue, 14 May 2019 18:04:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4649228885 for ; Tue, 14 May 2019 18:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727035AbfENSEH (ORCPT ); Tue, 14 May 2019 14:04:07 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39441 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726332AbfENSEF (ORCPT ); Tue, 14 May 2019 14:04:05 -0400 Received: by mail-wm1-f68.google.com with SMTP id n25so27258wmk.4 for ; Tue, 14 May 2019 11:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=nASAkG9LFdEMkYOsj/hg9OnOgwU/MZOaALnQ/b8M4qg=; b=uvowXe9Tn0mSUuHzjY+MwgXzhJyRBspMOW/ul1Te/obK+b8MpVAWTn4cqns7svTlgp OrbtmWKO7uigrk1Kcv5hwJA3iwM8uPoxahtQjoobSrZWhpeKppQcK/LoXO+kyi6KH0mm 8IfJcvUdLpGnWdKLzIb9tFtETt/+bohWmlPVuYyA5eD43zahUy80GWijdJryeFByGJIi Hj8Dw4EElf3Jkpr6n1dNVcJ+MYQZD2XbswBTKaPtmKDYdIu3IGIMzUw0ajuZMmgAdMBx Nn4D1XQMXzofZDGYQVjtEuwHQYHHbOKnrFSXf4Lw6y1MM5Yi7KKNvymJNaRerIOSxULo lSUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=nASAkG9LFdEMkYOsj/hg9OnOgwU/MZOaALnQ/b8M4qg=; b=KbmHQS2ErPzWz0db8lfz7V8S2bZi1f7W1LSaX7bM6JULBgzHVwCG+Qf84T15T28Sis FGbrwxpSG5/bGWOsHJd6BBYtaGupmgoeoxYK604IilGvh2CGbBfVPzsGefNSPkT5MObc DnQSQdwJjJn++EY1hGElrjBe5FXczpdfooa88sLd4K3ay0YpJ4H0t6lopG0mk3RC/ovc B2NeJM9EPUxYQdVNv2popahoQjjdWFCUYxj3BKPQtUpfEHTy3NgVT7fmBXjrgXfjO4ng ZchOMfNVS30MOL7yW/eokN9r64w2ziZZSOiK8KxqzXoQEN7tsvr2NZBS2iyxBoMD7mQ+ BBdw== X-Gm-Message-State: APjAAAUkRZtAtRGPqlBZU9eAKj/DT/G4f5rJx5Gyn8q5MZAT3nMBN17L BO8gro0EQlNWpFFrM6XotjsHG+NB X-Google-Smtp-Source: APXvYqxr3Ig1UlK9MuOrOK4NM/Kt+UNMD0EFAsaB8n9krZHIjyLearEY8DpS9nJB5G10uk6r4r77Hw== X-Received: by 2002:a1c:7e8d:: with SMTP id z135mr9974101wmc.72.1557857043616; Tue, 14 May 2019 11:04:03 -0700 (PDT) Received: from lindisfarne.localdomain (host-89-242-178-164.as13285.net. [89.242.178.164]) by smtp.gmail.com with ESMTPSA id a4sm4528230wmf.45.2019.05.14.11.04.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:04:03 -0700 (PDT) From: Phillip Wood To: Git Mailing List , Johannes Schindelin , Junio C Hamano Cc: Phillip Wood Subject: [PATCH v2 3/4] sequencer: return errors from sequencer_remove_state() Date: Tue, 14 May 2019 19:03:48 +0100 Message-Id: <20190514180349.17245-4-phillip.wood123@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514180349.17245-1-phillip.wood123@gmail.com> References: <20190426103212.8097-1-phillip.wood123@gmail.com> <20190514180349.17245-1-phillip.wood123@gmail.com> Reply-To: Phillip Wood MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood 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 --- 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) From patchwork Tue May 14 18:03:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10943511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3ABE792A for ; Tue, 14 May 2019 18:04:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B82828885 for ; Tue, 14 May 2019 18:04:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F62628889; Tue, 14 May 2019 18:04:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A246F28885 for ; Tue, 14 May 2019 18:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727194AbfENSEI (ORCPT ); Tue, 14 May 2019 14:04:08 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38747 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726982AbfENSEH (ORCPT ); Tue, 14 May 2019 14:04:07 -0400 Received: by mail-wm1-f65.google.com with SMTP id f2so33330wmj.3 for ; Tue, 14 May 2019 11:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=ssgWnfsVXAVIL9ZEdxizKDh8pM5BtMAVAj/SZnNyPlM=; b=ebnutD1EcWPyZn7MYzx1BjLldpwsn6uyjPDZicuLjqk/6gbxILeZO7Jpu0h0K94plz jDyEwCQvFdHvvggMXCiJAvDMVpz+2XU4Ni2u3cXEWDJyjNWoVQ/SRpqrdZ2ZPx9mjMCt IChBTmV4VlbOqOR/a5r5Ov50eraOc5jX4k4SpMcKXsfamPPkqtUVW4Fq+sdL7MRhx8mw acbz54FsHOOPuV0kdRjQrU99VQRYN3RVqp4jBwqSTNPde2/rk+cY7lllR5rWmDRi/lKe qFAixKMW+kiW4sCNSYpaDxlbtflnXr7eMoLuuVe1ScVumfuDc5IFqIXLjCkDtnW/Tih3 Ujgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=ssgWnfsVXAVIL9ZEdxizKDh8pM5BtMAVAj/SZnNyPlM=; b=Odv4hb39aVmzjn9IaBO0dQNZSnCqyRotuvRH3hTaP94cjWBsgty4O4fmaLr9CkvTW6 w7mW1Oe4lQPAQ6GmPBqFnM/Vk7SrOLbLXpHZ8Tz8NMcNeaT10qRZyghOo1YmUU8Jkjc7 tl5Ybk0jEwICSbWt1MzySdaY6TgQlRNZ9LscO9LsMkOEhhwnxMFIRH+a+L4287J//2G/ N5vh1XQAsDcTSg+RKBOyjbhVEfGC/EGdwcyKa8Orfdo0noRwh6mQ8NENxZsqe5UDJ4vn R0mmcyt006z6Y0h5/7Kqrv7OylNGfiaYFPAPeG1E1sUPIUleTlgxFfYWySzikBIKD67Y HghQ== X-Gm-Message-State: APjAAAWsR/EQDyQpcMi6WRrkStvGGBS1vNgX0fHxgP3oNVL+eDSJhPjD JPKIYc/5D3PUdquc1EVAO4XFFsy6 X-Google-Smtp-Source: APXvYqwVhYgdi9lV9mwvGr938N7w8McjVL/Ht/2Zk1zf8sFZ5RUbNhkUR2YDSlbOIrkvpoZ+Ngg4EA== X-Received: by 2002:a1c:7005:: with SMTP id l5mr20340050wmc.149.1557857044670; Tue, 14 May 2019 11:04:04 -0700 (PDT) Received: from lindisfarne.localdomain (host-89-242-178-164.as13285.net. [89.242.178.164]) by smtp.gmail.com with ESMTPSA id a4sm4528230wmf.45.2019.05.14.11.04.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:04:04 -0700 (PDT) From: Phillip Wood To: Git Mailing List , Johannes Schindelin , Junio C Hamano Cc: Phillip Wood Subject: [PATCH v2 4/4] rebase --abort/--quit: cleanup refs/rewritten Date: Tue, 14 May 2019 19:03:49 +0100 Message-Id: <20190514180349.17245-5-phillip.wood123@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514180349.17245-1-phillip.wood123@gmail.com> References: <20190426103212.8097-1-phillip.wood123@gmail.com> <20190514180349.17245-1-phillip.wood123@gmail.com> Reply-To: Phillip Wood MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood 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 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 --- 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 &&