From patchwork Tue Dec 24 11:04:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309241 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 6058C138D for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3559420643 for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o8ut4gB3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726183AbfLXLFt (ORCPT ); Tue, 24 Dec 2019 06:05:49 -0500 Received: from mail-qt1-f176.google.com ([209.85.160.176]:42248 "EHLO mail-qt1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726091AbfLXLFt (ORCPT ); Tue, 24 Dec 2019 06:05:49 -0500 Received: by mail-qt1-f176.google.com with SMTP id j5so17851294qtq.9 for ; Tue, 24 Dec 2019 03:05:48 -0800 (PST) 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=E2jOqMPrWzDQF0yutufREOmEJCTOvkNbo/0lRKaFUjg=; b=o8ut4gB3LAfdyfYvTTp2gFnvW6xALybppSv4up0D4m7OQGAVsOeBGmsRNdStyQdXRy awhb8GvgnQJXPVxlwPHyHj0BLSp0nxOi/IE96+zF2IKxUZJ6FdbMCB4fNCLsnZb/d0aR jPznaopiQjbj253J1Os8u13EZk0XgTIQPjOl0GKkRYrKOge0CBBYZJx+cZsseLw9bo1C yxv6VTKScF0pHI9HNyRzdoRqeFIySFHvqi6uchdxR/1+vDdhR70o8FlrOW81b4K8b93t KviTS/mmTzzyjcT9m+RdyUl/+Gam9hr18kaM8rdmH3mW2uoQXB2g3LzRkrr08aKFrB48 dpOA== 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=E2jOqMPrWzDQF0yutufREOmEJCTOvkNbo/0lRKaFUjg=; b=UkpTEn9CEzPgWBnosUDCI29I7YPtmbyouS6jtXXNjSDBqxZAQCvU1p9bUJkhlIcpMa sJ9kFRhjVIGmXbmf7c/YphotjhxOt1f+TWGbIZ7kg/raKbRAWiUMADVs5Sshh1DMY1uO Tl04urGuudFhRAiHv6ujvuYOEKgdYbPTxw8MptXxv1jtNw7AntSDR3a6MXsIkyIkkJJM ZwJJh6Y4YEB4ueGVkXSFpMRXFZjhcOypbsRX+kmgpbJXuIzZI/4/IQicFLcXs0Wf54Ko m3nDLtsMn4rCe6OBo0QtbtClmCsW0rvzJ2pygNEJCCxDpZm4ZRzbV6NMFNASxMSkzYzQ prYQ== X-Gm-Message-State: APjAAAVACZHeGpUUJnkeA2iJ7EalzZOrPidR/OKCvXAroux7N/u/spuI p+YAu+4ABfqhfCye0DwNV3msOSK8 X-Google-Smtp-Source: APXvYqyTBnDEns7idA/snanmiXBaxkqRH5+9wsulYWA2WCkbtVgepWluQTHc4w2vioz0QnjrIKtKyQ== X-Received: by 2002:ac8:684:: with SMTP id f4mr5116158qth.184.1577185547661; Tue, 24 Dec 2019 03:05:47 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:47 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 01/17] Makefile: alphabetically sort += lists Date: Tue, 24 Dec 2019 06:04:58 -0500 Message-Id: <31055cdac4a5bfc48cf6f18179f4e9bce9a04c8c.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 order, alphabetically. Alphabetically sort all += lists to bring them back in order. Note that 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. As a result, we want to ensure that anybody can easily reproduce the sort order and that is very simple when we don't have to treat the prefix specially. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu --- Makefile | 75 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 42a061d3fb..de149947f6 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 @@ -736,8 +736,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 @@ -747,10 +747,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. @@ -787,10 +787,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 @@ -829,9 +829,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 @@ -847,9 +847,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 @@ -863,17 +863,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 @@ -891,7 +891,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 @@ -901,9 +900,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 @@ -912,31 +912,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 @@ -954,6 +954,7 @@ LIB_OBJS += range-diff.o LIB_OBJS += reachable.o LIB_OBJS += read-cache.o LIB_OBJS += rebase-interactive.o +LIB_OBJS += ref-filter.o LIB_OBJS += reflog-walk.o LIB_OBJS += refs.o LIB_OBJS += refs/files-backend.o @@ -961,7 +962,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 @@ -976,8 +976,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 @@ -987,9 +987,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 @@ -1008,11 +1008,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 @@ -1052,9 +1052,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 @@ -1085,13 +1085,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 @@ -1111,9 +1111,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 @@ -2328,16 +2328,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 @@ -3146,9 +3146,10 @@ endif # ALL_COMMANDS = $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) ALL_COMMANDS += git +ALL_COMMANDS += git-citool +ALL_COMMANDS += git-gui ALL_COMMANDS += gitk ALL_COMMANDS += gitweb -ALL_COMMANDS += git-gui git-citool .PHONY: check-docs check-docs:: From patchwork Tue Dec 24 11:04:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309243 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 9497A186E for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69BC920643 for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NM13H0Vs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726225AbfLXLFu (ORCPT ); Tue, 24 Dec 2019 06:05:50 -0500 Received: from mail-qt1-f173.google.com ([209.85.160.173]:43633 "EHLO mail-qt1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfLXLFt (ORCPT ); Tue, 24 Dec 2019 06:05:49 -0500 Received: by mail-qt1-f173.google.com with SMTP id d18so15172320qtj.10 for ; Tue, 24 Dec 2019 03:05:49 -0800 (PST) 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=RjOU2K7Uk41XDxasv1W2GCcRamYrZpRuMlCN34TchkI=; b=NM13H0Vsco+GxYsv/1UNtX8t7cexkVKNgHu/8ULrmuW0+nqRGYremO6l3HAdpQOUG0 ff4Bgr3ReZsh8kDjXIsq2rJy8q4nvgB3Ybbq5pZQCX9GV8uzT7B/oIsC1oz+ZYX+18H4 6ihWsm9AF7aDitHM7zkJzd7URiv03l/8VOAhR5sAAuZindvwVUuXDo1H3EADgchBeCjh 5JvTme2JcwFFx2o5xrCfvbDiPdsq/8wce5qEU4tctQPDBxOb2NJMAExcMc+c9hGbP4Pi k/hVMSv3IdpayqaLJJxUPrDbm+pLnFzC1BZw5k/AAqs2C2duIv9JA+i5z+tALBrVxfEB eLEQ== 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=RjOU2K7Uk41XDxasv1W2GCcRamYrZpRuMlCN34TchkI=; b=cgFAwMHu9yl9ilAimV+m8D4CWEo1lPZKr9LOnzM10MwU9Utxkf5ttVXxI5rZhm+YvW 6RsjZmin+mQXHQ4d3hXZ/q9yGVoYiuojkS60p+6xNpnbuF0jfXPfRcU8d1Tf2+9phxhk 2yTAVHmQhby/2G5N9vTuOzlY83qqbiE9yTglf2OtkUliLmO1d7ky08vSfzVFC87FZMtA euTcORwXWYeVj3kjRlMErMdV4lKakT3Y7HpkEWLU65n0vFdHa6Gpncze+gkiJI/HG5NL umUii0LdMd6J6b1LQmKIDf22UUEvFeaYwzqB0uDa20edxlfoRdeZb0VHMCWzz0lPhXzP Hmrw== X-Gm-Message-State: APjAAAXS0REZ7QuHxGdhuaGobRPsTMh3Wuxl7IjSRvwhCEA2srjLB4Nh Rn0zRLI55Kfc+8HZ8gn0RwX7b0uF X-Google-Smtp-Source: APXvYqwFxnlYRNhCMvc1GeTEW//zLyMvFrUYEIyfuL11/WvXui/eAxNFkkXQKWcSHT0Oah9k4Pg/XQ== X-Received: by 2002:aed:3fb7:: with SMTP id s52mr26616197qth.311.1577185548489; Tue, 24 Dec 2019 03:05:48 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:48 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 02/17] t7600: use test_write_lines() Date: Tue, 24 Dec 2019 06:04:59 -0500 Message-Id: <2e0020b3e3d58d4be4fe9fabfb079d17b30cc994.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In t7600, we were rewriting `printf '%s\n' ...` to create files from parameters, one per line. However, we already have a function that wraps this for us: test_write_lines(). Rewrite these instances to use that function instead of open coding it. Signed-off-by: Denton Liu --- t/t7600-merge.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 132608879a..4fa0ef8e3b 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -29,15 +29,15 @@ Testing basic merge operations/option parsing. . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh -printf '%s\n' 1 2 3 4 5 6 7 8 9 >file -printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1 -printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y -printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1 -printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 -printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z +test_write_lines 1 2 3 4 5 6 7 8 9 >file +test_write_lines '1 X' 2 3 4 5 6 7 8 9 >file.1 +test_write_lines 1 2 3 4 '5 X' 6 7 8 9 >file.5 +test_write_lines 1 2 3 4 5 6 7 8 '9 X' >file.9 +test_write_lines 1 2 3 4 5 6 7 8 '9 Y' >file.9y +test_write_lines '1 X' 2 3 4 5 6 7 8 9 >result.1 +test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 +test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 +test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z create_merge_msgs () { echo "Merge tag 'c2'" >msg.1-5 && @@ -81,7 +81,7 @@ verify_head () { } verify_parents () { - printf '%s\n' "$@" >parents.expected && + test_write_lines "$@" >parents.expected && >parents.actual && i=1 && while test $i -le $# @@ -95,7 +95,7 @@ verify_parents () { } verify_mergeheads () { - printf '%s\n' "$@" >mergehead.expected && + test_write_lines "$@" >mergehead.expected && while read sha1 rest do git rev-parse $sha1 From patchwork Tue Dec 24 11:05:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309245 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 CA5FE17EE for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E31020643 for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aq35PQXc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726237AbfLXLFv (ORCPT ); Tue, 24 Dec 2019 06:05:51 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:37236 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726154AbfLXLFu (ORCPT ); Tue, 24 Dec 2019 06:05:50 -0500 Received: by mail-qt1-f193.google.com with SMTP id w47so17881812qtk.4 for ; Tue, 24 Dec 2019 03:05:50 -0800 (PST) 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=gc3wctujx0pytxtJt0GHE/bW2ail+olVBf+H6OYuszA=; b=aq35PQXcpzXT/Rdbc23jdqvSGcCFhkx94NqYcDlNT6Soiehw/Wj9+2w44qqnw64OLg ZvfFzeSlDXZfvUCU+utGVWqATJ46SCs0/1qVQgPxtNd8fMTxZJAuC+wtu08Dm0F6gbjj d60oQSsGk4ogNBZ3U8Lg9iXpl2xw8mdU+WXfYolKLYHUceyZYkwsXg31DtU7UWjAPiLW AcV6w/UpefYoC+C1ShDga2Ay+lwzFjV6/gvkOrQY05+JYCY+7Bi6uRb6MrF0tackZXQn HIgIGzAj3v1/9RZ64qIQylapXgK5xHD2UM3yzmbg8UHHdIU/Zkfs3MSmVMVk5XA1eWMS f3oQ== 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=gc3wctujx0pytxtJt0GHE/bW2ail+olVBf+H6OYuszA=; b=Q3UUEN26QTdPsPq8bKYxN6HzTLbt+tbKg095IP1SAnHrjpqGj03pdNyCEoEJ3h+T8Q iU9m5igGf9dcQ7XgskU4LyEOhRRjAet1EuwKyTwb5+UTf045RjIsSB0R2PpvdGyr56d2 1tH3SlMzF7GeduRx4kNIoNh6dS1M/VuslsKuAzZIzPJo+6uY23cnEvYtAhggd4d7lBO9 6G9HXp/Ka8dU5ksL0a0SdO++GPsUB+pSc6QxWNqEE6CP3pMSH4FRLfEqdPIihbZ+VbrH YaPXP4NFfP4cbeWjqYcXfE+gWvMZQHVKLSyoIVlbv7LpyW4raNcSOmcEDgZF280SJTfV kcFA== X-Gm-Message-State: APjAAAXlct/cm/eQ/UszR6LdK3CYjgXYFkejl+/8ofZiGmFRb/xMUjNC L10lk7KdruR7NKBxWEFeqL0k5khn X-Google-Smtp-Source: APXvYqy1ydJ0AgVxUPvLc8bOT51lyZlfItodCbv3PcxNIJ9unkrNf9Tn+K5oAPQIQ29ocFflIaoq7A== X-Received: by 2002:ac8:784:: with SMTP id l4mr26156735qth.286.1577185549752; Tue, 24 Dec 2019 03:05:49 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:49 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 03/17] sequencer: use file strbuf for read_oneliner() Date: Tue, 24 Dec 2019 06:05:00 -0500 Message-Id: X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 763ccbbc45..5ba8b4383f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -429,26 +429,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 Tue Dec 24 11:05:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309247 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 F3CD118EC for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D27D220643 for ; Tue, 24 Dec 2019 11:05:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OPQleFu9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726251AbfLXLFx (ORCPT ); Tue, 24 Dec 2019 06:05:53 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:40818 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726154AbfLXLFw (ORCPT ); Tue, 24 Dec 2019 06:05:52 -0500 Received: by mail-qk1-f193.google.com with SMTP id c17so15775914qkg.7 for ; Tue, 24 Dec 2019 03:05:51 -0800 (PST) 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=YlNOBbYAcOpwwPjd99hpmWTBnvLFoWj33D3WEAz/l9k=; b=OPQleFu98UGv+hlH29+ZyWpq8K3H5qBz37ScfFMZXlcj8PzGrrl7te4edM9kzvz8Ym 6QGih8uOJm97OxaJpNvFM3jby9WNqyliaUvKQ64o1IPiA23uU00B8YDvHZFVQMybKwbA 13georxYa/3Wz1BERtMCSMIjaGnXekGP90SOTztcqqjpQJtxe8poDti0wuVXRuj4dnW8 GVNTHwd3c7uOuCw3xAzXxTeLseidCPKwmA6uJ6Y5vimgWaiyzziHUS/FJIf6bpRoeKDJ LvtVWxg3BDeLS2KmQCq88lMjSitXWbg/Rqga48OKrKsl3IZjY/KMWmspEk72XhuQYBLs 9QVw== 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=YlNOBbYAcOpwwPjd99hpmWTBnvLFoWj33D3WEAz/l9k=; b=EhHP3bxLWC93vbl/TsfCRTtKH58qJVrpQqhYlDbUN0SsTb462VFoZxkmMASbvaWxub xBk78RiW54bxsXMXHH7mXX84Uqr5pezq5pRTeBPMVHou3ijd70mjXOgaLb5jBEr3h5mn R1aZdWzCAe8K2mAPTius1CQPHtu2Q21pl6CY8PlyFRx2AsXVcq0Rr39xAnMS4SmcsEr4 7fvv4NAZmWxzdLelnVWKyF4IrVLxcU4fwRfOcP7gX6c3YgLRn2EwXh4CkhGXQKIZCQp3 VrtWMcHBIMEMHRwqvp0ssa6i+e27ciDZW/DZikSaSKkkwL8bK3Ty9ZQKj5OagCAi1KcR SeYA== X-Gm-Message-State: APjAAAXJ6L5yorR70Q9Lfs4TYRRfdE6vulWl4zclKP2xN+PXLZ1GmTq9 YgIRlqajarIj+sc0bR90Y0SON/Ck X-Google-Smtp-Source: APXvYqwODRIypAISTgrEzwrN77bV5M+tjq7IIQ0TiJEMIyDg6Wc5/mwD8dT3JfN8uJZUvILgWoi4lw== X-Received: by 2002:a05:620a:1522:: with SMTP id n2mr29983986qkk.108.1577185550698; Tue, 24 Dec 2019 03:05:50 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:50 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 04/17] sequencer: configurably warn on non-existent files Date: Tue, 24 Dec 2019 06:05:01 -0500 Message-Id: X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 `warn_nonexistence` parameter which, if true, would issue a warning when a file doesn't exist by skipping the `!file_exists()` check and letting `strbuf_read_file()` handle that case. Mechanically replace uses of read_oneliner() in sequencer.c with the following spatch so that current behaviour is maintained: @@ expression a, b, c; @@ read_oneliner(a, b, c + , 0 ) Signed-off-by: Denton Liu --- sequencer.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/sequencer.c b/sequencer.c index 5ba8b4383f..103cea1460 100644 --- a/sequencer.c +++ b/sequencer.c @@ -426,13 +426,13 @@ 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) +static int read_oneliner(struct strbuf *buf, const char *path, + int skip_if_empty, int warn_nonexistence) { int ret = 0; struct strbuf file_buf = STRBUF_INIT; - if (!file_exists(path)) + if (!warn_nonexistence && !file_exists(path)) return 0; if (strbuf_read_file(&file_buf, path, 0) < 0) { @@ -2558,10 +2558,10 @@ void parse_strategy_opts(struct replay_opts *opts, char *raw_opts) static void read_strategy_opts(struct replay_opts *opts, struct strbuf *buf) { strbuf_reset(buf); - if (!read_oneliner(buf, rebase_path_strategy(), 0)) + if (!read_oneliner(buf, rebase_path_strategy(), 0, 0)) return; opts->strategy = strbuf_detach(buf, NULL); - if (!read_oneliner(buf, rebase_path_strategy_opts(), 0)) + if (!read_oneliner(buf, rebase_path_strategy_opts(), 0, 0)) return; parse_strategy_opts(opts, buf->buf); @@ -2572,7 +2572,7 @@ 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(), 1, 0)) { if (!starts_with(buf.buf, "-S")) strbuf_reset(&buf); else { @@ -2582,7 +2582,7 @@ 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(), 1, 0)) { if (!strcmp(buf.buf, "--rerere-autoupdate")) opts->allow_rerere_auto = RERERE_AUTOUPDATE; else if (!strcmp(buf.buf, "--no-rerere-autoupdate")) @@ -2618,7 +2618,7 @@ 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(), 1, 0)) { const char *p = opts->current_fixups.buf; opts->current_fixup_count = 1; while ((p = strchr(p, '\n'))) { @@ -2627,7 +2627,7 @@ static int read_populate_opts(struct replay_opts *opts) } } - if (read_oneliner(&buf, rebase_path_squash_onto(), 0)) { + if (read_oneliner(&buf, rebase_path_squash_onto(), 0, 0)) { if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) return error(_("unusable squash-onto")); opts->have_squash_onto = 1; @@ -3759,7 +3759,7 @@ 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(), 1, 0)) { strbuf_release(&stash_sha1); return 0; } @@ -4093,7 +4093,7 @@ static int pick_commits(struct repository *r, if (todo_list->current < todo_list->nr) return 0; - if (read_oneliner(&head_ref, rebase_path_head_name(), 0) && + if (read_oneliner(&head_ref, rebase_path_head_name(), 0, 0) && starts_with(head_ref.buf, "refs/")) { const char *msg; struct object_id head, orig; @@ -4106,13 +4106,13 @@ static int pick_commits(struct repository *r, strbuf_release(&buf); return res; } - if (!read_oneliner(&buf, rebase_path_orig_head(), 0) || + if (!read_oneliner(&buf, rebase_path_orig_head(), 0, 0) || get_oid_hex(buf.buf, &orig)) { res = error(_("could not read orig-head")); goto cleanup_head_ref; } strbuf_reset(&buf); - if (!read_oneliner(&buf, rebase_path_onto(), 0)) { + if (!read_oneliner(&buf, rebase_path_onto(), 0, 0)) { res = error(_("could not read 'onto'")); goto cleanup_head_ref; } @@ -4145,7 +4145,7 @@ static int pick_commits(struct repository *r, DIFF_FORMAT_DIFFSTAT; log_tree_opt.disable_stdin = 1; - if (read_oneliner(&buf, rebase_path_orig_head(), 0) && + if (read_oneliner(&buf, rebase_path_orig_head(), 0, 0) && !get_oid(buf.buf, &orig) && !get_oid("HEAD", &head)) { diff_tree_oid(&orig, &head, "", @@ -4230,7 +4230,7 @@ static int commit_staged_changes(struct repository *r, if (get_oid("HEAD", &head)) return error(_("cannot amend non-existing commit")); - if (!read_oneliner(&rev, rebase_path_amend(), 0)) + if (!read_oneliner(&rev, rebase_path_amend(), 0, 0)) return error(_("invalid file: '%s'"), rebase_path_amend()); if (get_oid_hex(rev.buf, &to_amend)) return error(_("invalid contents: '%s'"), @@ -4391,7 +4391,7 @@ 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(), 1, 0) && !get_oid_committish(buf.buf, &oid)) record_in_rewritten(&oid, peek_command(&todo_list, 0)); strbuf_release(&buf); From patchwork Tue Dec 24 11:05:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309255 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 B4725186E for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 937D120643 for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="olmsvdfK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726259AbfLXLFy (ORCPT ); Tue, 24 Dec 2019 06:05:54 -0500 Received: from mail-qt1-f176.google.com ([209.85.160.176]:43638 "EHLO mail-qt1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbfLXLFw (ORCPT ); Tue, 24 Dec 2019 06:05:52 -0500 Received: by mail-qt1-f176.google.com with SMTP id d18so15172398qtj.10 for ; Tue, 24 Dec 2019 03:05:52 -0800 (PST) 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=zU/36mqyT+YjZcY2b2v+QdftOJ5deD3IJu6PHjUcp0A=; b=olmsvdfKC+Bj4PEzDx24CKhGmpDbbYvcIYrsddaDAkwLyk6gpvwj5oOi3lH9EoVijL 0r912WyrlHeULXkdxmKd/HCNJBPFOzYzJMlQ8VNIsUtGtuKbZYWE796Z5KMwkhhR6/PL us11sraSDACzQavEFpG/OrNW+q4YZEEifnTkhh6TxKDQbElqYeABakr9JGKyCjPmg3ai J+vqRsCDM7s8pcfBPKKsOXAZOuqKYHGcMM73dbnIvafNgidlT3p0OC39MZKDX/fpw7zR ahXdc+UBP9J01T/+HLgSGL7Xe+PAEismRte+sBr6oGkIT8JOwEK/kHRPBlQgZkwlTpA0 gsbg== 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=zU/36mqyT+YjZcY2b2v+QdftOJ5deD3IJu6PHjUcp0A=; b=IG3irQLVbmA6SYnIiEc2ZC/RNusIysKjdKklexj7j5rs0c5WWLuX8Xfj4lTwZ9+bVt GtKE+j3erzz76mZa525fulwo9IvNlfwMKS3i8OFzB5fTbYumT/hAzxR6Vvmy3m4D8cRn mUMm/vF1M/rp1kZaWpusIwSPp4Qxzl1UQvIEn6AaWB+G1WEjxgMway3fK2VCT1Jd1EUz 361/jAAy/SvNYUR4H2B3VN9xZGI45OtYX45xweMc4swWI/QYF5NsaxIwbHU5DomPdBwX Ky7/TlaSpfXWaX6IfsdNvy2ERHXfiv5Yed1mJaURJ4XXiybF0+1OR+mWF9t4SdaHjodw AVAg== X-Gm-Message-State: APjAAAWHt57pVfjej2R07/j43D2WtYoAGJwSwV9rMwtUpw4EkdF94lEl Sh7FLSIyqBP0P7txBDQmCCa9UutD X-Google-Smtp-Source: APXvYqwKclAeKeiwgbZdHXU7T7PLo9LKCppGdnz9Oo8a8rbJkWPM83T/RkS7klBok6LxLCOTl1o2vQ== X-Received: by 2002:ac8:2ffa:: with SMTP id m55mr26612949qta.189.1577185551586; Tue, 24 Dec 2019 03:05:51 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:51 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 05/17] sequencer: make read_oneliner() extern Date: Tue, 24 Dec 2019 06:05:02 -0500 Message-Id: <819fb2203ba59df1fc446167d5648c6aae46ad17.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 | 13 ++----------- sequencer.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sequencer.c b/sequencer.c index 103cea1460..9ef9424f88 100644 --- a/sequencer.c +++ b/sequencer.c @@ -417,17 +417,8 @@ static int write_message(const void *buf, size_t len, const char *filename, return 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. - * - * 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, const char *path, - int skip_if_empty, int warn_nonexistence) +int read_oneliner(struct strbuf *buf, const char *path, + int skip_if_empty, int warn_nonexistence) { int ret = 0; struct strbuf file_buf = STRBUF_INIT; diff --git a/sequencer.h b/sequencer.h index e9a0e03ea2..56cea80dd8 100644 --- a/sequencer.h +++ b/sequencer.h @@ -202,6 +202,17 @@ void print_commit_summary(struct repository *repo, const struct object_id *oid, unsigned int flags); +/* + * 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, + int skip_if_empty, int warn_nonexistence); int read_author_script(const char *path, char **name, char **email, char **date, int allow_missing); void parse_strategy_opts(struct replay_opts *opts, char *raw_opts); From patchwork Tue Dec 24 11:05:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309249 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 2A90318B8 for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0961F20643 for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I/5ZURlp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726271AbfLXLFz (ORCPT ); Tue, 24 Dec 2019 06:05:55 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:37243 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbfLXLFx (ORCPT ); Tue, 24 Dec 2019 06:05:53 -0500 Received: by mail-qt1-f196.google.com with SMTP id w47so17881897qtk.4 for ; Tue, 24 Dec 2019 03:05:53 -0800 (PST) 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=YFgXMROkeed/QDYtZ0Ndb0D56tSzSKygOpSe5QnYWm0=; b=I/5ZURlp7ko4Qy4FbAK30EGstIVC5hhg98ECD5A1xVrw6m9jKTsOA4PxO9/n9ai6ff k6SRrmzyY44aE+6Tvx3viEABZE5LoaHkwuoESwL7Y0XldKPT8aQ84v8OhGPt3+SiOR0j E2jV4nxKAYNVpZwOPZUaKBdHpVFJQqoqxaEKGmBHPjtriguhm0qRrMdcCmC7JmhdASWc mUIhPDh6xtRKlmg/BYD3D44WKtBDiEwP41CifMZHLEtNLBHiX/N/xdz98eEwriL0ifwg lLILjlkvNWXRG+8oWNrREuDVoGNTMb1IIz7FyJdW9ArAcnNx8JZ7IgYheTnoSdJHA1kK A7Bg== 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=YFgXMROkeed/QDYtZ0Ndb0D56tSzSKygOpSe5QnYWm0=; b=qBXmN9uYlsK/9BykcqYG1dlxORJ7Y9PuRhN/HZderI8lR2cuECO7EY8NYIg3lDxGQi XKghir7zgC6mXOp5yfgBP4vg0LA6eTvRQnmRJyzlOKRyinNBfzYTYab5yKXgcy8h3LQ5 R8UQPbAKXqVyLcKQ/39wvN5d4mrGRJtZqaOisFR0wcQjqyBe7PrLMHZAM0QVx/5zT82l chulYfxMr+saVIVHyoDmwG/YtmaYTAeQrvR0ijpMtZIs7T0SmX1iYiyhu+AtWOEYnLkY TwSCON9HdFHZbcCFnnuLkP7dA6mxW9BQ9kjf0OV02h3GbE6ukyXQq+P+2LhntGXgz86p 7A+Q== X-Gm-Message-State: APjAAAUGkOppH2U7k/hR9gTTf76sRNCTtTPKYzDsChAutw+OugekbLMm Q8lk3OdyeFpexLMBAPTgwRZ6T+KD X-Google-Smtp-Source: APXvYqyun0yvbYimOfw3DBjzoVnviTZ4EccyljhiEcivxevQaAAtVuWLQUGjky5vEvgjd4Vt+RFoVg== X-Received: by 2002:ac8:6153:: with SMTP id d19mr26358923qtm.18.1577185552470; Tue, 24 Dec 2019 03:05:52 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:52 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 06/17] rebase: use read_oneliner() Date: Tue, 24 Dec 2019 06:05:03 -0500 Message-Id: <06c5bd48d767ff5dce45bebb58505888745af861.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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, 0, 1) Signed-off-by: Denton Liu --- builtin/rebase.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index ddf33bc9d4..68bedccb95 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -582,15 +582,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) { @@ -598,8 +589,8 @@ 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), 0, 1) || + !read_oneliner(&buf, state_dir_path("onto", opts), 0, 1)) return -1; opts->head_name = starts_with(head_name.buf, "refs/") ? xstrdup(head_name.buf) : NULL; @@ -615,9 +606,9 @@ 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), 0, 1)) return -1; - } else if (read_one(state_dir_path("head", opts), &buf)) + } else if (!read_oneliner(&buf, state_dir_path("head", opts), 0, 1)) return -1; if (get_oid(buf.buf, &opts->orig_head)) return error(_("invalid orig-head: '%s'"), buf.buf); @@ -637,8 +628,7 @@ 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), 0, 1)) return -1; if (!strcmp(buf.buf, "--rerere-autoupdate")) opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE; @@ -651,8 +641,7 @@ 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), 0, 1)) return -1; free(opts->gpg_sign_opt); opts->gpg_sign_opt = xstrdup(buf.buf); @@ -660,7 +649,7 @@ 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), 0, 1)) return -1; free(opts->strategy); opts->strategy = xstrdup(buf.buf); @@ -668,7 +657,7 @@ 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), 0, 1)) return -1; free(opts->strategy_opts); opts->strategy_opts = xstrdup(buf.buf); @@ -720,7 +709,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, 0, 1)) return error(_("Could not read '%s'"), path); /* Ensure that the hash is not mistaken for a number */ strbuf_addstr(&autostash, "^0"); From patchwork Tue Dec 24 11:05:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309251 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 5EF77184C for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 341D220643 for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vBE+vpyS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726268AbfLXLFz (ORCPT ); Tue, 24 Dec 2019 06:05:55 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:37242 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbfLXLFy (ORCPT ); Tue, 24 Dec 2019 06:05:54 -0500 Received: by mail-qt1-f193.google.com with SMTP id w47so17881917qtk.4 for ; Tue, 24 Dec 2019 03:05:53 -0800 (PST) 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=WD/kT5LIQG0g26xmrzoO7BeLyh+1b/dMXYQFa6b2kaQ=; b=vBE+vpySSP259K+PugYPNW3G6g/d3m32pcRH6T+dpszUHfyfMXfLIs/HmOtqGvJF2p KcBagcBUun54xyTxxJtIvP2gPxbJ7KXd1zFU8tZwXroAZ7G5/K0l0nW53bUKyassp2Vz gqrox/stJdxvpCz+mDznPV1Kqyq8kBdoXVAhZ5koPmrefVI7SmaflH6fw1ZJV7Z7e973 udGf6Ouy1Qz8T84zOOX42++TfBcAWkm3McGkWawuGwN9Yd9xueY3HQRb9t6fo/xUlmSd IGPdTMa7SV/LZ7QNnvLZoIz/61Pg+WbvOZSEcSUEvW8YGF2MKeBVyzMxmjVweBQXwbtd mb0g== 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=WD/kT5LIQG0g26xmrzoO7BeLyh+1b/dMXYQFa6b2kaQ=; b=Opt5TBadQI5fvS1KQPAQnZcYsEgUiHYYrjMm4JboVg0kcbTZGQ9XJqWYG/78k7rO8z H5hW/wSCU6FJakC2WKOPReWoag0g9wGkWAgrLUKQEROPIDophgPXKPR1adggdAnpSlbQ EbG4OE5dUhUDaDbQeIEwiyH7eNty8jCXaJPy1chl5Wt/GXVbnwXpmGOF/c5BKvLyFHSk zYIpsO57pfa1mJ4u5ml9ImuVvmTC51RQFLuArGm/BbdprlpydLCi3dnQIAvoA05vEAa2 WUnq/CguQ320JIo3jv/ltMdE8ZlFbdyPSm/6YtqMEsS191Hi7AqFvS3tTGDF+TQWVwEs H2Zg== X-Gm-Message-State: APjAAAXPjZiXs4OzKp38mDhPjvqaPtwAvmELsHgbsP0+Uf5Nbj9Y+5u9 atulF/ibJXd3Q8x4qBaayjNU6C6x X-Google-Smtp-Source: APXvYqyGc31zvfUeDkFERgdRnnf/jHv/Hwhv8Eyh6EaIZArEkcM3pNE4xOABCG+o0azMscAj2p++/Q== X-Received: by 2002:ac8:5205:: with SMTP id r5mr26928681qtn.230.1577185553320; Tue, 24 Dec 2019 03:05:53 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:52 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 07/17] sequencer: make apply_rebase() accept a path Date: Tue, 24 Dec 2019 06:05:04 -0500 Message-Id: <12c37d11babf2df496066d113328242584e405f0.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 9ef9424f88..e1b7cb461c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3744,13 +3744,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(), 1, 0)) { + if (!read_oneliner(&stash_sha1, path, 1, 0)) { strbuf_release(&stash_sha1); return 0; } @@ -3856,7 +3856,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")); } @@ -4172,7 +4172,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) @@ -5213,7 +5213,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")); @@ -5224,12 +5224,12 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla if (res == -1) return -1; else if (res == -2) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); return -1; } else if (res == -3) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); todo_list_release(&new_todo); From patchwork Tue Dec 24 11:05:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309253 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 89B0117EE for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68A8220643 for ; Tue, 24 Dec 2019 11:05:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MlPej5oj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726278AbfLXLF4 (ORCPT ); Tue, 24 Dec 2019 06:05:56 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:46037 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbfLXLFz (ORCPT ); Tue, 24 Dec 2019 06:05:55 -0500 Received: by mail-qt1-f196.google.com with SMTP id l12so17838809qtq.12 for ; Tue, 24 Dec 2019 03:05:54 -0800 (PST) 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=sBMHWZJ9hO7pdb+IpMcFoxe2MgW66NHF+kCOzu/bud4=; b=MlPej5ojiFg9bvAlVrR6jFqbyTH9s7sneBeITVE2gi6fCfVPFqeMrAxuDlh8uko6uA FPGJvFDi12H/x8Vo4Shaly3VZQic9B7MvhnWv98SVcTvpUwLIKZWwHF8+Pe4ixTswGPr Y6jwuBZq0MjGQLIJ6d4Q3EbKmlNvr9f1xi0YsfAjH/wBzzIeswj8M96w4g5dZW1wncjS UNyEe0IH9MK3kA54QPTFp3ETN9cd/Lr05NGa4SABOdsGLPzhZxqh2JJzvu31ujjGyLc6 11yljr2ooZcXk9Dax4Yf99rvLe6Oy6SxGF7odialtdbHqQGDsKOIgQxtDjrYIB7KxyGx IGZQ== 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=sBMHWZJ9hO7pdb+IpMcFoxe2MgW66NHF+kCOzu/bud4=; b=kSNXscm+guDfu2XfwzbEw6z19WmT80D4KcXSMyellFhiMAQXL9ra+uZzJ6yprJbcyc QrI4MJjXg5JZuGZJ5MREqj3ZjuFsb0k9xfF8iLxoVm+OiLVUB8DnpaLwsEfdHPQBZ+DZ Q0sEYNuQvEMCUiLuLA3T4JOZUdDcPbJg7pdEndU8wGzbRZZyw/vD0R7jtGGyvmgxIKLq mlNbQHVd/6oVN6hLGvVZ1+vTBrx3ic8tkT5YpP2KIbA+duK/bAloY+LnJZcL7+cWinlp u6UQv0C2rf/6RCNF/qkKLCQOokm3lgRVZ6WomITR6P0Mb9aRKpiKEwa0dCu4HE+lF6/+ 1drA== X-Gm-Message-State: APjAAAVV8Io2VDsJF66+DYpwZKC1vhu5onyfh0QNavEQHWDlnvV37fum MgvBiLxfAwnL53ySIUeLYcKas7Fm X-Google-Smtp-Source: APXvYqwCYLzM6CwqV5LkCK0dwl00V5sUfJY76Eh4g7dMaVKOmKPj9jL2X+80q5Pwhm9Tb81VbqFHng== X-Received: by 2002:aed:33c5:: with SMTP id v63mr21478443qtd.298.1577185554206; Tue, 24 Dec 2019 03:05:54 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:53 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 08/17] rebase: use apply_autostash() from sequencer.c Date: Tue, 24 Dec 2019 06:05:05 -0500 Message-Id: <893a2f9825f8a9640b747048f1c7de37c8c12cce.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 68bedccb95..07674a16d8 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -700,51 +700,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, 0, 1)) - 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; @@ -752,7 +707,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 @@ -1206,7 +1161,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 e1b7cb461c..98e08dbbe0 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3744,7 +3744,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 56cea80dd8..ecef2c144c 100644 --- a/sequencer.h +++ b/sequencer.h @@ -195,6 +195,8 @@ void commit_post_rewrite(struct repository *r, int prepare_branch_to_be_rebased(struct repository *r, struct replay_opts *opts, const char *commit); +int apply_autostash(const char *path); + #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) void print_commit_summary(struct repository *repo, From patchwork Tue Dec 24 11:05:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309265 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 01BD6138D for ; Tue, 24 Dec 2019 11:06:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C73972071A for ; Tue, 24 Dec 2019 11:06:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oh5vroCH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726353AbfLXLGE (ORCPT ); Tue, 24 Dec 2019 06:06:04 -0500 Received: from mail-qv1-f66.google.com ([209.85.219.66]:38724 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbfLXLF6 (ORCPT ); Tue, 24 Dec 2019 06:05:58 -0500 Received: by mail-qv1-f66.google.com with SMTP id t6so7363968qvs.5 for ; Tue, 24 Dec 2019 03:05:57 -0800 (PST) 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=jSaqnkUZna3sHGOrMFyTSjRqbn0EQ/4+aJkSbImWlxw=; b=Oh5vroCH55KRG6ItMsUHLsCdToFIN8a4u9grQVsUtcH2a1jTCT2Nbx8Y88ySOPWE3J +HA+u0Jqj8fAKKWehonbMT6t59r3XMQ2jZvDpxzSNlrZYSPrNoD5tqchVEIzmRWOjuyV zxWM1s797Uzz5E978KifQGx4l0aCGcAjkBDXUWFzS4WnosJYOc6mQ+yJtrARwZCc/9HI u3VMIN/MGevy9LTydDUjcjSE3e+zsBQEq52ZUYd7Rbgtum/yVHQWJCbdazoMG7Gc6ZjI x8eAKChXE2hgqvqUvwmORYCKoue+NPeOZd3ezV0Cttu6L+vCl3DpxzcKqn4bffIuv1RO d+OA== 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=jSaqnkUZna3sHGOrMFyTSjRqbn0EQ/4+aJkSbImWlxw=; b=QZ0rDpehNH1qzFewUsr25yDkJba+mp+7RLKotKE3/c9PS8pOymQNSyZ2UE2Itwwqvf vEwFT5D8odGh59l17V2eZpQToNZ+FGEelaOjVuW5RLmrdudUZY+Xij0Vl+oRozfSREl7 N7s4qMhPNIjUoc/gfVy6itZyUg+oOscjihqyAfmll+T75O1Vm0I0uZsuJKJw3H2yY3oY /BBELfx0O/3LcrZ7kiTJwIXR44E5O1pwGofVjKXptWHrh/ylnrZaRjhBnMUhnKlNNWra tirvxi4FgP7mAFeowKmzpvjcQ7Sz1ZdyvlvgIwarS0SAFr5ityr6zxC9rqkN/xxqmfA2 zecw== X-Gm-Message-State: APjAAAWfpUdWBDPGw9ySM3kTA7lzKeLhyDQJmEEYyQxl3gVhJ0zc03RS PQACDXClD7beMmVeAG10FZDdRHzj X-Google-Smtp-Source: APXvYqwZQz6Ktr+tAErb+vw3wRsBgjKWsrEVWDQfTOwpGi2J6JHVBQyMrrMnKZnEBMPQ5Yw06OtNaQ== X-Received: by 2002:a0c:9c86:: with SMTP id i6mr28129161qvf.214.1577185555141; Tue, 24 Dec 2019 03:05:55 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:54 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 09/17] rebase: generify reset_head() Date: Tue, 24 Dec 2019 06:05:06 -0500 Message-Id: <8e3c0c0aecf0bcee68d88fddc772f1af4a0d66fb.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 | 63 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 07674a16d8..4e3cb0852d 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] [ []]"), @@ -760,9 +762,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; @@ -784,7 +787,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; } @@ -803,26 +806,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; } @@ -833,16 +836,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) { @@ -904,8 +907,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); @@ -999,8 +1004,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" @@ -1609,8 +1615,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)) @@ -1627,9 +1633,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); @@ -1998,8 +2004,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 || @@ -2045,10 +2052,11 @@ 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(&oid, "checkout", + if (reset_head(the_repository, &oid, "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); @@ -2120,10 +2128,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); @@ -2138,8 +2146,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "rebase finished: %s onto %s", options.head_name ? options.head_name : "detached HEAD", oid_to_hex(&options.onto->object.oid)); - reset_head(NULL, "Fast-forwarded", options.head_name, - RESET_HEAD_REFS_ONLY, "HEAD", msg.buf); + reset_head(the_repository, NULL, "Fast-forwarded", options.head_name, + RESET_HEAD_REFS_ONLY, "HEAD", msg.buf, + DEFAULT_REFLOG_ACTION); strbuf_release(&msg); ret = !!finish_rebase(&options); goto cleanup; From patchwork Tue Dec 24 11:05:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309259 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 D35B514E3 for ; Tue, 24 Dec 2019 11:06:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EBEA20706 for ; Tue, 24 Dec 2019 11:06:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SikrTzGh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbfLXLGA (ORCPT ); Tue, 24 Dec 2019 06:06:00 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:46585 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbfLXLF5 (ORCPT ); Tue, 24 Dec 2019 06:05:57 -0500 Received: by mail-qt1-f193.google.com with SMTP id g1so10956470qtr.13 for ; Tue, 24 Dec 2019 03:05:56 -0800 (PST) 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=7m/yseedTabB0Td9/VTva/ztPXJmlmciz+vE2ytao/E=; b=SikrTzGh7OaFMoBs4t9RdRfoLDgH+TSgARCyA+n4acXUeHAIAuUs7/1PqjMitaALd5 MQvgulwrSWq8/pHFzCEoJmgZWP8znhMwwEcgNdkYsTPsz9KcVIVoI0yN0zAulTTOcTEI VgDqcyESKbcGjWmkIf5MhM3/HF3zpG52iWbHrYf/mjUJkgLDni8B3T9PYAM4zHQMzIgU Y37FtgK7e4EUjO2tJ1+4hSs+zDhJ2cSPwDwDNJvmwODg2YN0oJN2DvCBzqo8I95d/T7K z7OuP3R/uWVdknKKy+q8wwIKGdKvRf9CGMS15IyDBxBtfVPFlf4c7MGWjW/CDiUjaQVN Deyw== 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=7m/yseedTabB0Td9/VTva/ztPXJmlmciz+vE2ytao/E=; b=gVk0ZI2VtIqRQc4/8mDkL3uyCjkCAhNqjt9ARPvd9GLmqrNPXUW22OeX1lMV9otswj 1aIyzanElYczCegBEsoKbJAeoznj0G7a8CwPC+OGEA1U09KK2pJMB46mjZyMQdOtcSwY YIrHV6kPHcbSShLzif20kGclmdks7auFxVvKYJeQYyO80JVfjJom+LmzYkBMRPzVoOVF O51Vdkc7Ss7CDusJdQazP/W7/01nFEL7hJPM5zA4qG0U6gdUGpvLN8ZXwr8u3Jh2jfVG J1/pLWkFa72tZYjjXeS1I9CeG8/AeDVR94zyHVS6Idg9JA/tl7hgsUVhNx6d0ZAn1gZ4 N5kw== X-Gm-Message-State: APjAAAVgMmHBl5rtDxDdHKfzpF4v6F+4l7BvuMw0LSenq48qFYn0WhLg SY7YGHAytvKQPDhQ8W3AeuKsxeLQ X-Google-Smtp-Source: APXvYqzMLd4tdILi/InmkHTsFV2xl+Sz3wz51j04hjHoX5IL9B1PsANg+J9Rf8pwDS5rpNfsHo3PJQ== X-Received: by 2002:ac8:5241:: with SMTP id y1mr25843616qtn.373.1577185556075; Tue, 24 Dec 2019 03:05:56 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:55 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 10/17] reset: extract reset_head() from rebase Date: Tue, 24 Dec 2019 06:05:07 -0500 Message-Id: <981969d23024e1b49c9efbcffe4f05a8c36bcd54.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 de149947f6..8d3aa4153e 100644 --- a/Makefile +++ b/Makefile @@ -967,6 +967,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 4e3cb0852d..a6d7527f4c 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" @@ -754,144 +755,6 @@ static void add_var(struct strbuf *buf, const char *name, const char *value) } } -#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" - -#define RESET_HEAD_DETACH (1<<0) -#define RESET_HEAD_HARD (1<<1) -#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) -#define RESET_HEAD_REFS_ONLY (1<<3) -#define RESET_ORIG_HEAD (1<<4) - -static int reset_head(struct repository *r, struct object_id *oid, const char *action, - const char *switch_to_branch, unsigned flags, - const char *reflog_orig_head, const char *reflog_head, - const char *default_reflog_action) -{ - unsigned detach_head = flags & RESET_HEAD_DETACH; - unsigned reset_hard = flags & RESET_HEAD_HARD; - unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; - unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; - unsigned update_orig_head = flags & RESET_ORIG_HEAD; - struct object_id head_oid; - struct tree_desc desc[2] = { { NULL }, { NULL } }; - struct lock_file lock = LOCK_INIT; - struct unpack_trees_options unpack_tree_opts; - struct tree *tree; - const char *reflog_action; - struct strbuf msg = STRBUF_INIT; - size_t prefix_len; - struct object_id *orig = NULL, oid_orig, - *old_orig = NULL, oid_old_orig; - int ret = 0, nr = 0; - - if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) - BUG("Not a fully qualified branch: '%s'", switch_to_branch); - - if (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { - ret = -1; - goto leave_reset_head; - } - - if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { - ret = error(_("could not determine HEAD revision")); - goto leave_reset_head; - } - - if (!oid) - oid = &head_oid; - - if (refs_only) - goto reset_head_refs; - - memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); - setup_unpack_trees_porcelain(&unpack_tree_opts, action); - unpack_tree_opts.head_idx = 1; - unpack_tree_opts.src_index = r->index; - unpack_tree_opts.dst_index = r->index; - unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; - unpack_tree_opts.update = 1; - unpack_tree_opts.merge = 1; - if (!detach_head) - unpack_tree_opts.reset = 1; - - if (repo_read_index_unmerged(r) < 0) { - ret = error(_("could not read index")); - goto leave_reset_head; - } - - if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) { - ret = error(_("failed to find tree of %s"), - oid_to_hex(&head_oid)); - goto leave_reset_head; - } - - if (!fill_tree_descriptor(r, &desc[nr++], oid)) { - ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); - goto leave_reset_head; - } - - if (unpack_trees(nr, desc, &unpack_tree_opts)) { - ret = -1; - goto leave_reset_head; - } - - tree = parse_tree_indirect(oid); - prime_cache_tree(r, r->index, tree); - - if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { - ret = error(_("could not write index")); - goto leave_reset_head; - } - -reset_head_refs: - reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); - strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action); - prefix_len = msg.len; - - if (update_orig_head) { - if (!get_oid("ORIG_HEAD", &oid_old_orig)) - old_orig = &oid_old_orig; - if (!get_oid("HEAD", &oid_orig)) { - orig = &oid_orig; - if (!reflog_orig_head) { - strbuf_addstr(&msg, "updating ORIG_HEAD"); - reflog_orig_head = msg.buf; - } - update_ref(reflog_orig_head, "ORIG_HEAD", orig, - old_orig, 0, UPDATE_REFS_MSG_ON_ERR); - } else if (old_orig) - delete_ref(NULL, "ORIG_HEAD", old_orig, 0); - } - - if (!reflog_head) { - strbuf_setlen(&msg, prefix_len); - strbuf_addstr(&msg, "updating HEAD"); - reflog_head = msg.buf; - } - if (!switch_to_branch) - ret = update_ref(reflog_head, "HEAD", oid, orig, - detach_head ? REF_NO_DEREF : 0, - UPDATE_REFS_MSG_ON_ERR); - else { - ret = update_ref(reflog_head, switch_to_branch, oid, - NULL, 0, UPDATE_REFS_MSG_ON_ERR); - if (!ret) - ret = create_symref("HEAD", switch_to_branch, - reflog_head); - } - if (run_hook) - run_hook_le(NULL, "post-checkout", - oid_to_hex(orig ? orig : &null_oid), - oid_to_hex(oid), "1", NULL); - -leave_reset_head: - strbuf_release(&msg); - rollback_lock_file(&lock); - while (nr) - free((void *)desc[--nr].buffer); - return ret; -} - static int move_to_original_branch(struct rebase_options *opts) { struct strbuf orig_head_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT; diff --git a/reset.c b/reset.c new file mode 100644 index 0000000000..79b683bffa --- /dev/null +++ b/reset.c @@ -0,0 +1,140 @@ +#include "git-compat-util.h" +#include "cache-tree.h" +#include "lockfile.h" +#include "refs.h" +#include "reset.h" +#include "run-command.h" +#include "tree-walk.h" +#include "tree.h" +#include "unpack-trees.h" + +int reset_head(struct repository *r, struct object_id *oid, const char *action, + const char *switch_to_branch, unsigned flags, + const char *reflog_orig_head, const char *reflog_head, + const char *default_reflog_action) +{ + unsigned detach_head = flags & RESET_HEAD_DETACH; + unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; + unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; + unsigned update_orig_head = flags & RESET_ORIG_HEAD; + struct object_id head_oid; + struct tree_desc desc[2] = { { NULL }, { NULL } }; + struct lock_file lock = LOCK_INIT; + struct unpack_trees_options unpack_tree_opts; + struct tree *tree; + const char *reflog_action; + struct strbuf msg = STRBUF_INIT; + size_t prefix_len; + struct object_id *orig = NULL, oid_orig, + *old_orig = NULL, oid_old_orig; + int ret = 0, nr = 0; + + if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) + BUG("Not a fully qualified branch: '%s'", switch_to_branch); + + if (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { + ret = -1; + goto leave_reset_head; + } + + if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { + ret = error(_("could not determine HEAD revision")); + goto leave_reset_head; + } + + if (!oid) + oid = &head_oid; + + if (refs_only) + goto reset_head_refs; + + memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); + setup_unpack_trees_porcelain(&unpack_tree_opts, action); + unpack_tree_opts.head_idx = 1; + unpack_tree_opts.src_index = r->index; + unpack_tree_opts.dst_index = r->index; + unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; + unpack_tree_opts.update = 1; + unpack_tree_opts.merge = 1; + if (!detach_head) + unpack_tree_opts.reset = 1; + + if (repo_read_index_unmerged(r) < 0) { + ret = error(_("could not read index")); + goto leave_reset_head; + } + + if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) { + ret = error(_("failed to find tree of %s"), + oid_to_hex(&head_oid)); + goto leave_reset_head; + } + + if (!fill_tree_descriptor(r, &desc[nr++], oid)) { + ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); + goto leave_reset_head; + } + + if (unpack_trees(nr, desc, &unpack_tree_opts)) { + ret = -1; + goto leave_reset_head; + } + + tree = parse_tree_indirect(oid); + prime_cache_tree(r, r->index, tree); + + if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { + ret = error(_("could not write index")); + goto leave_reset_head; + } + +reset_head_refs: + reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); + strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action); + prefix_len = msg.len; + + if (update_orig_head) { + if (!get_oid("ORIG_HEAD", &oid_old_orig)) + old_orig = &oid_old_orig; + if (!get_oid("HEAD", &oid_orig)) { + orig = &oid_orig; + if (!reflog_orig_head) { + strbuf_addstr(&msg, "updating ORIG_HEAD"); + reflog_orig_head = msg.buf; + } + update_ref(reflog_orig_head, "ORIG_HEAD", orig, + old_orig, 0, UPDATE_REFS_MSG_ON_ERR); + } else if (old_orig) + delete_ref(NULL, "ORIG_HEAD", old_orig, 0); + } + + if (!reflog_head) { + strbuf_setlen(&msg, prefix_len); + strbuf_addstr(&msg, "updating HEAD"); + reflog_head = msg.buf; + } + if (!switch_to_branch) + ret = update_ref(reflog_head, "HEAD", oid, orig, + detach_head ? REF_NO_DEREF : 0, + UPDATE_REFS_MSG_ON_ERR); + else { + ret = update_ref(reflog_head, switch_to_branch, oid, + NULL, 0, UPDATE_REFS_MSG_ON_ERR); + if (!ret) + ret = create_symref("HEAD", switch_to_branch, + reflog_head); + } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); + +leave_reset_head: + strbuf_release(&msg); + rollback_lock_file(&lock); + while (nr) + free((void *)desc[--nr].buffer); + return ret; + +} diff --git a/reset.h b/reset.h new file mode 100644 index 0000000000..12f83c78e2 --- /dev/null +++ b/reset.h @@ -0,0 +1,20 @@ +#ifndef RESET_H +#define RESET_H + +#include "hash.h" +#include "repository.h" + +#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" + +#define RESET_HEAD_DETACH (1<<0) +#define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) +#define RESET_HEAD_REFS_ONLY (1<<3) +#define RESET_ORIG_HEAD (1<<4) + +int reset_head(struct repository *r, struct object_id *oid, const char *action, + const char *switch_to_branch, unsigned flags, + const char *reflog_orig_head, const char *reflog_head, + const char *default_reflog_action); + +#endif From patchwork Tue Dec 24 11:05:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309267 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 60C2F14E3 for ; Tue, 24 Dec 2019 11:06:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4008E2071A for ; Tue, 24 Dec 2019 11:06:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lzPcaI7e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726370AbfLXLGG (ORCPT ); Tue, 24 Dec 2019 06:06:06 -0500 Received: from mail-qv1-f65.google.com ([209.85.219.65]:34016 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726284AbfLXLF6 (ORCPT ); Tue, 24 Dec 2019 06:05:58 -0500 Received: by mail-qv1-f65.google.com with SMTP id o18so7369968qvf.1 for ; Tue, 24 Dec 2019 03:05:57 -0800 (PST) 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=jISNjuGpTicokuJp5vmp/6Rn7RrL3GkXj1JlnI6OnDY=; b=lzPcaI7eYXTAqGXDLneKQG6Av/FbrgMiRa4vBRvg/ZmHNaet1bBaOLQXYOcyPYN9A8 ZBoDqPd2oJbYNntHKx633u1C9enJMi2xTK/ILSS0Od4LXOeUsjnb2YuBqZ6OEtM9Ce4S cHskYfbC9KC/XYEMW6o5u142No+q1BeqrAdzlLrbxVk2e9zqaIluy8oDuX47OqICwewf a12qhatCChzUjIiLP653GvEFD9b515Jp3Fx3vPRb9z2HgSCEkZ+M9QACeXNDMSo78XXJ 9/ARcku/kESrUKRn+stgybbixBez3apeEOpL9NSBFTEkMsko416nd8KNGXfdV841AGjI npUg== 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=jISNjuGpTicokuJp5vmp/6Rn7RrL3GkXj1JlnI6OnDY=; b=ljDOgWhR4IU9nQD0ouOmYAHy6BzJkb5gOCOvo5OmF2925QWHuPm0bp/TulN7R4A4Ob BalkuH4wi8Xis9pkWlXTpB/Jnn3AuoRkjN3dHLquNDnnUuTqPfyH5uUrUmjh2BUrDrsn HhNRuh4jPVeYEjRcq5Eb3xysJvsHLZISUElJYCEsQXh34+74/wDI+LiE+2i1Wc+76/gL g+W0GNKkWYpKpoJPIvNa1HNa2C3gUvClQtXsojgV6RxckGkgWSxv3qEoCvYu+2v9jy0T ksIUKqiEmKoj/dum51po9Tajt+fmqXgB55KMVzjUiwJWOL3j8JiRdu6n3I4oHxYhaNId OyGQ== X-Gm-Message-State: APjAAAWce6qArAQJn8dpdnXTWw8sr3LkEOQyCalExwv5vO6WhDUwwYyT 1/5auvf8/vKh69QDaFvk3VB4VmD5 X-Google-Smtp-Source: APXvYqwep1CZwfQ6aJl1QoqRpGYVDDxD5fzCNcNSm74sNotGnn08mikNmaxCj8HbojpB7emC7mINGg== X-Received: by 2002:ad4:444a:: with SMTP id l10mr28898817qvt.194.1577185557057; Tue, 24 Dec 2019 03:05:57 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:56 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 11/17] rebase: extract create_autostash() Date: Tue, 24 Dec 2019 06:05:08 -0500 Message-Id: <1b5bbe66dc4a6034f465ce565eef4d34f8db8124.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 a6d7527f4c..b60be5c875 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1232,6 +1232,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) { @@ -1832,50 +1881,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("could not read index")); if (options.autostash) { - struct lock_file lock_file = LOCK_INIT; - int fd; - - fd = hold_locked_index(&lock_file, 0); - refresh_cache(REFRESH_QUIET); - if (0 <= fd) - repo_update_index_if_able(the_repository, &lock_file); - rollback_lock_file(&lock_file); - - if (has_unstaged_changes(the_repository, 1) || - has_uncommitted_changes(the_repository, 1)) { - const char *autostash = - state_dir_path("autostash", &options); - struct child_process stash = CHILD_PROCESS_INIT; - struct object_id oid; - - argv_array_pushl(&stash.args, - "stash", "create", "autostash", NULL); - stash.git_cmd = 1; - stash.no_stdin = 1; - strbuf_reset(&buf); - if (capture_command(&stash, &buf, GIT_MAX_HEXSZ)) - die(_("Cannot autostash")); - strbuf_trim_trailing_newline(&buf); - if (get_oid(buf.buf, &oid)) - die(_("Unexpected stash response: '%s'"), - buf.buf); - strbuf_reset(&buf); - strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); - - if (safe_create_leading_directories_const(autostash)) - die(_("Could not create directory for '%s'"), - options.state_dir); - write_file(autostash, "%s", oid_to_hex(&oid)); - printf(_("Created autostash: %s\n"), buf.buf); - if (reset_head(the_repository, NULL, "reset --hard", - NULL, RESET_HEAD_HARD, NULL, NULL, - DEFAULT_REFLOG_ACTION) < 0) - die(_("could not reset --hard")); - - if (discard_index(the_repository->index) < 0 || - repo_read_index(the_repository) < 0) - die(_("could not read index")); - } + create_autostash(&options); } if (require_clean_work_tree(the_repository, "rebase", From patchwork Tue Dec 24 11:05:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309261 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 0B3F017EE for ; Tue, 24 Dec 2019 11:06:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE7CD20643 for ; Tue, 24 Dec 2019 11:06:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="txwi/ngA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726322AbfLXLGB (ORCPT ); Tue, 24 Dec 2019 06:06:01 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:46589 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbfLXLF7 (ORCPT ); Tue, 24 Dec 2019 06:05:59 -0500 Received: by mail-qt1-f194.google.com with SMTP id g1so10956518qtr.13 for ; Tue, 24 Dec 2019 03:05:58 -0800 (PST) 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=95FT44X1fafYIi6ZPoieZf54Wx0KhlfDBBonSUy6A1I=; b=txwi/ngA+mGAhC9vOcc4rFMRiMA8Js/v4EHUq31ckVU3914hkHYYZwl2i8B2krvuTU RtWtLtMbZfGmDxhXssuR4t8h9H27/Y7B4Dv34VHl1aMYsgfZFrxzDPcrm1067OaWgenH mjkT4/jYsIULieiqNfDhYp7/MbL4sac5Uo/aJtaNwCzacyRJ35zEMIBiqZa2wYWVm8s0 63qe1vN88jp3MAtPI7/uLi/F8R6ix/QUhvflkWtlzg8Pamuh4tdoqyE2Dj8Q0M2b//0m Vf2RDcQc5saJyg4Yn/JbZ6L4Sz79z6Ti1US7saQmmbZMa73dDtdbj1gZhnGhsIJA4zOt esuA== 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=95FT44X1fafYIi6ZPoieZf54Wx0KhlfDBBonSUy6A1I=; b=UEWYVrMNE9pOL1hslYTtxckDf85fKeiv4p9jfm6ojhwcoBGpZ0U8OqjLfIVqGX/BFb VPNQ6hN9PcS6GzSVG5XG/AA1IAesWleNZ6PM2gdMvLf2S5K8W6NyE82b90VmSxUOa3PN ccaq4GLbhD6mxuAXKSUUtcemqggOCFz5gVOpKN2exDBZ9OTDbsOCmFU97xX70+pPOZH/ iNJ8vwXMhOWbw04ra021VIkHHhN5q/GBnt67BQzStYMLuk7TP98qgQEZJo4nGXUf4rXa 0zDsvTIF6FNN9FN8Io/dTove48AaCUsHxrteKK/Z52DbPL+sqW5XFulRhLA4so/qpGpJ WOHA== X-Gm-Message-State: APjAAAW24FuyGVjreZ4jic82sORdKIAwcCDjvjc/iGPsRW5svWNNSYdw ssmbNefp588n6ebOhKwP5S6tu+N9 X-Google-Smtp-Source: APXvYqzEnAl6H9l8Y+yUzirRR6AmPj/3cMNQ2cK/hwwsuwSmCcaxSHi2nj/QybuTgQkS9iVoRquxYg== X-Received: by 2002:ac8:604b:: with SMTP id k11mr26869770qtm.372.1577185557972; Tue, 24 Dec 2019 03:05:57 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:57 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 12/17] rebase: generify create_autostash() Date: Tue, 24 Dec 2019 06:05:09 -0500 Message-Id: X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 b60be5c875..fea4ae754d 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1232,22 +1232,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; @@ -1265,18 +1264,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); @@ -1881,7 +1880,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("could not read index")); if (options.autostash) { - create_autostash(&options); + create_autostash(the_repository, state_dir_path("autostash", &options), + DEFAULT_REFLOG_ACTION); } if (require_clean_work_tree(the_repository, "rebase", From patchwork Tue Dec 24 11:05:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309263 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 8A2B1138D for ; Tue, 24 Dec 2019 11:06:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F4F72071A for ; Tue, 24 Dec 2019 11:06:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wg8CWZ0i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726332AbfLXLGC (ORCPT ); Tue, 24 Dec 2019 06:06:02 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:44387 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbfLXLGA (ORCPT ); Tue, 24 Dec 2019 06:06:00 -0500 Received: by mail-qt1-f193.google.com with SMTP id t3so17850271qtr.11 for ; Tue, 24 Dec 2019 03:05:59 -0800 (PST) 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=ZdNn547eEV48EQGchFj3dbcbQnZ0aMFqfkJbKWNoe48=; b=Wg8CWZ0iUEuD9gXrKq8GuC5qBjp4U4ZX8dIWeVowh1NPtzfEINDoAE1dm1o5/XoUAH xfaRmdM9gFvVeEKdxQ6MR/HGoKiiCXUAQRjlF1Fr1Dknn9SWTgnX7z43IG6GCDlz37n6 LbE1rwkYxsQ2BmZ1hO8wRKQ4OWGDxluDqhECWEWPNF3pyrRsYAVNKsZlxXB/WfLc/+mC VTbTwH8SQVgcNnrqgzxTlS28gvsEXLRlFA7PuLswF0Acy8YPV5td8V5glS4zgagJTjb+ rLfYvJkzQDNmZHykiL4qKT0fr6NFdn1ZOUQi82m0tTVscq32EdalFLeXPDTtP+mUWPQm ftFA== 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=ZdNn547eEV48EQGchFj3dbcbQnZ0aMFqfkJbKWNoe48=; b=I7aX2xIGjyN89ioZeCQvsKX+bDg4TZTJ+pW4mlhgvdCejTlSkFIxa6GvhsEA12QqL1 hC4EVMvIyrEvqY5oNp2bTVnvFKDmkSF6z+8SvnZWYw8ngK4RTHoY2Kqr9rhTSw3EML1g ZwjsR9BJFExE8gqAPnBkHgJW+lM2/LxgsvbqUeoIvsK+VzVrBT0R7T0H/NxBN9utt3xF CpkKPIPGWVyLEtDHeCq2pQWLqGzQaxED4w4h8nvfgXr60ySABmP6gEvZNYw2TR98ig2R zlgUPvc/p4hUFAUSpVaXyGPcEVXge8OnhmbVTOlNYxX0QAfiUWViWRuBe4/RknezH7Ef Mvrw== X-Gm-Message-State: APjAAAVHGfj7rXTnnA8TAaHtW2OTq5ghOLD4NO5HnCcBZpN5Z30z2JSH x43m8Of1nbYAeYW1UNCGr1AYkKE/ X-Google-Smtp-Source: APXvYqy3AmHrEhVLJM55FXzZS7kDgIdBnZmI6tiQdD/5RT70RtzBSGYid1M0QflpOycRkRJe9PkSMA== X-Received: by 2002:ac8:1184:: with SMTP id d4mr26781769qtj.104.1577185558810; Tue, 24 Dec 2019 03:05:58 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:58 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 13/17] sequencer: extract perform_autostash() from rebase Date: Tue, 24 Dec 2019 06:05:10 -0500 Message-Id: <2ff189692f82dc34391715ce68e85938190b06c5.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 fea4ae754d..666d3f0181 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1232,55 +1232,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 98e08dbbe0..ba04ee2de8 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" @@ -3744,6 +3745,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 ecef2c144c..8beb1472f7 100644 --- a/sequencer.h +++ b/sequencer.h @@ -195,6 +195,8 @@ void commit_post_rewrite(struct repository *r, int prepare_branch_to_be_rebased(struct repository *r, struct replay_opts *opts, const char *commit); +void create_autostash(struct repository *r, const char *path, + const char *default_reflog_action); int apply_autostash(const char *path); #define SUMMARY_INITIAL_COMMIT (1 << 0) From patchwork Tue Dec 24 11:05:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309271 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 BA149138D for ; Tue, 24 Dec 2019 11:06:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 994092071A for ; Tue, 24 Dec 2019 11:06:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bc1WNmEd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726407AbfLXLGI (ORCPT ); Tue, 24 Dec 2019 06:06:08 -0500 Received: from mail-qv1-f68.google.com ([209.85.219.68]:37554 "EHLO mail-qv1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbfLXLGC (ORCPT ); Tue, 24 Dec 2019 06:06:02 -0500 Received: by mail-qv1-f68.google.com with SMTP id f16so7361615qvi.4 for ; Tue, 24 Dec 2019 03:06:01 -0800 (PST) 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=Orhsbl7UW5kzoTvVCex4pVPAyfm4BNosFr2OoqF3ox4=; b=Bc1WNmEdqVGr6g2H5Hdtli4g30gMLuUEEhPF6KKHH0rUYIH5I4GHLtOTs7Yex8cy5n NfGOgOU9UznjfxpYNvIUY5HcDmp9daovhx50U3CbTBVz4t2bTqBgZHmbzBsRnRocGmuz 5hCRigy/v4g+DeOv805grpxx179j+/O/O9lJ4wdH0TDBmym4dbFu234T7Gwn1UQHk6hS coiqaLynOVkEJjxKCuyiBSG5OkO2lrwAwoH82TU6nllG3Rhf4FsqR0xpT+TqZIvOItc0 t9kq0d99aFD9aaHeeOEuCf7eM6/HCG90Teoji6376ygv2JqZXzMmEevDmKPnddciKJfw R/nw== 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=Orhsbl7UW5kzoTvVCex4pVPAyfm4BNosFr2OoqF3ox4=; b=j/grJTuh3S/gWFCK9dbCOWX/dPQGgloW+eDrI1dz1NO0BV3nh5Zu169lAnEtgN6VMB h2iOvk3YVroQe+qvsZwzuMhUMy0Rh7wi5lgKuKcc6TfitkFthnqubYQwfYjYxlqn0/Sf 0Rwr+ycqvWd3wM9+/jjOhDZ9/ReNK13DUMytOurqx5X/1h/Ki9Tucg2YAaF/yZaXb2ng qllDDY/JGMm4ktctooIAdTVRIfHcIM4qVK6D/Ghvvdrubg+EKjktFPbqQ5HwdyDo5cWy KMXtrOitYwlAe/ZP3OOjq5mkCvVZuQVXMRcw11+sm3aANgdGaGvfAvoo2rE7xrHFhKu+ Q/Qg== X-Gm-Message-State: APjAAAUUqD7Bcrn0vBt4yNE2fQS7S93edhcQg+a1X/Hv95qlYKWxZ98p cwc6Xg5V1OxcIDrK4rQW+aIO1Qs0 X-Google-Smtp-Source: APXvYqx0MVaT0LgrfFl1gyUMNPxnBa2RT6CJjuDa5Mmioa8XO7eCqZy7jfRUE8sLG7sBhosMVtjFMw== X-Received: by 2002:a0c:ef0f:: with SMTP id t15mr28475374qvr.123.1577185559703; Tue, 24 Dec 2019 03:05:59 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:05:59 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 14/17] sequencer: unlink autostash in apply_autostash() Date: Tue, 24 Dec 2019 06:05:11 -0500 Message-Id: <2b167116802c7130e4cdecd0ecd5df501fe9a6e0.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 ba04ee2de8..cc0391ca35 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3834,6 +3834,7 @@ int apply_autostash(const char *path) " \"git stash drop\" at any time.\n")); } + unlink(path); strbuf_release(&stash_sha1); return ret; } From patchwork Tue Dec 24 11:05:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309275 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 2CF1014E3 for ; Tue, 24 Dec 2019 11:06:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01B932071A for ; Tue, 24 Dec 2019 11:06:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e4J9hrKo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726559AbfLXLGL (ORCPT ); Tue, 24 Dec 2019 06:06:11 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:46593 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbfLXLGC (ORCPT ); Tue, 24 Dec 2019 06:06:02 -0500 Received: by mail-qt1-f194.google.com with SMTP id g1so10956597qtr.13 for ; Tue, 24 Dec 2019 03:06:01 -0800 (PST) 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=H7QKuwLbnxTzeR6wlJIup1vWnTbHIMvnSnCLFnjonc8=; b=e4J9hrKoIOwA/6rhZ72Hm+w/8KA62IRCfv+Ip8PgTPkCU8dmUxn+Aq4ymTWmmQYmCM tKBXVC5ZLtZ5sWYMEiHA2Mk2tlo4BtZN/3Krni5x+fGMyR9x9vKBGpZyCj8R1ZKOWzdw shxs2GEo2OfqUq+FuBNxjhPec6pvz3PGN1MPoiKlC8m3LXBbE1sKisvqRkl6SOmEzzcW C5Y53m4HDVFK16TC9RwMUyTvVUYccfJQrjvOOyqDrepGq2K7HI9hxEnOZaEDdrGOGP2t 38ek7Ppn2pWpEjqsXJ1Bk65LrR2koRb3vvxExOJg1kOl6u+3VghJ2VizgRUiPtvxkxRM Y06w== 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=H7QKuwLbnxTzeR6wlJIup1vWnTbHIMvnSnCLFnjonc8=; b=bsCWWb4NIiTBydyEResnEDEK5Wv75RW4pOFXHUMbTVI1tXxSin50Ndk7VUstyqxGXS POM6HyPoZgytijB3Z5/mueYQgpHIWGtjJ/xGhX24mds9bytFCvs51Ua815IatyeXkyEP knhNS/IFGGuq3lP5sWe6a2DhWOxQvaQAwcINYd92iwA02vpyOKAbkhg2egFtHZrrGTeS 30oUoWovwN61g/NE+fBaUmWGAGNW0Q/rh6sfoxKIPq8JSU1qLc4sq/qq3GDVKExGeA4E 7XKt0GkfCI7rUFIf67c2Fp0fLzpTSWAsaXj9n1CwqzjFwQ2AUwLQOFMaOY0OHx3qX7zM AxAw== X-Gm-Message-State: APjAAAX1+B30gy/U8fCnyEMstEbVVOP3EXdGLUPFPjMQFgC/rYOmOH0c wQ31EwqQrld2W7dLhfusXIMqfmYe X-Google-Smtp-Source: APXvYqzO+6onqXiTpN25i7+eNK8Ggv2QOnK3Poog5EBg4NLnDlsOLoAWJCv0AngWoo5w/rvuau+cYA== X-Received: by 2002:ac8:602:: with SMTP id d2mr27139914qth.245.1577185560679; Tue, 24 Dec 2019 03:06:00 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:06:00 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 15/17] merge: teach --autostash option Date: Tue, 24 Dec 2019 06:05:12 -0500 Message-Id: <6e987052c0910f0131317093cb917dcf9eea127d.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 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 +++++++++ path.c | 1 + path.h | 4 +- t/t3033-merge-toplevel.sh | 22 +++++++++++ t/t7600-merge.sh | 65 +++++++++++++++++++++++++++++++++ 9 files changed, 129 insertions(+), 1 deletion(-) 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 e48c1fd90a..ebb7f4d80e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1679,6 +1679,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 062e911441..a940bd4cbf 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -81,6 +81,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[] = { @@ -285,6 +286,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")), @@ -440,6 +443,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 { @@ -631,6 +635,9 @@ static int git_merge_config(const char *k, const char *v, void *cb) } else if (!strcmp(k, "commit.gpgsign")) { sign_commit = git_config_bool(k, v) ? "" : NULL; return 0; + } else if (!strcmp(k, "merge.autostash")) { + autostash = git_config_bool(k, v); + return 0; } status = fmt_merge_msg_config(k, v, cb); @@ -1288,6 +1295,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; } @@ -1508,6 +1516,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, @@ -1574,6 +1586,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/path.c b/path.c index a76eec8b96..d8c4072f1a 100644 --- a/path.c +++ b/path.c @@ -1533,5 +1533,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..e0c8a0bad4 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,67 @@ 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 'merge with conflicted --autostash changes' ' + git reset --hard c1 && + git merge-file file file.orig file.9y && + git diff >expect && + test_when_finished "test_might_fail git stash drop" && + git merge --autostash c3 2>err && + test_i18ngrep "Applying autostash resulted in conflicts." err && + git show HEAD:file >merge-result && + test_cmp result.1-9 merge-result && + git stash show -p >actual && + test_cmp expect actual +' + cat >expected.branch <<\EOF Merge branch 'c5-branch' (early part) EOF From patchwork Tue Dec 24 11:05:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309273 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 3D18717EE for ; Tue, 24 Dec 2019 11:06:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D7F02071A for ; Tue, 24 Dec 2019 11:06:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KiJ1ATKa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726184AbfLXLGJ (ORCPT ); Tue, 24 Dec 2019 06:06:09 -0500 Received: from mail-qv1-f47.google.com ([209.85.219.47]:35170 "EHLO mail-qv1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfLXLGC (ORCPT ); Tue, 24 Dec 2019 06:06:02 -0500 Received: by mail-qv1-f47.google.com with SMTP id u10so7285871qvi.2 for ; Tue, 24 Dec 2019 03:06:02 -0800 (PST) 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=/3hRU+fqnAEdWhaHhgxjxvWGuQ2nCDHFjrxD+49aImA=; b=KiJ1ATKaWUItYDXuuBXiBpV10sxTqts4xp83uaWO2U1PnMF2WdTKAOyWGJOhVOaFnh 8c7Bv5HhXa2qextydUym+kGr6pCEFuk2EBGi04gyw5HvyNLJy+k1GXI88L46PpIp1CWK pqHHMQvGZQXRrB/Ck9IYCNlQFeI0zx1u5HJQAlmuX0kmlFOQPvAPnvxKVCHh9PMlH0SR he6Ahz7zdXo09Pf+nuZAxP00P4OFQfyXJpk9fJzEw+7m3W7Pmn2/F68zjQzsd0DkmLe5 BTzNcmdyJMNEkMbw9gnLwI3w1GdYi+xuZn5NxUgvPg+MoEFmtG63ZDOVju3e7VAzLZps Xy4A== 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=/3hRU+fqnAEdWhaHhgxjxvWGuQ2nCDHFjrxD+49aImA=; b=rbBHbFIPX35QYHSkScaBAunVaHc1AboVC6kY93M0+l3Ul3UZWnD520KZCy7oFBMiGu yOVkGI6y4oOYMDWvkXeq4jqmKwL9BAPyQgVgMiHgOVOo6Ip+6He/rPCB00FfC/QasUAA vkwe3d/i3K+tL9zDU1+E04gEngU0jq+lKFuxYscv3hM+7BBR2k0GrVJjh16U1r0kWBHP 030GqIxNXohpGRrEOfBkzlqNhhRve1GgFFr5mFgQCgFlhSF/adtF5gvOtTiq9T9iEDko x8kTKdWyq4U8HwlvixX2zDwqNluyjDZuqEXRqiukYH0g2DBMG7fD20EsGzUMtNynW6To xyUQ== X-Gm-Message-State: APjAAAXMlMRuKYR7XpE0kS3xMZb1AmmlldJOyfomGQ6AbiBLk9lNJ8p1 zlpYq1pWFn6h52l618tMWNxUMOtV X-Google-Smtp-Source: APXvYqygCKsyk8fvVRUSzIU3XPE51Tlzj+dpFwjd6DbDTj4Cb2mNHk/IjElijw7rMgVoV58TrJFT5g== X-Received: by 2002:a05:6214:11ac:: with SMTP id u12mr28429843qvv.85.1577185561630; Tue, 24 Dec 2019 03:06:01 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:06:01 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 16/17] t5520: make test_pull_autostash() accept expect_parent_num Date: Tue, 24 Dec 2019 06:05:13 -0500 Message-Id: X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 602d996a33..218f469d0a 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 && @@ -356,22 +358,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' ' @@ -409,7 +411,7 @@ test_expect_success 'pull.rebase' ' test_expect_success 'pull --autostash & pull.rebase=true' ' test_config pull.rebase true && - test_pull_autostash --autostash + test_pull_autostash 1 --autostash ' test_expect_success 'pull --no-autostash & pull.rebase=true' ' From patchwork Tue Dec 24 11:05:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11309269 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 1E27214E3 for ; Tue, 24 Dec 2019 11:06:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E684620706 for ; Tue, 24 Dec 2019 11:06:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R5kT32Yt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726388AbfLXLGH (ORCPT ); Tue, 24 Dec 2019 06:06:07 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:34786 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726347AbfLXLGE (ORCPT ); Tue, 24 Dec 2019 06:06:04 -0500 Received: by mail-qk1-f195.google.com with SMTP id j9so16177001qkk.1 for ; Tue, 24 Dec 2019 03:06:03 -0800 (PST) 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=Dd4cRdrwUOdnxiynbesblqHwrYI4u9VIiC1VHZZfibA=; b=R5kT32YtU3mp/PHZ0cfomub7PXgHu0SaJUGSBWpHqIBuGNuhO5qTkksZLiZ/WDV0On iGiWdI7xa8f6o5Y54P1xjuVykhn/GR6kkgsSwUqFOI0w2DwtMlH4o4cjf8ODHYcQRYBF GQ6SGL1m4X1wV8mI4v98wjFl5lpt/rkcbgioY8MvNmDG42aO+KEEhgecVvaymNMqa0er MmBGOw+3WHF16hhi19afFbjK9OM+ORElaWpdYkNz7/o0OA0263hYCFwIPPYJPRY4D0GS 2YqPRplmFV8Ea4+uChrNkUR+riENidQTVeYxaXVYZTK7dKZ65zwEXl1VMIrR3C9SM16l e23g== 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=Dd4cRdrwUOdnxiynbesblqHwrYI4u9VIiC1VHZZfibA=; b=QwAN1jJftucOkWpLpt8rsn6ZR7wdxxjgEhT5Ih0lQYCTh71XQDoXDp+5QJiCM1L0xS 8cOr7syQfTK8Rg+eJd0O3FOI84beqfOFkWqz9HWA91x09JBszNghageMDpfTsQCd9lNn BPeu3eFh5TcUwmqky1AhoF93P9kfazv+qDG1kHNWTrECosdzg1EvDIn0oAGgxIsdhegb wIDUbuxLRyM+V+MW9rxY7ZxOk0NIgDvnOIFBh24loW/ROPlxZt07Zyg+Dh2o/rlfV901 UBFSfjyYLVPtusONc6Z+E0cuR29u+p8Vgs8ea6IDgpTFJ1BRyTaATGfmazvyok4dV+UR jKiQ== X-Gm-Message-State: APjAAAUtg0VmtqegLM8HbbnYj2H387VcPD4su037QnOfEEsVKEpZaf7Z PtkGNYWEp2deVqX6HI4ukuoKIiu0 X-Google-Smtp-Source: APXvYqxudq11m/LDDJxX7tqkJv8RWYnimVaJ/UZFLq8C457iK7/L/50/snXPl2MUC/cB9e3S+OhyZg== X-Received: by 2002:a37:9ec2:: with SMTP id h185mr29976975qke.14.1577185562709; Tue, 24 Dec 2019 03:06:02 -0800 (PST) Received: from archbookpro.localdomain (CPE18593399858a-CM185933998587.cpe.net.cable.rogers.com. [174.112.65.113]) by smtp.gmail.com with ESMTPSA id o19sm7446944qtb.43.2019.12.24.03.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2019 03:06:02 -0800 (PST) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v2 17/17] pull: pass --autostash to merge Date: Tue, 24 Dec 2019 06:05:14 -0500 Message-Id: <6ebae1d7588acbba5dd11d6a0d6dcdb78e266b17.1577185374.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.24.1.810.g65a2f617f4 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 d25ff13a60..ee186781ae 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -183,7 +183,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), @@ -671,6 +671,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"); @@ -918,9 +922,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 218f469d0a..2919ad4f81 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 ' @@ -391,13 +391,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 &&