From patchwork Tue Apr 7 14:27:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478165 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7446D159A for ; Tue, 7 Apr 2020 14:28:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DCC9207FF for ; Tue, 7 Apr 2020 14:28:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uRhO03eg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729028AbgDGO2W (ORCPT ); Tue, 7 Apr 2020 10:28:22 -0400 Received: from mail-qv1-f43.google.com ([209.85.219.43]:44390 "EHLO mail-qv1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728855AbgDGO2V (ORCPT ); Tue, 7 Apr 2020 10:28:21 -0400 Received: by mail-qv1-f43.google.com with SMTP id ef12so1861353qvb.11 for ; Tue, 07 Apr 2020 07:28:21 -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 :mime-version:content-transfer-encoding; bh=k4eKyQET1CoPr+njRS/c7UTku2TF4XktbZ4P78bJkfk=; b=uRhO03egcPKVeBVtXaSFRTLFYJqlS2wmxi9yVoPFsXnW7iFyoeNFWJTPAO+4Df/DK9 yv5fx65GtmkjXRFQGASiNGj5w3evEwwHeubqAG0MlcaUuQ0jriJDHwE0lpEMZeBVi+cX MFNZGUYE98f7AyD+RR78TVzJlU/noQnHC7RugyRrfb8j9rt89INb0MkCAH2gtHq7KqVk gLoKJAYO3fy7LQnnPUXd33NBH80E46nBspwUiSpR1lhaBCVLmtpCWRVy047oJJpWSf6w eiKJ7rUPN8uEzNpfiIcZ3IJAgKdevizNiBJ5+IHGMC0gLKaoNIzOyv7MmSxfvjcjw5Xv q3TQ== 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:mime-version:content-transfer-encoding; bh=k4eKyQET1CoPr+njRS/c7UTku2TF4XktbZ4P78bJkfk=; b=S7FP4ZkSguqg3x128dDN8jHo6fW1YWvLayHTMzpHFkP914UMUFz4kGn7tAOT79sSoM BqjeTEZ79zp6HOd0xX90IL7fy5/L6ugfloTbcSJbpYdAUmzoy7bch9SS5N3fIqr4+WcE fX4rBzlQuMbTn8XF0KZCg4rvcLryn3raKT+3QihDXCYQRvHT2krXzHtxjSCHSf9KukWt f0Jag1Xrc87jHEWrRiOfS5tje9c6hFY53/lGzZWIEFiwtzjDk6j6sOy7Gzg/d2/NVxKt p6JtBEbPRBAK0v+mC46L13jYCZ8bpBTBxzSlLsRPZOEHgR9biAQOgUjq+Myu17XxbuuI YjNQ== X-Gm-Message-State: AGi0PuZTSS4jN3tvDpkQON5yq4PC2/486emJA7G1ZhFRD5iKIJYL3nVT z0KqkTGanpCin6QleOnsRTH92sPQ X-Google-Smtp-Source: APiQypLQ789FEfhx9fmtpNoTiDUrGRBYJQSPepzzgKkSSjKYhPZ7SvlrXyhw4XOvsp/WILIJjl9Ctw== X-Received: by 2002:a05:6214:1781:: with SMTP id ct1mr2515543qvb.87.1586269699758; Tue, 07 Apr 2020 07:28:19 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:19 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 01/22] Makefile: ASCII-sort += lists Date: Tue, 7 Apr 2020 10:27:48 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There are many += lists in the Makefile and, over time, they have gotten slightly out of ASCII order. Sort all += lists to bring them back in order. ASCII sorting was chosen over strict alphabetical order even though, if we omit file prefixes, the lists aren't sorted in strictly alphabetical order (e.g. archive.o comes after archive-zip.o instead of before archive-tar.o). This is intentional because the purpose of maintaining the sorted list is to ensure line insertions are deterministic. By using ASCII ordering, it is more easily mechanically reproducible in the future, such as by using :sort in Vim. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu --- Makefile | 77 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 9804a0758b..f709fc3f77 100644 --- a/Makefile +++ b/Makefile @@ -604,12 +604,12 @@ unexport CDPATH SCRIPT_SH += git-bisect.sh SCRIPT_SH += git-difftool--helper.sh SCRIPT_SH += git-filter-branch.sh +SCRIPT_SH += git-legacy-stash.sh SCRIPT_SH += git-merge-octopus.sh SCRIPT_SH += git-merge-one-file.sh SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-quiltimport.sh -SCRIPT_SH += git-legacy-stash.sh SCRIPT_SH += git-request-pull.sh SCRIPT_SH += git-submodule.sh SCRIPT_SH += git-web--browse.sh @@ -617,8 +617,8 @@ SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib SCRIPT_LIB += git-parse-remote SCRIPT_LIB += git-rebase--preserve-merges -SCRIPT_LIB += git-sh-setup SCRIPT_LIB += git-sh-i18n +SCRIPT_LIB += git-sh-setup SCRIPT_PERL += git-add--interactive.perl SCRIPT_PERL += git-archimport.perl @@ -686,9 +686,9 @@ PROGRAM_OBJS += daemon.o PROGRAM_OBJS += fast-import.o PROGRAM_OBJS += http-backend.o PROGRAM_OBJS += imap-send.o +PROGRAM_OBJS += remote-testsvn.o PROGRAM_OBJS += sh-i18n--envsubst.o PROGRAM_OBJS += shell.o -PROGRAM_OBJS += remote-testsvn.o # Binary suffix, set to .exe for Windows builds X = @@ -709,9 +709,9 @@ TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-example-decorate.o TEST_BUILTINS_OBJS += test-genrandom.o TEST_BUILTINS_OBJS += test-genzeros.o +TEST_BUILTINS_OBJS += test-hash-speed.o TEST_BUILTINS_OBJS += test-hash.o TEST_BUILTINS_OBJS += test-hashmap.o -TEST_BUILTINS_OBJS += test-hash-speed.o TEST_BUILTINS_OBJS += test-index-version.o TEST_BUILTINS_OBJS += test-json-writer.o TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o @@ -737,8 +737,8 @@ TEST_BUILTINS_OBJS += test-revision-walking.o TEST_BUILTINS_OBJS += test-run-command.o TEST_BUILTINS_OBJS += test-scrap-cache-tree.o TEST_BUILTINS_OBJS += test-serve-v2.o -TEST_BUILTINS_OBJS += test-sha1.o TEST_BUILTINS_OBJS += test-sha1-array.o +TEST_BUILTINS_OBJS += test-sha1.o TEST_BUILTINS_OBJS += test-sha256.o TEST_BUILTINS_OBJS += test-sigchain.o TEST_BUILTINS_OBJS += test-strcmp-offset.o @@ -748,10 +748,10 @@ TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o TEST_BUILTINS_OBJS += test-subprocess.o TEST_BUILTINS_OBJS += test-trace2.o TEST_BUILTINS_OBJS += test-urlmatch-normalization.o -TEST_BUILTINS_OBJS += test-xml-encode.o TEST_BUILTINS_OBJS += test-wildmatch.o TEST_BUILTINS_OBJS += test-windows-named-pipe.o TEST_BUILTINS_OBJS += test-write-cache.o +TEST_BUILTINS_OBJS += test-xml-encode.o # Do not add more tests here unless they have extra dependencies. Add # them in TEST_BUILTINS_OBJS above. @@ -788,10 +788,10 @@ OTHER_PROGRAMS = git$X # what test wrappers are needed and 'install' will install, in bindir BINDIR_PROGRAMS_NEED_X += git -BINDIR_PROGRAMS_NEED_X += git-upload-pack BINDIR_PROGRAMS_NEED_X += git-receive-pack -BINDIR_PROGRAMS_NEED_X += git-upload-archive BINDIR_PROGRAMS_NEED_X += git-shell +BINDIR_PROGRAMS_NEED_X += git-upload-archive +BINDIR_PROGRAMS_NEED_X += git-upload-pack BINDIR_PROGRAMS_NO_X += git-cvsserver @@ -831,9 +831,9 @@ LIB_OBJS += advice.o LIB_OBJS += alias.o LIB_OBJS += alloc.o LIB_OBJS += apply.o -LIB_OBJS += archive.o LIB_OBJS += archive-tar.o LIB_OBJS += archive-zip.o +LIB_OBJS += archive.o LIB_OBJS += argv-array.o LIB_OBJS += attr.o LIB_OBJS += base85.o @@ -849,9 +849,9 @@ LIB_OBJS += checkout.o LIB_OBJS += color.o LIB_OBJS += column.o LIB_OBJS += combine-diff.o -LIB_OBJS += commit.o LIB_OBJS += commit-graph.o LIB_OBJS += commit-reach.o +LIB_OBJS += commit.o LIB_OBJS += compat/obstack.o LIB_OBJS += compat/terminal.o LIB_OBJS += config.o @@ -865,17 +865,17 @@ LIB_OBJS += ctype.o LIB_OBJS += date.o LIB_OBJS += decorate.o LIB_OBJS += delta-islands.o +LIB_OBJS += diff-delta.o +LIB_OBJS += diff-lib.o +LIB_OBJS += diff-no-index.o +LIB_OBJS += diff.o LIB_OBJS += diffcore-break.o LIB_OBJS += diffcore-delta.o LIB_OBJS += diffcore-order.o LIB_OBJS += diffcore-pickaxe.o LIB_OBJS += diffcore-rename.o -LIB_OBJS += diff-delta.o -LIB_OBJS += diff-lib.o -LIB_OBJS += diff-no-index.o -LIB_OBJS += diff.o -LIB_OBJS += dir.o LIB_OBJS += dir-iterator.o +LIB_OBJS += dir.o LIB_OBJS += editor.o LIB_OBJS += entry.o LIB_OBJS += environment.o @@ -893,7 +893,6 @@ LIB_OBJS += gpg-interface.o LIB_OBJS += graph.o LIB_OBJS += grep.o LIB_OBJS += hashmap.o -LIB_OBJS += linear-assignment.o LIB_OBJS += help.o LIB_OBJS += hex.o LIB_OBJS += ident.o @@ -903,9 +902,10 @@ LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o LIB_OBJS += line-log.o LIB_OBJS += line-range.o -LIB_OBJS += list-objects.o -LIB_OBJS += list-objects-filter.o +LIB_OBJS += linear-assignment.o LIB_OBJS += list-objects-filter-options.o +LIB_OBJS += list-objects-filter.o +LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o LIB_OBJS += log-tree.o @@ -914,31 +914,31 @@ LIB_OBJS += mailinfo.o LIB_OBJS += mailmap.o LIB_OBJS += match-trees.o LIB_OBJS += mem-pool.o -LIB_OBJS += merge.o LIB_OBJS += merge-blobs.o LIB_OBJS += merge-recursive.o +LIB_OBJS += merge.o LIB_OBJS += mergesort.o LIB_OBJS += midx.o LIB_OBJS += name-hash.o LIB_OBJS += negotiator/default.o LIB_OBJS += negotiator/skipping.o -LIB_OBJS += notes.o LIB_OBJS += notes-cache.o LIB_OBJS += notes-merge.o LIB_OBJS += notes-utils.o +LIB_OBJS += notes.o LIB_OBJS += object.o LIB_OBJS += oidmap.o LIB_OBJS += oidset.o -LIB_OBJS += packfile.o -LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-bitmap-write.o +LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-check.o LIB_OBJS += pack-objects.o LIB_OBJS += pack-revindex.o LIB_OBJS += pack-write.o +LIB_OBJS += packfile.o LIB_OBJS += pager.o -LIB_OBJS += parse-options.o LIB_OBJS += parse-options-cb.o +LIB_OBJS += parse-options.o LIB_OBJS += patch-delta.o LIB_OBJS += patch-ids.o LIB_OBJS += path.o @@ -955,8 +955,9 @@ LIB_OBJS += quote.o LIB_OBJS += range-diff.o LIB_OBJS += reachable.o LIB_OBJS += read-cache.o -LIB_OBJS += rebase.o LIB_OBJS += rebase-interactive.o +LIB_OBJS += rebase.o +LIB_OBJS += ref-filter.o LIB_OBJS += reflog-walk.o LIB_OBJS += refs.o LIB_OBJS += refs/files-backend.o @@ -964,7 +965,6 @@ LIB_OBJS += refs/iterator.o LIB_OBJS += refs/packed-backend.o LIB_OBJS += refs/ref-cache.o LIB_OBJS += refspec.o -LIB_OBJS += ref-filter.o LIB_OBJS += remote.o LIB_OBJS += replace-object.o LIB_OBJS += repo-settings.o @@ -979,8 +979,8 @@ LIB_OBJS += serve.o LIB_OBJS += server-info.o LIB_OBJS += setup.o LIB_OBJS += sha1-array.o -LIB_OBJS += sha1-lookup.o LIB_OBJS += sha1-file.o +LIB_OBJS += sha1-lookup.o LIB_OBJS += sha1-name.o LIB_OBJS += shallow.o LIB_OBJS += sideband.o @@ -990,9 +990,9 @@ LIB_OBJS += stable-qsort.o LIB_OBJS += strbuf.o LIB_OBJS += streaming.o LIB_OBJS += string-list.o -LIB_OBJS += submodule.o -LIB_OBJS += submodule-config.o LIB_OBJS += sub-process.o +LIB_OBJS += submodule-config.o +LIB_OBJS += submodule.o LIB_OBJS += symlinks.o LIB_OBJS += tag.o LIB_OBJS += tempfile.o @@ -1011,11 +1011,11 @@ LIB_OBJS += trace2/tr2_tgt_normal.o LIB_OBJS += trace2/tr2_tgt_perf.o LIB_OBJS += trace2/tr2_tls.o LIB_OBJS += trailer.o -LIB_OBJS += transport.o LIB_OBJS += transport-helper.o +LIB_OBJS += transport.o LIB_OBJS += tree-diff.o -LIB_OBJS += tree.o LIB_OBJS += tree-walk.o +LIB_OBJS += tree.o LIB_OBJS += unpack-trees.o LIB_OBJS += upload-pack.o LIB_OBJS += url.o @@ -1055,9 +1055,9 @@ BUILTIN_OBJS += builtin/checkout.o BUILTIN_OBJS += builtin/clean.o BUILTIN_OBJS += builtin/clone.o BUILTIN_OBJS += builtin/column.o +BUILTIN_OBJS += builtin/commit-graph.o BUILTIN_OBJS += builtin/commit-tree.o BUILTIN_OBJS += builtin/commit.o -BUILTIN_OBJS += builtin/commit-graph.o BUILTIN_OBJS += builtin/config.o BUILTIN_OBJS += builtin/count-objects.o BUILTIN_OBJS += builtin/credential.o @@ -1088,13 +1088,13 @@ BUILTIN_OBJS += builtin/ls-remote.o BUILTIN_OBJS += builtin/ls-tree.o BUILTIN_OBJS += builtin/mailinfo.o BUILTIN_OBJS += builtin/mailsplit.o -BUILTIN_OBJS += builtin/merge.o BUILTIN_OBJS += builtin/merge-base.o BUILTIN_OBJS += builtin/merge-file.o BUILTIN_OBJS += builtin/merge-index.o BUILTIN_OBJS += builtin/merge-ours.o BUILTIN_OBJS += builtin/merge-recursive.o BUILTIN_OBJS += builtin/merge-tree.o +BUILTIN_OBJS += builtin/merge.o BUILTIN_OBJS += builtin/mktag.o BUILTIN_OBJS += builtin/mktree.o BUILTIN_OBJS += builtin/multi-pack-index.o @@ -1114,9 +1114,9 @@ BUILTIN_OBJS += builtin/read-tree.o BUILTIN_OBJS += builtin/rebase.o BUILTIN_OBJS += builtin/receive-pack.o BUILTIN_OBJS += builtin/reflog.o -BUILTIN_OBJS += builtin/remote.o BUILTIN_OBJS += builtin/remote-ext.o BUILTIN_OBJS += builtin/remote-fd.o +BUILTIN_OBJS += builtin/remote.o BUILTIN_OBJS += builtin/repack.o BUILTIN_OBJS += builtin/replace.o BUILTIN_OBJS += builtin/rerere.o @@ -2335,16 +2335,16 @@ reconfigure config.mak.autogen: config.status endif XDIFF_OBJS += xdiff/xdiffi.o -XDIFF_OBJS += xdiff/xprepare.o -XDIFF_OBJS += xdiff/xutils.o XDIFF_OBJS += xdiff/xemit.o +XDIFF_OBJS += xdiff/xhistogram.o XDIFF_OBJS += xdiff/xmerge.o XDIFF_OBJS += xdiff/xpatience.o -XDIFF_OBJS += xdiff/xhistogram.o +XDIFF_OBJS += xdiff/xprepare.o +XDIFF_OBJS += xdiff/xutils.o +VCSSVN_OBJS += vcs-svn/fast_export.o VCSSVN_OBJS += vcs-svn/line_buffer.o VCSSVN_OBJS += vcs-svn/sliding_window.o -VCSSVN_OBJS += vcs-svn/fast_export.o VCSSVN_OBJS += vcs-svn/svndiff.o VCSSVN_OBJS += vcs-svn/svndump.o @@ -3152,9 +3152,10 @@ endif # ALL_COMMANDS = $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) ALL_COMMANDS += git +ALL_COMMANDS += git-citool +ALL_COMMANDS += git-gui ALL_COMMANDS += gitk ALL_COMMANDS += gitweb -ALL_COMMANDS += git-gui git-citool .PHONY: check-docs check-docs:: From patchwork Tue Apr 7 14:27:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478163 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 588E9112C for ; Tue, 7 Apr 2020 14:28:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2CCED2080C for ; Tue, 7 Apr 2020 14:28:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lNgGlPyz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729034AbgDGO2W (ORCPT ); Tue, 7 Apr 2020 10:28:22 -0400 Received: from mail-qv1-f66.google.com ([209.85.219.66]:43559 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728943AbgDGO2W (ORCPT ); Tue, 7 Apr 2020 10:28:22 -0400 Received: by mail-qv1-f66.google.com with SMTP id c28so1869434qvb.10 for ; Tue, 07 Apr 2020 07:28:21 -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 :mime-version:content-transfer-encoding; bh=Ub/Rqz/ZQ52smebEp7L5zy/sTdobfJ66/yCyFnDZTAI=; b=lNgGlPyz+xWgJHvDZ1qEzG5chHtWy53dZ/RONoKqOPGs8KhGOmlYjVhG4utOIjndgB i9R9ozVh5nQMehW5mr1IlAF86nMP/J/37fA0Do/LXQU9voRitP7kw8rZgGA4x1aQ6x6R 8FZaID6oh6ZEH/oqZSpiiwmCBsKByvujTJwipsyKvzeOL9er+IMSU1fs4EuGQIPdHNmX HcfC3HvRsO9dmoBDp/TRRWsTnQoKImv+GkBPSqL2aenyY/OxfVMX6F7g3+PHUPlfXZeC mFVGmF/TOrdxR8jrKmw+51pNHIkAsVHeDsdMkgGSuuOMyzXlpGkZ7zr6Ye4F5gODZBFY WsNw== 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:mime-version:content-transfer-encoding; bh=Ub/Rqz/ZQ52smebEp7L5zy/sTdobfJ66/yCyFnDZTAI=; b=PMNnZLuIr2s2uml9srno5QdXgEi3E9Yl+pZmulG7Bl9nscyOIJLUmGQl4iiu0JjrPU 2c8AakVlbtYlFHEpBKjBJ0AGtbFt57OtiSDdeG1oPwtWw7mPNjP23zyEIzNAnQEjB1Yk 6SmydbDUgWi0Azi9C0A5VDN/2/Oq7/j+Zu/YHQQxQCY/+uEtg3aj9yc35iB4FNhlHcoM gwtW6LI/1YeprFGA4LMU1iIDGEHPGM9gNPIz9ViCJ2N3g4uMbPCfTzWOCUpHKDChHDD0 0dFMB1FmHaSZFoK355tgHka3fgP8MlfDgftFzO/uI8JlZK7ejtXdPaF2tI9s//ZByzWd nqaQ== X-Gm-Message-State: AGi0PuYSmwPcH6phlOgk8hJqIPuCWTNWpKT4oHkltukXNsxT/4QC30Ka BfC08fCXNZmlHY8Jkgm7/KqODs7C X-Google-Smtp-Source: APiQypJDS+uBtPkIQ/CQPd9fSwy/jxnllZDwBFoKpvEVBKh+TZweZm/kCMvBvS7Vea8OAQ7e/VXceA== X-Received: by 2002:a0c:ffca:: with SMTP id h10mr2500949qvv.100.1586269700786; Tue, 07 Apr 2020 07:28:20 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:20 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 02/22] t7600: use test_write_lines() Date: Tue, 7 Apr 2020 10:27:49 -0400 Message-Id: <059e0e8e43f633086fc297f8328288047b45d0e0.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In t7600, we were rewriting `printf '%s\n' ...` to create files from parameters, one per line. However, we already have a function that wraps this for us: test_write_lines(). Rewrite these instances to use that function instead of open coding it. Signed-off-by: Denton Liu --- t/t7600-merge.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 132608879a..4fa0ef8e3b 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -29,15 +29,15 @@ Testing basic merge operations/option parsing. . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh -printf '%s\n' 1 2 3 4 5 6 7 8 9 >file -printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1 -printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y -printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1 -printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 -printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z +test_write_lines 1 2 3 4 5 6 7 8 9 >file +test_write_lines '1 X' 2 3 4 5 6 7 8 9 >file.1 +test_write_lines 1 2 3 4 '5 X' 6 7 8 9 >file.5 +test_write_lines 1 2 3 4 5 6 7 8 '9 X' >file.9 +test_write_lines 1 2 3 4 5 6 7 8 '9 Y' >file.9y +test_write_lines '1 X' 2 3 4 5 6 7 8 9 >result.1 +test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 +test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 +test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z create_merge_msgs () { echo "Merge tag 'c2'" >msg.1-5 && @@ -81,7 +81,7 @@ verify_head () { } verify_parents () { - printf '%s\n' "$@" >parents.expected && + test_write_lines "$@" >parents.expected && >parents.actual && i=1 && while test $i -le $# @@ -95,7 +95,7 @@ verify_parents () { } verify_mergeheads () { - printf '%s\n' "$@" >mergehead.expected && + test_write_lines "$@" >mergehead.expected && while read sha1 rest do git rev-parse $sha1 From patchwork Tue Apr 7 14:27:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478167 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34667112C for ; Tue, 7 Apr 2020 14:28:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10C8620801 for ; Tue, 7 Apr 2020 14:28:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FkE8W4DJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729075AbgDGO2Z (ORCPT ); Tue, 7 Apr 2020 10:28:25 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:36381 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728943AbgDGO2Y (ORCPT ); Tue, 7 Apr 2020 10:28:24 -0400 Received: by mail-qt1-f196.google.com with SMTP id m33so2787638qtb.3 for ; Tue, 07 Apr 2020 07:28:23 -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 :mime-version:content-transfer-encoding; bh=S0aG82s5CcnkkAJmRuKrOrhMfbEmERigVtMxWONZzI8=; b=FkE8W4DJ7L0oZ7K6alXBZW8houe/WokQ89n42jaiDP3Wjy4RWc1+enhZ5GJ+y5iiYG gdhtLMVASIlfrgVim9mhAx979k5s9/5m2GL8VlD088sYcL6g+YNsfm03R+eZ/Q18tewc RPJ4Q87CiRN+FkDgVVoaJsQaDLEt5R3q8lQElheD8gJUKqkCZfnyJ/lbOLU1XEyVGOCn 0Fq0UAwj8vfWqd0uCwQVEtQeY0S6uZLTnqZRYrN9dbbPNIYqN/lhshL4UHc3tpqlQU/s /jkzkUmE9YWF/UDrK84EkV/filmKCvyZeabEKBZuPfj6Fns1eAdrFt45shcK0HQw58DV vzpA== 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:mime-version:content-transfer-encoding; bh=S0aG82s5CcnkkAJmRuKrOrhMfbEmERigVtMxWONZzI8=; b=FvhnqzCacWHsPL1eKolzt7LJNeyfKtXh5RCp9hXNrXObf4CIoVdaW1uzQrZbwA8le/ K0lZCwZfN+oKhka0b1zGsraCOuF6P3CYsLEgZoVni6wRJAlh8b556XJkMXwtketYxYdf nYLByIk2EOyl3oGEeEJgVwdrNv9AtcruuhVspOw/D8Atg/WRJcL1uULXEGSQx6zN5iBO 0hNiNCmm6aWwe/PgCQs60YjeCzQSya9W/sqakxOOsxHTy69hN/kfpwyScOXqxMG41dY0 xirvDVx5x16AX6iwTj5QOAeCVYck0zeoWtvZnpUzWPTk5XLjYC5UQtRNit3kpWcV6HOr UfLg== X-Gm-Message-State: AGi0PubqFcQ5Nzk/Ai4/Fwnf7E3rL/3+NXMR0mg1X8BKdzAtzXUp9+fI KDcduAHDkgNTlyG2Zb/5WvqvvcVm X-Google-Smtp-Source: APiQypI/5xAXttBaYEjAmOWTVFt+kgDG8GETjn4OfxOseWA2Gjgf87rxpCBG9YXPIeTLAfFtFJbCbg== X-Received: by 2002:ac8:6890:: with SMTP id m16mr2475359qtq.5.1586269701882; Tue, 07 Apr 2020 07:28:21 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:21 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 03/22] sequencer: stop leaking buf Date: Tue, 7 Apr 2020 10:27:50 -0400 Message-Id: <76585e5b1367a3adf18d761b2af9356ee64b46fd.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In read_populate_opts(), we call read_oneliner() _after_ calling strbuf_release(). This means that `buf` is leaked at the end of the function. Always clean up the strbuf by going to `done_rebase_i` whether or not we return an error. Signed-off-by: Denton Liu --- sequencer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sequencer.c b/sequencer.c index e528225e78..faab0b13e8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2485,6 +2485,7 @@ static int read_populate_opts(struct replay_opts *opts) { if (is_rebase_i(opts)) { struct strbuf buf = STRBUF_INIT; + int ret = 0; if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) { if (!starts_with(buf.buf, "-S")) @@ -2525,7 +2526,7 @@ static int read_populate_opts(struct replay_opts *opts) opts->keep_redundant_commits = 1; read_strategy_opts(opts, &buf); - strbuf_release(&buf); + strbuf_reset(&buf); if (read_oneliner(&opts->current_fixups, rebase_path_current_fixups(), 1)) { @@ -2538,12 +2539,16 @@ static int read_populate_opts(struct replay_opts *opts) } if (read_oneliner(&buf, rebase_path_squash_onto(), 0)) { - if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) - return error(_("unusable squash-onto")); + if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) { + ret = error(_("unusable squash-onto")); + goto done_rebase_i; + } opts->have_squash_onto = 1; } - return 0; +done_rebase_i: + strbuf_release(&buf); + return ret; } if (!file_exists(git_path_opts_file())) From patchwork Tue Apr 7 14:27:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478169 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C6A6C159A for ; Tue, 7 Apr 2020 14:28:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A548620801 for ; Tue, 7 Apr 2020 14:28:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iTLwaDfx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729080AbgDGO20 (ORCPT ); Tue, 7 Apr 2020 10:28:26 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:42451 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729040AbgDGO2Y (ORCPT ); Tue, 7 Apr 2020 10:28:24 -0400 Received: by mail-qt1-f196.google.com with SMTP id b10so2759971qtt.9 for ; Tue, 07 Apr 2020 07:28:23 -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 :mime-version:content-transfer-encoding; bh=b/2hoE+6wPB6yrTn/Ub3LVA7378nqWm6uLTwohQhczY=; b=iTLwaDfx4WG7H/dWmEHzH+yEbjtcy+bo90vKhoo9ClsN+3b+BoEOE+5wc0z6d04cc/ Q1STb/TofwmT1NOvaq1T0bROuUXOg64i+YPk5aB7/1F4lRBvka87OXTxITkdBM6aRher dcI9kY0TOqXoJjKFiuX/bODSBSEiIAz927yz4Bv/vEHHWacJ2g5WfYEYFBg/eafmw66f WHGqWrXTSRiPYKchTgga+7PfzeicTbaGZYDQt5wVpHgWzTT3GZ4yXQu/2WB6YlgZgGpP gucZu01Ne8hwF7PPtiIYnUk/ZbdyB8Q8+/VdIluXuzn4sdgTYc9juKQ95ASHJ0Hgnumi q16A== 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:mime-version:content-transfer-encoding; bh=b/2hoE+6wPB6yrTn/Ub3LVA7378nqWm6uLTwohQhczY=; b=kBFUwMLpyzsU5xibEA77EXRqfD2zzeVc8LJaz72HvpLatRRlrUUZdf3yvXIKTJN34F +TvJEo1oqVl4flvrKPKJraw3XvgmpH1pKZ26+swlm1M0QNWI5TJL4HY/ybvbKupvOKWu UDJJ2V28+vBsYGDAMZuhnDFc1nKRLZ8IFvoY3KL2sJu4JI1lVZYkErJpp9W+tmGDkO6d 6eu+9n4sqXE5T1e0lgL4hMOWt0VhYGAqStiBDDWybEKT0QJCBbuEXTqJimbUjrW+lb6Q ySaHfyxTAC8G2+mGtk3rOlJ5nJKZYPRkh6DF/RsbbIWdFtqTJkhziNFk3k3FZD4t7RAI Q0rQ== X-Gm-Message-State: AGi0PuY4ht9ay1eJ6SMryDhRAljosu27pDmSDJGrsffrM9LLUwhaf+gZ E2HJ089KvZxQq3m580yS74xwcsTW X-Google-Smtp-Source: APiQypKfFsREyAotkEnKmGnS6qxWKZlhf5TRdf8HyiPGDPUZgPNeeeo6y5YAojYYaP4VX91s3bt/IQ== X-Received: by 2002:ac8:3466:: with SMTP id v35mr2544377qtb.308.1586269702991; Tue, 07 Apr 2020 07:28:22 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:22 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 04/22] sequencer: make file exists check more efficient Date: Tue, 7 Apr 2020 10:27:51 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We currently check whether a file exists and return early before reading the file. Instead of accessing the file twice, always read the file and check `errno` to see if the file doesn't exist. Signed-off-by: Denton Liu --- sequencer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sequencer.c b/sequencer.c index faab0b13e8..a961cf5a9b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -433,11 +433,9 @@ static int read_oneliner(struct strbuf *buf, { int orig_len = buf->len; - if (!file_exists(path)) - return 0; - if (strbuf_read_file(buf, path, 0) < 0) { - warning_errno(_("could not read '%s'"), path); + if (errno != ENOENT && errno != ENOTDIR) + warning_errno(_("could not read '%s'"), path); return 0; } From patchwork Tue Apr 7 14:27:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 767B9159A for ; Tue, 7 Apr 2020 14:28:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 556382078C for ; Tue, 7 Apr 2020 14:28:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FYa7hkXK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729087AbgDGO22 (ORCPT ); Tue, 7 Apr 2020 10:28:28 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:45081 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729060AbgDGO2Z (ORCPT ); Tue, 7 Apr 2020 10:28:25 -0400 Received: by mail-qk1-f195.google.com with SMTP id m67so612685qke.12 for ; Tue, 07 Apr 2020 07:28:25 -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 :mime-version:content-transfer-encoding; bh=9RY3BND5SfeTlPhgSuFM1vnMiDc3w6JLlucpcDFJ81w=; b=FYa7hkXKc2ujY65SCC4jp7mFWfkAK9niWtc3oS0smP3tdAz7PnqRFRfYrEBMMHv2td fC596krHueGeLkaFnXx1rNM3vbPBA+K1bj1Zj/hD02a8On6HiPg0tN1u9JCeWV6hJmJ3 gqE3uuhT1E64F6FVHp6EoO4gh5YzXGfjrxPIvPv4yOFWp9YKS8+5+1kRPvaW00R7K7+l HWBjqi+DwTUoFZgWIICiQduNPDpjHtEKcTBudMoSc+aXNJNWznO9rAWcKBcMMeJYdpQk FMAKYtAHNQsCHnz36BmDJM0wUbY/qYTkAOnTR+N2/fQxktaQPiTg8P3ycPeYdKBpbK6l uAWg== 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:mime-version:content-transfer-encoding; bh=9RY3BND5SfeTlPhgSuFM1vnMiDc3w6JLlucpcDFJ81w=; b=boMl3UJoxE58XUw6NopTH8Wwfox2UqdtqKUc9BzF5IHXEPr0BQpeAyWM3HNQj+wD/B ANC2Tk0NyeCCMCq8O5BMiHLdfh8lw0dKxWZcIzWSZL3cLtC18xtSKEKSjMiXvXkKz3jB PBn+1Y3KDoe+mhihhQ/TKeNIOg0xf+P5o72bu3NNRHiFhFL0VE0FGsWNFz+lU+JAwxgB a6qH0yTquJLj2J4cCb+MQBIWO1WPP2otx6Aqsk5vHLi2mX47f4u/Qh1vVyYKE3g0Lbnx 9NEsyPnizeX5frOZKRk4drOJGFsyzsLG46kTX35RTw/d0RQZTt6dMZX3KpwvYtCHFgpB 8BfA== X-Gm-Message-State: AGi0PuZNvJJAEsMUqxoz+F4s77nZ5K4TX1LWI2519CldeuUfQoUJePCa jJP/QOeRUdm3rAjeuwD/2mpBICLk X-Google-Smtp-Source: APiQypIFvpkQJOMVJT4WxhlhFf79pg3v5F15sq5SvzXjQ2vmTg3yiBe/8iEnew7X1EY0cKZdrNfVoA== X-Received: by 2002:a05:620a:22b1:: with SMTP id p17mr2594791qkh.396.1586269704415; Tue, 07 Apr 2020 07:28:24 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:23 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 05/22] sequencer: make read_oneliner() accept flags Date: Tue, 7 Apr 2020 10:27:52 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will need read_oneliner() to accept flags other than just `skip_if_empty`. Instead of having an argument for each flag, teach read_oneliner() to accept the bitfield `flags` instead. For now, only recognize the `READ_ONELINER_SKIP_IF_EMPTY` flag. More flags will be added in a future commit. The result of this is that parallel topics which introduce invocations of read_oneliner() will still be compatible with this new function signature since, instead of passing 1 or 0 for `skip_if_empty`, they'll be passing 1 or 0 to `flags`, which gives equivalent behavior. Mechanically fix up invocations of read_oneliner() with the following spatch @@ expression a, b; @@ read_oneliner(a, b, - 1 + READ_ONELINER_SKIP_IF_EMPTY ) and manually break up long lines in the result. Signed-off-by: Denton Liu --- sequencer.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sequencer.c b/sequencer.c index a961cf5a9b..6c4e8743ef 100644 --- a/sequencer.c +++ b/sequencer.c @@ -419,6 +419,8 @@ static int write_message(const void *buf, size_t len, const char *filename, return 0; } +#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) + /* * Reads a file that was presumably written by a shell script, i.e. with an * end-of-line marker that needs to be stripped. @@ -429,7 +431,7 @@ static int write_message(const void *buf, size_t len, const char *filename, * Returns 1 if the file was read, 0 if it could not be read or does not exist. */ static int read_oneliner(struct strbuf *buf, - const char *path, int skip_if_empty) + const char *path, unsigned flags) { int orig_len = buf->len; @@ -445,7 +447,7 @@ static int read_oneliner(struct strbuf *buf, buf->buf[buf->len] = '\0'; } - if (skip_if_empty && buf->len == orig_len) + if ((flags & READ_ONELINER_SKIP_IF_EMPTY) && buf->len == orig_len) return 0; return 1; @@ -2485,7 +2487,8 @@ static int read_populate_opts(struct replay_opts *opts) struct strbuf buf = STRBUF_INIT; int ret = 0; - if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) { + if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), + READ_ONELINER_SKIP_IF_EMPTY)) { if (!starts_with(buf.buf, "-S")) strbuf_reset(&buf); else { @@ -2495,7 +2498,8 @@ static int read_populate_opts(struct replay_opts *opts) strbuf_reset(&buf); } - if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), 1)) { + if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), + READ_ONELINER_SKIP_IF_EMPTY)) { if (!strcmp(buf.buf, "--rerere-autoupdate")) opts->allow_rerere_auto = RERERE_AUTOUPDATE; else if (!strcmp(buf.buf, "--no-rerere-autoupdate")) @@ -2527,7 +2531,8 @@ static int read_populate_opts(struct replay_opts *opts) strbuf_reset(&buf); if (read_oneliner(&opts->current_fixups, - rebase_path_current_fixups(), 1)) { + rebase_path_current_fixups(), + READ_ONELINER_SKIP_IF_EMPTY)) { const char *p = opts->current_fixups.buf; opts->current_fixup_count = 1; while ((p = strchr(p, '\n'))) { @@ -3668,7 +3673,8 @@ static int apply_autostash(struct replay_opts *opts) struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_sha1, rebase_path_autostash(), 1)) { + if (!read_oneliner(&stash_sha1, rebase_path_autostash(), + READ_ONELINER_SKIP_IF_EMPTY)) { strbuf_release(&stash_sha1); return 0; } @@ -4292,7 +4298,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) struct strbuf buf = STRBUF_INIT; struct object_id oid; - if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) && + if (read_oneliner(&buf, rebase_path_stopped_sha(), + READ_ONELINER_SKIP_IF_EMPTY) && !get_oid_committish(buf.buf, &oid)) record_in_rewritten(&oid, peek_command(&todo_list, 0)); strbuf_release(&buf); From patchwork Tue Apr 7 14:27:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAABA159A for ; Tue, 7 Apr 2020 14:28:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9FDF20801 for ; Tue, 7 Apr 2020 14:28:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nYagHF4k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729089AbgDGO23 (ORCPT ); Tue, 7 Apr 2020 10:28:29 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:44769 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729076AbgDGO20 (ORCPT ); Tue, 7 Apr 2020 10:28:26 -0400 Received: by mail-qt1-f196.google.com with SMTP id x16so2739597qts.11 for ; Tue, 07 Apr 2020 07:28:26 -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 :mime-version:content-transfer-encoding; bh=an4v6n1HzMOUK6tSWzdiCun/05pQI8hO9zSr23BZ90E=; b=nYagHF4kyoCv7WvLybvW2GbZBqwf6p8FhARDo6QPa8STLqjyPraU54/PhGPIumPnSs lYE0d+O9ut8vzKOHuatCrr/S1ch/Cyd5LOi86ul4DG+FNoGax66jMJmkFgy+VB/KK1C2 tWwNGiRObmql7GG36zxwfmtkwjszBplKIGfhr3iMQHPuTikLrMMZuTLHtYAizVGvL0wE c7IPHRBHMXQ943DAWmZyvTUQThW31RpP5IgvTXBh5pM6vEN3KZERfUWcdU7R5y2sZVIs maoBc/gMYleMttfQkHlwsyy1sC6kdMaZ31ST0wcBYMKXSFoxH3WGggXga2EmhVJH/1IC J/uw== 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:mime-version:content-transfer-encoding; bh=an4v6n1HzMOUK6tSWzdiCun/05pQI8hO9zSr23BZ90E=; b=OwW56AS1E5Nquw+pfy0/ligz8mZZzbVi5/FXpA1w0dsBpIxcRX/qMsdnMsegX3zwYl tUy77EqRS5IBSjKah6xHT4bdDQ5NbmcifCPG0xD5gM/HpSwExc5xNlRGUsK2nGMVnfAS Q+Z/BWjcZYdf+qRARCKMqoRJOsCxkOHZiuu4wRVlvq6LdzSI0OLlxp60q4g/wwkTgaUf a4gHCnRiQkyNgGSm+WqVxRTe97Ee36/fDen/3yrdUJ3+c2LH+nHvR0NC/X6TBh5pZinI Hmwa3gANRa/AkirWFawcDAbw4p26SntXxJKZ1Scx/dhHyp4ISihuAXqzeHYXVRFo9Rx3 rTOA== X-Gm-Message-State: AGi0PubRmPGuavUxkjHnALw9wbFNLjce9+LxT52j0Oqcna11L+Ma9u0L vrqsk5e+gvltvmmPWDMSwXK5bITv X-Google-Smtp-Source: APiQypI84r3lacbIaEuSeOGuAy/OeKNVY7B8HpeFZiQjh1eL6MOTLBgrwXD8XzZfCHwuBapRBwi9aQ== X-Received: by 2002:ac8:3f78:: with SMTP id w53mr2558363qtk.26.1586269705695; Tue, 07 Apr 2020 07:28:25 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:25 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 06/22] sequencer: configurably warn on non-existent files Date: Tue, 7 Apr 2020 10:27:53 -0400 Message-Id: <8c504427e376470fb0d939b9c9da315e7fabf36f.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the future, we plan on externing read_oneliner(). Future users of read_oneliner() will want the ability to output warnings in the event that the `path` doesn't exist. Introduce the `READ_ONELINER_WARN_MISSING` flag which, if active, would issue a warning when a file doesn't exist by always executing warning_errno() in the case where strbuf_read_file() fails. Signed-off-by: Denton Liu --- sequencer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 6c4e8743ef..32cc289da3 100644 --- a/sequencer.c +++ b/sequencer.c @@ -420,6 +420,7 @@ static int write_message(const void *buf, size_t len, const char *filename, } #define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) +#define READ_ONELINER_WARN_MISSING (1 << 1) /* * Reads a file that was presumably written by a shell script, i.e. with an @@ -436,7 +437,8 @@ static int read_oneliner(struct strbuf *buf, int orig_len = buf->len; if (strbuf_read_file(buf, path, 0) < 0) { - if (errno != ENOENT && errno != ENOTDIR) + if ((flags & READ_ONELINER_WARN_MISSING) || + (errno != ENOENT && errno != ENOTDIR)) warning_errno(_("could not read '%s'"), path); return 0; } From patchwork Tue Apr 7 14:27:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478177 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 394CF112C for ; Tue, 7 Apr 2020 14:28:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 183E42078C for ; Tue, 7 Apr 2020 14:28:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BZDiMInC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729098AbgDGO2a (ORCPT ); Tue, 7 Apr 2020 10:28:30 -0400 Received: from mail-qv1-f49.google.com ([209.85.219.49]:36291 "EHLO mail-qv1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729085AbgDGO22 (ORCPT ); Tue, 7 Apr 2020 10:28:28 -0400 Received: by mail-qv1-f49.google.com with SMTP id z13so1901080qvw.3 for ; Tue, 07 Apr 2020 07:28:27 -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 :mime-version:content-transfer-encoding; bh=Wa2yiFIEEyk0AqLOmMfh2cG0f/BmgdXoO+zDzix18sM=; b=BZDiMInC85sSPZf3zEAY2IjnuHt3gIBA2tCDV6s0JK1uIyutzxzADsGGKAaXOW26J8 iJTWH8F07et5g+T+1yK5KuNnw5kMIRPnhh+2yIyXKK8pfNYAtshpBPQlddF68Adbll9z XNUICBYRx87M7zIk/VKHhpcGb2alqfrmxcnLi/GQ5hsW9mBpvW8O2/PAQvq0pAnFqXXg CPIoBY00BI1skJVBRqoJ+3BK2c2D2SKvc10YKtpkUaM1ZJxgfq4EM0cYL1kvcCkusWNu 1Gwuu8E/MwIYMKtmGziQgMGngoYdPc9MTT2aDP8OfUdbRmnWL+AVf/BeK2ik0OZ/Syzs raIw== 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:mime-version:content-transfer-encoding; bh=Wa2yiFIEEyk0AqLOmMfh2cG0f/BmgdXoO+zDzix18sM=; b=g9xgvlFowXFqP9u4qfR7faTrDxk37Rvld2LQo4TQHx8R/uIu3/dKFIgMXH/uXZdCE+ HalxUBSRvZseF5acK+lwegSgnj4yORv7flrMm2Ts1pPVpEGX4ADdhwHaHiDF7GxCj1sN SgAYKafaTCBoxHk89nCwYIIM/2+xBjcuHXNIqVelBn+St9jcTjerA1dmfJEAbGB5H01n 3mpZAOgy15lxxkInWK77IH8ykqh/3otVL9r4ANYDaO6/wRPuWQHq+lpjpVXfYQ0Wsp9n p417zcekehpIC4IwVLSxZJ9SVdjan/e6wfS+adyt9oFR+GezSFgdSVuHyGxDvZA7u0wf dUqQ== X-Gm-Message-State: AGi0PuaRcVvwnXpBsy3+wQbAexjD0uQMxOB2nXjL/C6g6atRoL54DMy5 enNUUYr4SXqs3ci9DcEo+cTk5gFS X-Google-Smtp-Source: APiQypJm1kNd86wo4Si+NvOGHcIDyRlxnF9JqxsEQxGTiXj+T2VXW0g34jC3DKwPVaL6K4jytR0hmg== X-Received: by 2002:a0c:a122:: with SMTP id d31mr1461608qva.109.1586269706945; Tue, 07 Apr 2020 07:28:26 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:26 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 07/22] sequencer: make read_oneliner() extern Date: Tue, 7 Apr 2020 10:27:54 -0400 Message-Id: <50e93770e76863b05e51c25192a7173dc38e0ffe.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The function read_oneliner() is a generally useful util function. Instead of hiding it as a static function within sequencer.c, extern it so that it can be reused by others. This patch is best viewed with --color-moved. Signed-off-by: Denton Liu --- sequencer.c | 14 +------------- sequencer.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sequencer.c b/sequencer.c index 32cc289da3..0d98ddc33c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -419,19 +419,7 @@ static int write_message(const void *buf, size_t len, const char *filename, return 0; } -#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) -#define READ_ONELINER_WARN_MISSING (1 << 1) - -/* - * Reads a file that was presumably written by a shell script, i.e. with an - * end-of-line marker that needs to be stripped. - * - * Note that only the last end-of-line marker is stripped, consistent with the - * behavior of "$(cat path)" in a shell script. - * - * Returns 1 if the file was read, 0 if it could not be read or does not exist. - */ -static int read_oneliner(struct strbuf *buf, +int read_oneliner(struct strbuf *buf, const char *path, unsigned flags) { int orig_len = buf->len; diff --git a/sequencer.h b/sequencer.h index 718a07426d..ab43717fd6 100644 --- a/sequencer.h +++ b/sequencer.h @@ -198,6 +198,20 @@ void print_commit_summary(struct repository *repo, const struct object_id *oid, unsigned int flags); +#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) +#define READ_ONELINER_WARN_MISSING (1 << 1) + +/* + * Reads a file that was presumably written by a shell script, i.e. with an + * end-of-line marker that needs to be stripped. + * + * Note that only the last end-of-line marker is stripped, consistent with the + * behavior of "$(cat path)" in a shell script. + * + * Returns 1 if the file was read, 0 if it could not be read or does not exist. + */ +int read_oneliner(struct strbuf *buf, + const char *path, unsigned flags); int read_author_script(const char *path, char **name, char **email, char **date, int allow_missing); void parse_strategy_opts(struct replay_opts *opts, char *raw_opts); From patchwork Tue Apr 7 14:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5655F159A for ; Tue, 7 Apr 2020 14:28:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34F952078C for ; Tue, 7 Apr 2020 14:28:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oloV0xMN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729119AbgDGO2f (ORCPT ); Tue, 7 Apr 2020 10:28:35 -0400 Received: from mail-qv1-f65.google.com ([209.85.219.65]:33736 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729093AbgDGO2a (ORCPT ); Tue, 7 Apr 2020 10:28:30 -0400 Received: by mail-qv1-f65.google.com with SMTP id p19so1912285qve.0 for ; Tue, 07 Apr 2020 07:28:28 -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 :mime-version:content-transfer-encoding; bh=hzwahygR6Ex6Vj2E9Vg3hIxPiu91jEJXpBDe0r5S+gQ=; b=oloV0xMNcoh9RlZfg8uWBay0OYwL6KoZ4EljMXd6aYdBvfKZj9sU/potdWrX+EDilG 6yACGIcWzzaSSwA/zG3L5dDrWAWEmaArhkZwc8B6KJH4NHGmRQeK5VtyTSBxzSSy870u qCh89EqRI2J+uJVJBJjWJPNNo6x8M5RkEPqyfBBGeReNnFzEH7ggUlPq4vuHt6lb0zJw mULdv6Zupg+vUnLyleFij65a7l/v8juO8CGWb8yWuuU8uGQ7O1lAOtl4PeJtTcayW08w RVRO3BsYe37qjmjOGUnCGBUdPQZ6qdRShfMnSC2G7e8k0p0xHFQSSJu92WDuuclArPuE UBdg== 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:mime-version:content-transfer-encoding; bh=hzwahygR6Ex6Vj2E9Vg3hIxPiu91jEJXpBDe0r5S+gQ=; b=TkLqghrZSXs0JK0ackwo1JF/s4f35uxS0aCedKPwAwf63GGMt90c4snIGejnjShx2q BVNwOrTsN+GAWOb77txcC7bbSlARI3emYhZkEalPDZWanpGlyTGPIheuytMjxaAXmfWu jhQcl+taojK3OTbohXfXQBYYpk+DOePMgZuhWDeI984yTy/UzEOF+minYXJQb+G+pb0k H/bDOtiC1MDGPoJ7X1jmljVCT/ZgObpcHGe70zqzSmpfKpUGzMXI9jeT17glJfD4P4k1 3K7AhaPxPN1ifAOIFDpIa527iHEsnCo6RmauXpyBRlAZBhxywQY4vIUf1VQIIlaJnerZ PHvw== X-Gm-Message-State: AGi0PuYGnZe7qj5cdpsWfy1rxatl4v3QQqOchTC8LY5VvDXez7+AStNV T4dqHSUX7K6Jdu+2LKWJio2ezlAJ X-Google-Smtp-Source: APiQypI8Jr2BGLiHnD4InrI2hTIaXMuCMLQn8ye6Gti71w70GPVxZdHwLFeWvoqLw4jFri3eBOP7CQ== X-Received: by 2002:a0c:9aea:: with SMTP id k42mr2445872qvf.91.1586269708065; Tue, 07 Apr 2020 07:28:28 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:27 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 08/22] rebase: use read_oneliner() Date: Tue, 7 Apr 2020 10:27:55 -0400 Message-Id: <0cc279fc14dd27ed2606064d236115aa72551dce.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since in sequencer.c, read_one() basically duplicates the functionality of read_oneliner(), reduce code duplication by replacing read_one() with read_oneliner(). This was done with the following Coccinelle script @@ expression a, b; @@ - read_one(a, b) + !read_oneliner(b, a, READ_ONELINER_WARN_NON_EXISTENCE) and long lines were manually broken up. Signed-off-by: Denton Liu --- builtin/rebase.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index bff53d5d16..57dbfd2a4f 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -586,15 +586,6 @@ static const char *state_dir_path(const char *filename, struct rebase_options *o return path.buf; } -/* Read one file, then strip line endings */ -static int read_one(const char *path, struct strbuf *buf) -{ - if (strbuf_read_file(buf, path, 0) < 0) - return error_errno(_("could not read '%s'"), path); - strbuf_trim_trailing_newline(buf); - return 0; -} - /* Initialize the rebase options from the state directory. */ static int read_basic_state(struct rebase_options *opts) { @@ -602,8 +593,10 @@ static int read_basic_state(struct rebase_options *opts) struct strbuf buf = STRBUF_INIT; struct object_id oid; - if (read_one(state_dir_path("head-name", opts), &head_name) || - read_one(state_dir_path("onto", opts), &buf)) + if (!read_oneliner(&head_name, state_dir_path("head-name", opts), + READ_ONELINER_WARN_MISSING) || + !read_oneliner(&buf, state_dir_path("onto", opts), + READ_ONELINER_WARN_MISSING)) return -1; opts->head_name = starts_with(head_name.buf, "refs/") ? xstrdup(head_name.buf) : NULL; @@ -619,9 +612,11 @@ static int read_basic_state(struct rebase_options *opts) */ strbuf_reset(&buf); if (file_exists(state_dir_path("orig-head", opts))) { - if (read_one(state_dir_path("orig-head", opts), &buf)) + if (!read_oneliner(&buf, state_dir_path("orig-head", opts), + READ_ONELINER_WARN_MISSING)) return -1; - } else if (read_one(state_dir_path("head", opts), &buf)) + } else if (!read_oneliner(&buf, state_dir_path("head", opts), + READ_ONELINER_WARN_MISSING)) return -1; if (get_oid(buf.buf, &opts->orig_head)) return error(_("invalid orig-head: '%s'"), buf.buf); @@ -641,8 +636,8 @@ static int read_basic_state(struct rebase_options *opts) if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) { strbuf_reset(&buf); - if (read_one(state_dir_path("allow_rerere_autoupdate", opts), - &buf)) + if (!read_oneliner(&buf, state_dir_path("allow_rerere_autoupdate", opts), + READ_ONELINER_WARN_MISSING)) return -1; if (!strcmp(buf.buf, "--rerere-autoupdate")) opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE; @@ -655,8 +650,8 @@ static int read_basic_state(struct rebase_options *opts) if (file_exists(state_dir_path("gpg_sign_opt", opts))) { strbuf_reset(&buf); - if (read_one(state_dir_path("gpg_sign_opt", opts), - &buf)) + if (!read_oneliner(&buf, state_dir_path("gpg_sign_opt", opts), + READ_ONELINER_WARN_MISSING)) return -1; free(opts->gpg_sign_opt); opts->gpg_sign_opt = xstrdup(buf.buf); @@ -664,7 +659,8 @@ static int read_basic_state(struct rebase_options *opts) if (file_exists(state_dir_path("strategy", opts))) { strbuf_reset(&buf); - if (read_one(state_dir_path("strategy", opts), &buf)) + if (!read_oneliner(&buf, state_dir_path("strategy", opts), + READ_ONELINER_WARN_MISSING)) return -1; free(opts->strategy); opts->strategy = xstrdup(buf.buf); @@ -672,7 +668,8 @@ static int read_basic_state(struct rebase_options *opts) if (file_exists(state_dir_path("strategy_opts", opts))) { strbuf_reset(&buf); - if (read_one(state_dir_path("strategy_opts", opts), &buf)) + if (!read_oneliner(&buf, state_dir_path("strategy_opts", opts), + READ_ONELINER_WARN_MISSING)) return -1; free(opts->strategy_opts); opts->strategy_opts = xstrdup(buf.buf); @@ -724,7 +721,7 @@ static int apply_autostash(struct rebase_options *opts) if (!file_exists(path)) return 0; - if (read_one(path, &autostash)) + if (!read_oneliner(&autostash, path, READ_ONELINER_WARN_MISSING)) return error(_("Could not read '%s'"), path); /* Ensure that the hash is not mistaken for a number */ strbuf_addstr(&autostash, "^0"); From patchwork Tue Apr 7 14:27:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3A061805 for ; Tue, 7 Apr 2020 14:28:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B350220801 for ; Tue, 7 Apr 2020 14:28:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qkk2Bsmi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729114AbgDGO2f (ORCPT ); Tue, 7 Apr 2020 10:28:35 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:43509 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729103AbgDGO2b (ORCPT ); Tue, 7 Apr 2020 10:28:31 -0400 Received: by mail-qk1-f194.google.com with SMTP id 13so1782620qko.10 for ; Tue, 07 Apr 2020 07:28:30 -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 :mime-version:content-transfer-encoding; bh=w6B8gL43WsD2IPA1NAxl28oY+FECJVQaDKQvwbKTeJo=; b=qkk2BsmiHyWDIba7wWtMEg+7yDNNoXMFiopotvvYJzhgBrJ88m+w4/VlXr9CAn1Ha3 md4+qExwykP8XVH+h+Fc5zn93RqSNljB7D1pYmItplJNybdBH34zzin6AXFb6Yy0X1lE K+HVNCGvXA+yyMEbjcTa4yMZPsPYUwFXIpfWZIYdXW3tJyAO3qYLTSpxsF6/X/oB8Wxi 1n3GuQzbZcamQx6JQbk8qfxc836ro+/Jxc+IYG+WK9H430zrA4/E9/12QxB7ocMIntyH E1B9hXf1SzmFEMMcr0S/cToYmdLhJ1Z05GIjQBOYvbUZKp5IxQm0KG8uFPuBfA7UNOKa SzzA== 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:mime-version:content-transfer-encoding; bh=w6B8gL43WsD2IPA1NAxl28oY+FECJVQaDKQvwbKTeJo=; b=N/TQVjUWON6kLYBCUabhBUP0bh1ZMza1oUV94MeweQWQ/y5aARZxl60NkwaeJ3zhl0 VILCS2F/Ndc1i6iYLkWX64nB+izHWcuGKYcQpRfZy7xSJPogpdkg22/EcbGyQUGjKOUN Acnsc0x8pm6RflMu2WWic5HiC5/Uck8wdKQPvWrKTdPmqWXziS3X4UlfnAVef3uxgtPY Inprm2k/g4rp1X728POvs0jw/n8ZMF89Y6EiC6PvTROahxduYRajau/sKoKm1nXR9Di0 CaKTZCPhAqL7rB3teIFpPDtZ9PbcPMHK/XwvZsmCoTVczrAGXEZt9makFKYxERgZB/6/ TspA== X-Gm-Message-State: AGi0PubPb2hJ5Q5GkgoohS5DnQWlHlNh7DgCPCl53aSXu9yKQHdwhQD0 EDwS9h2uq3E+pH4jJqspF5mPVG6v X-Google-Smtp-Source: APiQypJzN2RYMbRyQ0X7OsRFkkl7gBToJSnQs4E6tb0+Ptk6pHpgbrOO1zaBWwvycTfgHJ0wT1srDw== X-Received: by 2002:a37:4885:: with SMTP id v127mr2577173qka.173.1586269709496; Tue, 07 Apr 2020 07:28:29 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:28 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 09/22] sequencer: make apply_autostash() accept a path Date: Tue, 7 Apr 2020 10:27:56 -0400 Message-Id: <3dbed2a832a713cba677bb482668a39ffd7f5ebf.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In order to make apply_autostash() more generic for future extraction, make it accept a `path` argument so that the location from where to read the reference to the autostash commit can be customized. Remove the `opts` argument since it was unused before anyway. Signed-off-by: Denton Liu --- sequencer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sequencer.c b/sequencer.c index 0d98ddc33c..4917c70a86 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3657,13 +3657,13 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) return -1; } -static int apply_autostash(struct replay_opts *opts) +static int apply_autostash(const char *path) { struct strbuf stash_sha1 = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_sha1, rebase_path_autostash(), + if (!read_oneliner(&stash_sha1, path, READ_ONELINER_SKIP_IF_EMPTY)) { strbuf_release(&stash_sha1); return 0; @@ -3756,7 +3756,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts, return error(_("%s: not a valid OID"), orig_head); if (run_git_checkout(r, opts, oid_to_hex(onto), action)) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); return error(_("could not detach HEAD")); } @@ -4070,7 +4070,7 @@ static int pick_commits(struct repository *r, run_command(&hook); } } - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); if (!opts->quiet) { if (!opts->verbose) @@ -5079,7 +5079,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla todo_list_add_exec_commands(todo_list, commands); if (count_commands(todo_list) == 0) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); return error(_("nothing to do")); @@ -5090,12 +5090,12 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla if (res == -1) return -1; else if (res == -2) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); return -1; } else if (res == -3) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); todo_list_release(&new_todo); From patchwork Tue Apr 7 14:27:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9414112C for ; Tue, 7 Apr 2020 14:28:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87808207FF for ; Tue, 7 Apr 2020 14:28:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jspAs+Q8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729111AbgDGO2e (ORCPT ); Tue, 7 Apr 2020 10:28:34 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:32835 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729106AbgDGO2b (ORCPT ); Tue, 7 Apr 2020 10:28:31 -0400 Received: by mail-qk1-f196.google.com with SMTP id v7so1821050qkc.0 for ; Tue, 07 Apr 2020 07:28:31 -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 :mime-version:content-transfer-encoding; bh=u0IRPHF+2p0k1bT1/v3/FOq8V/yFy8XbQoyH3Ew1eGU=; b=jspAs+Q8H/vzhEXgyFIEZZ7jUBXwIjeUJbzax8QjkGP+ltAVV/7Nkr4snUoYF84M7X 8eWcEElj6H2I3KMiJsjow2nJmeA+YhZT8EEL5MZQq6XUT+liSLJNJpHxe7hAt0pdMTve hKNmVFqo7XEwL9mfF9hjCzVK1DI4qAcV9BRw6TA4fdmu1nURUkGZtha8JAK1oUAGbJ1z Trxhcv6oFwFx9zb+ozbG1KC3DE/mwUystae93PqzPhKW5yQO/W+202u3o4AbDIyhkRho yPdJo0v7OvxuRmQpAKkZsH5RK1fZjqHdUwCK1Xq2VQxeBtf2kv/iUnrcyvAdRgaW4QDf eQEw== 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:mime-version:content-transfer-encoding; bh=u0IRPHF+2p0k1bT1/v3/FOq8V/yFy8XbQoyH3Ew1eGU=; b=reBK/wFEMhae8YKaVjHs12t4lZcung6XQvd8eGgtjKbhA1kUM3ewYTU4wiZL8RdWRA ifGySbcX8eoA78Tch6ggtjl0GoElOt9bpmoBv1+xNRkM5t7jceHxWryjN4b6aTR9CGIb sZFfy+0FKt8FRJzXNB2MlSPci2SM/mt/qPyC6EaHEMBTPtUD43u1pH/ZNYMUCHOEmaQF 4rJiFZMELAwhZAYo4FPDNGp9Etd3PXv4yhUuaE7El5MeLRgcHdi6MI6tTqYkyLA49vIS 0Cd5YF/2G0cTsXspfR80JwAsN7kZOiCp/gs8rckRcfxEHDuCzLDxYTwp7yahKMCftOo+ Uwbg== X-Gm-Message-State: AGi0PuZlkq/KcKEMzthDrHhsWOrBseOQMq+5X39tEPQWMHJ4fEHLFaTk 9lFZCaFrIe9y6iZb9MLr1MFcloId X-Google-Smtp-Source: APiQypL+vJMqt6+O3rX+fBjw2yvgDi4dXT+hbGYJIvNeAQ8HoAgXtcwDjL5lRAMAP4tD67Ikx0u2LQ== X-Received: by 2002:a37:af86:: with SMTP id y128mr2561607qke.429.1586269710672; Tue, 07 Apr 2020 07:28:30 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:30 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 10/22] sequencer: rename stash_sha1 to stash_oid Date: Tue, 7 Apr 2020 10:27:57 -0400 Message-Id: <937b4964d14cd2f41521722d370cf0d89b3b9f24.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The preferred terminology is to refer to object identifiers as "OIDs". Rename the `stash_sha1` variable to `stash_oid` in order to conform to this. Signed-off-by: Denton Liu --- sequencer.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sequencer.c b/sequencer.c index 4917c70a86..4a6812e90e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3659,23 +3659,23 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) static int apply_autostash(const char *path) { - struct strbuf stash_sha1 = STRBUF_INIT; + struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_sha1, path, + if (!read_oneliner(&stash_oid, path, READ_ONELINER_SKIP_IF_EMPTY)) { - strbuf_release(&stash_sha1); + strbuf_release(&stash_oid); return 0; } - strbuf_trim(&stash_sha1); + strbuf_trim(&stash_oid); child.git_cmd = 1; child.no_stdout = 1; child.no_stderr = 1; argv_array_push(&child.args, "stash"); argv_array_push(&child.args, "apply"); - argv_array_push(&child.args, stash_sha1.buf); + argv_array_push(&child.args, stash_oid.buf); if (!run_command(&child)) fprintf(stderr, _("Applied autostash.\n")); else { @@ -3687,9 +3687,9 @@ static int apply_autostash(const char *path) argv_array_push(&store.args, "-m"); argv_array_push(&store.args, "autostash"); argv_array_push(&store.args, "-q"); - argv_array_push(&store.args, stash_sha1.buf); + argv_array_push(&store.args, stash_oid.buf); if (run_command(&store)) - ret = error(_("cannot store %s"), stash_sha1.buf); + ret = error(_("cannot store %s"), stash_oid.buf); else fprintf(stderr, _("Applying autostash resulted in conflicts.\n" @@ -3698,7 +3698,7 @@ static int apply_autostash(const char *path) " \"git stash drop\" at any time.\n")); } - strbuf_release(&stash_sha1); + strbuf_release(&stash_oid); return ret; } From patchwork Tue Apr 7 14:27:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478181 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED0F71805 for ; Tue, 7 Apr 2020 14:28:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB83620801 for ; Tue, 7 Apr 2020 14:28:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lDdVcJNr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729124AbgDGO2f (ORCPT ); Tue, 7 Apr 2020 10:28:35 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:37732 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729040AbgDGO2e (ORCPT ); Tue, 7 Apr 2020 10:28:34 -0400 Received: by mail-qk1-f196.google.com with SMTP id 130so1802138qke.4 for ; Tue, 07 Apr 2020 07:28:33 -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 :mime-version:content-transfer-encoding; bh=f7rob1mWGcVE1KDjaw3ZNwh6mElGTNX1Hs/jI6OLoJQ=; b=lDdVcJNrxY3pWcfwJTP7mCY2PzBGH2OETVAcMskQ6TB3iSraYMg5rA7ZP3F440d5tW gFbSWWngU/JLnYAxxfkzPM6EyESHvFcaCzPpvWLnDjIk88Izi6KFZtYbIsZrdoRXzito XXcJA6kgHu+4w3JyrfWtEz/ZN+uiPTcwdQnsXYHnFEV+1PbKyAnq95CBkXC5IMIMp+m/ fW7xDOTzI0CAQfxk2Ahq94PjvkFI0h6QFUuEPwqVBJp1S16RxuD+TpSZZxLMiZtymF7M q5DQvPKXxvrVuqykLp4Pj++sW7q3qMlsN6KvVvV+krjlDZF8nKKaX9tBxZfYj35qKI7A v/Gw== 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:mime-version:content-transfer-encoding; bh=f7rob1mWGcVE1KDjaw3ZNwh6mElGTNX1Hs/jI6OLoJQ=; b=lcsM6inGqGEA3wxj+AVKsecLqqdFE5+1H0uDwAk+u6qz4Ph2WnhoZwWWCYcMlHsV4J Zx6Y3IeN+GvuDubAVVtZTM43imXT02Zo/wOhbHQHIaL54ADLP5mdojM1enyv+W5OxN/q OW6Em+9Devl/fp7UnCpzWQ3WsEnAkwPfZYO2F2XlXt2og2e2rynfqeydXddqHCoKR7ux /Ssf8mFislcfakQwTB9olduiPsCTxOF+xlU+y+JKe1O9C+GRKvWmcQVwrC4PM2s1HIkV ohGwCxMw52oINiuQcqZ11p11P7M2xSJftuZjfVQfamj6RVyA87h6hGiI0cIVkSSIgpOH d4fA== X-Gm-Message-State: AGi0PuZQA8HKCPZmynmMTSWIzZcnmW0EAW4KoQIJcKeW+g6PYPgl9/R0 Tkcvey1cII6qKPQzqJ+5UMpB0Qwp X-Google-Smtp-Source: APiQypLqby+Z9XYaeLflzLZ11BzlzuOTaS5iwUS7giVjm+Af27nwvWaWgmxPvU82MPA/2G1PZuO73w== X-Received: by 2002:a37:67c4:: with SMTP id b187mr2488584qkc.209.1586269712300; Tue, 07 Apr 2020 07:28:32 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:31 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 11/22] rebase: use apply_autostash() from sequencer.c Date: Tue, 7 Apr 2020 10:27:58 -0400 Message-Id: <98a7f5280c12a3244d0c5d92d1b65d6de7be3cb5.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The apply_autostash() function in builtin/rebase.c is similar enough to the apply_autostash() function in sequencer.c that they are almost interchangeable, except for the type of arg they accept. Make the sequencer.c version extern and use it in rebase. The rebase version was introduced in 6defce2b02 (builtin rebase: support `--autostash` option, 2018-09-04) as part of the shell to C conversion. It opted to duplicate the function because, at the time, there was another in-progress project converting interactive rebase from shell to C as well and they did not want to clash with them by refactoring sequencer.c version of apply_autostash(). Since both efforts are long done, we can freely combine them together now. Signed-off-by: Denton Liu --- builtin/rebase.c | 49 ++---------------------------------------------- sequencer.c | 2 +- sequencer.h | 2 ++ 3 files changed, 5 insertions(+), 48 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 57dbfd2a4f..cb0bdfc3e4 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -712,51 +712,6 @@ static int rebase_write_basic_state(struct rebase_options *opts) return 0; } -static int apply_autostash(struct rebase_options *opts) -{ - const char *path = state_dir_path("autostash", opts); - struct strbuf autostash = STRBUF_INIT; - struct child_process stash_apply = CHILD_PROCESS_INIT; - - if (!file_exists(path)) - return 0; - - if (!read_oneliner(&autostash, path, READ_ONELINER_WARN_MISSING)) - return error(_("Could not read '%s'"), path); - /* Ensure that the hash is not mistaken for a number */ - strbuf_addstr(&autostash, "^0"); - argv_array_pushl(&stash_apply.args, - "stash", "apply", autostash.buf, NULL); - stash_apply.git_cmd = 1; - stash_apply.no_stderr = stash_apply.no_stdout = - stash_apply.no_stdin = 1; - if (!run_command(&stash_apply)) - printf(_("Applied autostash.\n")); - else { - struct argv_array args = ARGV_ARRAY_INIT; - int res = 0; - - argv_array_pushl(&args, - "stash", "store", "-m", "autostash", "-q", - autostash.buf, NULL); - if (run_command_v_opt(args.argv, RUN_GIT_CMD)) - res = error(_("Cannot store %s"), autostash.buf); - argv_array_clear(&args); - strbuf_release(&autostash); - if (res) - return res; - - fprintf(stderr, - _("Applying autostash resulted in conflicts.\n" - "Your changes are safe in the stash.\n" - "You can run \"git stash pop\" or \"git stash drop\" " - "at any time.\n")); - } - - strbuf_release(&autostash); - return 0; -} - static int finish_rebase(struct rebase_options *opts) { struct strbuf dir = STRBUF_INIT; @@ -764,7 +719,7 @@ static int finish_rebase(struct rebase_options *opts) int ret = 0; delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF); - apply_autostash(opts); + apply_autostash(state_dir_path("autostash", opts)); close_object_store(the_repository->objects); /* * We ignore errors in 'gc --auto', since the @@ -1209,7 +1164,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action) } else if (status == 2) { struct strbuf dir = STRBUF_INIT; - apply_autostash(opts); + apply_autostash(state_dir_path("autostash", opts)); strbuf_addstr(&dir, opts->state_dir); remove_dir_recursively(&dir, 0); strbuf_release(&dir); diff --git a/sequencer.c b/sequencer.c index 4a6812e90e..f5bb1cc1fb 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3657,7 +3657,7 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) return -1; } -static int apply_autostash(const char *path) +int apply_autostash(const char *path) { struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; diff --git a/sequencer.h b/sequencer.h index ab43717fd6..ab686146d1 100644 --- a/sequencer.h +++ b/sequencer.h @@ -191,6 +191,8 @@ void commit_post_rewrite(struct repository *r, const struct commit *current_head, const struct object_id *new_head); +int apply_autostash(const char *path); + #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) void print_commit_summary(struct repository *repo, From patchwork Tue Apr 7 14:27:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 56B2A112C for ; Tue, 7 Apr 2020 14:28:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B65B2078C for ; Tue, 7 Apr 2020 14:28:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PcgH6pXo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729128AbgDGO2h (ORCPT ); Tue, 7 Apr 2020 10:28:37 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:39649 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729052AbgDGO2g (ORCPT ); Tue, 7 Apr 2020 10:28:36 -0400 Received: by mail-qk1-f194.google.com with SMTP id b62so1795418qkf.6 for ; Tue, 07 Apr 2020 07:28:34 -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 :mime-version:content-transfer-encoding; bh=F2WJdj+vcpkyQTRWraWJXcqfaaKKMndaZPLFnnJ/MJI=; b=PcgH6pXok8FX3V9Vpr4vqj4afZ2LvIKe+UavmRRJ6OvAyunAs0I4opp7ipffVnOk4+ W8eCZNvgPvB8hxtbVYys6rHPdtMT3+4HB7kuwC1bTAS9a4vBMBiEuHqYtjOIo4Yh95e1 XTCONC0DU9ZeI1Wrf/AGPXKRBK2lPaRwfrxy61gdwmq2S44P/RGImlxEebseijpCs3bv upnuSVJMLZlOjsg5SkgbuXsIqW/Wx0iI4bM4HrLpdsviAZRubBb4BijjUZPYQ5jiEbNV FcNVZ8GeQLdJpBN78GWEwliqSRx7OsIGemNDUEN6OjlgJtrgugyPkZhv3itmEvHwdV+r sBOw== 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:mime-version:content-transfer-encoding; bh=F2WJdj+vcpkyQTRWraWJXcqfaaKKMndaZPLFnnJ/MJI=; b=e//A+9IcTcIDqUKXcmRtc9dVIGgvv6FqlaKwij4WF3YHjOPG0A19INpO7sBVG/MsUf LneVlgp7ihGf0jrc8mkIWuACCTpidgXCvHHScKCW+jRkEyj6lUEV2lPbHJYw0Cjjtfwh iDK3Qr4nh500oL0iQ1WYyxWeNpD2n5A0OEVST6x8VfW0OcgkKu3IxyNwu6t7+c2B+TkS ul3Zjn+VT9Ox6MDI9F8Wn/LeWKaYZ/JviEgjJ5bpUCYNPk3twP8PU2Rg40d6hGEGfUcT bT18Iu5udhNDhuo+EgKpBEeDCVrywsY5YuYSUsxorYJj2U4RRh9EGjVw83Zhhkgwy1sI gkKw== X-Gm-Message-State: AGi0PuZ+V1B5/8xEqIzFmb87IzGx8sRuX86iFcSRl9rdIZGu5fsdC1KZ iGZqjWx2BbeCKwd2PQ4odKdtSXl4 X-Google-Smtp-Source: APiQypKHOErrE9AEKtXpP00bPnwP8nBaO0pJYBJUOmFvo70vv9UEWdQSP4g3zqqnBCQAVheOL959vw== X-Received: by 2002:a05:620a:1187:: with SMTP id b7mr2340534qkk.272.1586269713572; Tue, 07 Apr 2020 07:28:33 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:32 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 12/22] rebase: generify reset_head() Date: Tue, 7 Apr 2020 10:27:59 -0400 Message-Id: <67f3b5c2256650411441c9328da2f9b9ba3b0bab.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the future, we plan on lib-ifying reset_head() so we need it to be more generic. Make it more generic by making it accept a `struct repository` argument instead of implicitly using the non-repo functions. Also, make it accept a `const char *default_reflog_action` argument so that the default action of "rebase" isn't hardcoded in. Signed-off-by: Denton Liu --- builtin/rebase.c | 64 ++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index cb0bdfc3e4..5532286142 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -28,6 +28,8 @@ #include "sequencer.h" #include "rebase-interactive.h" +#define DEFAULT_REFLOG_ACTION "rebase" + static char const * const builtin_rebase_usage[] = { N_("git rebase [-i] [options] [--exec ] " "[--onto | --keep-base] [ []]"), @@ -772,9 +774,10 @@ static void add_var(struct strbuf *buf, const char *name, const char *value) #define RESET_HEAD_REFS_ONLY (1<<3) #define RESET_ORIG_HEAD (1<<4) -static int reset_head(struct object_id *oid, const char *action, +static int reset_head(struct repository *r, struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, - const char *reflog_orig_head, const char *reflog_head) + const char *reflog_orig_head, const char *reflog_head, + const char *default_reflog_action) { unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; @@ -796,7 +799,7 @@ static int reset_head(struct object_id *oid, const char *action, if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) BUG("Not a fully qualified branch: '%s'", switch_to_branch); - if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { + if (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { ret = -1; goto leave_reset_head; } @@ -815,26 +818,26 @@ static int reset_head(struct object_id *oid, const char *action, memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); setup_unpack_trees_porcelain(&unpack_tree_opts, action); unpack_tree_opts.head_idx = 1; - unpack_tree_opts.src_index = the_repository->index; - unpack_tree_opts.dst_index = the_repository->index; + unpack_tree_opts.src_index = r->index; + unpack_tree_opts.dst_index = r->index; unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; unpack_tree_opts.update = 1; unpack_tree_opts.merge = 1; if (!detach_head) unpack_tree_opts.reset = 1; - if (repo_read_index_unmerged(the_repository) < 0) { + if (repo_read_index_unmerged(r) < 0) { ret = error(_("could not read index")); goto leave_reset_head; } - if (!reset_hard && !fill_tree_descriptor(the_repository, &desc[nr++], &head_oid)) { + if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) { ret = error(_("failed to find tree of %s"), oid_to_hex(&head_oid)); goto leave_reset_head; } - if (!fill_tree_descriptor(the_repository, &desc[nr++], oid)) { + if (!fill_tree_descriptor(r, &desc[nr++], oid)) { ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); goto leave_reset_head; } @@ -845,16 +848,16 @@ static int reset_head(struct object_id *oid, const char *action, } tree = parse_tree_indirect(oid); - prime_cache_tree(the_repository, the_repository->index, tree); + prime_cache_tree(r, r->index, tree); - if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) { + if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { ret = error(_("could not write index")); goto leave_reset_head; } reset_head_refs: reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); - strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase"); + strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action); prefix_len = msg.len; if (update_orig_head) { @@ -916,8 +919,10 @@ static int move_to_original_branch(struct rebase_options *opts) opts->head_name, oid_to_hex(&opts->onto->object.oid)); strbuf_addf(&head_reflog, "rebase finished: returning to %s", opts->head_name); - ret = reset_head(NULL, "", opts->head_name, RESET_HEAD_REFS_ONLY, - orig_head_reflog.buf, head_reflog.buf); + ret = reset_head(the_repository, NULL, "", opts->head_name, + RESET_HEAD_REFS_ONLY, + orig_head_reflog.buf, head_reflog.buf, + DEFAULT_REFLOG_ACTION); strbuf_release(&orig_head_reflog); strbuf_release(&head_reflog); @@ -1005,8 +1010,9 @@ static int run_am(struct rebase_options *opts) free(rebased_patches); argv_array_clear(&am.args); - reset_head(&opts->orig_head, "checkout", opts->head_name, 0, - "HEAD", NULL); + reset_head(the_repository, &opts->orig_head, "checkout", + opts->head_name, 0, + "HEAD", NULL, DEFAULT_REFLOG_ACTION); error(_("\ngit encountered an error while preparing the " "patches to replay\n" "these revisions:\n" @@ -1661,8 +1667,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) rerere_clear(the_repository, &merge_rr); string_list_clear(&merge_rr, 1); - if (reset_head(NULL, "reset", NULL, RESET_HEAD_HARD, - NULL, NULL) < 0) + if (reset_head(the_repository, NULL, "reset", NULL, RESET_HEAD_HARD, + NULL, NULL, DEFAULT_REFLOG_ACTION) < 0) die(_("could not discard worktree changes")); remove_branch_state(the_repository, 0); if (read_basic_state(&options)) @@ -1679,9 +1685,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (read_basic_state(&options)) exit(1); - if (reset_head(&options.orig_head, "reset", + if (reset_head(the_repository, &options.orig_head, "reset", options.head_name, RESET_HEAD_HARD, - NULL, NULL) < 0) + NULL, NULL, DEFAULT_REFLOG_ACTION) < 0) die(_("could not move back to %s"), oid_to_hex(&options.orig_head)); remove_branch_state(the_repository, 0); @@ -2073,8 +2079,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.state_dir); write_file(autostash, "%s", oid_to_hex(&oid)); printf(_("Created autostash: %s\n"), buf.buf); - if (reset_head(NULL, "reset --hard", - NULL, RESET_HEAD_HARD, NULL, NULL) < 0) + if (reset_head(the_repository, NULL, "reset --hard", + NULL, RESET_HEAD_HARD, NULL, NULL, + DEFAULT_REFLOG_ACTION) < 0) die(_("could not reset --hard")); if (discard_index(the_repository->index) < 0 || @@ -2114,10 +2121,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&buf, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.switch_to); - if (reset_head(&options.orig_head, "checkout", + if (reset_head(the_repository, + &options.orig_head, "checkout", options.head_name, RESET_HEAD_RUN_POST_CHECKOUT_HOOK, - NULL, buf.buf) < 0) { + NULL, buf.buf, + DEFAULT_REFLOG_ACTION) < 0) { ret = !!error(_("could not switch to " "%s"), options.switch_to); @@ -2189,10 +2198,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); - if (reset_head(&options.onto->object.oid, "checkout", NULL, + if (reset_head(the_repository, &options.onto->object.oid, "checkout", NULL, RESET_HEAD_DETACH | RESET_ORIG_HEAD | RESET_HEAD_RUN_POST_CHECKOUT_HOOK, - NULL, msg.buf)) + NULL, msg.buf, DEFAULT_REFLOG_ACTION)) die(_("Could not detach HEAD")); strbuf_release(&msg); @@ -2207,8 +2216,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "rebase finished: %s onto %s", options.head_name ? options.head_name : "detached HEAD", oid_to_hex(&options.onto->object.oid)); - reset_head(NULL, "Fast-forwarded", options.head_name, - RESET_HEAD_REFS_ONLY, "HEAD", msg.buf); + reset_head(the_repository, NULL, "Fast-forwarded", options.head_name, + RESET_HEAD_REFS_ONLY, "HEAD", msg.buf, + DEFAULT_REFLOG_ACTION); strbuf_release(&msg); ret = !!finish_rebase(&options); goto cleanup; From patchwork Tue Apr 7 14:28:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29847159A for ; Tue, 7 Apr 2020 14:28:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F282920801 for ; Tue, 7 Apr 2020 14:28:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="px/Zb4g6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729134AbgDGO2i (ORCPT ); Tue, 7 Apr 2020 10:28:38 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:47032 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729093AbgDGO2g (ORCPT ); Tue, 7 Apr 2020 10:28:36 -0400 Received: by mail-qk1-f196.google.com with SMTP id g74so1281816qke.13 for ; Tue, 07 Apr 2020 07:28:35 -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 :mime-version:content-transfer-encoding; bh=NJkJIejIt/YdiKuwj5Su9WKLH/aw+ER+W4kGfifi9yw=; b=px/Zb4g6nKdlkMPKnkjUGqTvsjH+e8EAnAZ2CA4fcagYNEbT9N0GvEWFEC8mdbkYPH fsAKI9BZ3BEGHe0aGiddrnXwibQnVCz7p0kkhwXjU5ONbWET/VL7mfm+U3j9sedIGF3h m3IwkzswaL/Dhte15tt4BhkQzBk+dbXrM3PdqOgrGjwbsvsavcmAuluBYHG1pmZstqju sKCXV5BPvQH6v+D8UFTQLTjBuzlK0QPDwsXPDl7zS3SM3+QD21HAyeQXtibcgSQhmGCV WB58QgtkpJp97H1F+epoXRV8Gjluovab9tV/suoq+JSCEfIuE6jAFTod5eYCx0a5oX03 HSuQ== 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:mime-version:content-transfer-encoding; bh=NJkJIejIt/YdiKuwj5Su9WKLH/aw+ER+W4kGfifi9yw=; b=IBIRYfHP5PLgMTA+uqxnSZAF/DFRIEVMdzzLg3Wfro3ubKtYsuwfQN+lXasaD+zp1n 8s4WvOzrVqbnQiVWLTbPo1HTYs82Z3S/7we3xN/tL8al4JKqAyZkqU8HgYfIgH/UDscf K3nztaLT8GZIYn/YDc0dfEPYVJOVLz8N5rUUeIcO5DsZ6YTgE9CPl/zXM+vWmGYEv1TK oGnbeKBXM5m0LBjLMAXKEIFcLi6WlYpWr3qyIPNm88t8mFdQDkPT3IoBuTQU+XfGtFpT O0WdRd0RKRuVtbxYXNPPcXhbXS46T5OTTA7k9nWsC7wRArz/z6RmIG/aDJw90eAGcikF 9VVg== X-Gm-Message-State: AGi0PubE/Cw2JGz12lrgaE87GFwPQEBt6kLlEmVdWCBL/dO7Qb0TuzX+ pKh+pOiAxoAxAg0k0DhPw+68LenT X-Google-Smtp-Source: APiQypK4AYxVCdBNnZVJDL+yiO5d0Wv8VAhdigmQEPWS85/ZAaQXj4QeMR8si3FoG6sICDI0TmMJnQ== X-Received: by 2002:a37:bec5:: with SMTP id o188mr2454345qkf.165.1586269714667; Tue, 07 Apr 2020 07:28:34 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:34 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 13/22] reset: extract reset_head() from rebase Date: Tue, 7 Apr 2020 10:28:00 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Continue the process of lib-ifying the autostash code. In a future commit, this will be used to implement `--autostash` in other builtins. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu --- Makefile | 1 + builtin/rebase.c | 139 +--------------------------------------------- reset.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++ reset.h | 20 +++++++ 4 files changed, 162 insertions(+), 138 deletions(-) create mode 100644 reset.c create mode 100644 reset.h diff --git a/Makefile b/Makefile index f709fc3f77..338fb55b73 100644 --- a/Makefile +++ b/Makefile @@ -970,6 +970,7 @@ LIB_OBJS += replace-object.o LIB_OBJS += repo-settings.o LIB_OBJS += repository.o LIB_OBJS += rerere.o +LIB_OBJS += reset.o LIB_OBJS += resolve-undo.o LIB_OBJS += revision.o LIB_OBJS += run-command.o diff --git a/builtin/rebase.c b/builtin/rebase.c index 5532286142..48ef36bd10 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -27,6 +27,7 @@ #include "branch.h" #include "sequencer.h" #include "rebase-interactive.h" +#include "reset.h" #define DEFAULT_REFLOG_ACTION "rebase" @@ -766,144 +767,6 @@ static void add_var(struct strbuf *buf, const char *name, const char *value) } } -#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" - -#define RESET_HEAD_DETACH (1<<0) -#define RESET_HEAD_HARD (1<<1) -#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) -#define RESET_HEAD_REFS_ONLY (1<<3) -#define RESET_ORIG_HEAD (1<<4) - -static int reset_head(struct repository *r, struct object_id *oid, const char *action, - const char *switch_to_branch, unsigned flags, - const char *reflog_orig_head, const char *reflog_head, - const char *default_reflog_action) -{ - unsigned detach_head = flags & RESET_HEAD_DETACH; - unsigned reset_hard = flags & RESET_HEAD_HARD; - unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; - unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; - unsigned update_orig_head = flags & RESET_ORIG_HEAD; - struct object_id head_oid; - struct tree_desc desc[2] = { { NULL }, { NULL } }; - struct lock_file lock = LOCK_INIT; - struct unpack_trees_options unpack_tree_opts; - struct tree *tree; - const char *reflog_action; - struct strbuf msg = STRBUF_INIT; - size_t prefix_len; - struct object_id *orig = NULL, oid_orig, - *old_orig = NULL, oid_old_orig; - int ret = 0, nr = 0; - - if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) - BUG("Not a fully qualified branch: '%s'", switch_to_branch); - - if (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { - ret = -1; - goto leave_reset_head; - } - - if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { - ret = error(_("could not determine HEAD revision")); - goto leave_reset_head; - } - - if (!oid) - oid = &head_oid; - - if (refs_only) - goto reset_head_refs; - - memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); - setup_unpack_trees_porcelain(&unpack_tree_opts, action); - unpack_tree_opts.head_idx = 1; - unpack_tree_opts.src_index = r->index; - unpack_tree_opts.dst_index = r->index; - unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; - unpack_tree_opts.update = 1; - unpack_tree_opts.merge = 1; - if (!detach_head) - unpack_tree_opts.reset = 1; - - if (repo_read_index_unmerged(r) < 0) { - ret = error(_("could not read index")); - goto leave_reset_head; - } - - if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) { - ret = error(_("failed to find tree of %s"), - oid_to_hex(&head_oid)); - goto leave_reset_head; - } - - if (!fill_tree_descriptor(r, &desc[nr++], oid)) { - ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); - goto leave_reset_head; - } - - if (unpack_trees(nr, desc, &unpack_tree_opts)) { - ret = -1; - goto leave_reset_head; - } - - tree = parse_tree_indirect(oid); - prime_cache_tree(r, r->index, tree); - - if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { - ret = error(_("could not write index")); - goto leave_reset_head; - } - -reset_head_refs: - reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); - strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action); - prefix_len = msg.len; - - if (update_orig_head) { - if (!get_oid("ORIG_HEAD", &oid_old_orig)) - old_orig = &oid_old_orig; - if (!get_oid("HEAD", &oid_orig)) { - orig = &oid_orig; - if (!reflog_orig_head) { - strbuf_addstr(&msg, "updating ORIG_HEAD"); - reflog_orig_head = msg.buf; - } - update_ref(reflog_orig_head, "ORIG_HEAD", orig, - old_orig, 0, UPDATE_REFS_MSG_ON_ERR); - } else if (old_orig) - delete_ref(NULL, "ORIG_HEAD", old_orig, 0); - } - - if (!reflog_head) { - strbuf_setlen(&msg, prefix_len); - strbuf_addstr(&msg, "updating HEAD"); - reflog_head = msg.buf; - } - if (!switch_to_branch) - ret = update_ref(reflog_head, "HEAD", oid, orig, - detach_head ? REF_NO_DEREF : 0, - UPDATE_REFS_MSG_ON_ERR); - else { - ret = update_ref(reflog_head, switch_to_branch, oid, - NULL, 0, UPDATE_REFS_MSG_ON_ERR); - if (!ret) - ret = create_symref("HEAD", switch_to_branch, - reflog_head); - } - if (run_hook) - run_hook_le(NULL, "post-checkout", - oid_to_hex(orig ? orig : &null_oid), - oid_to_hex(oid), "1", NULL); - -leave_reset_head: - strbuf_release(&msg); - rollback_lock_file(&lock); - while (nr) - free((void *)desc[--nr].buffer); - return ret; -} - static int move_to_original_branch(struct rebase_options *opts) { struct strbuf orig_head_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT; diff --git a/reset.c b/reset.c new file mode 100644 index 0000000000..79b683bffa --- /dev/null +++ b/reset.c @@ -0,0 +1,140 @@ +#include "git-compat-util.h" +#include "cache-tree.h" +#include "lockfile.h" +#include "refs.h" +#include "reset.h" +#include "run-command.h" +#include "tree-walk.h" +#include "tree.h" +#include "unpack-trees.h" + +int reset_head(struct repository *r, struct object_id *oid, const char *action, + const char *switch_to_branch, unsigned flags, + const char *reflog_orig_head, const char *reflog_head, + const char *default_reflog_action) +{ + unsigned detach_head = flags & RESET_HEAD_DETACH; + unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; + unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; + unsigned update_orig_head = flags & RESET_ORIG_HEAD; + struct object_id head_oid; + struct tree_desc desc[2] = { { NULL }, { NULL } }; + struct lock_file lock = LOCK_INIT; + struct unpack_trees_options unpack_tree_opts; + struct tree *tree; + const char *reflog_action; + struct strbuf msg = STRBUF_INIT; + size_t prefix_len; + struct object_id *orig = NULL, oid_orig, + *old_orig = NULL, oid_old_orig; + int ret = 0, nr = 0; + + if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) + BUG("Not a fully qualified branch: '%s'", switch_to_branch); + + if (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { + ret = -1; + goto leave_reset_head; + } + + if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { + ret = error(_("could not determine HEAD revision")); + goto leave_reset_head; + } + + if (!oid) + oid = &head_oid; + + if (refs_only) + goto reset_head_refs; + + memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); + setup_unpack_trees_porcelain(&unpack_tree_opts, action); + unpack_tree_opts.head_idx = 1; + unpack_tree_opts.src_index = r->index; + unpack_tree_opts.dst_index = r->index; + unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; + unpack_tree_opts.update = 1; + unpack_tree_opts.merge = 1; + if (!detach_head) + unpack_tree_opts.reset = 1; + + if (repo_read_index_unmerged(r) < 0) { + ret = error(_("could not read index")); + goto leave_reset_head; + } + + if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) { + ret = error(_("failed to find tree of %s"), + oid_to_hex(&head_oid)); + goto leave_reset_head; + } + + if (!fill_tree_descriptor(r, &desc[nr++], oid)) { + ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); + goto leave_reset_head; + } + + if (unpack_trees(nr, desc, &unpack_tree_opts)) { + ret = -1; + goto leave_reset_head; + } + + tree = parse_tree_indirect(oid); + prime_cache_tree(r, r->index, tree); + + if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { + ret = error(_("could not write index")); + goto leave_reset_head; + } + +reset_head_refs: + reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); + strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action); + prefix_len = msg.len; + + if (update_orig_head) { + if (!get_oid("ORIG_HEAD", &oid_old_orig)) + old_orig = &oid_old_orig; + if (!get_oid("HEAD", &oid_orig)) { + orig = &oid_orig; + if (!reflog_orig_head) { + strbuf_addstr(&msg, "updating ORIG_HEAD"); + reflog_orig_head = msg.buf; + } + update_ref(reflog_orig_head, "ORIG_HEAD", orig, + old_orig, 0, UPDATE_REFS_MSG_ON_ERR); + } else if (old_orig) + delete_ref(NULL, "ORIG_HEAD", old_orig, 0); + } + + if (!reflog_head) { + strbuf_setlen(&msg, prefix_len); + strbuf_addstr(&msg, "updating HEAD"); + reflog_head = msg.buf; + } + if (!switch_to_branch) + ret = update_ref(reflog_head, "HEAD", oid, orig, + detach_head ? REF_NO_DEREF : 0, + UPDATE_REFS_MSG_ON_ERR); + else { + ret = update_ref(reflog_head, switch_to_branch, oid, + NULL, 0, UPDATE_REFS_MSG_ON_ERR); + if (!ret) + ret = create_symref("HEAD", switch_to_branch, + reflog_head); + } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); + +leave_reset_head: + strbuf_release(&msg); + rollback_lock_file(&lock); + while (nr) + free((void *)desc[--nr].buffer); + return ret; + +} diff --git a/reset.h b/reset.h new file mode 100644 index 0000000000..12f83c78e2 --- /dev/null +++ b/reset.h @@ -0,0 +1,20 @@ +#ifndef RESET_H +#define RESET_H + +#include "hash.h" +#include "repository.h" + +#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" + +#define RESET_HEAD_DETACH (1<<0) +#define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) +#define RESET_HEAD_REFS_ONLY (1<<3) +#define RESET_ORIG_HEAD (1<<4) + +int reset_head(struct repository *r, struct object_id *oid, const char *action, + const char *switch_to_branch, unsigned flags, + const char *reflog_orig_head, const char *reflog_head, + const char *default_reflog_action); + +#endif From patchwork Tue Apr 7 14:28:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3997F159A for ; Tue, 7 Apr 2020 14:28:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 17C2C20801 for ; Tue, 7 Apr 2020 14:28:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JEowklLl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729142AbgDGO2i (ORCPT ); Tue, 7 Apr 2020 10:28:38 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:38405 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729040AbgDGO2h (ORCPT ); Tue, 7 Apr 2020 10:28:37 -0400 Received: by mail-qk1-f195.google.com with SMTP id h14so1797626qke.5 for ; Tue, 07 Apr 2020 07:28:37 -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 :mime-version:content-transfer-encoding; bh=yNOyiS3Y7o7KMBjDf4zmPCsz3aXDud+4hBeyGRElu4I=; b=JEowklLl05gHk4QLMo2JivhJx0t4j/23hBrSmnwPqwODc/r4INEc7efmeQZs+BaQiX i0NMB/4fTGZNxWdR7o/lEPO5eT9DRzAcO8y16BOkp+Ijf6MiKi+efa/eikpSi0uiSDx4 9P19fx+JgKuL6NNlHx5rOYjAuTijwHbmVYCZNjkbKnsu+vc6JllFmANsEOdOdFzcdB2M Kl1v/LdlCb3o0zhOBxhkt2TJh0J5niD7Tbg5nbTa6FUBFEFvZ+eacqzX1RMQ8DkMskdc ddeBeFJRpZVny7AqW+khCLjKeoRXCo5yWuYzVsB6ptWhS1YhnWrBfqc2bjEbvq0by7jG VM2Q== 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:mime-version:content-transfer-encoding; bh=yNOyiS3Y7o7KMBjDf4zmPCsz3aXDud+4hBeyGRElu4I=; b=o5rCjfx9qd1/kdKdSuGGOXZbfIlq7IndNWR1OlPvRC954jAXYbKhsbsEKGMxZhccPd vgYwoLpeaGVlnpv5AuPrBSfuS6fquSoWAV37VOYnLVwr+FC8sgy0DoAluvnY0p9dCZ1K OqTMIsezEC2oJx7zyvefN4lKWC6nDrSHGb83Hg9Acx19XvKxo9nOM0I+PrCwppx0qAmE k9YeoKqLvYyHbfDLsdPoKshBNGTjmNQhyaQu8yhn0Z44epgUYIWrqQ4VHiG79jg68uR4 w/Y7k3KQNtR669KZgDWa3czoJf9cbYD8+x8KFFcpswWKfy/2ZrEwqga7EaEY+hneng52 4a1w== X-Gm-Message-State: AGi0PubKLRrM4UPh8flt4FkVsHmZULq6k/LGmwcWf3s0RX/3OKlUyE3v VbuszOD/xZYATftrN6YDijFj8i8A X-Google-Smtp-Source: APiQypLQ4RlW1NQdHw34r6NNSmey4/AUyLqbjjxGqpybXtp9ds1yDNaGfvi/5xdHMwfrUV4Dww1Ssg== X-Received: by 2002:a05:620a:103c:: with SMTP id a28mr2384379qkk.313.1586269716302; Tue, 07 Apr 2020 07:28:36 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:35 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 14/22] rebase: extract create_autostash() Date: Tue, 7 Apr 2020 10:28:01 -0400 Message-Id: <114d9a765531d2e232dbc94484f5ef544bda8170.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will lib-ify this code. In preparation for this, extract the code into the create_autostash() function so that it can be cleaned up before it is finally lib-ified. This patch is best viewed with `--color-moved` and `--color-moved-ws=allow-indentation-change`. Signed-off-by: Denton Liu --- builtin/rebase.c | 94 +++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 48ef36bd10..581ad3af7b 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1274,6 +1274,55 @@ static int check_exec_cmd(const char *cmd) return 0; } +static void create_autostash(struct rebase_options *options) +{ + struct strbuf buf = STRBUF_INIT; + struct lock_file lock_file = LOCK_INIT; + int fd; + + fd = hold_locked_index(&lock_file, 0); + refresh_cache(REFRESH_QUIET); + if (0 <= fd) + repo_update_index_if_able(the_repository, &lock_file); + rollback_lock_file(&lock_file); + + if (has_unstaged_changes(the_repository, 1) || + has_uncommitted_changes(the_repository, 1)) { + const char *autostash = + state_dir_path("autostash", options); + struct child_process stash = CHILD_PROCESS_INIT; + struct object_id oid; + + argv_array_pushl(&stash.args, + "stash", "create", "autostash", NULL); + stash.git_cmd = 1; + stash.no_stdin = 1; + strbuf_reset(&buf); + if (capture_command(&stash, &buf, GIT_MAX_HEXSZ)) + die(_("Cannot autostash")); + strbuf_trim_trailing_newline(&buf); + if (get_oid(buf.buf, &oid)) + die(_("Unexpected stash response: '%s'"), + buf.buf); + strbuf_reset(&buf); + strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); + + if (safe_create_leading_directories_const(autostash)) + die(_("Could not create directory for '%s'"), + options->state_dir); + write_file(autostash, "%s", oid_to_hex(&oid)); + printf(_("Created autostash: %s\n"), buf.buf); + if (reset_head(the_repository, NULL, "reset --hard", + NULL, RESET_HEAD_HARD, NULL, NULL, + DEFAULT_REFLOG_ACTION) < 0) + die(_("could not reset --hard")); + + if (discard_index(the_repository->index) < 0 || + repo_read_index(the_repository) < 0) + die(_("could not read index")); + } + strbuf_release(&buf); +} int cmd_rebase(int argc, const char **argv, const char *prefix) { @@ -1907,50 +1956,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("could not read index")); if (options.autostash) { - struct lock_file lock_file = LOCK_INIT; - int fd; - - fd = hold_locked_index(&lock_file, 0); - refresh_cache(REFRESH_QUIET); - if (0 <= fd) - repo_update_index_if_able(the_repository, &lock_file); - rollback_lock_file(&lock_file); - - if (has_unstaged_changes(the_repository, 1) || - has_uncommitted_changes(the_repository, 1)) { - const char *autostash = - state_dir_path("autostash", &options); - struct child_process stash = CHILD_PROCESS_INIT; - struct object_id oid; - - argv_array_pushl(&stash.args, - "stash", "create", "autostash", NULL); - stash.git_cmd = 1; - stash.no_stdin = 1; - strbuf_reset(&buf); - if (capture_command(&stash, &buf, GIT_MAX_HEXSZ)) - die(_("Cannot autostash")); - strbuf_trim_trailing_newline(&buf); - if (get_oid(buf.buf, &oid)) - die(_("Unexpected stash response: '%s'"), - buf.buf); - strbuf_reset(&buf); - strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); - - if (safe_create_leading_directories_const(autostash)) - die(_("Could not create directory for '%s'"), - options.state_dir); - write_file(autostash, "%s", oid_to_hex(&oid)); - printf(_("Created autostash: %s\n"), buf.buf); - if (reset_head(the_repository, NULL, "reset --hard", - NULL, RESET_HEAD_HARD, NULL, NULL, - DEFAULT_REFLOG_ACTION) < 0) - die(_("could not reset --hard")); - - if (discard_index(the_repository->index) < 0 || - repo_read_index(the_repository) < 0) - die(_("could not read index")); - } + create_autostash(&options); } if (require_clean_work_tree(the_repository, "rebase", From patchwork Tue Apr 7 14:28:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6185E112C for ; Tue, 7 Apr 2020 14:28:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 36D3F20801 for ; Tue, 7 Apr 2020 14:28:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ojImca48" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729144AbgDGO2j (ORCPT ); Tue, 7 Apr 2020 10:28:39 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:45116 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729133AbgDGO2i (ORCPT ); Tue, 7 Apr 2020 10:28:38 -0400 Received: by mail-qk1-f195.google.com with SMTP id m67so613528qke.12 for ; Tue, 07 Apr 2020 07:28:38 -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 :mime-version:content-transfer-encoding; bh=cbePUmxJ16mQRaPfNX0o6pIqYlsrieIb5KHd0Q/gLKA=; b=ojImca48A1vfPdcgFOYbJ7m9YmA8fYebSF4hO1W39rm3qxRM9mMRLavVkp9nxmscLe UDbVoS0cikNbxOMOrFj7uF6XWLBIz6UDYNDVZPDnrvZTipmKilUItiEfmHVFkzk0p2ze WRKzhivkTJM6gM020TciznBolHYoMSDvJlaquOWe0pi9zS8JuzSlK592o6Pr5ur8sYLu Id8L5IIi6uvie4MCbzELLUkQtOyjG5g5TRW8rqH3SYzXqCbE8IBagZ0iK1fueBH1piIm rA0ZNvWJWcfDvqD2SzHlQd1GeSOygPbgjDKQvHcfuecGl4lWR9ANpVytQcnbGgdI9phH FX4Q== 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:mime-version:content-transfer-encoding; bh=cbePUmxJ16mQRaPfNX0o6pIqYlsrieIb5KHd0Q/gLKA=; b=Z0O3gQTJa16C660ohcij4cCc4UIdapLL/rHK9iZY4DMfeV7XLEouhOLVNqJpVlMKWp MJO08BiCrThl6x48gy/rM19BrV8AsLuL7Sm9VhAzAtsW2/Xz8t0FU3FcZFJY1zxxrPds z1plD/wzoGcpOtxFMmgwZsgViJKbCSerjea7KqpdgPiFRLB3p54T2+PMm9BBYFnBkWUG IdJR/7VUAI+An0CLQZGba+ygIGJ3YGVyJBxYzLuv84h29h0kT3a+jTqbrL5o0/lS7fJI g0Cj4DcszKDT6KzDEIGtdrOqaK+u9u8C83csrFD1KlFiUqBlGBqP1FDloMg0CWG8XtNv 79Yg== X-Gm-Message-State: AGi0PuZlhx+kB9glhla77zADaGcRmaL+D/AgWZxtA0/jC4G0Y6EXhnFP BuFE5D5e/MN3Eq2ukC+Hi0vz0naC X-Google-Smtp-Source: APiQypIHF75adwvXw80RNQN8BaXq2V158RsAMANRqicMIyomeQ4sYCrxPxKK0YgQKNWTOZmzJB5x3A== X-Received: by 2002:a37:6585:: with SMTP id z127mr2477976qkb.463.1586269717471; Tue, 07 Apr 2020 07:28:37 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:36 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 15/22] rebase: generify create_autostash() Date: Tue, 7 Apr 2020 10:28:02 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the future, we plan on lib-ifying create_autostash() so we need it to be more generic. Make it more generic by making it accept a `struct repository` argument instead of implicitly using the non-repo functions and `the_repository`. Also, make it accept a `path` argument so that we no longer rely have to rely on `struct rebase_options`. Finally, make it accept a `default_reflog_action` argument so we no longer have to rely on `DEFAULT_REFLOG_ACTION`. Signed-off-by: Denton Liu --- builtin/rebase.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 581ad3af7b..ae345c9e57 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1274,22 +1274,21 @@ static int check_exec_cmd(const char *cmd) return 0; } -static void create_autostash(struct rebase_options *options) +static void create_autostash(struct repository *r, const char *path, + const char *default_reflog_action) { struct strbuf buf = STRBUF_INIT; struct lock_file lock_file = LOCK_INIT; int fd; - fd = hold_locked_index(&lock_file, 0); - refresh_cache(REFRESH_QUIET); + fd = repo_hold_locked_index(r, &lock_file, 0); + refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); if (0 <= fd) - repo_update_index_if_able(the_repository, &lock_file); + repo_update_index_if_able(r, &lock_file); rollback_lock_file(&lock_file); - if (has_unstaged_changes(the_repository, 1) || - has_uncommitted_changes(the_repository, 1)) { - const char *autostash = - state_dir_path("autostash", options); + if (has_unstaged_changes(r, 1) || + has_uncommitted_changes(r, 1)) { struct child_process stash = CHILD_PROCESS_INIT; struct object_id oid; @@ -1307,18 +1306,18 @@ static void create_autostash(struct rebase_options *options) strbuf_reset(&buf); strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); - if (safe_create_leading_directories_const(autostash)) + if (safe_create_leading_directories_const(path)) die(_("Could not create directory for '%s'"), - options->state_dir); - write_file(autostash, "%s", oid_to_hex(&oid)); + path); + write_file(path, "%s", oid_to_hex(&oid)); printf(_("Created autostash: %s\n"), buf.buf); - if (reset_head(the_repository, NULL, "reset --hard", + if (reset_head(r, NULL, "reset --hard", NULL, RESET_HEAD_HARD, NULL, NULL, - DEFAULT_REFLOG_ACTION) < 0) + default_reflog_action) < 0) die(_("could not reset --hard")); - if (discard_index(the_repository->index) < 0 || - repo_read_index(the_repository) < 0) + if (discard_index(r->index) < 0 || + repo_read_index(r) < 0) die(_("could not read index")); } strbuf_release(&buf); @@ -1956,7 +1955,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("could not read index")); if (options.autostash) { - create_autostash(&options); + create_autostash(the_repository, state_dir_path("autostash", &options), + DEFAULT_REFLOG_ACTION); } if (require_clean_work_tree(the_repository, "rebase", From patchwork Tue Apr 7 14:28:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 623BD112C for ; Tue, 7 Apr 2020 14:28:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3776520801 for ; Tue, 7 Apr 2020 14:28:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kbxeQo+x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728861AbgDGO2o (ORCPT ); Tue, 7 Apr 2020 10:28:44 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:40183 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbgDGO2k (ORCPT ); Tue, 7 Apr 2020 10:28:40 -0400 Received: by mail-qt1-f193.google.com with SMTP id y25so2765930qtv.7 for ; Tue, 07 Apr 2020 07:28:39 -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 :mime-version:content-transfer-encoding; bh=UEzgRKezWZjx4ccNWcDOD2Fu4xo8RPkVpircpq0w+6Q=; b=kbxeQo+xa4jGdMap5KE0NImCgu7QBkwE0THcNxaethH+YozPDm10FAf58nvn7HuLPf dlRlkjVT7PDLBvZFpMxI2lZfBHYomC7RRVY7UHGGT/WTHS3nkPVCIgMAsnUAI3VFzNKx JAq/xqCy6yZxDeC+vjFBfp0V0zZIeySBNc+iT8qJlU6dB/6zAI5/ZafbEISSwjMZYhPy NGKs2WRifCd3QJpgZ7NcQwgpm5UFrKZy7k6bG9ITNcYOOIXmgQo9BstEKIkugyyJsiv4 HTG0bzj0FPOa9CqcV8rgv4o+vD9GriR+XjWsWS7FZqa1fRl5JS934BwznH3+zUFAuAcU lsbw== 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:mime-version:content-transfer-encoding; bh=UEzgRKezWZjx4ccNWcDOD2Fu4xo8RPkVpircpq0w+6Q=; b=JkOu5m3J5N0XR95QkbRheOumY/7yoPsHmZPr4ow/GNrv8xhPVNKfj8S9z0HaNFThpB yYsQhfWacSqVeIfo0wmz5H1lNlcM9LtJiVWKX/AFRcnQeMgoGfSQwCBSaL8tlaN2yfEp gMqvuX7Y4E0vGS8gr7LaCTMCBY+Ieodooo2xxlzFW+OJRsKty7DTwbO5/Y9YuB11Bjbf AYM7jGB4FIH7VSllUJjI79e0othLfxOwXseCxpAoeAdGMvKBagaeTAarT/Tthw1bc3r6 UocCCnbxU3HDwe5aXCDFqQ7sKpVxWc59ziCY6BVl/lteUo6UlHL0v05OIPnUQ1KGmnYt tjBg== X-Gm-Message-State: AGi0PuZUjSdvRcKLl5N+N4eh/MDfgtiQ1JLCgJ5reqTIZA3LeCSQO3My xVlyzvwNj3nDLXKf5BpMtehWlot6 X-Google-Smtp-Source: APiQypI/zI+N+Y5KLUpkgFVLyTpzvrV2DPTyScmRf68vnKxhT3gto+xRfN9z9CCF6Wzy+Q97Psxm2A== X-Received: by 2002:ac8:424e:: with SMTP id r14mr1320253qtm.324.1586269718818; Tue, 07 Apr 2020 07:28:38 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:38 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 16/22] sequencer: extract perform_autostash() from rebase Date: Tue, 7 Apr 2020 10:28:03 -0400 Message-Id: <3be4a27dfe0f91c6f0730d0b3a5d1883e4b0eac4.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Lib-ify the autostash code by extracting perform_autostash() from rebase into sequencer. In a future commit, this will be used to implement `--autostash` in other builtins. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu --- builtin/rebase.c | 49 ----------------------------------------------- sequencer.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 2 ++ 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index ae345c9e57..08b89869b3 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1274,55 +1274,6 @@ static int check_exec_cmd(const char *cmd) return 0; } -static void create_autostash(struct repository *r, const char *path, - const char *default_reflog_action) -{ - struct strbuf buf = STRBUF_INIT; - struct lock_file lock_file = LOCK_INIT; - int fd; - - fd = repo_hold_locked_index(r, &lock_file, 0); - refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); - if (0 <= fd) - repo_update_index_if_able(r, &lock_file); - rollback_lock_file(&lock_file); - - if (has_unstaged_changes(r, 1) || - has_uncommitted_changes(r, 1)) { - struct child_process stash = CHILD_PROCESS_INIT; - struct object_id oid; - - argv_array_pushl(&stash.args, - "stash", "create", "autostash", NULL); - stash.git_cmd = 1; - stash.no_stdin = 1; - strbuf_reset(&buf); - if (capture_command(&stash, &buf, GIT_MAX_HEXSZ)) - die(_("Cannot autostash")); - strbuf_trim_trailing_newline(&buf); - if (get_oid(buf.buf, &oid)) - die(_("Unexpected stash response: '%s'"), - buf.buf); - strbuf_reset(&buf); - strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); - - if (safe_create_leading_directories_const(path)) - die(_("Could not create directory for '%s'"), - path); - write_file(path, "%s", oid_to_hex(&oid)); - printf(_("Created autostash: %s\n"), buf.buf); - if (reset_head(r, NULL, "reset --hard", - NULL, RESET_HEAD_HARD, NULL, NULL, - default_reflog_action) < 0) - die(_("could not reset --hard")); - - if (discard_index(r->index) < 0 || - repo_read_index(r) < 0) - die(_("could not read index")); - } - strbuf_release(&buf); -} - int cmd_rebase(int argc, const char **argv, const char *prefix) { struct rebase_options options = REBASE_OPTIONS_INIT; diff --git a/sequencer.c b/sequencer.c index f5bb1cc1fb..e0b8262521 100644 --- a/sequencer.c +++ b/sequencer.c @@ -32,6 +32,7 @@ #include "alias.h" #include "commit-reach.h" #include "rebase-interactive.h" +#include "reset.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@ -3657,6 +3658,55 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) return -1; } +void create_autostash(struct repository *r, const char *path, + const char *default_reflog_action) +{ + struct strbuf buf = STRBUF_INIT; + struct lock_file lock_file = LOCK_INIT; + int fd; + + fd = repo_hold_locked_index(r, &lock_file, 0); + refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); + if (0 <= fd) + repo_update_index_if_able(r, &lock_file); + rollback_lock_file(&lock_file); + + if (has_unstaged_changes(r, 1) || + has_uncommitted_changes(r, 1)) { + struct child_process stash = CHILD_PROCESS_INIT; + struct object_id oid; + + argv_array_pushl(&stash.args, + "stash", "create", "autostash", NULL); + stash.git_cmd = 1; + stash.no_stdin = 1; + strbuf_reset(&buf); + if (capture_command(&stash, &buf, GIT_MAX_HEXSZ)) + die(_("Cannot autostash")); + strbuf_trim_trailing_newline(&buf); + if (get_oid(buf.buf, &oid)) + die(_("Unexpected stash response: '%s'"), + buf.buf); + strbuf_reset(&buf); + strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); + + if (safe_create_leading_directories_const(path)) + die(_("Could not create directory for '%s'"), + path); + write_file(path, "%s", oid_to_hex(&oid)); + printf(_("Created autostash: %s\n"), buf.buf); + if (reset_head(r, NULL, "reset --hard", + NULL, RESET_HEAD_HARD, NULL, NULL, + default_reflog_action) < 0) + die(_("could not reset --hard")); + + if (discard_index(r->index) < 0 || + repo_read_index(r) < 0) + die(_("could not read index")); + } + strbuf_release(&buf); +} + int apply_autostash(const char *path) { struct strbuf stash_oid = STRBUF_INIT; diff --git a/sequencer.h b/sequencer.h index ab686146d1..9d1fe0ccfb 100644 --- a/sequencer.h +++ b/sequencer.h @@ -191,6 +191,8 @@ void commit_post_rewrite(struct repository *r, const struct commit *current_head, const struct object_id *new_head); +void create_autostash(struct repository *r, const char *path, + const char *default_reflog_action); int apply_autostash(const char *path); #define SUMMARY_INITIAL_COMMIT (1 << 0) From patchwork Tue Apr 7 14:28:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A30E2112C for ; Tue, 7 Apr 2020 14:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 822F520801 for ; Tue, 7 Apr 2020 14:28:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RDIr+tm3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729152AbgDGO2q (ORCPT ); Tue, 7 Apr 2020 10:28:46 -0400 Received: from mail-qv1-f65.google.com ([209.85.219.65]:41058 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728768AbgDGO2m (ORCPT ); Tue, 7 Apr 2020 10:28:42 -0400 Received: by mail-qv1-f65.google.com with SMTP id t4so1875388qvz.8 for ; Tue, 07 Apr 2020 07:28:40 -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 :mime-version:content-transfer-encoding; bh=zS0gld0GlFxWR031gLldH2Q+tnEzRcMviULWd6TSjdI=; b=RDIr+tm37rwIU1ixrvbp8rjPjnVdRllWzOtz5FMjSsPVTiz/TfvFnau9s4aqgRyhO+ eBFeZrvzMNvPJjp8k5ej/NB8N5yHbQ68JJ9ika14FqhHQAWx6tWemxg4E8357rtgsfil 10lBEQf+c93dkwFlgU1A4MDMsPxBQZ53cvAzN3xB4iDHDD+AtlJAosiZf1jEr+sioevU FfSIVcjvWjlhhlMxuLqwps0tXEmhVDh3eiVmb39FigXSRpJRVaAY4BrQWsSkCyFhTB/1 WIJYOy4SoGusET0KVSGbyA8FRTQgTgoBam4gWFpEogm1EVolBtfPrDzYQWSu+7uFlez6 ib2w== 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:mime-version:content-transfer-encoding; bh=zS0gld0GlFxWR031gLldH2Q+tnEzRcMviULWd6TSjdI=; b=l2q1v0nlvNAnAcyB0YgyK8DEDw1mVJ8HZcE5DSkeb0h1DC/nQSmZzH0GJNdQMfjxzf xBpomq+D4Nadcp0vwP8pCgZ19nHYUVsue7grQwVrdILCeA7NFtteh+v1H/uJnRL+F3RH 2HKz7mN+9nvxAox/mTfoG5UjCaiyk0mwhI3+2nw+vAdwwpYW4XniYD6vRo09ISHLVLD5 MkiMH+lD5I977yU01Vqm2CyniLBGbVoHGEieerolYjHeban6XiqB4Bd/yW62krbOw/AG kibt9e7aPcL255/AeAFF2yqjpSRIPjGPUdEfRg/LAXMWkOYZjU6gtf+zdp5XnfV6B3+1 e9Fg== X-Gm-Message-State: AGi0PuaE+oKqQd9pnSD72BhUh9lFyDjEBv0lBPXJeEb/qiR0t64HExOR BS2k5POPeITmxIiwu09HyhhZDC8K X-Google-Smtp-Source: APiQypKQuEX/O1n83HL+l/P8OhGVgugfmN4O85HKMrR8PKq0xSSbUYdFHLBuGCT1HqF0Hp0z1Kz7yw== X-Received: by 2002:a0c:c251:: with SMTP id w17mr2363677qvh.95.1586269719873; Tue, 07 Apr 2020 07:28:39 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:39 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 17/22] sequencer: unlink autostash in apply_autostash() Date: Tue, 7 Apr 2020 10:28:04 -0400 Message-Id: <129d5d97aefdc5b75046f0b9051c5fe9378f54ac.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Explicitly remove autostash file in apply_autostash() once it has been applied successfully. This is currently a no-op because the only users of this function will unlink the state (including the autostash file) after this function runs. However, in the future, we will introduce a user of the function that does not explicitly remove the state so we do it here. Signed-off-by: Denton Liu --- sequencer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sequencer.c b/sequencer.c index e0b8262521..645bc47ce3 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3748,6 +3748,7 @@ int apply_autostash(const char *path) " \"git stash drop\" at any time.\n")); } + unlink(path); strbuf_release(&stash_oid); return ret; } From patchwork Tue Apr 7 14:28:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 725B6159A for ; Tue, 7 Apr 2020 14:28:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5188E20801 for ; Tue, 7 Apr 2020 14:28:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nhxz4Wyz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729162AbgDGO2s (ORCPT ); Tue, 7 Apr 2020 10:28:48 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:38098 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728917AbgDGO2o (ORCPT ); Tue, 7 Apr 2020 10:28:44 -0400 Received: by mail-qt1-f195.google.com with SMTP id 13so895037qtt.5 for ; Tue, 07 Apr 2020 07:28:42 -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 :mime-version:content-transfer-encoding; bh=ZVpvRBsOEcGbH9LZoGNRkq69RUMJ2X5uwsFCDN5jT7s=; b=Nhxz4Wyz/3ndD6UVfrpcrogbQkFuCUwr+6JHR97oQNk8+h815BKjU6r2rFtlGsstSb e5nUWNwuHJriuSn4G5XIJ6XK+/B9uAqXfoX492qwYhgANp1XhYjlTGgDvRq3jL3Ss88h 3KkGPslm9aEN21oIyY2NQx4qTn4+9XS54GmGGcZxr+/ZSTB0Kz0Q6VphO+4yvcRHUQtU 78mCx228YFWSFFzuS5CuyiyJmRzmjKJCA/B9f3lURwWs5Aoo/o3InC9rnO02nNZfRs9Z oK1AM+gIIvx8EdJptgYFVB9EKis72KPJ9mY8inpfRbSv2ZHvOaoO8rJM9w62PuoSD2bO enKw== 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:mime-version:content-transfer-encoding; bh=ZVpvRBsOEcGbH9LZoGNRkq69RUMJ2X5uwsFCDN5jT7s=; b=jGTvhtNDWpjWcNCmBHyH6KD4/Ue6TSZ8JQBCI8RifVlOc/cRLf/ZEq1D8qxzA/3Kdr Xog06KhU3LcH11K7udQBv3OptF3K1KpfsDeQM9x4KocErgwlPgPE6qWzE3lxlRRCbw0C EEE/A6bHXYHS7lA9SXimtOnPFisI/PRZxziHMZbedNIsRPsVZS8KK/vTr03uD31eKAaY Qf4BntRQRxWz0W3ZxVA7VXtY04Gv5MGqq6299MGYpvNFgDkZybDUn8cuPMa0G8PN78fg 1tUmfncaNwq0+4Nu6nu9UXVWriucyOvKOtR4mTxKUuNJkB+c9qDuMiAlw1YPZoXUe3nv UIMA== X-Gm-Message-State: AGi0PuanDai1zmVQRZ9kkshv7FXh0mq0w54YpFD6pLb4eTSCLRG8Rbeh cajwMaEmSAQ11/YWIdni5g72Zd/s X-Google-Smtp-Source: APiQypK8rNbTX6Y47tm920cNe1HpBtAV8EPQdh03JUyhLJ3Z/stxLx5TJ8x32YkCxLF9puIhYGX+Ag== X-Received: by 2002:ac8:4557:: with SMTP id z23mr2522790qtn.350.1586269721122; Tue, 07 Apr 2020 07:28:41 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:40 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 18/22] sequencer: implement save_autostash() Date: Tue, 7 Apr 2020 10:28:05 -0400 Message-Id: <7e04ce8d8e8ec8308efda05ea7f0cd31f9612ea0.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Extract common functionality of apply_autostash() into apply_save_autostash() and use it to implement save_autostash(). This function will be used in a future commit. The difference between save_autostash() and apply_autostash() is that the former does not try to apply the stash. It skips that step and just stores the created entry in the stash reflog. This is useful in the case where we abort an operation when an autostash is present but we don't want to dirty the worktree with the application of the stash. For example, in a future commit, we will implement `git merge --autostash`. Since merges can be aborted using `git reset --hard`, we'd make use of save_autostash() to save the autostash entry instead of applying it to the worktree thus keeping the worktree undirtied. Signed-off-by: Denton Liu --- sequencer.c | 37 +++++++++++++++++++++++++++---------- sequencer.h | 1 + 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/sequencer.c b/sequencer.c index 645bc47ce3..084ea4117e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3707,7 +3707,7 @@ void create_autostash(struct repository *r, const char *path, strbuf_release(&buf); } -int apply_autostash(const char *path) +static int apply_save_autostash(const char *path, int attempt_apply) { struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; @@ -3720,13 +3720,17 @@ int apply_autostash(const char *path) } strbuf_trim(&stash_oid); - child.git_cmd = 1; - child.no_stdout = 1; - child.no_stderr = 1; - argv_array_push(&child.args, "stash"); - argv_array_push(&child.args, "apply"); - argv_array_push(&child.args, stash_oid.buf); - if (!run_command(&child)) + if (attempt_apply) { + child.git_cmd = 1; + child.no_stdout = 1; + child.no_stderr = 1; + argv_array_push(&child.args, "stash"); + argv_array_push(&child.args, "apply"); + argv_array_push(&child.args, stash_oid.buf); + ret = run_command(&child); + } + + if (attempt_apply && !ret) fprintf(stderr, _("Applied autostash.\n")); else { struct child_process store = CHILD_PROCESS_INIT; @@ -3742,10 +3746,13 @@ int apply_autostash(const char *path) ret = error(_("cannot store %s"), stash_oid.buf); else fprintf(stderr, - _("Applying autostash resulted in conflicts.\n" + _("%s\n" "Your changes are safe in the stash.\n" "You can run \"git stash pop\" or" - " \"git stash drop\" at any time.\n")); + " \"git stash drop\" at any time.\n"), + attempt_apply ? + _("Applying autostash resulted in conflicts.") : + _("Autostash exists; creating a new stash entry.")); } unlink(path); @@ -3753,6 +3760,16 @@ int apply_autostash(const char *path) return ret; } +int save_autostash(const char *path) +{ + return apply_save_autostash(path, 0); +} + +int apply_autostash(const char *path) +{ + return apply_save_autostash(path, 1); +} + static const char *reflog_message(struct replay_opts *opts, const char *sub_action, const char *fmt, ...) { diff --git a/sequencer.h b/sequencer.h index 9d1fe0ccfb..306d4cecfb 100644 --- a/sequencer.h +++ b/sequencer.h @@ -193,6 +193,7 @@ void commit_post_rewrite(struct repository *r, void create_autostash(struct repository *r, const char *path, const char *default_reflog_action); +int save_autostash(const char *path); int apply_autostash(const char *path); #define SUMMARY_INITIAL_COMMIT (1 << 0) From patchwork Tue Apr 7 14:28:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96D8A112C for ; Tue, 7 Apr 2020 14:28:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 751C820801 for ; Tue, 7 Apr 2020 14:28:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ugznGEkP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729164AbgDGO2t (ORCPT ); Tue, 7 Apr 2020 10:28:49 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:42486 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729148AbgDGO2o (ORCPT ); Tue, 7 Apr 2020 10:28:44 -0400 Received: by mail-qt1-f195.google.com with SMTP id b10so2760937qtt.9 for ; Tue, 07 Apr 2020 07:28:43 -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 :mime-version:content-transfer-encoding; bh=sgPcTgpTgIyew8hRZr8Ws7nuOduXFE7R9jvKARasCX8=; b=ugznGEkPf9qXlYhtfTAdc1oESfmK3PN4tjh+zNa74rhTkCxI9eKGRALJOTc1ddwAMH VpDegveIAAvC77hIzIBbqebyVvNGdg1bdDCjofwKaMFhEsP5gbgHLdPg848pcTdLfUNS 8OHg7a5GA8m+iyzG9OCl6x5c0IRxDhljO6RsgvMN9Kd/uT+/SGa/ovz7iVNknP4mzyIs FPxxptGc9rPNAq5vy0wIjMfxRiz9mRGk07PcJMb/i7V5L6uBPoknEaSP6Lsj3DH7Fl7R OjaXGmgXSqan6jlXQI+Mm1Uk90x7pAfhWWtR/gsR38hdqfMXRPu7c13yOpxuYWdVn5N7 ridA== 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:mime-version:content-transfer-encoding; bh=sgPcTgpTgIyew8hRZr8Ws7nuOduXFE7R9jvKARasCX8=; b=rRZfPjJPfd825CJ23vBz9KsGd3JQhug66zX5rqKYohWV3VBvFdvnRO657tgDjx69qs ESQNo8xGhncA5E59jKoXBLFASaV3MdbqwMoyNh97Bwt9O1JEbkrumHsZVJL+vdgJJdLd wDRZrPhSqCp/7o0xtONRE/Xft0M6DpygQLa8o9QgKMb3fJp8SOZ7kXK2D50bqvDyY3BO 7Z9xjMxf73fuX7eUF6WIg00jFQiXr8olJebtPo84QAUVOIRFwCgRWAoYXw/O3sskn0jT 1ged9WKe0ol6LX4+OsRViSVEQzuo5iVY53crKc+Oc2IsxPMbf2U0faM4Ms1X09R0UO6P 5PFw== X-Gm-Message-State: AGi0PuZhVv17gDfS33AbvLs0khlSth4calL9Vr7qMBzLkWP6e/5cpr0h 7hFe5kkaj3hbxUIA4UabPB6Wt+gm X-Google-Smtp-Source: APiQypJr/D2ww1k+jm7LFRAOHAE4F1Qs3PLVxLx2gI5iXi8Cp3eqw+ql9+U+TN6di8jL9WXpsRtDCw== X-Received: by 2002:ac8:1901:: with SMTP id t1mr2484739qtj.269.1586269722843; Tue, 07 Apr 2020 07:28:42 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:41 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 19/22] sequencer: implement apply_autostash_oid() Date: Tue, 7 Apr 2020 10:28:06 -0400 Message-Id: <732b3f99455066ae780dd8a0e662173f1bd02e60.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split apply_save_autostash() into apply_autostash_oid() and apply_save_autostash() where the former operates on an OID string and the latter reads the OID from a file before passing it into apply_save_autostash_oid(). This function is required for a future commmit which will rely on being able to apply an autostash whose OID is stored as a string. Signed-off-by: Denton Liu --- sequencer.c | 38 ++++++++++++++++++++++++++------------ sequencer.h | 1 + 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/sequencer.c b/sequencer.c index 084ea4117e..f1eba4cb1f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3707,26 +3707,18 @@ void create_autostash(struct repository *r, const char *path, strbuf_release(&buf); } -static int apply_save_autostash(const char *path, int attempt_apply) +static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply) { - struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_oid, path, - READ_ONELINER_SKIP_IF_EMPTY)) { - strbuf_release(&stash_oid); - return 0; - } - strbuf_trim(&stash_oid); - if (attempt_apply) { child.git_cmd = 1; child.no_stdout = 1; child.no_stderr = 1; argv_array_push(&child.args, "stash"); argv_array_push(&child.args, "apply"); - argv_array_push(&child.args, stash_oid.buf); + argv_array_push(&child.args, stash_oid); ret = run_command(&child); } @@ -3741,9 +3733,9 @@ static int apply_save_autostash(const char *path, int attempt_apply) argv_array_push(&store.args, "-m"); argv_array_push(&store.args, "autostash"); argv_array_push(&store.args, "-q"); - argv_array_push(&store.args, stash_oid.buf); + argv_array_push(&store.args, stash_oid); if (run_command(&store)) - ret = error(_("cannot store %s"), stash_oid.buf); + ret = error(_("cannot store %s"), stash_oid); else fprintf(stderr, _("%s\n" @@ -3755,6 +3747,23 @@ static int apply_save_autostash(const char *path, int attempt_apply) _("Autostash exists; creating a new stash entry.")); } + return ret; +} + +static int apply_save_autostash(const char *path, int attempt_apply) +{ + struct strbuf stash_oid = STRBUF_INIT; + int ret = 0; + + if (!read_oneliner(&stash_oid, path, + READ_ONELINER_SKIP_IF_EMPTY)) { + strbuf_release(&stash_oid); + return 0; + } + strbuf_trim(&stash_oid); + + ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply); + unlink(path); strbuf_release(&stash_oid); return ret; @@ -3770,6 +3779,11 @@ int apply_autostash(const char *path) return apply_save_autostash(path, 1); } +int apply_autostash_oid(const char *stash_oid) +{ + return apply_save_autostash_oid(stash_oid, 1); +} + static const char *reflog_message(struct replay_opts *opts, const char *sub_action, const char *fmt, ...) { diff --git a/sequencer.h b/sequencer.h index 306d4cecfb..5a85eeef92 100644 --- a/sequencer.h +++ b/sequencer.h @@ -195,6 +195,7 @@ void create_autostash(struct repository *r, const char *path, const char *default_reflog_action); int save_autostash(const char *path); int apply_autostash(const char *path); +int apply_autostash_oid(const char *stash_oid); #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) From patchwork Tue Apr 7 14:28:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478205 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7356112C for ; Tue, 7 Apr 2020 14:28:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2B372080C for ; Tue, 7 Apr 2020 14:28:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b8U8P0ys" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729169AbgDGO2u (ORCPT ); Tue, 7 Apr 2020 10:28:50 -0400 Received: from mail-qv1-f67.google.com ([209.85.219.67]:46746 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728768AbgDGO2r (ORCPT ); Tue, 7 Apr 2020 10:28:47 -0400 Received: by mail-qv1-f67.google.com with SMTP id bu9so1857491qvb.13 for ; Tue, 07 Apr 2020 07:28:46 -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 :mime-version:content-transfer-encoding; bh=P/+3gprgE5npm4P8AqyBDrWL0UAt3z4Q30R42zshnew=; b=b8U8P0ysdoLOnDgC7qDJMWw268/dQ4DCXynUFougTsdRe3GdwpodLXhfzwmuagLdQn 6Fk0XQPStXEXDT/bGqH39+qSffyPBFgrA5UiF8SBifJ8GNN82Qh3ELEkbYgJCCLoyQzd zOGEjCrAEEpgX+5LlGFo0GFcCs2uD+Vown/3sEJS0kspbYMcEhAhhx2zc60i5aqWQKgj nySFu7nGWh/vsHEy1cj3EJIVKE6tkgcMrLu8Px2qagYCflt8qXjPceQf48Y1gxuZThaO InWZOMytvVAD6dvr/hTHCWveVDGDciVLcQvwmXXIkq3aJIu5M564yZJUS6HQt8BLfuD/ R72g== 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:mime-version:content-transfer-encoding; bh=P/+3gprgE5npm4P8AqyBDrWL0UAt3z4Q30R42zshnew=; b=svQTmWQjYl90fvmVRXa4GMU15aS751dr1umJvnA64EsWovgHRCsCsphwNmSu5LjBIJ ImoQ6wN7gcVX5OHYNlRF9IR6HNi39ADneHxPeN8ASIhU/voGIBLjrgfRvRzlJDKtQr4J 7GHC1EHXlWj+vECxBQ+9rMLcJmdtXX0UiofyN8m+lFM/3TbPqwOqghZ7FeVNuXiFtb+3 v/dx+smpLvh/o9Jn7lM8qqQk5VXpZH9kqyzlbY7nOff7ONTlIvS69Fo3hSIJQlzHwrQS r4/4vambJIYB1d8MMwWz4u1nmcWs0X511x31WgRUYCCZUUfp7AGYEcC7unIpqxiK6frw FNqw== X-Gm-Message-State: AGi0PuZh/s8kEpX4WzRWtek5fVppttJQxcp2VzeCOl5RgRMQcCy/thkD 9OFuR/z6MrA+uYtSmqODwZUnBIM2 X-Google-Smtp-Source: APiQypLd1hUyfMpDb0SVg0MEphnTelXmv4aWm4DHa1QDV4RmVo/O2PghgHU7AOaNRc87KWQqivlXcw== X-Received: by 2002:a0c:8444:: with SMTP id l62mr2490835qva.239.1586269724107; Tue, 07 Apr 2020 07:28:44 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:43 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood , Phillip Wood Subject: [PATCH v5 20/22] merge: teach --autostash option Date: Tue, 7 Apr 2020 10:28:07 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In rebase, one can pass the `--autostash` option to cause the worktree to be automatically stashed before continuing with the rebase. This option is missing in merge, however. Implement the `--autostash` option and corresponding `merge.autoStash` option in merge which stashes before merging and then pops after. This option is useful when a developer has some local changes on a topic branch but they realize that their work depends on another branch. Previously, they had to run something like git fetch ... git stash push git merge FETCH_HEAD git stash pop but now, that is reduced to git fetch ... git merge --autostash FETCH_HEAD When an autostash is generated, it is automatically reapplied to the worktree only in three explicit situations: 1. An incomplete merge is commit using `git commit`. 2. A merge completes successfully. 3. A merge is aborted using `git merge --abort`. In all other situations where the merge state is removed using remove_merge_branch_state() such as aborting a merge via `git reset --hard`, the autostash is saved into the stash reflog instead keeping the worktree clean. Helped-by: Phillip Wood Suggested-by: Alban Gruin Signed-off-by: Denton Liu --- Documentation/config/merge.txt | 10 +++ Documentation/git-merge.txt | 11 ++- Documentation/merge-options.txt | 8 ++ branch.c | 1 + builtin/commit.c | 2 + builtin/merge.c | 25 ++++++ builtin/rebase.c | 3 +- parse-options.h | 1 + path.c | 1 + path.h | 4 +- t/t3033-merge-toplevel.sh | 22 ++++++ t/t7600-merge.sh | 132 ++++++++++++++++++++++++++++++++ 12 files changed, 214 insertions(+), 6 deletions(-) diff --git a/Documentation/config/merge.txt b/Documentation/config/merge.txt index 6a313937f8..cb2ed58907 100644 --- a/Documentation/config/merge.txt +++ b/Documentation/config/merge.txt @@ -70,6 +70,16 @@ merge.stat:: Whether to print the diffstat between ORIG_HEAD and the merge result at the end of the merge. True by default. +merge.autoStash:: + When set to true, automatically create a temporary stash entry + before the operation begins, and apply it after the operation + ends. This means that you can run merge on a dirty worktree. + However, use with care: the final stash application after a + successful merge might result in non-trivial conflicts. + This option can be overridden by the `--no-autostash` and + `--autostash` options of linkgit:git-merge[1]. + Defaults to false. + merge.tool:: Controls which merge tool is used by linkgit:git-mergetool[1]. The list below shows the valid built-in values. diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 092529c619..ec06b2f8c2 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -94,7 +94,8 @@ will be appended to the specified message. --abort:: Abort the current conflict resolution process, and - try to reconstruct the pre-merge state. + try to reconstruct the pre-merge state. If an autostash entry is + present, apply it to the worktree. + If there were uncommitted worktree changes present when the merge started, 'git merge --abort' will in some cases be unable to @@ -102,11 +103,15 @@ reconstruct these changes. It is therefore recommended to always commit or stash your changes before running 'git merge'. + 'git merge --abort' is equivalent to 'git reset --merge' when -`MERGE_HEAD` is present. +`MERGE_HEAD` is present unless `MERGE_AUTOSTASH` is also present in +which case 'git merge --abort' applies the stash entry to the worktree +whereas 'git reset --merge' will save the stashed changes in the stash +reflog. --quit:: Forget about the current merge in progress. Leave the index - and the working tree as-is. + and the working tree as-is. If `MERGE_AUTOSTASH` is present, the + stash entry will be saved to the stash reflog. --continue:: After a 'git merge' stops due to conflicts you can conclude the diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 40dc4f5e8c..3985e6d4a9 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -155,6 +155,14 @@ ifndef::git-pull[] Note that not all merge strategies may support progress reporting. +--autostash:: +--no-autostash:: + Automatically create a temporary stash entry before the operation + begins, and apply it after the operation ends. This means + that you can run the operation on a dirty worktree. However, use + with care: the final stash application after a successful + merge might result in non-trivial conflicts. + endif::git-pull[] --allow-unrelated-histories:: diff --git a/branch.c b/branch.c index 579494738a..2d9e7675a6 100644 --- a/branch.c +++ b/branch.c @@ -344,6 +344,7 @@ void remove_merge_branch_state(struct repository *r) unlink(git_path_merge_rr(r)); unlink(git_path_merge_msg(r)); unlink(git_path_merge_mode(r)); + save_autostash(git_path_merge_autostash(r)); } void remove_branch_state(struct repository *r, int verbose) diff --git a/builtin/commit.c b/builtin/commit.c index 7ba33a3bec..c1b25d2954 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1713,6 +1713,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) &oid, flags); } + apply_autostash(git_path_merge_autostash(the_repository)); + UNLEAK(err); UNLEAK(sb); return 0; diff --git a/builtin/merge.c b/builtin/merge.c index d127d2225f..f86ae90bfc 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -82,6 +82,7 @@ static int show_progress = -1; static int default_to_upstream = 1; static int signoff; static const char *sign_commit; +static int autostash; static int no_verify; static struct strategy all_strategy[] = { @@ -286,6 +287,7 @@ static struct option builtin_merge_options[] = { OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1), { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"), N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, + OPT_AUTOSTASH(&autostash), OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")), OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")), OPT_BOOL(0, "no-verify", &no_verify, N_("bypass pre-merge-commit and commit-msg hooks")), @@ -475,6 +477,7 @@ static void finish(struct commit *head_commit, /* Run a post-merge hook */ run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL); + apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); } @@ -634,6 +637,9 @@ static int git_merge_config(const char *k, const char *v, void *cb) return 0; } else if (!strcmp(k, "gpg.mintrustlevel")) { check_trust_level = 0; + } else if (!strcmp(k, "merge.autostash")) { + autostash = git_config_bool(k, v); + return 0; } status = fmt_merge_msg_config(k, v, cb); @@ -1281,6 +1287,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (abort_current_merge) { int nargc = 2; const char *nargv[] = {"reset", "--merge", NULL}; + struct strbuf stash_oid = STRBUF_INIT; if (orig_argc != 2) usage_msg_opt(_("--abort expects no arguments"), @@ -1289,8 +1296,17 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (!file_exists(git_path_merge_head(the_repository))) die(_("There is no merge to abort (MERGE_HEAD missing).")); + if (read_oneliner(&stash_oid, git_path_merge_autostash(the_repository), + READ_ONELINER_SKIP_IF_EMPTY)) + unlink(git_path_merge_autostash(the_repository)); + /* Invoke 'git reset --merge' */ ret = cmd_reset(nargc, nargv, prefix); + + if (stash_oid.len) + apply_autostash_oid(stash_oid.buf); + + strbuf_release(&stash_oid); goto done; } @@ -1513,6 +1529,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } + if (autostash) + create_autostash(the_repository, + git_path_merge_autostash(the_repository), + "merge"); if (checkout_fast_forward(the_repository, &head_commit->object.oid, &commit->object.oid, @@ -1579,6 +1599,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (fast_forward == FF_ONLY) die(_("Not possible to fast-forward, aborting.")); + if (autostash) + create_autostash(the_repository, + git_path_merge_autostash(the_repository), + "merge"); + /* We are going to make a new commit. */ git_committer_info(IDENT_STRICT); diff --git a/builtin/rebase.c b/builtin/rebase.c index 08b89869b3..bc4fc69906 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1376,8 +1376,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) { OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"), N_("GPG-sign commits"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, - OPT_BOOL(0, "autostash", &options.autostash, - N_("automatically stash/stash pop before and after")), + OPT_AUTOSTASH(&options.autostash), OPT_STRING_LIST('x', "exec", &exec, N_("exec"), N_("add exec lines after each commit of the " "editable list")), diff --git a/parse-options.h b/parse-options.h index fece5ba628..46af942093 100644 --- a/parse-options.h +++ b/parse-options.h @@ -336,5 +336,6 @@ int parse_opt_passthru_argv(const struct option *, const char *, int); #define OPT_CLEANUP(v) OPT_STRING(0, "cleanup", v, N_("mode"), N_("how to strip spaces and #comments from message")) #define OPT_PATHSPEC_FROM_FILE(v) OPT_FILENAME(0, "pathspec-from-file", v, N_("read pathspec from file")) #define OPT_PATHSPEC_FILE_NUL(v) OPT_BOOL(0, "pathspec-file-nul", v, N_("with --pathspec-from-file, pathspec elements are separated with NUL character")) +#define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after")) #endif diff --git a/path.c b/path.c index 88cf593007..d764738146 100644 --- a/path.c +++ b/path.c @@ -1535,5 +1535,6 @@ REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG") REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR") REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE") REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD") +REPO_GIT_PATH_FUNC(merge_autostash, "MERGE_AUTOSTASH") REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD") REPO_GIT_PATH_FUNC(shallow, "shallow") diff --git a/path.h b/path.h index 14d6dcad16..1f1bf8f87a 100644 --- a/path.h +++ b/path.h @@ -177,11 +177,12 @@ struct path_cache { const char *merge_rr; const char *merge_mode; const char *merge_head; + const char *merge_autostash; const char *fetch_head; const char *shallow; }; -#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } +#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } const char *git_path_cherry_pick_head(struct repository *r); const char *git_path_revert_head(struct repository *r); @@ -190,6 +191,7 @@ const char *git_path_merge_msg(struct repository *r); const char *git_path_merge_rr(struct repository *r); const char *git_path_merge_mode(struct repository *r); const char *git_path_merge_head(struct repository *r); +const char *git_path_merge_autostash(struct repository *r); const char *git_path_fetch_head(struct repository *r); const char *git_path_shallow(struct repository *r); diff --git a/t/t3033-merge-toplevel.sh b/t/t3033-merge-toplevel.sh index d314599428..e29c284b9b 100755 --- a/t/t3033-merge-toplevel.sh +++ b/t/t3033-merge-toplevel.sh @@ -142,6 +142,17 @@ test_expect_success 'refuse two-project merge by default' ' test_must_fail git merge five ' +test_expect_success 'refuse two-project merge by default, quit before --autostash happens' ' + t3033_reset && + git reset --hard four && + echo change >>one.t && + git diff >expect && + test_must_fail git merge --autostash five 2>err && + test_i18ngrep ! "stash" err && + git diff >actual && + test_cmp expect actual +' + test_expect_success 'two-project merge with --allow-unrelated-histories' ' t3033_reset && git reset --hard four && @@ -149,4 +160,15 @@ test_expect_success 'two-project merge with --allow-unrelated-histories' ' git diff --exit-code five ' +test_expect_success 'two-project merge with --allow-unrelated-histories with --autostash' ' + t3033_reset && + git reset --hard four && + echo change >>one.t && + git diff one.t >expect && + git merge --allow-unrelated-histories --autostash five 2>err && + test_i18ngrep "Applied autostash." err && + git diff one.t >actual && + test_cmp expect actual +' + test_done diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 4fa0ef8e3b..5883a6adc3 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -30,13 +30,17 @@ Testing basic merge operations/option parsing. . "$TEST_DIRECTORY"/lib-gpg.sh test_write_lines 1 2 3 4 5 6 7 8 9 >file +cp file file.orig test_write_lines '1 X' 2 3 4 5 6 7 8 9 >file.1 +test_write_lines 1 2 '3 X' 4 5 6 7 8 9 >file.3 test_write_lines 1 2 3 4 '5 X' 6 7 8 9 >file.5 test_write_lines 1 2 3 4 5 6 7 8 '9 X' >file.9 test_write_lines 1 2 3 4 5 6 7 8 '9 Y' >file.9y test_write_lines '1 X' 2 3 4 5 6 7 8 9 >result.1 test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 +test_write_lines '1 X' 2 3 4 5 6 7 8 '9 X' >result.1-9 test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 +test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9 test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z create_merge_msgs () { @@ -675,6 +679,134 @@ test_expect_success 'refresh the index before merging' ' git merge c3 ' +test_expect_success 'merge with --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git merge --autostash c2 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'merge with merge.autoStash' ' + test_config merge.autoStash true && + git reset --hard c1 && + git merge-file file file.orig file.9 && + git merge c2 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'fast-forward merge with --autostash' ' + git reset --hard c0 && + git merge-file file file.orig file.5 && + git merge --autostash c1 2>err && + test_i18ngrep "Applied autostash." err && + test_cmp result.1-5 file +' + +test_expect_success 'octopus merge with --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.3 && + git merge --autostash c2 c3 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5-9 merge-result && + test_cmp result.1-3-5-9 file +' + +test_expect_success 'conflicted merge with --autostash, --abort restores stash' ' + git reset --hard c3 && + cp file.1 file && + test_must_fail git merge --autostash c7 && + git merge --abort 2>err && + test_i18ngrep "Applied autostash." err && + test_cmp file.1 file +' + +test_expect_success 'completed merge (git commit) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git commit 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'completed merge (git merge --continue) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git merge --continue 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'aborted merge (merge --abort) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git merge --abort 2>err && + test_i18ngrep "Applied autostash." err && + git diff >actual && + test_cmp expect actual +' + +test_expect_success 'aborted merge (reset --hard) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git reset --hard 2>err && + test_i18ngrep "Autostash exists; creating a new stash entry." err && + git diff --exit-code +' + +test_expect_success 'quit merge with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git diff HEAD >expect && + git merge --quit 2>err && + test_i18ngrep "Autostash exists; creating a new stash entry." err && + git diff HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'merge with conflicted --autostash changes' ' + git reset --hard c1 && + git merge-file file file.orig file.9y && + git diff >expect && + test_when_finished "test_might_fail git stash drop" && + git merge --autostash c3 2>err && + test_i18ngrep "Applying autostash resulted in conflicts." err && + git show HEAD:file >merge-result && + test_cmp result.1-9 merge-result && + git stash show -p >actual && + test_cmp expect actual +' + cat >expected.branch <<\EOF Merge branch 'c5-branch' (early part) EOF From patchwork Tue Apr 7 14:28:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D069159A for ; Tue, 7 Apr 2020 14:28:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B984207FF for ; Tue, 7 Apr 2020 14:28:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dwGZzAez" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729157AbgDGO2r (ORCPT ); Tue, 7 Apr 2020 10:28:47 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:34005 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729149AbgDGO2q (ORCPT ); Tue, 7 Apr 2020 10:28:46 -0400 Received: by mail-qt1-f194.google.com with SMTP id 14so2805327qtp.1 for ; Tue, 07 Apr 2020 07:28:45 -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 :mime-version:content-transfer-encoding; bh=Y3JpD1BmGlEgxfNhigHedIBI5YZ1431gBF8qqQU816M=; b=dwGZzAezgKF0Jii3S4JsVy1aslt1nQj+jL+6g52mlBVhwubTyLmJnWnhA/QXcIXG8D Mc3dGwkd1RR5WRGFonhgMSiS1WVL0+HDQWBLWTDrRN8GqKfSi/nttdq3IjP1COyQjVJ7 FGba1im2wBJ6U/sOjzQCfgomKeOqEKq8JNeYXb6Ff6pKw2HeIhIWj04JdPrBDZciex2k Fcr5io/jXr1nx46LBWV+hIpwqLWGYRMDRSUoEjjOdNCOS+rgYL6TRtHGPtvoBkcfvn1a mJYN7iPUUIatGTP427Igv5YwJTsyV17vKIAoAgwwebCWp+1JqA++RIM50Iu1kp0qZBng QKeA== 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:mime-version:content-transfer-encoding; bh=Y3JpD1BmGlEgxfNhigHedIBI5YZ1431gBF8qqQU816M=; b=lnu85eBCqgI1pGOrztNm/9lc9jhjQePiQl4jZejDrhOgT3jdK9VVocDdgxWnfiEfYJ xQJIpVC0r6qsJzGlo+bnvSsl4Ydz7adUmLUmqvAVe3j00uverr0uJKdAzXBrNH37SzWO tsIGreDSzU6Faz95+QBUW55/vaUgHuOYgNw/T4Iq/xAPGzPyjwEChhZHtr1G5WbDbHF4 F/Jn31cq2Cm+Gh+heEjs22alCb1IoTq4kdApoZKzDZbrqfwFb7gzlkF03ZXdwus6a/Hi 86NEPkiizkA9a3l7Yt1EqHaVPmxxuL4JFgg8Z6KZxDPFRlZXlAJ3HygXeEUQJGonD4gF QNqg== X-Gm-Message-State: AGi0Pub9L8pwpK9Xzb/d35myV8h4T06Sqry7X15xAqwJUvu9qmX4UVOl 97e5qD7o0SpEAI/VCw54bJXLRZ4s X-Google-Smtp-Source: APiQypJCVnyJ8qEFNM2xMnuntZ7rQBa8WVrsKU/7Iq6xNi+DrmgqUKldSTe3++v7zMJi+9Lbv/JSWQ== X-Received: by 2002:ac8:7752:: with SMTP id g18mr2464230qtu.125.1586269725071; Tue, 07 Apr 2020 07:28:45 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:44 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 21/22] t5520: make test_pull_autostash() accept expect_parent_num Date: Tue, 7 Apr 2020 10:28:08 -0400 Message-Id: <13f3fadbef41476a7a7715574621729eb8f6e200.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Before, test_pull_autostash() was hardcoded to run `test_cmp_rev HEAD^ copy` to test that a rebase happened. However, in a future patch, we plan on testing merging as well. Make test_pull_autostash() accept a parent number as an argument so that, in the future, we can test if a merge happened in addition to a rebase. Signed-off-by: Denton Liu --- t/t5520-pull.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 2f86fca042..f610dc14de 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -10,11 +10,13 @@ modify () { } test_pull_autostash () { + expect_parent_num="$1" && + shift && git reset --hard before-rebase && echo dirty >new_file && git add new_file && git pull "$@" . copy && - test_cmp_rev HEAD^ copy && + test_cmp_rev HEAD^"$expect_parent_num" copy && echo dirty >expect && test_cmp expect new_file && echo "modified again" >expect && @@ -369,22 +371,22 @@ test_expect_success '--rebase fails with multiple branches' ' test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' ' test_config rebase.autostash true && - test_pull_autostash --rebase + test_pull_autostash 1 --rebase ' test_expect_success 'pull --rebase --autostash & rebase.autostash=true' ' test_config rebase.autostash true && - test_pull_autostash --rebase --autostash + test_pull_autostash 1 --rebase --autostash ' test_expect_success 'pull --rebase --autostash & rebase.autostash=false' ' test_config rebase.autostash false && - test_pull_autostash --rebase --autostash + test_pull_autostash 1 --rebase --autostash ' test_expect_success 'pull --rebase --autostash & rebase.autostash unset' ' test_unconfig rebase.autostash && - test_pull_autostash --rebase --autostash + test_pull_autostash 1 --rebase --autostash ' test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' ' @@ -422,7 +424,7 @@ test_expect_success 'pull.rebase' ' test_expect_success 'pull --autostash & pull.rebase=true' ' test_config pull.rebase true && - test_pull_autostash --autostash + test_pull_autostash 1 --autostash ' test_expect_success 'pull --no-autostash & pull.rebase=true' ' From patchwork Tue Apr 7 14:28:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478207 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E86B112C for ; Tue, 7 Apr 2020 14:28:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EC7452078C for ; Tue, 7 Apr 2020 14:28:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cigJmtnS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729178AbgDGO2w (ORCPT ); Tue, 7 Apr 2020 10:28:52 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:38105 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729155AbgDGO2s (ORCPT ); Tue, 7 Apr 2020 10:28:48 -0400 Received: by mail-qt1-f193.google.com with SMTP id 13so895302qtt.5 for ; Tue, 07 Apr 2020 07:28:47 -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 :mime-version:content-transfer-encoding; bh=SfqKQCJxrbAI7q9qgz7feSm3n/yolzfRqw44OcRExYc=; b=cigJmtnSkAJBQBmgDFDxlt3YrTyVMi8vMZixpVRhve+3siMYtY6UEGO+Gwg2xIUsvZ og9TQspl7biUy9uXfqW87YZZL7+taUSSQMNgXwHccm3YK+hSFXB+ljnGx1c9szyvgN85 rt81XJC0g95tGlww/pSznBrjB1lLT5wKcVI4pa4qAO+e2j06SVE2RqvQ0g8Blbx6ligP MWAKSnrr9cbKpH60gRG4Imfhg76PDXB76zYrF3zvCLzrCyS99RjU45xRiienIIcKZqKd vjBFfAkIKfpv53cvjWUeOg5j6Cd2tYRT45c2hr7EpK1UNkLzOVhXJQVvCA3FB4oswfF6 gfhw== 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:mime-version:content-transfer-encoding; bh=SfqKQCJxrbAI7q9qgz7feSm3n/yolzfRqw44OcRExYc=; b=S3z6sPzArtE+vdQDLY/+PwgY+kCiBsNDZ/Vcbjpqx4zpodDsERCXzNiP/0QsKNedJa GFYp4L19MIxgVaEvviZ48ANPAARMm4YWPsJMIC/SlFq7HQKt9ORAa5Wz4vV8+ZP99Z+x V2wP58dZu2lPbe/dCgel+S21TkfiPMR3phiUewZBjraIAnNLDnxaVZQT5juBtuNwCoxn Gv+CHABni96JM0WUXO4Ib6PD82tUSWhbjdxtXWoxUAwD4XYHMXTYkcXSd3nlxZDnTMt1 Sw7Xg+Y7SGzgNSdeq9JDmVz5kzvu2vLDzrHfZUAWHQFuEF8SAijdHnfLEdE3OIkHonPJ dwFA== X-Gm-Message-State: AGi0PuaxihA2Ob4dgtZctrhnwrVroxn0xa+Z1YBLs00an61Fy2bpN9Yr fDQI5PEGR9v4FhijVQ2QdjjTTkpe X-Google-Smtp-Source: APiQypJDTGtkDTAx0RpMQVC73uA74PXch5DHnsE8nNLf6n0yW7uV1nGzI/7Jlk87RAOethS1tA5gvQ== X-Received: by 2002:ac8:5195:: with SMTP id c21mr2408254qtn.75.1586269726561; Tue, 07 Apr 2020 07:28:46 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:45 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 22/22] pull: pass --autostash to merge Date: Tue, 7 Apr 2020 10:28:09 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Before, `--autostash` only worked with `git pull --rebase`. However, in the last patch, merge learned `--autostash` as well so there's no reason why we should have this restriction anymore. Teach pull to pass `--autostash` to merge, just like it did for rebase. Signed-off-by: Denton Liu --- Documentation/git-pull.txt | 9 ------- Documentation/merge-options.txt | 4 +-- builtin/pull.c | 9 ++++--- t/t5520-pull.sh | 43 +++++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index dfb901f8b8..ba3772de9f 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -133,15 +133,6 @@ unless you have read linkgit:git-rebase[1] carefully. --no-rebase:: Override earlier --rebase. ---autostash:: ---no-autostash:: - Before starting rebase, stash local modifications away (see - linkgit:git-stash[1]) if needed, and apply the stash entry when - done. `--no-autostash` is useful to override the `rebase.autoStash` - configuration variable (see linkgit:git-config[1]). -+ -This option is only valid when "--rebase" is used. - Options related to fetching ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 3985e6d4a9..48bfcda084 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -155,6 +155,8 @@ ifndef::git-pull[] Note that not all merge strategies may support progress reporting. +endif::git-pull[] + --autostash:: --no-autostash:: Automatically create a temporary stash entry before the operation @@ -163,8 +165,6 @@ ifndef::git-pull[] with care: the final stash application after a successful merge might result in non-trivial conflicts. -endif::git-pull[] - --allow-unrelated-histories:: By default, `git merge` command refuses to merge histories that do not share a common ancestor. This option can be diff --git a/builtin/pull.c b/builtin/pull.c index 3e624d1e00..9beb4841d1 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -163,7 +163,7 @@ static struct option pull_options[] = { N_("verify that the named commit has a valid GPG signature"), PARSE_OPT_NOARG), OPT_BOOL(0, "autostash", &opt_autostash, - N_("automatically stash/stash pop before and after rebase")), + N_("automatically stash/stash pop before and after")), OPT_PASSTHRU_ARGV('s', "strategy", &opt_strategies, N_("strategy"), N_("merge strategy to use"), 0), @@ -661,6 +661,10 @@ static int run_merge(void) argv_array_pushv(&args, opt_strategy_opts.argv); if (opt_gpg_sign) argv_array_push(&args, opt_gpg_sign); + if (opt_autostash == 0) + argv_array_push(&args, "--no-autostash"); + else if (opt_autostash == 1) + argv_array_push(&args, "--autostash"); if (opt_allow_unrelated_histories > 0) argv_array_push(&args, "--allow-unrelated-histories"); @@ -908,9 +912,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (get_oid("HEAD", &orig_head)) oidclr(&orig_head); - if (!opt_rebase && opt_autostash != -1) - die(_("--[no-]autostash option is only valid with --rebase.")); - autostash = config_autostash; if (opt_rebase) { if (opt_autostash != -1) diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index f610dc14de..37535d63a9 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -28,7 +28,7 @@ test_pull_autostash_fail () { echo dirty >new_file && git add new_file && test_must_fail git pull "$@" . copy 2>err && - test_i18ngrep "uncommitted changes." err + test_i18ngrep "\(uncommitted changes.\)\|\(overwritten by merge:\)" err } test_expect_success setup ' @@ -404,13 +404,40 @@ test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' ' test_pull_autostash_fail --rebase --no-autostash ' -for i in --autostash --no-autostash -do - test_expect_success "pull $i (without --rebase) is illegal" ' - test_must_fail git pull $i . copy 2>err && - test_i18ngrep "only valid with --rebase" err - ' -done +test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' ' + test_config merge.autostash true && + test_pull_autostash 2 +' + +test_expect_success 'pull --autostash & merge.autostash=true' ' + test_config merge.autostash true && + test_pull_autostash 2 --autostash +' + +test_expect_success 'pull --autostash & merge.autostash=false' ' + test_config merge.autostash false && + test_pull_autostash 2 --autostash +' + +test_expect_success 'pull --autostash & merge.autostash unset' ' + test_unconfig merge.autostash && + test_pull_autostash 2 --autostash +' + +test_expect_success 'pull --no-autostash & merge.autostash=true' ' + test_config merge.autostash true && + test_pull_autostash_fail --no-autostash +' + +test_expect_success 'pull --no-autostash & merge.autostash=false' ' + test_config merge.autostash false && + test_pull_autostash_fail --no-autostash +' + +test_expect_success 'pull --no-autostash & merge.autostash unset' ' + test_unconfig merge.autostash && + test_pull_autostash_fail --no-autostash +' test_expect_success 'pull.rebase' ' git reset --hard before-rebase &&