From patchwork Sat Mar 21 09:21:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450763 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 D73B51894 for ; Sat, 21 Mar 2020 09:22:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5F752070A for ; Sat, 21 Mar 2020 09:22:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cm1q1RdN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbgCUJWN (ORCPT ); Sat, 21 Mar 2020 05:22:13 -0400 Received: from mail-qt1-f169.google.com ([209.85.160.169]:42379 "EHLO mail-qt1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbgCUJWM (ORCPT ); Sat, 21 Mar 2020 05:22:12 -0400 Received: by mail-qt1-f169.google.com with SMTP id t9so3334055qto.9 for ; Sat, 21 Mar 2020 02:22:10 -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=IIIFPfowLgl0tpT5uGrEPCId2FDvfBDXtMs7UrAxmME=; b=Cm1q1RdNP34BwDZ25QnJLD/Sie4+V2WnoNpgPs2Au4seSTC/kcqHIDSb2G7OG3/Eq5 KUHUXqB47qmgTJ9hW4aJAZbhbrMVGSD+G5SGEfrP7F/9fy2W+kEGO5to+IkUT3UrXsFw 0a9Ea3LJMRCbJ91SonE2oRiTiCr8dstWVcF/h16IgMadYZnX4ja8Ay7U3t5fHavNdWmy VsFdfFrE9mxmkqupIYOwK5W7KrDDpP3fOFzYy3k5GNjhhJFcXO9tph4drjiOXpTaT2dF vkP97/MHgK8cN+IdsKU6ZCqYd7FyU1pZGCFQUPnEHz/JmsgyIUcHZwaNgdpk3LYDz8Qp 73vg== 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=IIIFPfowLgl0tpT5uGrEPCId2FDvfBDXtMs7UrAxmME=; b=MBRPnRvLVtjMmrhxWeyIHxndSDQbz0E7h3mRTbwKjaBdTS4iGPHSSy26HqdV6sLL/V +HWpm7ahwkveAzkp0/1A1ht4wEmZtTW2OVLFGI2z9YyCXftztkcT43RRLtrtWPSe/Qla 9SRbEZL34kQoA781bwqqxi3OfcJriCGIwNjwiAh5ej35E6vQwlk/xIbhqZ7tEGQt4Z0N z+S05b0ntuZrauTjAQ79GIF99h/7wUSR9voqqbqJgHuJ6zEI6AngytKfL878OHKqSltX auAw3gWggIY1Pa7BDKlSj+Me6Q9jG767pJPgsjKEQ8K+p+Jwgdzw3acPNztSr6Ct4KDk xPQw== X-Gm-Message-State: ANhLgQ2jXQ0qSDdASD2aNeat5OfDZ1XGgjYuS2xof+WjPfgVQo0zWgWF 5ED6MmGcfaEAkv9BqW6Sc1sjIrEf X-Google-Smtp-Source: ADFU+vs7VA5fwUjXv82QYZB3JekifNcQ93GatTKcCcew7ivM3vGnIik5YmZ1ahbyXfAkfmEd+ylV9Q== X-Received: by 2002:aed:3988:: with SMTP id m8mr12612273qte.9.1584782529480; Sat, 21 Mar 2020 02:22:09 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:09 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 01/19] Makefile: ASCII-sort += lists Date: Sat, 21 Mar 2020 05:21:20 -0400 Message-Id: <77506a39d04c838773757b189e1b409ce98d612e.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 Sat Mar 21 09:21:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450761 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 78D8592A for ; Sat, 21 Mar 2020 09:22:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5175B2070A for ; Sat, 21 Mar 2020 09:22:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IVI0/Asr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726710AbgCUJWM (ORCPT ); Sat, 21 Mar 2020 05:22:12 -0400 Received: from mail-qv1-f68.google.com ([209.85.219.68]:44320 "EHLO mail-qv1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726597AbgCUJWM (ORCPT ); Sat, 21 Mar 2020 05:22:12 -0400 Received: by mail-qv1-f68.google.com with SMTP id w5so4435551qvp.11 for ; Sat, 21 Mar 2020 02:22:11 -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=FnIa+ZqBno7V8ODa2J7tI2V+bmWCguOTvHF0mu2bJDs=; b=IVI0/AsriNo2nrDU5rivOI+x4X9ns8mMUpa39VKXvWgpP1jETVtzwjellHYrg+A0i7 otjCpav6uWRH83wbx4kIwzlDfn3XcX4bvci6bWOrs+wPpMbd3bB1uxTrBQbveM5JFFyb 1oN02tW0E3Ya3bQudeJKLeCXbrjQAsbET8ELin68gjfWsI5fjAPUQSA6F+PjS4uuWXCW oQGHnpX7x6CLf3s1fkHAqPGtn6wIIWVrkhgfQ+NSkLMsvEBIzsu24re5Y1VkuDA5Esn/ nsE/gN+/LsVHyUJcxmFFlGPKR7cUqKFxG3QsmSre9PN5WY32deImRZTI922FXrcLiqu0 zaPw== 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=FnIa+ZqBno7V8ODa2J7tI2V+bmWCguOTvHF0mu2bJDs=; b=lIue8Wlp+m1l9jjDgblzWzKRtwPUhIOA2BHLHgBweFlj0t/jdkR0o9N+kKUQOhZJrO WOXxHKcUIiMpCb/cFRUJrFYRClrHJscNWHigSaD4iVxyLdQ8NVroyqfbJP+IG9IRkmIZ OVjznhFg7Oj7s78igCoIe1dGUnHcWS3ZVONtkglwtX29mqhiGX0qvOkvfQaDKgbaXthL z8M7iQb/sADEYcoR/zbUZIhGFsSxeRzb3d18aeOgO7jRhFmnMsxpbT+YkLe4bUN1GHB8 HqtTj+st17oRaMLQsecVrXfqbayfqJgrPKPszhGJK26ftgxumtOQcKynuUwwwXjb40RQ fBjg== X-Gm-Message-State: ANhLgQ0FAPWsPtkVgVrulNFkXDrvZ63EnNGbiwcY370Ged4O5KMOV5xQ I0JHxeEn0UH7kC11DtOnBIDMjXt5 X-Google-Smtp-Source: ADFU+vtyMnb5+73P3I5cS7ARK14Avxl+wvGoBWpajWmaROPLMOaNHsX2Nc8DtC5t7u2C0GDEzWFLqw== X-Received: by 2002:a05:6214:110d:: with SMTP id e13mr11729926qvs.60.1584782530699; Sat, 21 Mar 2020 02:22:10 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:10 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 02/19] t7600: use test_write_lines() Date: Sat, 21 Mar 2020 05:21:21 -0400 Message-Id: <70699b8b73c1e86cdbe47d9d4162bf0b678a9dbc.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 Sat Mar 21 09:21:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450765 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 0BE3A1893 for ; Sat, 21 Mar 2020 09:22:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE7912070A for ; Sat, 21 Mar 2020 09:22:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="romVce3g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727104AbgCUJWR (ORCPT ); Sat, 21 Mar 2020 05:22:17 -0400 Received: from mail-qv1-f66.google.com ([209.85.219.66]:35931 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbgCUJWR (ORCPT ); Sat, 21 Mar 2020 05:22:17 -0400 Received: by mail-qv1-f66.google.com with SMTP id z13so4473351qvw.3 for ; Sat, 21 Mar 2020 02:22:16 -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=nsep9eFqDJqK599AyBuyguj4crSxZCp/l2148748kJg=; b=romVce3gpiObfyo6Bs/87Kmn1IUdl9I+iplWAp2+cbssVCs88Je2zbt9i9ZWT58dyb DU1xshGxyhZAPOThr+ewaM0DdSAniR6/CzDKsiaj+aRQA+Wh4NLzYsDyMypqff49mOYE Y2W9X8EB+UPUsa8k/lfsNwsJ9DGAUsbMwqSiNI5jEs/kfzwoSgz7wTsD0488ZzY1ScnY 7/kWHMVWonmqv4qrkPyAjYS7ux0Esi7RjGU0ErwPUSzUwiVrNmIJ9KnY/CALuoPnEiHg uJu0YeDdIZueBeaJmqhnpkw/Uqh3cLoihR46PWFdMxjKm9/9abhhAM+bAGZeD7nydPEl 0+7Q== 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=nsep9eFqDJqK599AyBuyguj4crSxZCp/l2148748kJg=; b=Jb4weo2lGmR2mC2FUQ/dZFrPDmIRX+JCdfQZqMldHS+BNxmKYhnDODOM26Tmpts+o9 +VZ7VDTEaP3lT9yqugEGwvynDwA7ZC+N0+Meoe724EjJIhi8KBSZ8yGBVlMPu+lqDcGW TAtKU45C/wPUnWNLrB4Z38wuV8F1t4SW0ZT7s80de9K2npxxRWG5yEkfqTJqVkvPrZwu LYKzZWQZuRjZGPBx0sf3plKEK64qQuAaFExTB4SCiQ8myMyrXt6siYDbdybcRKYQHAhl OJX9WRX/j8nW2uKebuK+g1T63EJpBUi2FfA4d5HgVRJ/hoQJzSioagDkcHWfg5aY1BgG UGtw== X-Gm-Message-State: ANhLgQ0/1zD5h5IbfGDaDjuLJXS5xzJunfim6n/ndVMTv4WSL+dwNrCp xZhFQbIs1sHQ5sUyOuzxDoSGBRbl X-Google-Smtp-Source: ADFU+vsKzBfrRdPXUyX4viK6cl/y1icN7A0VrJ4rghOu8p+3a9pomuzahj4rvpc+KNCMTHiL45zGyg== X-Received: by 2002:ad4:4364:: with SMTP id u4mr11677961qvt.58.1584782535933; Sat, 21 Mar 2020 02:22:15 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:15 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 03/19] sequencer: use file strbuf for read_oneliner() Date: Sat, 21 Mar 2020 05:21:22 -0400 Message-Id: <7c37777f07191c8ac1d26300f9465b90758550b2.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 original read_oneliner logic, we duplicated the logic for strbuf_trim_trailing_newline() with one exception: instead of preventing buffer accesses below index 0, it would prevent buffer accesses below index `orig_len`. Although this is correct, it isn't worth having the duplicated logic around. Add a second strbuf to which files are read and run strbuf_trim_trailing_newline() directly on this strbuf then concatenate this strbuf with the argument strbuf at the end of the function. The function's external behaviour is unchanged. Signed-off-by: Denton Liu --- sequencer.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sequencer.c b/sequencer.c index e528225e78..c49fe76fe6 100644 --- a/sequencer.c +++ b/sequencer.c @@ -431,26 +431,28 @@ static int write_message(const void *buf, size_t len, const char *filename, static int read_oneliner(struct strbuf *buf, const char *path, int skip_if_empty) { - int orig_len = buf->len; + int ret = 0; + struct strbuf file_buf = STRBUF_INIT; if (!file_exists(path)) return 0; - if (strbuf_read_file(buf, path, 0) < 0) { + if (strbuf_read_file(&file_buf, path, 0) < 0) { warning_errno(_("could not read '%s'"), path); - return 0; + goto done; } - if (buf->len > orig_len && buf->buf[buf->len - 1] == '\n') { - if (--buf->len > orig_len && buf->buf[buf->len - 1] == '\r') - --buf->len; - buf->buf[buf->len] = '\0'; - } + strbuf_trim_trailing_newline(&file_buf); - if (skip_if_empty && buf->len == orig_len) - return 0; + if (skip_if_empty && !file_buf.len) + goto done; - return 1; + strbuf_addbuf(buf, &file_buf); + ret = 1; + +done: + strbuf_release(&file_buf); + return ret; } static struct tree *empty_tree(struct repository *r) From patchwork Sat Mar 21 09:21:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450769 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 8889417E6 for ; Sat, 21 Mar 2020 09:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5A0052070A for ; Sat, 21 Mar 2020 09:22:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EL+BWaXA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727124AbgCUJWT (ORCPT ); Sat, 21 Mar 2020 05:22:19 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:38434 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbgCUJWT (ORCPT ); Sat, 21 Mar 2020 05:22:19 -0400 Received: by mail-qk1-f193.google.com with SMTP id h14so9831342qke.5 for ; Sat, 21 Mar 2020 02:22:18 -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=OT4Sx+tSiVsN/fSK9K4GX5MlFsY2JuB7NQZzi5CNb34=; b=EL+BWaXAhAVT5SPGQThXD12r1GACwTD8Ae8KyF+Ak4sL8gvd7CW1Fzu5b+2Dyb8ti8 I5tE6IXMzZ3d2CNpxQqlu8yvdRx4mGfwQBFBL8hCGGJxSMGy7DGWjuctpjyVKJ+VsP3U r3khGNl9JaL5QYJo/yZLwNV1O8C4p9Lc8iggJRTKBYfwQ7wyrdK6fF7zrABjllpNQq7v CJ3yrZF8Q80FWT+gWJ82GcqznxBFQ6vNFNf5i1wjo8vsgPOriDAKI65ERgDuNDuZoGix eQS1nmopxc1C5/6+g9osF6WZQ/JDH557JdDynVqc1rgeXNEVcSB6mEyMgMofEjcxp9jc jR+w== 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=OT4Sx+tSiVsN/fSK9K4GX5MlFsY2JuB7NQZzi5CNb34=; b=IXAO2TMhr+SfRMRXMm3W8pyiEoUKrmWVxhyVg3S3EjNg8VC1Aw/PdBNTd82sNyluuU PvIaplg2WceMP310UdYaZXdXTNLS7KF5K1Jkc0gSdSBiXwFXhu7iXK3zblNuVb+x6hcV 8B3ubG5+4wCbfeaY4uzzx/QFhxANxyDZkWyGdJPMBRIy9rF/jA6Dk+jfyLhhmJa2oRxI h8B/H/QLOgxERnuSEHK0wUnD7DAUavNKirjBYp04HWzfcfgxjqodwWr2DySx6/Rc5R7X NlHe1Waf+ANmq5b/pgbtvmtWy+6YhHFShLsLTioczO/+tQ2yDWfIB41T7o2OJRw/XCjH /prw== X-Gm-Message-State: ANhLgQ3TsiPbGL4KhD8r+s+H3jGp3Heaptn2JdgnyKWcG/SGgGJQM10j xL8NeJljMLBptD/oKdM7VXITQ7Lr X-Google-Smtp-Source: ADFU+vtmMfUBq6ExaTHZiM5cbXP04CuUeDADQkDJezyPVlYVdFL8YZS0jgMx/Yuu+rD4eZHbPau4cA== X-Received: by 2002:a37:9dc9:: with SMTP id g192mr12273918qke.50.1584782537358; Sat, 21 Mar 2020 02:22:17 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:16 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 04/19] sequencer: make read_oneliner() accept flags Date: Sat, 21 Mar 2020 05:21:23 -0400 Message-Id: <4f9708682877f4d3689781009dc2695b913eff29.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 c49fe76fe6..abb2a21e9d 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 ret = 0; struct strbuf file_buf = STRBUF_INIT; @@ -444,7 +446,7 @@ static int read_oneliner(struct strbuf *buf, strbuf_trim_trailing_newline(&file_buf); - if (skip_if_empty && !file_buf.len) + if ((flags & READ_ONELINER_SKIP_IF_EMPTY) && !file_buf.len) goto done; strbuf_addbuf(buf, &file_buf); @@ -2488,7 +2490,8 @@ static int read_populate_opts(struct replay_opts *opts) if (is_rebase_i(opts)) { struct strbuf buf = STRBUF_INIT; - 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 { @@ -2498,7 +2501,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")) @@ -2530,7 +2534,8 @@ static int read_populate_opts(struct replay_opts *opts) strbuf_release(&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'))) { @@ -3667,7 +3672,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; } @@ -4291,7 +4297,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 Sat Mar 21 09:21:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450771 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 B3D3792A for ; Sat, 21 Mar 2020 09:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9108C2070A for ; Sat, 21 Mar 2020 09:22:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WjSdCeQG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727132AbgCUJWU (ORCPT ); Sat, 21 Mar 2020 05:22:20 -0400 Received: from mail-qv1-f66.google.com ([209.85.219.66]:44323 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727110AbgCUJWT (ORCPT ); Sat, 21 Mar 2020 05:22:19 -0400 Received: by mail-qv1-f66.google.com with SMTP id w5so4435630qvp.11 for ; Sat, 21 Mar 2020 02:22:19 -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/9uW24LgcQGfFEnY3l1C8SMQVOQeOo85lsYeBd//A=; b=WjSdCeQGNHiHslA2O5O/qPFMRSVvQDM20wTK+vUzFVbFFjhKOWZsLWrU8QnalSyohv KrAhlaDbOoHqeYHtngIaCYaN52o1sumfaCeAFYLC/1pJNh9yCpWJx/TcQRxhIluCnDNS gIN8NkH42qBBtVazMhplHYP1SgWZwv4HXy6WMjIreN5fcnxdDdGLPKj6Cu2AN6hnNKvw 3nzxKlL4wiCvhEV7MrVwc7bQbazgYQA2wwnmNDKOdBm4IzNaq9/EcfYruf7xRGaGePPS gK7X5HXCX6lU2/3yqJkhn6zhyo8+8wtzL0zKOWSNC12p5tBv+m/JDEHsVQwbVQAtxI9V Fkhg== 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/9uW24LgcQGfFEnY3l1C8SMQVOQeOo85lsYeBd//A=; b=aDmuOWLfdAdgBEutTC/Or1dedl2YbcyBT/gTl8bBs+oHQHpyCI9Us0DZOmkouuf0JF AJIvimUxhOUleeIYqr1/wGH/Vc5a18QDdEQ2fKycw2+/7JXFfnq8KXBYx2rCl2D/2dQ2 myUV3RMtCltvLraqZS2qn2BHoXLVKPO3Btvo2MofXgc9lRpmVFG5yRVMJ6KyzAr2ASLx hLRmoijXMedqRHBzQBUIKkFU95apmAslHjK2splicnEkPLsvAGbt3A8Kb5MV393WnDLI 6ycL2OlRPwHadMOa4e5WRjs1S7HAbTNN8zAkDqq+y/2dXJVajf0l11sm9XmNg9tgo0qz la/g== X-Gm-Message-State: ANhLgQ3nu0fwHTMwnwPc9t9EcUF0uLOZ7vcZejVRjB2QhKDbi2bzQtOg TrG6cEnNsJfRyofESiYdOzlm2B4R X-Google-Smtp-Source: ADFU+vvX/nAvL8HgwwcnOZSy7bH454E94AfEqL1A6HdcCBVvbFzNlwn24IRllxeFbeUfFm3yCIRYTg== X-Received: by 2002:ad4:58c2:: with SMTP id dh2mr11882982qvb.242.1584782538485; Sat, 21 Mar 2020 02:22:18 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:17 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 05/19] sequencer: configurably warn on non-existent files Date: Sat, 21 Mar 2020 05:21:24 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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_NON_EXISTENCE` flag which, if active, would issue a warning when a file doesn't exist by skipping the `!file_exists()` check and letting `strbuf_read_file()` handle that case. Signed-off-by: Denton Liu --- sequencer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index abb2a21e9d..92e8d38290 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_NON_EXISTENCE (1 << 1) /* * Reads a file that was presumably written by a shell script, i.e. with an @@ -436,7 +437,7 @@ static int read_oneliner(struct strbuf *buf, int ret = 0; struct strbuf file_buf = STRBUF_INIT; - if (!file_exists(path)) + if (!(flags & READ_ONELINER_WARN_NON_EXISTENCE) && !file_exists(path)) return 0; if (strbuf_read_file(&file_buf, path, 0) < 0) { From patchwork Sat Mar 21 09:21:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450773 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 E95AB1894 for ; Sat, 21 Mar 2020 09:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC8F520753 for ; Sat, 21 Mar 2020 09:22:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l0m1m4iS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727160AbgCUJWV (ORCPT ); Sat, 21 Mar 2020 05:22:21 -0400 Received: from mail-qk1-f173.google.com ([209.85.222.173]:42622 "EHLO mail-qk1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727110AbgCUJWV (ORCPT ); Sat, 21 Mar 2020 05:22:21 -0400 Received: by mail-qk1-f173.google.com with SMTP id e11so9791999qkg.9 for ; Sat, 21 Mar 2020 02:22: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=nbK5JJ+rVte9qzemA7w3H7vu9iGm737vIQwcsQLzN1I=; b=l0m1m4iSuEP/OgvYcW5c1WrXJqra2ppPdbPrDzCiZbabm78r0VzlBgZApJhZpbKLTh 7O6iye4WdLPzlZ7yK9yr4isMUvA8Xl4qg/QachDV/CgNWZ2SiMpMHn0Tr+nrGslojr3c 1FnAAmMduIIgYaKG7T5Sx7LA0/iwhKTDPIECXNLj5DplqjXOpX6EuFBBkcB1hoPU5idr 2wTtnfCYpLVSR990Hudnn8d3R3YdPaNlSKAIpo+w9GJ6vCvvKh1OHy5YJmwch6S5K5Am xjonSyCABdGeBvvHpqWkENgN7e/I2OyjoZTCtOUqJ2wv5yhLtX/WzvRa1oNDEy52g35v ZWWw== 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=nbK5JJ+rVte9qzemA7w3H7vu9iGm737vIQwcsQLzN1I=; b=HdYT55jyzbxVlgetFzL85H2QhoJ17c7Lpc/U+o2bceZvyUy/gVo9qZJLF5rDKh3sKv YdZAIyD50ITtcFNVlREvrV0qDV+fgYt6CtqM9xUG98pgEoUsUgwyzFP+kHLs6LOBhvb9 les1giWvOpDTw21O31PzsYvjBj7QE6Svr9D3EXAmCaV9PMmfWS+TrS/T6PeQ3v36Nmj4 HCvzglXuaqjBGYXU+WBcVhKMuH7IBnn2t7xezeYf996P3uOKFQFlAdTGwaMB1vQeuUAY cAlIv4zw0gn3fKhIkq2ua9lk8xSJu57muxF+36pAlN+VbpcVHUDZ0YiRavUEKWFvaVdJ l7HA== X-Gm-Message-State: ANhLgQ05MjcgQr12CGAxMT3Mdbn452UXlyNWcYJIe8CUNLYUw/kKkxVI 1MJGA6KTAQOMDHhjCCJfIl1seSuE X-Google-Smtp-Source: ADFU+vvK785FogmySlmd4hMgsiYunKXBTJ3k3myz9yJYFvw5l35IFJlMmNohhbwcffJQ6MZf67nSUQ== X-Received: by 2002:a37:9d89:: with SMTP id g131mr12332694qke.166.1584782540160; Sat, 21 Mar 2020 02:22:20 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:19 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 06/19] sequencer: make read_oneliner() extern Date: Sat, 21 Mar 2020 05:21:25 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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. 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 92e8d38290..c2102cc2eb 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_NON_EXISTENCE (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 ret = 0; diff --git a/sequencer.h b/sequencer.h index 718a07426d..5c9662a60a 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_NON_EXISTENCE (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. + */ +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 Sat Mar 21 09:21:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450775 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 1EED81893 for ; Sat, 21 Mar 2020 09:22:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F0D042070A for ; Sat, 21 Mar 2020 09:22:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tZwCQPaD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727233AbgCUJWX (ORCPT ); Sat, 21 Mar 2020 05:22:23 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:34458 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727110AbgCUJWW (ORCPT ); Sat, 21 Mar 2020 05:22:22 -0400 Received: by mail-qk1-f196.google.com with SMTP id i6so750198qke.1 for ; Sat, 21 Mar 2020 02:22:22 -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=BVUCGP0h63x/93nH/Byok+kuU1ZmeApiq/kH5F0BVso=; b=tZwCQPaD7JrdQDtg+JL6N8kn8YLgK3D1mZ54NnyJFT/zUjhtUa8IgXgERFujlwODga A7vhLk3KpH02DthyN1X75YT33EpxoF9HF4krWaFYKFSX++ZFm/mNf9XPXdTa5OKqlshd PpIMmyONnIFB0jDJMh+oghYdAHImX9r5weSNmBHmz82czFMRFu2nqlekTl1E3uQpeeFv UdekjSn5nkO3wLH1l+5n1OMHnEUadIoLaVpDyFhrpqLDzVXA7PXlEXMKAgnuQlJj5ZqO QN3EViIgKjqjsn/YAEAuGJv49V2PiUu/QJzQA+lBZjSxJykQV62mDdrrNJc1mzvlN48T pSvw== 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=BVUCGP0h63x/93nH/Byok+kuU1ZmeApiq/kH5F0BVso=; b=Krgm2ITT7Ne1cRiAH97LDf+a0eDOxemP14IZs0Wun5zp3CtiWnbmhWXWAK0xq0jl37 8CIkRWxEGB+VkbzscD+bLO1J0DIT6KOKCHViTkm8b409LMV/TTBM1U3vq3YZhbSRxiEv qMkJUxThrTEGwiixd0/B8sJFZTZrHsDQ50/Db/SE6wl34YYdDon4GFNRfaxwW5O38vzN ZqIsArYqxPLmAx4MabQnv7mYR2ts6Zuuc6xT7gy+DMcXU+QqTwlWO8sdq3P2mjWpnk6b jCkIBz4t2ttTI0SaljULCPi+vNOyA7nDqqYnlW+h4/XtsMiwha1jhOJWvftma7K1cYia C3kA== X-Gm-Message-State: ANhLgQ2so/CgFU9NOWjgNzz1rAkYGQkpe76SQ0dsfLHhjhsh56RP8SNB d41x4aJKMCEW7laaEiBfOjvVdlQ1 X-Google-Smtp-Source: ADFU+vt281c5ZTd9FOcnlpjOORL912lDoTYSCtpHGABcWl+ytidK49/fdq+OKNK9Y9cUgPKwWGH2/g== X-Received: by 2002:a05:620a:15d1:: with SMTP id o17mr11455702qkm.457.1584782541253; Sat, 21 Mar 2020 02:22:21 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:20 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 07/19] rebase: use read_oneliner() Date: Sat, 21 Mar 2020 05:21:26 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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..1146463099 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_NON_EXISTENCE) || + !read_oneliner(&buf, state_dir_path("onto", opts), + READ_ONELINER_WARN_NON_EXISTENCE)) 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_NON_EXISTENCE)) 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_NON_EXISTENCE)) 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_NON_EXISTENCE)) 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_NON_EXISTENCE)) 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_NON_EXISTENCE)) 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_NON_EXISTENCE)) 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_NON_EXISTENCE)) return error(_("Could not read '%s'"), path); /* Ensure that the hash is not mistaken for a number */ strbuf_addstr(&autostash, "^0"); From patchwork Sat Mar 21 09:21:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450777 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 6C97817E6 for ; Sat, 21 Mar 2020 09:22:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B43D20753 for ; Sat, 21 Mar 2020 09:22:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ViA0Pmw9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbgCUJW1 (ORCPT ); Sat, 21 Mar 2020 05:22:27 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:36985 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727110AbgCUJWY (ORCPT ); Sat, 21 Mar 2020 05:22:24 -0400 Received: by mail-qt1-f193.google.com with SMTP id d12so4848146qtj.4 for ; Sat, 21 Mar 2020 02:22: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=SrEUjfSMPCZuP6l6Bg3aCTF9UDmgU0T9O42moAZVIC8=; b=ViA0Pmw9oObQBtucuijLplMDUUzHQRyVfW36LKf6EyVpi4S1AeVGZ0p94AMHyxgj57 INJMYW1dx2gK0pCvXQV3QKCoPAOgujy9ETkbjab9KvW187CvIP3BqjguhF1uBYK6jaOE OZsFNsDodu6ZsgGUscJepXZZ22vPiv4B8A8aJDz0DQ4yS7seN6hKyJF4O6sv9Y5Z7fJn DM44ztN+RnK5Hpocry6xAT2vSN7P5I2lzTVOqe5dAmkKx3JSL7r4Ztbo4sYlBpT+Xp4T m+x4Y/F5YtVsQlQRBTjBFpn5FhKOCXgNcn9bFYkdmRIGYHzMugl5KydURirmAUE2pKXS jygQ== 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=SrEUjfSMPCZuP6l6Bg3aCTF9UDmgU0T9O42moAZVIC8=; b=Tvi1pRXnjAhAFy7qwvwTxvbQdc6SuQ57h/1OnrRpCvGTThCexqTfN1JXxuXLmFjzTQ aUOjWQ434G2y5ShoSIs9eSLE1Eoew/SsqlZNkF5Ervko0TAnOQOtD/diRodene49fwKB rOmdI5lMqmE8ZHdUEszl+5aAewudytZem2ftpRko+t7SHylmYEsc7+ffUto7WWy7GC2T NJH59rFb877vQ2BfJSNdsBg9B4mSPFaw7U/xQUE36xSdSt/cl1bu0av0Xv1rjmDZABGy txIgly1Qa+nTqWKtrVgmD9UyMVIC80WWsINYfXy1aBuPbK1qH+c9tYkIHIh6JmnQ6uk4 zMuQ== X-Gm-Message-State: ANhLgQ0PNvqaBgFImVfwHthnVFSmiOZizENq2yLqyhxoGtQEpMKI1vbS PqJ0RzFYwC3cCGKu6k0Qwmz19vI1 X-Google-Smtp-Source: ADFU+vsccqa1kmGgwKdFUuLjIlngJ1cVYVRclzi74YLCuToa3SMwArhk8MCg8kAYSE9LWJxH3xjWkg== X-Received: by 2002:ac8:4e44:: with SMTP id e4mr12115648qtw.313.1584782543313; Sat, 21 Mar 2020 02:22:23 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:22 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 08/19] sequencer: make apply_rebase() accept a path Date: Sat, 21 Mar 2020 05:21:27 -0400 Message-Id: <5bce4aeb96f21d39677a735e6fbdd42f7405d28a.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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_rebase() 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 c2102cc2eb..ad40a8b3fc 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3655,13 +3655,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; @@ -3754,7 +3754,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")); } @@ -4068,7 +4068,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) @@ -5077,7 +5077,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")); @@ -5088,12 +5088,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 Sat Mar 21 09:21:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450779 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 95D7C1893 for ; Sat, 21 Mar 2020 09:22:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 73FEC2070A for ; Sat, 21 Mar 2020 09:22:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jxky0aZZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727387AbgCUJW1 (ORCPT ); Sat, 21 Mar 2020 05:22:27 -0400 Received: from mail-qv1-f65.google.com ([209.85.219.65]:37753 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727290AbgCUJW1 (ORCPT ); Sat, 21 Mar 2020 05:22:27 -0400 Received: by mail-qv1-f65.google.com with SMTP id n1so4460933qvz.4 for ; Sat, 21 Mar 2020 02:22: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=YvtwJLP5tteu5dpCHs0ngn7N49g0vhrSuG1WRaxIPBk=; b=jxky0aZZgTk7OMfJDi/1r0wCZIV6kvXxridI+Z0u5sasniqoIQ8uhogvL4w2Yxsi0N GW7J2sYPnCiXnQdsyyZqiQyxXhwkCSpRH1D/C+LaxlMjGgqgsvin6Bwmg1daaFMXVBtA cgv0oALaqYUJHkBuomlOqrtTSVWGZvudVZwyqknjfd1Zg/D0g/xUDQ8yndhUj36u9Vla cr43WspDUlLRxXU+dy4tHO/gKckt27TkicwtAZoqZvPoH/crwlDsDld5ANbl8MnyYf+z WBm8K74J8WDiSGrn+0lk8uaVPc3rY5fXtXu5ar3Fih/LiphbFsh6N3SBYJ9+7P0xdCEP E0Cw== 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=YvtwJLP5tteu5dpCHs0ngn7N49g0vhrSuG1WRaxIPBk=; b=SZsxldqGRpKnkSjYCDjMlaJZeXFIgdwmyDvYl8pFgwQohARHQApfI2ygl/nl3mLITI zBhiG5nQFNuWywqwG0K/BShbGaS7IsevPRql/ng16J19NJIDKKVsRz8BWwlm+sWpejhb Q0KWkyrK0Z1n7rUWUD9anYMkezvX1z+se6sITRWHNBbKYoBBMrWBo43nXC91FKdnuhIB WPfrf2sy1aucGtHdoyYotWHHF3lSZWzkRLlaWP2CzJStL793KwXz8dXK7d5TVzBRJjGg o429vAdu+EoFy4dvIpOpO3jG8HZUcXKk7SQ6yHBG/O+YdKY+QSvsInh6Qao647jWE9LR L0lA== X-Gm-Message-State: ANhLgQ0FZsbh/ahylthKJ8bO50Af2VFtsLeauPglbO5n4N2E9krr9SVg ntG3wQpC6DHfJ6Hx8Evtafu0/uk3 X-Google-Smtp-Source: ADFU+vvfqUGCMcYeF+yIA3+SsFBuFFvzxC3+XQTf1lZdZOK77AYe4EOnigZxjsHjxqeNu+UVn3LzRA== X-Received: by 2002:a05:6214:68f:: with SMTP id r15mr11824750qvz.96.1584782545191; Sat, 21 Mar 2020 02:22:25 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:24 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 09/19] rebase: use apply_autostash() from sequencer.c Date: Sat, 21 Mar 2020 05:21:28 -0400 Message-Id: <03bdaeebc993058bf14a0d196f5a1a68800e538e.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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. 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 1146463099..ceb115247a 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_NON_EXISTENCE)) - 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 ad40a8b3fc..b52668f8de 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3655,7 +3655,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_sha1 = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; diff --git a/sequencer.h b/sequencer.h index 5c9662a60a..bab910f012 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 Sat Mar 21 09:21:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450781 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 A60D292A for ; Sat, 21 Mar 2020 09:22:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 708122070A for ; Sat, 21 Mar 2020 09:22:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZnPi2qxV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727438AbgCUJW3 (ORCPT ); Sat, 21 Mar 2020 05:22:29 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:41294 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727110AbgCUJW2 (ORCPT ); Sat, 21 Mar 2020 05:22:28 -0400 Received: by mail-qk1-f195.google.com with SMTP id q188so4508765qke.8 for ; Sat, 21 Mar 2020 02:22: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=bpp2JCFebKJpkKs8nki9F4yxZSl7gSPjlkoH1MU/e6w=; b=ZnPi2qxVwsaCVdzPq53LwhN31ebkO0EUMKGvzBDcmL+ylLo133b24OFSmocpyhctXu Suevfsi1dmLkH2I1z7s1Zn6XXvVFzPYRkwFbL3FbmXDcZUYvF6DoCipwdnnZFWOs1E8Z N8Ikifqfz93nl+PItcLNedLsf5Y6ZaPkNQw5PZrhcRDF27i0qr+k3CUKSMmJ2lld3JHV q8PNDPT39IvjqNNztmRMIuqrEaeJErXzrexf1wDcUEWNqTXa3BVcXNVUY54c1DnzpulX +Bft0zHqopa4Oa63Zegusl8K5C8XA1Clm4+2gOErN44ScbSjh/+jEB4ywVyJSLZbP+Pa LVwA== 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=bpp2JCFebKJpkKs8nki9F4yxZSl7gSPjlkoH1MU/e6w=; b=WYxuRYgsOT4V2I3+4Z/R3tzeykF9Raj4+TM7AfsHspIHqoXxAhkUS85wYhoECIujHM dIJtJtbEpf42odiN4oZpQzmKIocmfkKS25NzvKOOrB+gun7M4j7d20GTjKWdbDGdxpCi AJYdqXJosjb5mD0dO0lj0lToDcp4WlYTKcaP8Q62TorwcPmMWtHf5X4UbYgpisWujfUK kOT4yXAHEVpU+QqiW0Oj0RtS7kx0EHzpFw/MyocbP4rqQxf6zdebNMno5vMXVJTfeegP SHZyfDjkLySIykLIArhTE4HJGxFbjFb9RgKMsGl0z6mQUW/GbphR054MBNJprZlY0sw+ mumQ== X-Gm-Message-State: ANhLgQ1zw1UgjY+AohlQVkMSLuJGkhBpILbdgzobjSeJLup2wKBptXu+ HVAY5YjcRUXxr5XqcusCN8vrMl84 X-Google-Smtp-Source: ADFU+vvDQQ5IqD75XIGA4JlB1hD5AOApU+J7B8aL49Be14cGgxQL1irhZEhUpl//540G4yPZgYzoMw== X-Received: by 2002:a37:6d3:: with SMTP id 202mr12136265qkg.267.1584782546546; Sat, 21 Mar 2020 02:22:26 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:26 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 10/19] rebase: generify reset_head() Date: Sat, 21 Mar 2020 05:21:29 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 ceb115247a..52eb45b6c4 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 Sat Mar 21 09:21:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450783 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 6A5CD92A for ; Sat, 21 Mar 2020 09:22:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2998120753 for ; Sat, 21 Mar 2020 09:22:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gIDsb+Xr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727480AbgCUJWa (ORCPT ); Sat, 21 Mar 2020 05:22:30 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:45391 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727290AbgCUJW3 (ORCPT ); Sat, 21 Mar 2020 05:22:29 -0400 Received: by mail-qk1-f194.google.com with SMTP id c145so9761470qke.12 for ; Sat, 21 Mar 2020 02:22: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=VBoyaYZcQpvDEtTUReIU0njJxA1ES6fXT6VXIGojb/Q=; b=gIDsb+XrXbI/EXyPPalsOBpZKqBPyEoNtBDed6pZh+w8re+cs8QYTjLke4U07q884a EEcDBiIhcsreWqjIQBC0VmMfFpXm0u7paqGbTL8xmWiuoQ8DRYdg2hPXQqdrnbsi4bzZ AbN1mTHU9RV5nz11/RON/D5GEufaQU7UIsbElHXuV48LVkAS8E8iB7yYNwqn8rPfqOui RpmcmF1GvvaFlGm2VqU9MFrhXP8wyNX1MTpf6lZqxaZikd4pgdrCJLRU8vrzMnNXxbLl hD/E0hhGbs+51lyGhlTghAdVRGDRqnGoewo1BSjC/wn2lCJ0WWtFW3HT+ix1TwwrXwjy 1SYg== 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=VBoyaYZcQpvDEtTUReIU0njJxA1ES6fXT6VXIGojb/Q=; b=pccLt2UI6TCaxoLO3zp/41fcErLRdQHHY2XZJmRnO7ZWG5PwuHOWfL18hXE+rc4Me4 xrJasoSlEqATLWtDsKqc6e1f6GaDD9ktEpd6gBMIreubgX0zn+EqpYsslVd6ik759Gb2 ON7MhNf7PYcbG2cEh9EVseQCaTHdsQnmH3ULsew5a6soZ3wIRrnzh2egDQyO5TackuhB bGrqm8t1ZEZtg3nfWjBvGm5tIPFQffNHH8Kmk7t0DSRUTTIYOJjKmZz2aI7fCYONDTmt nKHUoE9dSKbFaFJGx9pcYQwSlGgfbO/2bnw5F9CBl2ouJ9qWvYP6ottfiJHG/VZjvK/9 Vugw== X-Gm-Message-State: ANhLgQ0EAHr1Zom8M9n+hJD9eWUDpbOm1LXhJWvTdhn2pjGEPOm0WXM4 A0ekCwr3fdhwI9lRF59l/HccevDs X-Google-Smtp-Source: ADFU+vv37aSvpzuFj1XWc+pzBRX/Kr3Jq1GNbW4z43HA467BAoZBb/9ib41MWTVTWYnznKMLu1hzAw== X-Received: by 2002:ae9:eb12:: with SMTP id b18mr12369600qkg.168.1584782547792; Sat, 21 Mar 2020 02:22:27 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:27 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 11/19] reset: extract reset_head() from rebase Date: Sat, 21 Mar 2020 05:21:30 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 52eb45b6c4..caff67b00d 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 Sat Mar 21 09:21:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450785 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 CF37C17E6 for ; Sat, 21 Mar 2020 09:22:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ACCE520754 for ; Sat, 21 Mar 2020 09:22:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cKtzisJo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727642AbgCUJWc (ORCPT ); Sat, 21 Mar 2020 05:22:32 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:37316 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727290AbgCUJWc (ORCPT ); Sat, 21 Mar 2020 05:22:32 -0400 Received: by mail-qk1-f194.google.com with SMTP id z25so9826346qkj.4 for ; Sat, 21 Mar 2020 02:22: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=KQzYfZfGitMPy9DZUivn5OQoLOpLrKzCQmzmrSedqUA=; b=cKtzisJo6zMVqgC7jCQlrridayfBo0lWDpbFZ5NXE+ABGjex9xp+bF0sidsJETJYgr zpR705pooU9DvSsO8UTgw8VsBwJkT39TLhDuzcfMKZxSXin0gm9N7JBKRgjn44WyngcN WmLoUPAaGQNmhujKq6vA5mPkIH6uxBoM62C0LtQ0YQtPYuE5ZcZzWFU85aVV0BV7lzTv cF97xLIrIexWlzI0PHGkL5hhQbRQYoUUDoN+UaPh/v1Rmp3/B/k/LP/Zz1dzuqO5pJ9v NgLXFrdFu+xRof1nHl+yVZ4I6hHGCEQZeYJjaBfJK45tET6vOiiu3QyKl5lJFA8CwaUw RF3A== 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=KQzYfZfGitMPy9DZUivn5OQoLOpLrKzCQmzmrSedqUA=; b=prXhh9sVKZc4pt5NCg5ghq+ceLlwiR7ZqySDipBnJBC4Vz4K/NcPErfQLkAgk+GMS6 DIpF1CuL6zF+8qqzQGxe/Z6uTLg+LFUSGp9irBWL97UWa+d3ju7/5IGnZplGiFVCGeja Mkkch2LFerdDFVfpW+PbEejLhsiIl0Dd1vosTeXD+y62b1a5NC/9hBvY2O2dFKFl8Tdf NDcnSmE2SEjNLrSEcIK7lB6+4S9gVCxFuEeL9LlhHg8oiNB3eM4A7anjeLXO23LRT1mh YvqXPR6pgsBmFZYwB7drpG81Can5l5Zk7bMGWY7CtVLq2KjSSWlPhQf7TRlPu9++jdUq 9IhQ== X-Gm-Message-State: ANhLgQ0oHSh/euXz8CO4ZDWDAb4WcMfuZfJSGK+IN9ImE4xrnejht4tw TOyFPIxG3CzAhta+fUA1yiYxyGnT X-Google-Smtp-Source: ADFU+vsnwsxpWtwJamdkVohMguqeiJmqYCYNlj+EW1JbWlsS166iJ1RxcjV58owLIbkHYGNg9+EILQ== X-Received: by 2002:a05:620a:1279:: with SMTP id b25mr1640871qkl.481.1584782550322; Sat, 21 Mar 2020 02:22:30 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:29 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 12/19] rebase: extract create_autostash() Date: Sat, 21 Mar 2020 05:21:31 -0400 Message-Id: <1dbae3dfbf0a9dbd0ef68d8788771b7dd04e7d0c.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 caff67b00d..037effc510 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 Sat Mar 21 09:21:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450787 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 01ED217E6 for ; Sat, 21 Mar 2020 09:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D332120753 for ; Sat, 21 Mar 2020 09:22:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lOIxAxIQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727688AbgCUJWf (ORCPT ); Sat, 21 Mar 2020 05:22:35 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:44048 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727290AbgCUJWe (ORCPT ); Sat, 21 Mar 2020 05:22:34 -0400 Received: by mail-qk1-f196.google.com with SMTP id j4so9762342qkc.11 for ; Sat, 21 Mar 2020 02:22: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=k0NxTigZ7S4/0pb8spV/wk3u0bSd2dMtokHnQKs1ut8=; b=lOIxAxIQ+d8ngedlfoc5yXI0/2hnGijDSrX/8GbUI8LvthI3g9M+BrJGo0cM5Sec75 yVVLuDJnJPigjLMje+jde0JOg8i6ibxrGp3ZAVqkduGMYuP8td7k1l32kZgJy3hfYUsO RoI8NdeeBxj+2AP8v+VAXj9coI1tzqWQTJCMHYgfs9vPZcGCU4GhSMgm4hi6HkfxJ40G LYKag0Srz9R1huQEa8lmIvnMPg24pZ8ALzkGIIbo29vG8AbPaBr4SizUaOepeGUDJh39 Wb7eazH2REiD0jEumaTZFVydUZ7Z5lmhiIVJBwycm4Rtvv1ZHKhzAekT+3N/ThnIocW1 9kwA== 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=k0NxTigZ7S4/0pb8spV/wk3u0bSd2dMtokHnQKs1ut8=; b=p5uohdQotcmV6OKiuUXd97d+1YRBbt0WLWCrKETZgvQtTzuJMp89BJfKnkjuRiOuCV 8jZfBwZ9eGYyRrWuovV3Qt/LGhEE+kLIcZ/Y0QiBeLCJFDNeykbxMh7+1BFLqR8QjIF+ JofJb0/Is3ZmaE+ebIPQ2RVbFRwgYTLzpx80ROo2ke0bWQ8OeBw3pBpSOFjFx+aEpPHd gfZ83NKOlXHxBvhrT8WEoPabMvWvdrvQO0+Pcx1Ly9wB5Lpecn3PyC+aJgI6+sjj/ojH 5od7JunGm5r3Ttc9eEQHoNjUsdnFlhzGZdk/OpnVx3XZPh7b0gPPZ5bBbJAsD081iiC8 GJYw== X-Gm-Message-State: ANhLgQ2CLDmvlKo9ixyjKxaCxgmvvVhK1Fomc2uhnGRgtntdA6kGqZ1C ggvv8BbIi9UUfxoI247AiaPb0HoU X-Google-Smtp-Source: ADFU+vsPE7/N+iWmUTJwsl4PFbOMDHWQPIry0amorZk0y94rWk+qMy18sl21t/iTItE0lkGxSEaKGA== X-Received: by 2002:a37:4b86:: with SMTP id y128mr812704qka.95.1584782553332; Sat, 21 Mar 2020 02:22:33 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:32 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 13/19] rebase: generify create_autostash() Date: Sat, 21 Mar 2020 05:21:32 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 037effc510..3370c8f2c4 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 Sat Mar 21 09:21:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450789 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 D9BEC92A for ; Sat, 21 Mar 2020 09:22:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC45420754 for ; Sat, 21 Mar 2020 09:22:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OHP8K+Bx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728008AbgCUJWg (ORCPT ); Sat, 21 Mar 2020 05:22:36 -0400 Received: from mail-qv1-f66.google.com ([209.85.219.66]:35942 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbgCUJWg (ORCPT ); Sat, 21 Mar 2020 05:22:36 -0400 Received: by mail-qv1-f66.google.com with SMTP id z13so4473524qvw.3 for ; Sat, 21 Mar 2020 02:22: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=pzbZ3ys4Y1U3aFmYFRHczPO7oubpzxQSsBh9CTMSZcI=; b=OHP8K+Bx4GinS4FNJT/RNpQybw64h2I44XXWNFUUAQcv8Rf3Prf++PIsF9X3lJ0Zb2 5qhn4UhIW9CcNwRAj+uqkQfXDwDdpQ/0LhvezBCUyWVNUBaXi5mxYKmpv2xvBmtv2BYB OoxR51Wm0zrZnu37ewUY5p4RXM9V9hojdQs/pAZmT6H8MZw5wLXoI7P+Xxrgs7heaEY2 SWp3UECPGT3O+6jBBxfTI/CwJUabzwosdzJLBkXxHWiX+ag2RAVkR5Rrcy+JL8ZkJc0+ DZPFk8to7qULANfNX4H48CeMZe5WdHW86tYChby6/kpYvu7XeqrB86T5td39en/zhUw8 wG6Q== 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=pzbZ3ys4Y1U3aFmYFRHczPO7oubpzxQSsBh9CTMSZcI=; b=VBDceso8qBApDwynYH/QqeSmFCtROGNCQAtHu9uP+BnaxKRzuJIck9RXF2idUURNZ6 qox8pVgq+dSsNDE87NzcTbriJnzLLHucr2PcL1rRlluMb5tQ1LdybQIueu2eEQbpLIdL 7mleoPtdtae8Zj6Mca58ygcOGM/c6aJe1r9xJDrc2N3NMm7qXUNCCut6aw/p9LScj/d2 BbNPtdaIF6fCeM3FZYxMmWQz6roqmufq2rSeVG4q0/Nj+oX571dY+ZMyk3p1AsiGf0k9 oj9MjO6fb5D3CAGPnvUnvEpgOWVCyHMN+nklP29CkKFnCKH735kfFAGzks/n5NvET9i5 ANbA== X-Gm-Message-State: ANhLgQ3ugjTfGF8IIhRp9g3Xt3msSyo4t/dTVBTO2Lxhx83M/qAoR5lQ ysx76QnMY7VeBKXmdiQaZo9jTAMI X-Google-Smtp-Source: ADFU+vtTUJDaXlhhVdM6NVWmdWXT4HXfWOuJDBL/uLFj5+RpL9FD2HmBtWGWK4d1BEl7jEAHNyki9Q== X-Received: by 2002:a0c:aee5:: with SMTP id n37mr11679367qvd.173.1584782555219; Sat, 21 Mar 2020 02:22:35 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:34 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 14/19] sequencer: extract perform_autostash() from rebase Date: Sat, 21 Mar 2020 05:21:33 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 3370c8f2c4..b6821be62b 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 b52668f8de..b2951843a1 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" @@ -3655,6 +3656,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_sha1 = STRBUF_INIT; diff --git a/sequencer.h b/sequencer.h index bab910f012..44ecfee7f3 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 Sat Mar 21 09:21:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450791 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 9DE2E92A for ; Sat, 21 Mar 2020 09:22:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A43720753 for ; Sat, 21 Mar 2020 09:22:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cE/nXRha" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728052AbgCUJWi (ORCPT ); Sat, 21 Mar 2020 05:22:38 -0400 Received: from mail-qv1-f65.google.com ([209.85.219.65]:34588 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727831AbgCUJWh (ORCPT ); Sat, 21 Mar 2020 05:22:37 -0400 Received: by mail-qv1-f65.google.com with SMTP id o18so4459105qvf.1 for ; Sat, 21 Mar 2020 02:22:36 -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=7NumuQO/ly6xOJmPf1n0dPzmvz7xqlc5+KcTK5eRjVA=; b=cE/nXRhazS/qL2ktsSfvAW0iTsyO6OJPDZB4F9cjJgcQ/FzuOgwT8m54wFS91lfPDL l7wfhZdGT/7kWePICUCHMIs9nRLuuAlH6uQAFwpKfpyITjKvTYHro6g25zwu0WSpRLqh 3+Ffv1+lWRuNxGd6zfm3ieFcsmBmPLcqsgAn2IqqDBYb7Txa+KuM16bf6tlow7u3uI8m CSN9gYMwa2OmPktqHqYCqPX1fdQe4m/7DC6lsdS+EPD5srEZf8GrmWirMmW60ZkCJrCc JhSU9DaGk5Tzd6PPiryo5C32ujWdENBqg7TgC5eX5PmcJw6XpyRhqFn+rBjA6ir7hUzS m/tw== 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=7NumuQO/ly6xOJmPf1n0dPzmvz7xqlc5+KcTK5eRjVA=; b=IVHJYsbmeakmWKWq0rlrTiqgDhhwp9C6TNBivy8UrPnODPMCQnnkUVSCjvftoCCfGm jgwL5bEite8zsQ5lRJ3mJclJO1R2/wphwwe2pvokHQsSVfDsMasT3HxeZVvZOIQEhTQs wolwCclEFt4pVcs2CPU3V1qaOGlR94vo1IwFmaS1lA8+JM0iwAzQvWTo/W59nJuYKACD mMIKd59SIcf45nztBIFfOjfo9i7D5LkpPNEojoWBKNoeXg9ZZkcWLOvMY11wr413NMoJ Kz19Zj4JagaGSROSV7BXzaGyNYfUPNfJMismqy43+30YTF+q1Kr1kcN3D4sHMyrP/ok6 ZQDg== X-Gm-Message-State: ANhLgQ3rIAb9YSrK5HhfFYCAWg/9L+xIRIi8JpgYGnS1er3uXN3bSZub 65y4TwNO8OYKU3XWF8RuTgU6s5y1 X-Google-Smtp-Source: ADFU+vs1WS16pdkBdop/zHmipZ6Ctoo/u7Ohlgvr9ZqfQFFaENrrknYgvp/j4MPO0r36wCznLHMUgg== X-Received: by 2002:a05:6214:7e8:: with SMTP id bp8mr12052762qvb.243.1584782556287; Sat, 21 Mar 2020 02:22:36 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:35 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 15/19] sequencer: unlink autostash in apply_autostash() Date: Sat, 21 Mar 2020 05:21:34 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 b2951843a1..81b6c700d1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3746,6 +3746,7 @@ int apply_autostash(const char *path) " \"git stash drop\" at any time.\n")); } + unlink(path); strbuf_release(&stash_sha1); return ret; } From patchwork Sat Mar 21 09:21:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450793 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 1630B1893 for ; Sat, 21 Mar 2020 09:22:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E704120753 for ; Sat, 21 Mar 2020 09:22:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NA7C/Q5W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727011AbgCUJWk (ORCPT ); Sat, 21 Mar 2020 05:22:40 -0400 Received: from mail-qk1-f171.google.com ([209.85.222.171]:40700 "EHLO mail-qk1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727831AbgCUJWj (ORCPT ); Sat, 21 Mar 2020 05:22:39 -0400 Received: by mail-qk1-f171.google.com with SMTP id l25so4930155qki.7 for ; Sat, 21 Mar 2020 02:22: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=zd+xNZq96Ta0A7aeOjKKd7jSrggp1/DrPjRs3WY3wic=; b=NA7C/Q5W8YV+PvnSR60HKVWpFBX09oo9IfMXEcGKOqAKe8zmxarXDV0bRFF9vBx603 GI52GcWSveRS4MiUU9cQZzTt2eAD1ID6ijsVbA3+33IBMlEhEBFgm67fKQXPRQGMrPPb 7E910NBhmkDTlLHZrnneTuSOPVmGJeYRcgAzYOCBdMIdRGO4RBy16cCVpwX5OhK2vF/A +k4eQp1EP6SzLGqw4WDGM+QKwFaHfxp0n3wtyaBUGJ4eji1GzT73qFb9wZ259V5dQzov wnBgkhudjxanP23aoKXwBhbt/jC0T4kv1IIZJ+4cq7MIFhbI0/faYqGW9/Z1LvMVgM7X uAgw== 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=zd+xNZq96Ta0A7aeOjKKd7jSrggp1/DrPjRs3WY3wic=; b=q/PKPp633ydRHuYifItxY1eSr7/pNf1NiboGS1CFrrqB18ZjXQjephu7TdEjjHejAd buKm5BCINCEebQMbqRjgH/wNPgDYb+QwylP9QSA4HzyCwtToe1I4IPcNxJzJ4OlnQqjM DsF4jt8FuZz1dk305bHNGiHA1vshh1ZM2j9Yf5zag82YArueYFUZ0dPEY2fC2rxtJoic LKqGDEkAeVK8GODRTVgDD3ZcpkFDDXq9PxxreZyA8CQwjRBJu6BevRfzyGYojAAVaSah eZvhUvSi8/eiC+DdnPHoHduPe+MsPPcNuNKVepVFK7JASilKlvLUW1fl9AOJOt4SCnqO iFEg== X-Gm-Message-State: ANhLgQ20EFYyzplzULvMajjM3GEIdcDSV/slNFtreBKoIr3MwppCoALt 9WCmcdkXpCijC0Oe92FGV1KVzTLU X-Google-Smtp-Source: ADFU+vuCyEFG3c4zcOFuUe2reF0+oNQa9M98pNLFr2UJn+kcXvhPQ/xsdGeZ6QimIjztTrI2uV0lcw== X-Received: by 2002:a37:4ec1:: with SMTP id c184mr11928287qkb.0.1584782557931; Sat, 21 Mar 2020 02:22:37 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:37 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 16/19] sequencer: implement save_autostash() Date: Sat, 21 Mar 2020 05:21:35 -0400 Message-Id: X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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. 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 81b6c700d1..d67d47b332 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3705,7 +3705,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_sha1 = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; @@ -3718,13 +3718,17 @@ int apply_autostash(const char *path) } strbuf_trim(&stash_sha1); - 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); - 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_sha1.buf); + ret = run_command(&child); + } + + if (attempt_apply && !ret) fprintf(stderr, _("Applied autostash.\n")); else { struct child_process store = CHILD_PROCESS_INIT; @@ -3740,10 +3744,13 @@ int apply_autostash(const char *path) ret = error(_("cannot store %s"), stash_sha1.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); @@ -3751,6 +3758,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 44ecfee7f3..1cb0e4e4b7 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 Sat Mar 21 09:21:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450797 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 EB56192A for ; Sat, 21 Mar 2020 09:22:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5D8F20753 for ; Sat, 21 Mar 2020 09:22:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YBDKWhcY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728207AbgCUJWq (ORCPT ); Sat, 21 Mar 2020 05:22:46 -0400 Received: from mail-qt1-f171.google.com ([209.85.160.171]:41725 "EHLO mail-qt1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727831AbgCUJWm (ORCPT ); Sat, 21 Mar 2020 05:22:42 -0400 Received: by mail-qt1-f171.google.com with SMTP id i3so3452550qtv.8 for ; Sat, 21 Mar 2020 02:22: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=CNdOaSMMTCA3LGdEz/bY1DoeHx277DFxc9SvKmOHQ20=; b=YBDKWhcY8MnF54YqvEy3+yXHnx6r6wggua8oEjvpJeWMJXxUE5pTIxv9l9MapV671j imW/kl83SuAzjZeSILlqxljpDQqODk4H3amZmVF8WaswDYnUVfOFLcpl40TQ0779B/WH ntUZICxpRHrO4XmW+DvPGGjmH30W6Kg46MDKaRmUA7OqCaqvXfP6gJxjIIfszvlDXMZt GDwseCF+IYcaFsK3pxKhR6SNp3TVMV2DED6UOF+3kJPbiK6CZ0dilIQCkdXkvAbCEWL7 y9OPiz4s9jZM4YwqqR61Q+ydyPDuzxmRd1nBT17bWn0Hcd5lcm1yL3NZ8ECNm8aDy65P lA+A== 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=CNdOaSMMTCA3LGdEz/bY1DoeHx277DFxc9SvKmOHQ20=; b=gqHhcz7y2ViN/hE6SkA0DmlxLnox6uRRO2i3jIoyvGRaFfLv7G3v844r4DkoyGvFFn WmjBwoNHEHGYSril+G+cHtt4Y25xp+qUwv8STYg/kayEBG1zobY3VuvzfHoVS5HtvceI eZn8esz2wct50wUy8aRh5wYqSBAsBrhTqPadH7VQ+fkWl4FQgsHEWgLr2uNia2JFMd3b I+by+fWiGuTmQ3QUpdPzjBbgZv1V8XrDlT07Zydp9rm2XEtuLAYGd16Ki2LMtswr9Dql iwXsmHWAu/FcpxmEgFBwvHYsuAVdE6uyGnCOJ056QliPakhup5qLWbnQcJUk43RDn61x JvUQ== X-Gm-Message-State: ANhLgQ2vFLQAQ2mx9y2JSk+HuQjxNN244SFdPlPvdi6+/zz7h1Wp06An pnc2HGKoT7RqMCl3Tne0JJXP30Rt X-Google-Smtp-Source: ADFU+vv83gJOuF++ez+9V+7oJmv2g4z2gzrD2f0pBhPu47Iq2ASXBY46zpNuVTpUijANMKAjtuk9yw== X-Received: by 2002:ac8:175d:: with SMTP id u29mr12602704qtk.150.1584782559772; Sat, 21 Mar 2020 02:22:39 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:39 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 17/19] merge: teach --autostash option Date: Sat, 21 Mar 2020 05:21:36 -0400 Message-Id: <9e3d4393cae8813cc4718c6ffcc28231b1344fbe.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 `git reset --hard` is run to abort a merge, the working tree will be left in a clean state, as expected, with the autostash pushed onto the stash stack. Suggested-by: Alban Gruin Signed-off-by: Denton Liu --- Documentation/config/merge.txt | 10 +++ Documentation/merge-options.txt | 8 +++ branch.c | 1 + builtin/commit.c | 2 + builtin/merge.c | 17 ++++++ builtin/reset.c | 7 ++- path.c | 1 + path.h | 4 +- t/t3033-merge-toplevel.sh | 22 +++++++ t/t7600-merge.sh | 104 ++++++++++++++++++++++++++++++++ 10 files changed, 174 insertions(+), 2 deletions(-) diff --git a/Documentation/config/merge.txt b/Documentation/config/merge.txt index 6a313937f8..88b29127bf 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 rebase on a dirty worktree. + However, use with care: the final stash application after a + successful rebase 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/merge-options.txt b/Documentation/merge-options.txt index 40dc4f5e8c..34493eb58b 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 rebase on a dirty worktree. However, use + with care: the final stash application after a successful + rebase might result in non-trivial conflicts. + endif::git-pull[] --allow-unrelated-histories:: diff --git a/branch.c b/branch.c index 579494738a..bf2536c70d 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)); + apply_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..c11894423a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1687,6 +1687,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) unlink(git_path_merge_mode(the_repository)); unlink(git_path_squash_msg(the_repository)); + apply_autostash(git_path_merge_autostash(the_repository)); + if (commit_index_files()) die(_("repository has been updated, but unable to write\n" "new_index file. Check that disk is not full and quota is\n" diff --git a/builtin/merge.c b/builtin/merge.c index d127d2225f..e038bef5ad 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,8 @@ 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_BOOL(0, "autostash", &autostash, + N_("automatically stash/stash pop before and after")), 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")), @@ -441,6 +444,7 @@ static void finish(struct commit *head_commit, strbuf_addf(&reflog_message, "%s: %s", getenv("GIT_REFLOG_ACTION"), msg); } + apply_autostash(git_path_merge_autostash(the_repository)); if (squash) { squash_message(head_commit, remoteheads); } else { @@ -634,6 +638,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); @@ -1291,6 +1298,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) /* Invoke 'git reset --merge' */ ret = cmd_reset(nargc, nargv, prefix); + apply_autostash(git_path_merge_autostash(the_repository)); goto done; } @@ -1513,6 +1521,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 +1591,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/reset.c b/builtin/reset.c index 18228c312e..038c8532eb 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -25,6 +25,7 @@ #include "cache-tree.h" #include "submodule.h" #include "submodule-config.h" +#include "sequencer.h" #define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000) @@ -437,8 +438,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (reset_type == HARD && !update_ref_status && !quiet) print_new_head_line(lookup_commit_reference(the_repository, &oid)); } - if (!pathspec.nr) + if (!pathspec.nr) { + if (reset_type == HARD) + save_autostash(git_path_merge_autostash(the_repository)); + remove_branch_state(the_repository, 0); + } return update_ref_status; } 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..c08e4315f4 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,106 @@ 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 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 '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 '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 Sat Mar 21 09:21:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450795 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 D827217E6 for ; Sat, 21 Mar 2020 09:22:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B398F2070A for ; Sat, 21 Mar 2020 09:22:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ez97GZQ1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbgCUJWl (ORCPT ); Sat, 21 Mar 2020 05:22:41 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:38461 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728114AbgCUJWl (ORCPT ); Sat, 21 Mar 2020 05:22:41 -0400 Received: by mail-qk1-f194.google.com with SMTP id h14so9831813qke.5 for ; Sat, 21 Mar 2020 02:22:41 -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=0y3tn0AzmPDQf8g6L5zFVRjlj5YTOiz548oR2xGq2JQ=; b=Ez97GZQ1XDR9d1n1V6pg4MGjGo4y/0cb5EflkyBlygj9eV9iTC2VO8makpY+D3pKck oKdvm9LbKYZY9OkgqWE+xWSlG2k65wKjmU/C1qahtcGNCo11B19VqSDHnnigb8bWBmNA WovFhMmzDNWr4GavFBoEhexiUwKGuanyfTFPAm4F9bR36C5YFyAb9UJJKmqcKsaPtdbK VRKkHFaLmzxABRVjkWaDAhDyrK3YEYWdyNa2KgG9pIzxzXU1N++4cuVFyY5Dn8ASl68h FWZvGezUhZLAj0ZfDL03j+El8u03t5Fqus3tkKAl1BNOjuyS0OxExHQmoPSrsj1+HWBs Ar/Q== 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=0y3tn0AzmPDQf8g6L5zFVRjlj5YTOiz548oR2xGq2JQ=; b=k5bWZdbFyCQ1E2cWkVmlggQE/jHbD451J+a7t/IpgbQ+uAoHPTbIogDJmO0jGIjNBd V7KWlDlgsgjYm1PElLCaHGMSLoJF2AA89jPHyEBy4KlTb0ejvb1+ec6J3zuwPB/zkHCI 6nsqktUiy7oQMEhWde+OdjJmggZJ2S5TSSeq+yIMsCBiSoXT9KUcbYvp/e65hwtx6Aoz YQ8NFknvtZLq7JaaP3qM0KOD0OricSfmFDCLqN8C7n950x2+xVfHHvIuOjd2AcfUQSYa +Qwm2y2F/Z19F8W1WHTzMgc5fbcJDAo/3S/RS2ywxl/M4nsA4ybHteUd5wjqa2hoOr0s 2kxw== X-Gm-Message-State: ANhLgQ3elp7MSVLwrGP7H5Ox1pNpBOmspLew/QIFQqoDVnSMC5zu+m4X beyeSWkckOVQmuXb+1zJftMqDVoc X-Google-Smtp-Source: ADFU+vtX4xg1oLwLmf6gxKIR2fXnIeDkkvCWxfpDVR+4Fp9xxloTEV+iNppIbus1XpYy36tbEbI24A== X-Received: by 2002:a05:620a:14d:: with SMTP id e13mr12493518qkn.470.1584782560651; Sat, 21 Mar 2020 02:22:40 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:40 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 18/19] t5520: make test_pull_autostash() accept expect_parent_num Date: Sat, 21 Mar 2020 05:21:37 -0400 Message-Id: <72aa56516efaf4e58c271da362ff157bcb8a9550.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 Sat Mar 21 09:21:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11450799 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 A2F4117E6 for ; Sat, 21 Mar 2020 09:22:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 775DC20753 for ; Sat, 21 Mar 2020 09:22:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uRboQhH7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728195AbgCUJWp (ORCPT ); Sat, 21 Mar 2020 05:22:45 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:42759 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728114AbgCUJWn (ORCPT ); Sat, 21 Mar 2020 05:22:43 -0400 Received: by mail-qk1-f195.google.com with SMTP id e11so9792383qkg.9 for ; Sat, 21 Mar 2020 02:22: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=NWtpMT1qwqplT8DYQDTsesksYkan0RzUr/I4M+dg4+A=; b=uRboQhH79M2q3dtwu7xF9MnT0Y5TNbqCvJKaGGxLYBTdpazpP8sTIH9YiSLq0CGj7j AARdVy8YoWW9cfiyKZDUlupnc35RYQ+Hfs6bVBM4v6Na7qvOqqBUqR8bz6rX7nqEnEdw LFAO4d0NWDGFEkjQL1WeIdGnUk5LmiewtqC1DIXGsveuE75rhHoY/FdXIX/8gS8wn6sB TwlR9HjD0dhAxXm/lnRgH5K91Wc9GQqjZhjYBZWEYRTt6GeCq7TQ5K3KvDzBZWAqxcKw G5Zxs3AFrcy3qdUFDdpZNcBXsLS/V7quGeYAyDYSqB2phxlqa/W0ZjwkcK6jpLBI4KfQ hz1g== 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=NWtpMT1qwqplT8DYQDTsesksYkan0RzUr/I4M+dg4+A=; b=t7VJHvM39Ni12pBO4zrVOH2dvRpRcspjCU+IoNLN2NECkBjaFRnlo5qoOEtQCZFGID mUJsKT4Ko7OOWpNVRNikIYsxusw0mCqj2pfgohjCLO4UGUmrMk2ZAi5jY9TicFCZ06xR Gt6fpQTdtBfzi+C64drvS765CUd/LQbwfa7j4UUggNv8drKaCnSsvifKXYQmp7luvpJj iWJellISahq6Yecufzk9qrVArBY14iWZtXX9o4TrBtJLTJ8HF543WN0YvNLkio/SxSUU 45KbY2nTqReFbLPaU0Hv3Dl/QnpTDTo8fItXUxEj8+zdPi+6vv6y19VpJsKrVfzpgpbp Ypug== X-Gm-Message-State: ANhLgQ3WDg29JLNkOXM0Tws+ObmU32YgDJzFcoGjMHMPUEVguDYyJbi0 zgKGnGKNzhj0N3k8NVfXLj5te6Bj X-Google-Smtp-Source: ADFU+vs7zfOZSdul9Ij8QXsFtl7ARn5RKckmWgl1OZX8VwwU93heAw4FeHvzM4SBBJZBeb0jzpjsyg== X-Received: by 2002:a37:b0d:: with SMTP id 13mr12426271qkl.9.1584782561829; Sat, 21 Mar 2020 02:22:41 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id z23sm6579890qkg.21.2020.03.21.02.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 02:22:41 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v3 19/19] pull: pass --autostash to merge Date: Sat, 21 Mar 2020 05:21:38 -0400 Message-Id: <17caf6d66f5ee33e6aef7265ab33dee83f24f05c.1584782450.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.25.0.114.g5b0ca878e0 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 34493eb58b..ae56cca826 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 rebase 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 &&