From patchwork Sat Apr 4 01:11:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473939 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 85E8C1668 for ; Sat, 4 Apr 2020 01:12:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BC3A20787 for ; Sat, 4 Apr 2020 01:12:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KcpCmCxs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726469AbgDDBMI (ORCPT ); Fri, 3 Apr 2020 21:12:08 -0400 Received: from mail-qk1-f171.google.com ([209.85.222.171]:45437 "EHLO mail-qk1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbgDDBMF (ORCPT ); Fri, 3 Apr 2020 21:12:05 -0400 Received: by mail-qk1-f171.google.com with SMTP id o18so7349730qko.12 for ; Fri, 03 Apr 2020 18:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k4eKyQET1CoPr+njRS/c7UTku2TF4XktbZ4P78bJkfk=; b=KcpCmCxsyK3hWwE0rWEtxSpdW1sTScoDoBKmbcxGujcxZXEmnsb0JE2KrXXng8JlVB rEUm7ZFtJR0I6uFtr+NcrrmP+1qeXbgWaLZVZcjCrKIysxBslT37rri9XAqrGDOZyUou c+qDGQnMgQ4Hy3ekBhVwpbC9uEL236b5LFQU2Z5zDEJxxv3AGjLk+jhA1gb2CYUcy3/x C8WT4q6apLHHaIjHMHzubvM8lr/g3PpM9fADU+TZl5pVAHmbD0+Ki4+Qh4uceQ6eIW0c i0qz6NKqmSw0RGNzkDb0Y6r2oRGAo3DjjjamDkNdbPJh0qAkBWPycffVnej4YLifucbD TVug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k4eKyQET1CoPr+njRS/c7UTku2TF4XktbZ4P78bJkfk=; b=sCJitdhIGG8YJRdksmnWV5z/EaLb9nqPg2TD+oapnF5iS2xesQa4m4SBHentL+/Zcz Hw1/+gEjjowQCIX2ZrbYoisXBWr4mmIW7d3yMwbD3n9pLmwz1USvIEDS0B5pNWsp/NfE kQ6V4/ixEAl762ZnxuYapZMQu6LSfLBfwf9lFlvB3mSEhbLN2KO/f8pjxGPiXwCSJy9m FsJ209vuSPYlHyGCZq/GK7Qf4Zp9ZEgrwQ+5zRIesuY7BlMjlSalWh45AwSVVI9u7iME 9rwQOxik3vglFUJA+g3RYzvSgEsgwTB6yvXJ7Q28/kYK635E3oF7DrCMvR+Njgs1UUe/ m4FA== X-Gm-Message-State: AGi0PuZlFoLTVWG5f+ccUAKbsy3zZVLebHx4ilXCog0kfuTRu2+ByP87 dtPtM8Hgk8pMM8UK4mhoWQKQ5p8M X-Google-Smtp-Source: APiQypIgS9dgcu2MXL4VftQeWoNBm7LBq1ywPY86Jf0z7z0oyuf61KkWTrHWZpH3iwbT4LqxZVENCQ== X-Received: by 2002:a05:620a:12bc:: with SMTP id x28mr11523426qki.175.1585962720200; Fri, 03 Apr 2020 18:12:00 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:11:59 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 01/23] Makefile: ASCII-sort += lists Date: Fri, 3 Apr 2020 21:11:14 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There are many += lists in the Makefile and, over time, they have gotten slightly out of ASCII order. Sort all += lists to bring them back in order. ASCII sorting was chosen over strict alphabetical order even though, if we omit file prefixes, the lists aren't sorted in strictly alphabetical order (e.g. archive.o comes after archive-zip.o instead of before archive-tar.o). This is intentional because the purpose of maintaining the sorted list is to ensure line insertions are deterministic. By using ASCII ordering, it is more easily mechanically reproducible in the future, such as by using :sort in Vim. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu --- Makefile | 77 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 9804a0758b..f709fc3f77 100644 --- a/Makefile +++ b/Makefile @@ -604,12 +604,12 @@ unexport CDPATH SCRIPT_SH += git-bisect.sh SCRIPT_SH += git-difftool--helper.sh SCRIPT_SH += git-filter-branch.sh +SCRIPT_SH += git-legacy-stash.sh SCRIPT_SH += git-merge-octopus.sh SCRIPT_SH += git-merge-one-file.sh SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-quiltimport.sh -SCRIPT_SH += git-legacy-stash.sh SCRIPT_SH += git-request-pull.sh SCRIPT_SH += git-submodule.sh SCRIPT_SH += git-web--browse.sh @@ -617,8 +617,8 @@ SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib SCRIPT_LIB += git-parse-remote SCRIPT_LIB += git-rebase--preserve-merges -SCRIPT_LIB += git-sh-setup SCRIPT_LIB += git-sh-i18n +SCRIPT_LIB += git-sh-setup SCRIPT_PERL += git-add--interactive.perl SCRIPT_PERL += git-archimport.perl @@ -686,9 +686,9 @@ PROGRAM_OBJS += daemon.o PROGRAM_OBJS += fast-import.o PROGRAM_OBJS += http-backend.o PROGRAM_OBJS += imap-send.o +PROGRAM_OBJS += remote-testsvn.o PROGRAM_OBJS += sh-i18n--envsubst.o PROGRAM_OBJS += shell.o -PROGRAM_OBJS += remote-testsvn.o # Binary suffix, set to .exe for Windows builds X = @@ -709,9 +709,9 @@ TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-example-decorate.o TEST_BUILTINS_OBJS += test-genrandom.o TEST_BUILTINS_OBJS += test-genzeros.o +TEST_BUILTINS_OBJS += test-hash-speed.o TEST_BUILTINS_OBJS += test-hash.o TEST_BUILTINS_OBJS += test-hashmap.o -TEST_BUILTINS_OBJS += test-hash-speed.o TEST_BUILTINS_OBJS += test-index-version.o TEST_BUILTINS_OBJS += test-json-writer.o TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o @@ -737,8 +737,8 @@ TEST_BUILTINS_OBJS += test-revision-walking.o TEST_BUILTINS_OBJS += test-run-command.o TEST_BUILTINS_OBJS += test-scrap-cache-tree.o TEST_BUILTINS_OBJS += test-serve-v2.o -TEST_BUILTINS_OBJS += test-sha1.o TEST_BUILTINS_OBJS += test-sha1-array.o +TEST_BUILTINS_OBJS += test-sha1.o TEST_BUILTINS_OBJS += test-sha256.o TEST_BUILTINS_OBJS += test-sigchain.o TEST_BUILTINS_OBJS += test-strcmp-offset.o @@ -748,10 +748,10 @@ TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o TEST_BUILTINS_OBJS += test-subprocess.o TEST_BUILTINS_OBJS += test-trace2.o TEST_BUILTINS_OBJS += test-urlmatch-normalization.o -TEST_BUILTINS_OBJS += test-xml-encode.o TEST_BUILTINS_OBJS += test-wildmatch.o TEST_BUILTINS_OBJS += test-windows-named-pipe.o TEST_BUILTINS_OBJS += test-write-cache.o +TEST_BUILTINS_OBJS += test-xml-encode.o # Do not add more tests here unless they have extra dependencies. Add # them in TEST_BUILTINS_OBJS above. @@ -788,10 +788,10 @@ OTHER_PROGRAMS = git$X # what test wrappers are needed and 'install' will install, in bindir BINDIR_PROGRAMS_NEED_X += git -BINDIR_PROGRAMS_NEED_X += git-upload-pack BINDIR_PROGRAMS_NEED_X += git-receive-pack -BINDIR_PROGRAMS_NEED_X += git-upload-archive BINDIR_PROGRAMS_NEED_X += git-shell +BINDIR_PROGRAMS_NEED_X += git-upload-archive +BINDIR_PROGRAMS_NEED_X += git-upload-pack BINDIR_PROGRAMS_NO_X += git-cvsserver @@ -831,9 +831,9 @@ LIB_OBJS += advice.o LIB_OBJS += alias.o LIB_OBJS += alloc.o LIB_OBJS += apply.o -LIB_OBJS += archive.o LIB_OBJS += archive-tar.o LIB_OBJS += archive-zip.o +LIB_OBJS += archive.o LIB_OBJS += argv-array.o LIB_OBJS += attr.o LIB_OBJS += base85.o @@ -849,9 +849,9 @@ LIB_OBJS += checkout.o LIB_OBJS += color.o LIB_OBJS += column.o LIB_OBJS += combine-diff.o -LIB_OBJS += commit.o LIB_OBJS += commit-graph.o LIB_OBJS += commit-reach.o +LIB_OBJS += commit.o LIB_OBJS += compat/obstack.o LIB_OBJS += compat/terminal.o LIB_OBJS += config.o @@ -865,17 +865,17 @@ LIB_OBJS += ctype.o LIB_OBJS += date.o LIB_OBJS += decorate.o LIB_OBJS += delta-islands.o +LIB_OBJS += diff-delta.o +LIB_OBJS += diff-lib.o +LIB_OBJS += diff-no-index.o +LIB_OBJS += diff.o LIB_OBJS += diffcore-break.o LIB_OBJS += diffcore-delta.o LIB_OBJS += diffcore-order.o LIB_OBJS += diffcore-pickaxe.o LIB_OBJS += diffcore-rename.o -LIB_OBJS += diff-delta.o -LIB_OBJS += diff-lib.o -LIB_OBJS += diff-no-index.o -LIB_OBJS += diff.o -LIB_OBJS += dir.o LIB_OBJS += dir-iterator.o +LIB_OBJS += dir.o LIB_OBJS += editor.o LIB_OBJS += entry.o LIB_OBJS += environment.o @@ -893,7 +893,6 @@ LIB_OBJS += gpg-interface.o LIB_OBJS += graph.o LIB_OBJS += grep.o LIB_OBJS += hashmap.o -LIB_OBJS += linear-assignment.o LIB_OBJS += help.o LIB_OBJS += hex.o LIB_OBJS += ident.o @@ -903,9 +902,10 @@ LIB_OBJS += kwset.o LIB_OBJS += levenshtein.o LIB_OBJS += line-log.o LIB_OBJS += line-range.o -LIB_OBJS += list-objects.o -LIB_OBJS += list-objects-filter.o +LIB_OBJS += linear-assignment.o LIB_OBJS += list-objects-filter-options.o +LIB_OBJS += list-objects-filter.o +LIB_OBJS += list-objects.o LIB_OBJS += ll-merge.o LIB_OBJS += lockfile.o LIB_OBJS += log-tree.o @@ -914,31 +914,31 @@ LIB_OBJS += mailinfo.o LIB_OBJS += mailmap.o LIB_OBJS += match-trees.o LIB_OBJS += mem-pool.o -LIB_OBJS += merge.o LIB_OBJS += merge-blobs.o LIB_OBJS += merge-recursive.o +LIB_OBJS += merge.o LIB_OBJS += mergesort.o LIB_OBJS += midx.o LIB_OBJS += name-hash.o LIB_OBJS += negotiator/default.o LIB_OBJS += negotiator/skipping.o -LIB_OBJS += notes.o LIB_OBJS += notes-cache.o LIB_OBJS += notes-merge.o LIB_OBJS += notes-utils.o +LIB_OBJS += notes.o LIB_OBJS += object.o LIB_OBJS += oidmap.o LIB_OBJS += oidset.o -LIB_OBJS += packfile.o -LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-bitmap-write.o +LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-check.o LIB_OBJS += pack-objects.o LIB_OBJS += pack-revindex.o LIB_OBJS += pack-write.o +LIB_OBJS += packfile.o LIB_OBJS += pager.o -LIB_OBJS += parse-options.o LIB_OBJS += parse-options-cb.o +LIB_OBJS += parse-options.o LIB_OBJS += patch-delta.o LIB_OBJS += patch-ids.o LIB_OBJS += path.o @@ -955,8 +955,9 @@ LIB_OBJS += quote.o LIB_OBJS += range-diff.o LIB_OBJS += reachable.o LIB_OBJS += read-cache.o -LIB_OBJS += rebase.o LIB_OBJS += rebase-interactive.o +LIB_OBJS += rebase.o +LIB_OBJS += ref-filter.o LIB_OBJS += reflog-walk.o LIB_OBJS += refs.o LIB_OBJS += refs/files-backend.o @@ -964,7 +965,6 @@ LIB_OBJS += refs/iterator.o LIB_OBJS += refs/packed-backend.o LIB_OBJS += refs/ref-cache.o LIB_OBJS += refspec.o -LIB_OBJS += ref-filter.o LIB_OBJS += remote.o LIB_OBJS += replace-object.o LIB_OBJS += repo-settings.o @@ -979,8 +979,8 @@ LIB_OBJS += serve.o LIB_OBJS += server-info.o LIB_OBJS += setup.o LIB_OBJS += sha1-array.o -LIB_OBJS += sha1-lookup.o LIB_OBJS += sha1-file.o +LIB_OBJS += sha1-lookup.o LIB_OBJS += sha1-name.o LIB_OBJS += shallow.o LIB_OBJS += sideband.o @@ -990,9 +990,9 @@ LIB_OBJS += stable-qsort.o LIB_OBJS += strbuf.o LIB_OBJS += streaming.o LIB_OBJS += string-list.o -LIB_OBJS += submodule.o -LIB_OBJS += submodule-config.o LIB_OBJS += sub-process.o +LIB_OBJS += submodule-config.o +LIB_OBJS += submodule.o LIB_OBJS += symlinks.o LIB_OBJS += tag.o LIB_OBJS += tempfile.o @@ -1011,11 +1011,11 @@ LIB_OBJS += trace2/tr2_tgt_normal.o LIB_OBJS += trace2/tr2_tgt_perf.o LIB_OBJS += trace2/tr2_tls.o LIB_OBJS += trailer.o -LIB_OBJS += transport.o LIB_OBJS += transport-helper.o +LIB_OBJS += transport.o LIB_OBJS += tree-diff.o -LIB_OBJS += tree.o LIB_OBJS += tree-walk.o +LIB_OBJS += tree.o LIB_OBJS += unpack-trees.o LIB_OBJS += upload-pack.o LIB_OBJS += url.o @@ -1055,9 +1055,9 @@ BUILTIN_OBJS += builtin/checkout.o BUILTIN_OBJS += builtin/clean.o BUILTIN_OBJS += builtin/clone.o BUILTIN_OBJS += builtin/column.o +BUILTIN_OBJS += builtin/commit-graph.o BUILTIN_OBJS += builtin/commit-tree.o BUILTIN_OBJS += builtin/commit.o -BUILTIN_OBJS += builtin/commit-graph.o BUILTIN_OBJS += builtin/config.o BUILTIN_OBJS += builtin/count-objects.o BUILTIN_OBJS += builtin/credential.o @@ -1088,13 +1088,13 @@ BUILTIN_OBJS += builtin/ls-remote.o BUILTIN_OBJS += builtin/ls-tree.o BUILTIN_OBJS += builtin/mailinfo.o BUILTIN_OBJS += builtin/mailsplit.o -BUILTIN_OBJS += builtin/merge.o BUILTIN_OBJS += builtin/merge-base.o BUILTIN_OBJS += builtin/merge-file.o BUILTIN_OBJS += builtin/merge-index.o BUILTIN_OBJS += builtin/merge-ours.o BUILTIN_OBJS += builtin/merge-recursive.o BUILTIN_OBJS += builtin/merge-tree.o +BUILTIN_OBJS += builtin/merge.o BUILTIN_OBJS += builtin/mktag.o BUILTIN_OBJS += builtin/mktree.o BUILTIN_OBJS += builtin/multi-pack-index.o @@ -1114,9 +1114,9 @@ BUILTIN_OBJS += builtin/read-tree.o BUILTIN_OBJS += builtin/rebase.o BUILTIN_OBJS += builtin/receive-pack.o BUILTIN_OBJS += builtin/reflog.o -BUILTIN_OBJS += builtin/remote.o BUILTIN_OBJS += builtin/remote-ext.o BUILTIN_OBJS += builtin/remote-fd.o +BUILTIN_OBJS += builtin/remote.o BUILTIN_OBJS += builtin/repack.o BUILTIN_OBJS += builtin/replace.o BUILTIN_OBJS += builtin/rerere.o @@ -2335,16 +2335,16 @@ reconfigure config.mak.autogen: config.status endif XDIFF_OBJS += xdiff/xdiffi.o -XDIFF_OBJS += xdiff/xprepare.o -XDIFF_OBJS += xdiff/xutils.o XDIFF_OBJS += xdiff/xemit.o +XDIFF_OBJS += xdiff/xhistogram.o XDIFF_OBJS += xdiff/xmerge.o XDIFF_OBJS += xdiff/xpatience.o -XDIFF_OBJS += xdiff/xhistogram.o +XDIFF_OBJS += xdiff/xprepare.o +XDIFF_OBJS += xdiff/xutils.o +VCSSVN_OBJS += vcs-svn/fast_export.o VCSSVN_OBJS += vcs-svn/line_buffer.o VCSSVN_OBJS += vcs-svn/sliding_window.o -VCSSVN_OBJS += vcs-svn/fast_export.o VCSSVN_OBJS += vcs-svn/svndiff.o VCSSVN_OBJS += vcs-svn/svndump.o @@ -3152,9 +3152,10 @@ endif # ALL_COMMANDS = $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) ALL_COMMANDS += git +ALL_COMMANDS += git-citool +ALL_COMMANDS += git-gui ALL_COMMANDS += gitk ALL_COMMANDS += gitweb -ALL_COMMANDS += git-gui git-citool .PHONY: check-docs check-docs:: From patchwork Sat Apr 4 01:11:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473925 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 28C79912 for ; Sat, 4 Apr 2020 01:12:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 043C12074B for ; Sat, 4 Apr 2020 01:12:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rGKfRAxV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726365AbgDDBMC (ORCPT ); Fri, 3 Apr 2020 21:12:02 -0400 Received: from mail-qt1-f173.google.com ([209.85.160.173]:42838 "EHLO mail-qt1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726170AbgDDBMC (ORCPT ); Fri, 3 Apr 2020 21:12:02 -0400 Received: by mail-qt1-f173.google.com with SMTP id b10so2483905qtt.9 for ; Fri, 03 Apr 2020 18:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ub/Rqz/ZQ52smebEp7L5zy/sTdobfJ66/yCyFnDZTAI=; b=rGKfRAxVGtQOZPMFvjObtEYwmEqqtxzdbKqd4ZZ8b/QeDCPWmEwgCbq94VZlnKGQc1 mK/J6E76o1LRswhuDvKN+veY0ZlLhXp/l805GvhY/UF5UgS7XGyKMsTfuSgYRPh3Rnw8 NcgQC8X5cfKJBzLoo3dazoB5C4vFhe9zBq3bB5Gpd573v2zlZNPMFO1mkvvHuhOvHFTN tkdfTyO9+v8zRrjwouhdVv9xmnMtw5gXStBJUy2ORW6yO2f9io7YzZujrua9fIGldIHh n07IIgfcBtx3vIBU7VYHFwwdWk2tLawvMUNz9AodLZNVtQ+FCysMSv/PsLq5YTeC+HOe Sjyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ub/Rqz/ZQ52smebEp7L5zy/sTdobfJ66/yCyFnDZTAI=; b=Hub7Ofngty0u60EdHY5UbTWIYFM2SncCYAI6Lzqt/9mtbApDBQPF9L5t0eGr5Icp3K Mv+ZOYU9n5Jgjo8bIp0tQdzhG1KP/AIz5fyoxHg/XE5gxYpEW8Tl9LxyvM127o4AR9Dw HSeFuLq/mRZ5LKzpH6hEYilFUS/TVFNzM6CrUcVYvEOQxQ2t3NVFsVSXcFS+Mx9JBt0I PUVnyUenSEcUAZdkiUfWQuRFqMsaqgAyDO6dhtmUTqNoP97sRKTmL4+qNTGwf94GZEtn IHCPc6nLewJKzl6uVr/j/lM3ThsgBmE4TrRWjtoFnpAMZgToer2+d4AaISHVbzVLH/UW +cCg== X-Gm-Message-State: AGi0PuZ5/mtwTekoHIn2W3dudD/oto0IJCzoctqsZX+duDw2bjZe3p0h zvQbxICHGoME7e05gQSW52mYvlS0 X-Google-Smtp-Source: APiQypId84ZTgVKzRxo5hHdc3xi/9wwkzlP3JAouSB5r2g8v3qlXaNJuqwbSddUGbBBpT7W57oTcbQ== X-Received: by 2002:ac8:342b:: with SMTP id u40mr10536993qtb.83.1585962721187; Fri, 03 Apr 2020 18:12:01 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:00 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 02/23] t7600: use test_write_lines() Date: Fri, 3 Apr 2020 21:11:15 -0400 Message-Id: <059e0e8e43f633086fc297f8328288047b45d0e0.1585962672.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In t7600, we were rewriting `printf '%s\n' ...` to create files from parameters, one per line. However, we already have a function that wraps this for us: test_write_lines(). Rewrite these instances to use that function instead of open coding it. Signed-off-by: Denton Liu --- t/t7600-merge.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 132608879a..4fa0ef8e3b 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -29,15 +29,15 @@ Testing basic merge operations/option parsing. . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh -printf '%s\n' 1 2 3 4 5 6 7 8 9 >file -printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1 -printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y -printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1 -printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 -printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 -printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z +test_write_lines 1 2 3 4 5 6 7 8 9 >file +test_write_lines '1 X' 2 3 4 5 6 7 8 9 >file.1 +test_write_lines 1 2 3 4 '5 X' 6 7 8 9 >file.5 +test_write_lines 1 2 3 4 5 6 7 8 '9 X' >file.9 +test_write_lines 1 2 3 4 5 6 7 8 '9 Y' >file.9y +test_write_lines '1 X' 2 3 4 5 6 7 8 9 >result.1 +test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 +test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 +test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z create_merge_msgs () { echo "Merge tag 'c2'" >msg.1-5 && @@ -81,7 +81,7 @@ verify_head () { } verify_parents () { - printf '%s\n' "$@" >parents.expected && + test_write_lines "$@" >parents.expected && >parents.actual && i=1 && while test $i -le $# @@ -95,7 +95,7 @@ verify_parents () { } verify_mergeheads () { - printf '%s\n' "$@" >mergehead.expected && + test_write_lines "$@" >mergehead.expected && while read sha1 rest do git rev-parse $sha1 From patchwork Sat Apr 4 01:11:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473927 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 8B37F1668 for ; Sat, 4 Apr 2020 01:12:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 672412074B for ; Sat, 4 Apr 2020 01:12:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OeaUB6uh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726464AbgDDBME (ORCPT ); Fri, 3 Apr 2020 21:12:04 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:42686 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgDDBMD (ORCPT ); Fri, 3 Apr 2020 21:12:03 -0400 Received: by mail-qt1-f195.google.com with SMTP id b10so2483930qtt.9 for ; Fri, 03 Apr 2020 18:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S0aG82s5CcnkkAJmRuKrOrhMfbEmERigVtMxWONZzI8=; b=OeaUB6uhaslrbMXMC0bLfWP2jdulth1cEwm7OrwD3ZqXOWT2noiN01+qMdJDtz8Gxe TNlP2hZZGwtzRMbDOmwGQa3nrl7NJYeWOMjXrPQKyxNO5ib3/TpdNorPTpjXyYPSdYBv vX0oRBLyI6xTKHFZK9E3BVx3ZUZ6OxFKFAM+XM9qNhNL1tjZCrICjy6dIK65ifn/uzAb Yijw1hYxYqor2dHJUJcxa/h61cQxN1S2MhKA+6eLWXfocL22iMJ5QFPHsp2EPyULVyKm 6hLJMUAdFPVRoY6DCS3iTJCzatQMV7yya2b1lcrveef09mhWEm4uK8XfNu3ojJoyp8ya G9Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S0aG82s5CcnkkAJmRuKrOrhMfbEmERigVtMxWONZzI8=; b=mG6L3gc3BikfeZii81jJ7sp2pjVInLCKRN0ehTFlZjEnfm1lYnEcBHEOSk9X9M6Y11 i0hUU+atvUrvvUOnQMGmE5/dKpMAmMX1NzSMu2gsAIqXvwENdYzJELCCL1006ECqBP49 bNe7h/94nbJYWw1Eo2VJIM29wF3ybRGIhCBlbREqYBt6nKQwY9Wog4M8v0q8/rRfS2A1 Uf4EEEaH3vsfmz4F4Fdi+PGnNlaOlQaV0AbxV2cSQD+hSobbCofRkkRV5h2a/Lp2Gelj tsiVIkmw4zauWJDeYb2zJOPQIPHYJ2dAnRlvTX9ekimz1WgFV5dLW6Qe6fJGzHBc9e9M TPUg== X-Gm-Message-State: AGi0PuaQJdvBknOQ85Qkg12RNaavRqZRx6vzTG41+NHpeU0Km5y8X2gr gv+zyNQAmWF+AsR79fPjYhURx8RI X-Google-Smtp-Source: APiQypLyt/b03Wgk8ML56syxvjdtIWL4xiYfCWpRpW2gWb1SRR9X+Aqd7m09VD+ow4OBcz1FJbVAYw== X-Received: by 2002:ac8:548d:: with SMTP id h13mr11079518qtq.144.1585962722157; Fri, 03 Apr 2020 18:12:02 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:01 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 03/23] sequencer: stop leaking buf Date: Fri, 3 Apr 2020 21:11:16 -0400 Message-Id: <76585e5b1367a3adf18d761b2af9356ee64b46fd.1585962672.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In read_populate_opts(), we call read_oneliner() _after_ calling strbuf_release(). This means that `buf` is leaked at the end of the function. Always clean up the strbuf by going to `done_rebase_i` whether or not we return an error. Signed-off-by: Denton Liu --- sequencer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sequencer.c b/sequencer.c index e528225e78..faab0b13e8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2485,6 +2485,7 @@ static int read_populate_opts(struct replay_opts *opts) { if (is_rebase_i(opts)) { struct strbuf buf = STRBUF_INIT; + int ret = 0; if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) { if (!starts_with(buf.buf, "-S")) @@ -2525,7 +2526,7 @@ static int read_populate_opts(struct replay_opts *opts) opts->keep_redundant_commits = 1; read_strategy_opts(opts, &buf); - strbuf_release(&buf); + strbuf_reset(&buf); if (read_oneliner(&opts->current_fixups, rebase_path_current_fixups(), 1)) { @@ -2538,12 +2539,16 @@ static int read_populate_opts(struct replay_opts *opts) } if (read_oneliner(&buf, rebase_path_squash_onto(), 0)) { - if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) - return error(_("unusable squash-onto")); + if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) { + ret = error(_("unusable squash-onto")); + goto done_rebase_i; + } opts->have_squash_onto = 1; } - return 0; +done_rebase_i: + strbuf_release(&buf); + return ret; } if (!file_exists(git_path_opts_file())) From patchwork Sat Apr 4 01:11:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473933 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 68EAC92A for ; Sat, 4 Apr 2020 01:12:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 460CC2074B for ; Sat, 4 Apr 2020 01:12:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NMSTryUN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726492AbgDDBMJ (ORCPT ); Fri, 3 Apr 2020 21:12:09 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:41441 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726170AbgDDBME (ORCPT ); Fri, 3 Apr 2020 21:12:04 -0400 Received: by mail-qt1-f195.google.com with SMTP id i3so8135698qtv.8 for ; Fri, 03 Apr 2020 18:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zoSZ85dusfySIzDfKdbJZOvwhBY4tPgDxaFqCM2Bk3E=; b=NMSTryUNrPzKzWP4gKkaUIrEe7oXdeyLPGVQ/6cay3oXPZ+rpmEd+LZaJ8wF5Epjxj 1dsBMY9eMZKASy5ln0aTh6YwNDR3RnFQMS591rzyyilgcGT5Svl4zXgsJPj0tG2tUbe9 JE8PQO8XK7DlKhNwmbSZfI3NXJBJ50csNAFMaB6OJnHNxweX+y/3S/WYARNcn77Mt3vh aJch1ZcOiCCsD/qIQtSvB4qQPCTWJvlP6/fLd6BeEfqNEn4F35diALhCZGtYkIEl+DZ8 6MzD0kQBpVNPIE/dlqzDFe1sytjp7nbDRiGiPv39j3K+yakUa4spIItmT7ycSR91PL0X igWw== 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=zoSZ85dusfySIzDfKdbJZOvwhBY4tPgDxaFqCM2Bk3E=; b=OZFnNxk00+8fKXkCZ8khriBZl3+jU4A0c2wN54SqdB5l1B7+C/oOm0pXwjGroA4Eet IR/15WLRJbumdTD8h2KSorhEvC83X+MbpTthnjXGqhHLb8kM+E9SLh5XoYMJDc8+smtY MJ9ULvkkx0imDr9MuFaGYoMX70l/FC8efkbBK+RPFhzSzIsrOOndorkL86IL0Cq3wNhJ Qw8bxe2ltZTqjfxZ8pjDoF6rEVLRasrI5AG4awAI/vpXCAavPX4EVF5zXu+F9CZRjT2J IasA0UpVDBwKlavvUeTACdHR3LCUiUc153iJNdB6HwqASlbf/AsxIp9tHOyMPQ9VR+hq ZqPg== X-Gm-Message-State: AGi0PuZ4ZnUA6emOYbn/FlcAwuS2B0Ouk75H1ThZHj3LZAbgqISoXKpB 5ZI0BA496VXL2GTlfqdiePwj+iU8 X-Google-Smtp-Source: APiQypLT0cHzEoPl5v9US1kVoTbcLGsjoTN8pNblr3pYZ7CQbCRgdvSNkOEiKlJHYTGXbG419F/edA== X-Received: by 2002:ac8:fe9:: with SMTP id f38mr11236695qtk.130.1585962723182; Fri, 03 Apr 2020 18:12:03 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:02 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 04/23] sequencer: reuse strbuf_trim() in read_oneliner() Date: Fri, 3 Apr 2020 21:11:17 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the 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. Reset `buf` before using it then replace the trimming logic with strbuf_trim(). As a cleanup, remove all reset_strbuf()s that happen before read_oneliner() is called. Signed-off-by: Denton Liu --- sequencer.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/sequencer.c b/sequencer.c index faab0b13e8..09ca68f540 100644 --- a/sequencer.c +++ b/sequencer.c @@ -420,8 +420,8 @@ static int write_message(const void *buf, size_t len, const char *filename, } /* - * Reads a file that was presumably written by a shell script, i.e. with an - * end-of-line marker that needs to be stripped. + * Resets a strbuf then 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. @@ -431,23 +431,19 @@ 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; if (!file_exists(path)) return 0; + strbuf_reset(buf); if (strbuf_read_file(buf, path, 0) < 0) { warning_errno(_("could not read '%s'"), path); return 0; } - 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(buf); - if (skip_if_empty && buf->len == orig_len) + if (skip_if_empty && !buf->len) return 0; return 1; @@ -2471,7 +2467,6 @@ 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)) return; opts->strategy = strbuf_detach(buf, NULL); @@ -2494,7 +2489,6 @@ static int read_populate_opts(struct replay_opts *opts) free(opts->gpg_sign); opts->gpg_sign = xstrdup(buf.buf + 2); } - strbuf_reset(&buf); } if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), 1)) { @@ -2526,7 +2520,6 @@ static int read_populate_opts(struct replay_opts *opts) opts->keep_redundant_commits = 1; read_strategy_opts(opts, &buf); - strbuf_reset(&buf); if (read_oneliner(&opts->current_fixups, rebase_path_current_fixups(), 1)) { @@ -4006,7 +3999,6 @@ static int pick_commits(struct repository *r, res = error(_("could not read orig-head")); goto cleanup_head_ref; } - strbuf_reset(&buf); if (!read_oneliner(&buf, rebase_path_onto(), 0)) { res = error(_("could not read 'onto'")); goto cleanup_head_ref; From patchwork Sat Apr 4 01:11:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473929 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 0FDCD1668 for ; Sat, 4 Apr 2020 01:12:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E290B20731 for ; Sat, 4 Apr 2020 01:12:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fte+Ytpg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726455AbgDDBMH (ORCPT ); Fri, 3 Apr 2020 21:12:07 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:37215 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgDDBMF (ORCPT ); Fri, 3 Apr 2020 21:12:05 -0400 Received: by mail-qt1-f195.google.com with SMTP id z24so8180183qtu.4 for ; Fri, 03 Apr 2020 18:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vJr4H9HQe+8dSCv9+aReBNKxwXXTrkp3NkLOLbdsidw=; b=Fte+YtpgkJ4scvpu/A0NAa8OIhfCj7INHCrhdwdbwm5bpvlzSG1Zwd/decAfvphCHu nNSnIOozJPGCQ7bS5xGu+AqxXCdOqbkVu7ooSTwNbstXoot9fBt6OSUjSfVyZVaFhQYW 7i4VHC7jDzCZzwJeI5QEdMYIi/V4DKuFIG7GJfvmWhLBiya80lQEaFBdLNHTOdOA26ac aVbbwVL6PdLtCPxnxboh/uRCk4vSCBxX5M4nQspmgUG636cB1Wv0E7PzFesi53rY/iKd y8q7RXYd60knzQAd+Mqu7fj8dwvLrmMZI96FVe4HgX5IIqBr8Z9eA7NZs5hv/D+gAn6H E3FQ== 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=vJr4H9HQe+8dSCv9+aReBNKxwXXTrkp3NkLOLbdsidw=; b=h7IWRhgLjrFVA6HhWWt50fo5U4IG6gi+5bZ6B0Wq9KzsKxCMviY+Ar9pok4TgBFJnt fwuXEQOMpfuXuOXRr1rddSXip8vxUfztmOTopgf7FCFDLNYT80vTAvSs9sIkxQdgth4A K7Kqg+3ho2tW8o6SIm6exBBonyczNKcZMmCeOxoe7XOJ2KDaK9A+t6USkWo6uC0B+/Lw XqJ0nb2UEFeqTm8jZ0NgY4mEmxvCsGdcFR0o3NbH2tIGwIaJfXoUOSC6Tc8hj1FLh+0Q BoHxZdM5J+CbDzhohcTcJ5D56IhmaUxnZD2VH9DlJlM+yHK55S9BhFcpc7OfvxVDP86D zdww== X-Gm-Message-State: AGi0PubF+iZtH4tZZ2D1s7CzK1cz3Tdp9cR9IEM7Aq7O7w1stdnke85L yllMsFOxN85SoMDCK8aBHFbrp+9X X-Google-Smtp-Source: APiQypLPvZ2403XO3B2b6RE5FsttTbZtZokzYdoZeBOie/IxwFNG/Oa1DQmrYKXGyLjU72+w3fAH6w== X-Received: by 2002:aed:34a3:: with SMTP id x32mr11284527qtd.306.1585962724144; Fri, 03 Apr 2020 18:12:04 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:03 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 05/23] sequencer: make file exists check more efficient Date: Fri, 3 Apr 2020 21:11:18 -0400 Message-Id: <58da8e95558d5d345030db51200962dde71522f1.1585962672.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We currently check whether a file exists and return early before reading the file. Instead of accessing the file twice, always read the file and check `errno` to see if the file doesn't exist. Signed-off-by: Denton Liu --- sequencer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sequencer.c b/sequencer.c index 09ca68f540..6e63224c41 100644 --- a/sequencer.c +++ b/sequencer.c @@ -431,13 +431,10 @@ 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) { - - if (!file_exists(path)) - return 0; - strbuf_reset(buf); if (strbuf_read_file(buf, path, 0) < 0) { - warning_errno(_("could not read '%s'"), path); + if (errno != ENOENT && errno != ENOTDIR) + warning_errno(_("could not read '%s'"), path); return 0; } From patchwork Sat Apr 4 01:11:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473971 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 2DD1F1668 for ; Sat, 4 Apr 2020 01:12:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B60220731 for ; Sat, 4 Apr 2020 01:12:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="syvUAGNb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726403AbgDDBMH (ORCPT ); Fri, 3 Apr 2020 21:12:07 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:44150 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbgDDBMG (ORCPT ); Fri, 3 Apr 2020 21:12:06 -0400 Received: by mail-qt1-f196.google.com with SMTP id x16so8115456qts.11 for ; Fri, 03 Apr 2020 18:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=grx6/aD7ArEongb9HzfT1qUQDXyZt7oCnPOOYVD57xk=; b=syvUAGNbcoyTq33aGjs469uGmT8Ntqsmg/2vFuYmyjQanVWQQqr4DKmKzas6xmJ18A l9fLZdpB139OnUDVhdLR6ZGtO/dwqWew2rGaM0TeKFf0NR26c9RELoIJJF25K78Wy/0s BcKnXvD7oMIQ1KmxG3NY/B6Lp0dHe6EC6omNgaXZwr8DciroyvzhcilDv1prkJYRP8wX SBQQ9dwrfDq7IL+tZEZ5Ta3qiCHqDWhKnIFHNqrvVCrYbyIgtLFij7GBBlEH/Vo/Lnxa nopz8u/tw4Fzzq8XT7BFsCCZE/sI+RZ0uXvscaE9rOinC4ZMtNM11chGBP7IOOITPyQw FpCg== 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=grx6/aD7ArEongb9HzfT1qUQDXyZt7oCnPOOYVD57xk=; b=ks2YrxRsGmYRE3Dg6NA8eBpDBwosFJRCFn+woS1gOINhNOQQVkgssYdqBw0CWFwCvP CUi+lQ0s9SyQ1ppe7b9uGY2NKeGWtVTqhRrnao0aw0SyC+wRqqoApMcn8Tujn0HpeGmy ycNAy+OJaOCvPIQ8zIVxLVxGTV6Ouhqd2Su6yaEfnCHbMwqjDRy+SALUz2EmFvdqUV0U x3lmWY+0rNTc7/zg2YC0qXAQRPE/3uxDcdVDLrINTIn2SWydOBj0a1suPhMb5Ts1DrYU grqy7j99SuEHzRf8r8GKWzc6cKbsmR7lGINlvwvI1AQFqZJVqTwuac4droqS4eSJ4ESD 9WCA== X-Gm-Message-State: AGi0Pubn1DjsJ4sXugJAKuEVvezlHQ+t+MzBhsG83HEUj2UOaWSJ5Tm9 DksXZl8zBKOj28Grs5k3u73aA4o/ X-Google-Smtp-Source: APiQypJFEpZ8k1ZULma97esE3a1TjHsnjBzCGJbLVEcD53rEBYoh/DB2Ys3e4hzOvmeK7MeuYhhj1Q== X-Received: by 2002:ac8:3ac7:: with SMTP id x65mr742658qte.45.1585962725081; Fri, 03 Apr 2020 18:12:05 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:04 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 06/23] sequencer: make read_oneliner() accept flags Date: Fri, 3 Apr 2020 21:11:19 -0400 Message-Id: <6ead240957da808be1261bc960227c4183da3dd9.1585962672.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will need read_oneliner() to accept flags other than just `skip_if_empty`. Instead of having an argument for each flag, teach read_oneliner() to accept the bitfield `flags` instead. For now, only recognize the `READ_ONELINER_SKIP_IF_EMPTY` flag. More flags will be added in a future commit. The result of this is that parallel topics which introduce invocations of read_oneliner() will still be compatible with this new function signature since, instead of passing 1 or 0 for `skip_if_empty`, they'll be passing 1 or 0 to `flags`, which gives equivalent behavior. Mechanically fix up invocations of read_oneliner() with the following spatch @@ expression a, b; @@ read_oneliner(a, b, - 1 + READ_ONELINER_SKIP_IF_EMPTY ) and manually break up long lines in the result. Signed-off-by: Denton Liu --- sequencer.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sequencer.c b/sequencer.c index 6e63224c41..6c26d61670 100644 --- a/sequencer.c +++ b/sequencer.c @@ -419,6 +419,8 @@ static int write_message(const void *buf, size_t len, const char *filename, return 0; } +#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) + /* * Resets a strbuf then reads a file that was presumably written by a shell * script, i.e. with an end-of-line marker that needs to be stripped. @@ -429,7 +431,7 @@ static int write_message(const void *buf, size_t len, const char *filename, * Returns 1 if the file was read, 0 if it could not be read or does not exist. */ static int read_oneliner(struct strbuf *buf, - const char *path, int skip_if_empty) + const char *path, unsigned flags) { strbuf_reset(buf); if (strbuf_read_file(buf, path, 0) < 0) { @@ -440,7 +442,7 @@ static int read_oneliner(struct strbuf *buf, strbuf_trim(buf); - if (skip_if_empty && !buf->len) + if ((flags & READ_ONELINER_SKIP_IF_EMPTY) && !buf->len) return 0; return 1; @@ -2479,7 +2481,8 @@ static int read_populate_opts(struct replay_opts *opts) struct strbuf buf = STRBUF_INIT; int ret = 0; - if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) { + if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), + READ_ONELINER_SKIP_IF_EMPTY)) { if (!starts_with(buf.buf, "-S")) strbuf_reset(&buf); else { @@ -2488,7 +2491,8 @@ static int read_populate_opts(struct replay_opts *opts) } } - if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), 1)) { + if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), + READ_ONELINER_SKIP_IF_EMPTY)) { if (!strcmp(buf.buf, "--rerere-autoupdate")) opts->allow_rerere_auto = RERERE_AUTOUPDATE; else if (!strcmp(buf.buf, "--no-rerere-autoupdate")) @@ -2519,7 +2523,8 @@ static int read_populate_opts(struct replay_opts *opts) read_strategy_opts(opts, &buf); if (read_oneliner(&opts->current_fixups, - rebase_path_current_fixups(), 1)) { + rebase_path_current_fixups(), + READ_ONELINER_SKIP_IF_EMPTY)) { const char *p = opts->current_fixups.buf; opts->current_fixup_count = 1; while ((p = strchr(p, '\n'))) { @@ -3660,7 +3665,8 @@ static int apply_autostash(struct replay_opts *opts) struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_sha1, rebase_path_autostash(), 1)) { + if (!read_oneliner(&stash_sha1, rebase_path_autostash(), + READ_ONELINER_SKIP_IF_EMPTY)) { strbuf_release(&stash_sha1); return 0; } @@ -4283,7 +4289,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) struct strbuf buf = STRBUF_INIT; struct object_id oid; - if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) && + if (read_oneliner(&buf, rebase_path_stopped_sha(), + READ_ONELINER_SKIP_IF_EMPTY) && !get_oid_committish(buf.buf, &oid)) record_in_rewritten(&oid, peek_command(&todo_list, 0)); strbuf_release(&buf); From patchwork Sat Apr 4 01:11:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473935 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 B7DE71668 for ; Sat, 4 Apr 2020 01:12:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9690920787 for ; Sat, 4 Apr 2020 01:12:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t6eFVTZO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726480AbgDDBMI (ORCPT ); Fri, 3 Apr 2020 21:12:08 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:36209 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbgDDBMH (ORCPT ); Fri, 3 Apr 2020 21:12:07 -0400 Received: by mail-qk1-f195.google.com with SMTP id l25so2129762qkk.3 for ; Fri, 03 Apr 2020 18:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LjRx+g8u7bV1eyg1BYwny79VL+Mmg3/NJGUxTvQfil0=; b=t6eFVTZOPShxzIkqwcwHwTC3tspZe33j4YZOQwyAIEaLDqFjSVcFId+m/OdRttP6Z1 HPazLIAv41VjWpoIxPACqcSxhHPzkHZvG4SqzW9GRG+rx3nHQuzGteUD6cTrOqhq3W37 tbvDYvShIvEL58naz/EMoDnbh++je+6HB6pq5jh45sq/w5uwUJ+oQ7oDjV24h1SJRdf9 1ujC9eJFnhZvkew8n1N5zr17BgDxQ7WW3wniek7/Kp9KI6RaE8D47QglsstHHK6RfQXP 9YR6TqnjrEgLO1q2L23pFWX2UphFZzb5oXf5N91+ZrhquWsL0+hWNriPKsuS5U/M/Ekj rP2w== 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=LjRx+g8u7bV1eyg1BYwny79VL+Mmg3/NJGUxTvQfil0=; b=ftHqIRRw8vVVzf6GFGeMwIskDpY87v7lP6i/1GkOdoAybnZOSOUC8HFyUtpw/X+hS/ 1RzKjWPcQtaRdmVq7cBGzPcj8NF9SJqO3zMJxHDxSWbQY+PX4GPPLXsxLyotXtA4R1bT YpiN8/2+vTgbMbl7TF+lBENI57Mxtbs48dVMQRsVHIHnkNf83M/ZjKbecTiyBev7MZrM t5NcR9TtSf7Kd9m8d/Vg3iglqp3KE0ztYSGdKihr3RNqAVGM4mu6rrmS6CY+93g4xcKe J1bnuWWCo2nM+cBxYK4rh8tDWbBUwQz8O3mJfNXwnI/pSttRpdGIFzaiVCdMwBvnPN6Q VaDg== X-Gm-Message-State: AGi0PuYJ3xS/xeFnO2eVSe91bWa1E0gGSR4HtOd49bWgN126/3RRq5mP eD+Z5JC3ToVgGgbxT6kkcdK4Jg8Q X-Google-Smtp-Source: APiQypK11peOSMnjGkm1cudNh2Pr1Zq5fxnqnU8RsW7CjFoRY/GJmsDhLpqtMQSS67SD2Kwfn5jFAg== X-Received: by 2002:a37:b95:: with SMTP id 143mr4165028qkl.412.1585962726220; Fri, 03 Apr 2020 18:12:06 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:05 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 07/23] sequencer: configurably warn on non-existent files Date: Fri, 3 Apr 2020 21:11:20 -0400 Message-Id: <2e7922b259851091b9014c761d340ff1a73a04e4.1585962672.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the future, we plan on externing read_oneliner(). Future users of read_oneliner() will want the ability to output warnings in the event that the `path` doesn't exist. Introduce the `READ_ONELINER_WARN_MISSING` flag which, if active, would issue a warning when a file doesn't exist by skipping the `!file_exists()` check and letting `strbuf_read_file()` handle that case. Signed-off-by: Denton Liu --- sequencer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 6c26d61670..b771e8f4ca 100644 --- a/sequencer.c +++ b/sequencer.c @@ -420,6 +420,7 @@ static int write_message(const void *buf, size_t len, const char *filename, } #define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) +#define READ_ONELINER_WARN_MISSING (1 << 1) /* * Resets a strbuf then reads a file that was presumably written by a shell @@ -435,7 +436,8 @@ static int read_oneliner(struct strbuf *buf, { strbuf_reset(buf); if (strbuf_read_file(buf, path, 0) < 0) { - if (errno != ENOENT && errno != ENOTDIR) + if ((flags & READ_ONELINER_WARN_MISSING) || + (errno != ENOENT && errno != ENOTDIR)) warning_errno(_("could not read '%s'"), path); return 0; } From patchwork Sat Apr 4 01:11:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473941 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 C0581912 for ; Sat, 4 Apr 2020 01:12:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A05BC2074B for ; Sat, 4 Apr 2020 01:12:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iet989v/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726387AbgDDBMM (ORCPT ); Fri, 3 Apr 2020 21:12:12 -0400 Received: from mail-qt1-f178.google.com ([209.85.160.178]:42848 "EHLO mail-qt1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbgDDBMI (ORCPT ); Fri, 3 Apr 2020 21:12:08 -0400 Received: by mail-qt1-f178.google.com with SMTP id b10so2484038qtt.9 for ; Fri, 03 Apr 2020 18:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tV4CttSRYi3W8kfZBwVbwBrlQdEf9yrZCMb+DKzbL7w=; b=iet989v/XYCCrzTdd4rzHfjynWPCWjl3ICtYgTb1BZgUNHbrT1ZKIAOXWLawuE0OCF fk8DgaPf0erxrU7GVqpYkW5yOahRNzCGsiYThFqdR/yM4EzmeXLDabMpi2kZdud1SWKz tRm1QbTwUPA6gAYKiOZBqnowcA1242CIIi3U7RT899KEYw9IibqhdDx8Q17ct2zhCId8 qG0LvWDQmxo7WSmidcbFUVCC2ShrMuZf8HIHnZLB/yZMgb5VFUB1PzrmsY6i18xLyMm1 NKOhDYX6+K7mvwAuUQiS10qrdCjOkvGJGQ0QZIEa0eGza8bhRw7UXBZlWaeZRJ203JQi H9NQ== 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=tV4CttSRYi3W8kfZBwVbwBrlQdEf9yrZCMb+DKzbL7w=; b=ky59rF5iEUI4h7Cjts/PWxiFDyNFJiyiQroOIWqJUktW1c43GTkQ+6NtpW3in53piX H6uLfq3dGO/IIb2SHjZxufXxyuVFcyP+u8X4Sln6sgts/1r7dZgSY+IwfsAhkFAgxVqY 8+tRBwMb3sa7x/TwTHXejxqLjWmDHbPPzWWpnpKPVyK5Uz63c1QR7GCBhtcb8/vSMX4S bmsjedefH5bKbeK5IjUfqil5x3fX4lY57lA6vGw1fnw/KSF/HggOrhweks+LKfqB4W4v wV5iLzo9rHLFU0DVGTpn0KrCvJ8xK7YB/xsPC3TxpMEBtiaEieFKjOlxPMAuj4HnXrhA S4SQ== X-Gm-Message-State: AGi0PuaI3Gtp7x1LUq3ZW7EQc4TNW3CYQy4Tyfs/ZY99Zb6Byjj++a3H evcssQJWFipW3jphITszewr6N0Qq X-Google-Smtp-Source: APiQypJs/ak2LSXmZcGjZ3JXJ+RRl9xAZBWvI4ZCCzwSrY5EBOSR/El87HfjFif2Aea2ZUJL0/J+3Q== X-Received: by 2002:aed:25a7:: with SMTP id x36mr10772824qtc.203.1585962727095; Fri, 03 Apr 2020 18:12:07 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:06 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 08/23] sequencer: make read_oneliner() extern Date: Fri, 3 Apr 2020 21:11:21 -0400 Message-Id: <6c3c37994babdf4749e3edfcaa9075e6ee94524b.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The function read_oneliner() is a generally useful util function. Instead of hiding it as a static function within sequencer.c, extern it so that it can be reused by others. This patch is best viewed with --color-moved. Signed-off-by: Denton Liu --- sequencer.c | 14 +------------- sequencer.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sequencer.c b/sequencer.c index b771e8f4ca..d1d59867ae 100644 --- a/sequencer.c +++ b/sequencer.c @@ -419,19 +419,7 @@ static int write_message(const void *buf, size_t len, const char *filename, return 0; } -#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) -#define READ_ONELINER_WARN_MISSING (1 << 1) - -/* - * Resets a strbuf then reads a file that was presumably written by a shell - * script, i.e. with an end-of-line marker that needs to be stripped. - * - * Note that only the last end-of-line marker is stripped, consistent with the - * behavior of "$(cat path)" in a shell script. - * - * Returns 1 if the file was read, 0 if it could not be read or does not exist. - */ -static int read_oneliner(struct strbuf *buf, +int read_oneliner(struct strbuf *buf, const char *path, unsigned flags) { strbuf_reset(buf); diff --git a/sequencer.h b/sequencer.h index 718a07426d..1f6eda70b6 100644 --- a/sequencer.h +++ b/sequencer.h @@ -198,6 +198,20 @@ void print_commit_summary(struct repository *repo, const struct object_id *oid, unsigned int flags); +#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0) +#define READ_ONELINER_WARN_MISSING (1 << 1) + +/* + * Resets a strbuf then reads a file that was presumably written by a shell + * script, i.e. with an end-of-line marker that needs to be stripped. + * + * Note that only the last end-of-line marker is stripped, consistent with the + * behavior of "$(cat path)" in a shell script. + * + * Returns 1 if the file was read, 0 if it could not be read or does not exist. + */ +int read_oneliner(struct strbuf *buf, + const char *path, unsigned flags); int read_author_script(const char *path, char **name, char **email, char **date, int allow_missing); void parse_strategy_opts(struct replay_opts *opts, char *raw_opts); From patchwork Sat Apr 4 01:11:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473937 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 EF5C6912 for ; Sat, 4 Apr 2020 01:12:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3D3B2074B for ; Sat, 4 Apr 2020 01:12:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gYOLjNVT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726510AbgDDBMK (ORCPT ); Fri, 3 Apr 2020 21:12:10 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:36979 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbgDDBMJ (ORCPT ); Fri, 3 Apr 2020 21:12:09 -0400 Received: by mail-qk1-f195.google.com with SMTP id x3so10213531qki.4 for ; Fri, 03 Apr 2020 18:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0BecW6VR8q+Mh1gBmcoBsRAHGRyq7eUcW1jl4/aKCP0=; b=gYOLjNVTiTXYBwGbGGy66MCDqpW3axe5G55WcEg7OS3pGZXryNxKdAZbfB6eayozFQ uXBnmuKs/KQICAqCNvHy/dNvEhZ51cIQhniyQYzUpwPRD5vti8IF6671zRzOQvptLDw4 X54v8SUXrsinwtKkUOFfLcI1eRSxt2JXuFEwjsDFKXlVuCoj6L4e03WrElqRMISioldZ SH3jJtNDLHPyVQoI9psCHlf3TepNsocbASCHuQajshbR5g0D6cAGu5yvu+kGbmPhGGoB jrQHIq/nudX49HIf04OwRIo8/Sq5MfPzSRysctocdebMYWnx/4fN7am4mMi94lL8FhtC TxNw== 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=0BecW6VR8q+Mh1gBmcoBsRAHGRyq7eUcW1jl4/aKCP0=; b=pkNuQKlyRgxCJ6JwMkjRIL3i1LxvdWAZvQv1KfRCXO8HIz+LE3stAEMBwxhW3dSvEL TebbzatDZenLE6XhPSV1mdcOd3nbqBI6ekFkTjq/H9zhyqMGAkdS9HJFZq5fmQIeeduH 8pMgl+qhEjRdFc24axJS+mEl6ICEZSCPzVecK/QS6PEB74HuJrdjjqSfLAL0FF0FrTjT C12v35+4tnzbk5BtJKxmujud8cHwgvhviPLE/GwL8kk/ZRopQEatcyAKlvlui0iDCs0i La8IiTEZ8Fuvhg1K0Auu1BA1NNnQVgqVJMYnvZPcOSb64wt4CL3kIeWO/ZwKWqX9gTmL HDwg== X-Gm-Message-State: AGi0PuYBEUEBY57G2K2221c/+QeDgL28EGAFWPjL3PDhB2O9dmbpVrqc rw/5cvgN2d6ttTOQueDrrUiHyReB X-Google-Smtp-Source: APiQypKed/TK5kXNjBwpKq7j6J766V8v2FZR9CQLRpp0arng2DL7Dsyt0ime8aVum4AKmI2qW9xaBw== X-Received: by 2002:ae9:e711:: with SMTP id m17mr12044052qka.129.1585962728237; Fri, 03 Apr 2020 18:12:08 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:07 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 09/23] rebase: use read_oneliner() Date: Fri, 3 Apr 2020 21:11:22 -0400 Message-Id: <689f34a2a56242d20f8692281847a5ff7aed36e3.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since in sequencer.c, read_one() basically duplicates the functionality of read_oneliner(), reduce code duplication by replacing read_one() with read_oneliner(). Also, delete strbuf_reset() calls prior to read_oneliner() as read_oneliner() already resets the strbuf. This was mostly done with the following Coccinelle script @@ expression a, b; @@ - read_one(a, b) + !read_oneliner(b, a, READ_ONELINER_WARN_NON_EXISTENCE) Long lines were broken up and strbuf_reset()s were deleted manually. Signed-off-by: Denton Liu --- builtin/rebase.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index bff53d5d16..91873fa0b5 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -586,15 +586,6 @@ static const char *state_dir_path(const char *filename, struct rebase_options *o return path.buf; } -/* Read one file, then strip line endings */ -static int read_one(const char *path, struct strbuf *buf) -{ - if (strbuf_read_file(buf, path, 0) < 0) - return error_errno(_("could not read '%s'"), path); - strbuf_trim_trailing_newline(buf); - return 0; -} - /* Initialize the rebase options from the state directory. */ static int read_basic_state(struct rebase_options *opts) { @@ -602,8 +593,10 @@ static int read_basic_state(struct rebase_options *opts) struct strbuf buf = STRBUF_INIT; struct object_id oid; - if (read_one(state_dir_path("head-name", opts), &head_name) || - read_one(state_dir_path("onto", opts), &buf)) + if (!read_oneliner(&head_name, state_dir_path("head-name", opts), + READ_ONELINER_WARN_MISSING) || + !read_oneliner(&buf, state_dir_path("onto", opts), + READ_ONELINER_WARN_MISSING)) return -1; opts->head_name = starts_with(head_name.buf, "refs/") ? xstrdup(head_name.buf) : NULL; @@ -617,11 +610,12 @@ static int read_basic_state(struct rebase_options *opts) * head. Fall back to reading from head to cover for the case that the * user upgraded git with an ongoing interactive rebase. */ - strbuf_reset(&buf); if (file_exists(state_dir_path("orig-head", opts))) { - if (read_one(state_dir_path("orig-head", opts), &buf)) + if (!read_oneliner(&buf, state_dir_path("orig-head", opts), + READ_ONELINER_WARN_MISSING)) return -1; - } else if (read_one(state_dir_path("head", opts), &buf)) + } else if (!read_oneliner(&buf, state_dir_path("head", opts), + READ_ONELINER_WARN_MISSING)) return -1; if (get_oid(buf.buf, &opts->orig_head)) return error(_("invalid orig-head: '%s'"), buf.buf); @@ -640,9 +634,8 @@ static int read_basic_state(struct rebase_options *opts) } if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) { - strbuf_reset(&buf); - if (read_one(state_dir_path("allow_rerere_autoupdate", opts), - &buf)) + if (!read_oneliner(&buf, state_dir_path("allow_rerere_autoupdate", opts), + READ_ONELINER_WARN_MISSING)) return -1; if (!strcmp(buf.buf, "--rerere-autoupdate")) opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE; @@ -654,25 +647,24 @@ static int read_basic_state(struct rebase_options *opts) } if (file_exists(state_dir_path("gpg_sign_opt", opts))) { - strbuf_reset(&buf); - if (read_one(state_dir_path("gpg_sign_opt", opts), - &buf)) + if (!read_oneliner(&buf, state_dir_path("gpg_sign_opt", opts), + READ_ONELINER_WARN_MISSING)) return -1; free(opts->gpg_sign_opt); opts->gpg_sign_opt = xstrdup(buf.buf); } if (file_exists(state_dir_path("strategy", opts))) { - strbuf_reset(&buf); - if (read_one(state_dir_path("strategy", opts), &buf)) + if (!read_oneliner(&buf, state_dir_path("strategy", opts), + READ_ONELINER_WARN_MISSING)) return -1; free(opts->strategy); opts->strategy = xstrdup(buf.buf); } if (file_exists(state_dir_path("strategy_opts", opts))) { - strbuf_reset(&buf); - if (read_one(state_dir_path("strategy_opts", opts), &buf)) + if (!read_oneliner(&buf, state_dir_path("strategy_opts", opts), + READ_ONELINER_WARN_MISSING)) return -1; free(opts->strategy_opts); opts->strategy_opts = xstrdup(buf.buf); @@ -724,7 +716,7 @@ static int apply_autostash(struct rebase_options *opts) if (!file_exists(path)) return 0; - if (read_one(path, &autostash)) + if (!read_oneliner(&autostash, path, READ_ONELINER_WARN_MISSING)) return error(_("Could not read '%s'"), path); /* Ensure that the hash is not mistaken for a number */ strbuf_addstr(&autostash, "^0"); From patchwork Sat Apr 4 01:11:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473969 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 8FDFE1668 for ; Sat, 4 Apr 2020 01:12:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 695AA2074B for ; Sat, 4 Apr 2020 01:12:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DTHEKduf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726554AbgDDBMP (ORCPT ); Fri, 3 Apr 2020 21:12:15 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:46335 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726170AbgDDBMK (ORCPT ); Fri, 3 Apr 2020 21:12:10 -0400 Received: by mail-qt1-f193.google.com with SMTP id g7so8087222qtj.13 for ; Fri, 03 Apr 2020 18:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pl1XNZPlETb/eF7+ncdGisECAzly55YIoQ5HmWsqVoQ=; b=DTHEKdufZ9W4nXMSkjFEK7/tplqeweWvyp1X7xBtEKZndN6znkVGEt8a4sjF+DNxg2 zolP0e8eethnqkkYBmAH3YYTO+ePXZBuAu289310mSkxLxza8dtXARgFU+8YOnNjXqBe FMX1s78XHMUnDQTsRY9Av3rs1S38fm9PLFj2X6Do0JFys39mSQebwwpXEPjPL7EP/zoN eDKT4Yfq8/61S3prFOPTwfJAFQP3z0r4GdmH1CCiXTZbouXPeo96QZRPF32QjtLXuMW0 5WtVk3YiOvXv+HQE7ldawcJqhZtvCQjhe8s8DAxbVKe+pZidValX4BI6VGLCcICX7Q0B Rxwg== 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=pl1XNZPlETb/eF7+ncdGisECAzly55YIoQ5HmWsqVoQ=; b=Z3Pn2zkmIJJASGB8s19YbHIw/+KJGOmVJ17qwwZLw0FcJ7zOs2X7cD/8POz6VgFytg nNbfT2L3/M3uktblyGcRmI70jBHqR85ghYJsejQmQ8eBYtz3U9MZVfbrjTNG0idIP+RU DZK7mMZMWDbZp8rF0qtMr5NUlhv4KMHRmtajYLbx8f1fd4+2m29nJ0tfgYcHwzDulTsW mMBKggyg3QFtI/Uayp0Oqcp1HxrgiRtyYbAjLt9KbUDJuITJ3ZgGb2xmXWoXqngcdzek w+QnXqYXRRylSnNnmItQEjkdbYsSKT4it3bzdzbCpSGoxl7bi8KfnwtrYwvDzxfYcEZo 1Oag== X-Gm-Message-State: AGi0PuaJyf0MPtmyS/mxbVXlLoKLKHYSz623BlFuQNs0yywrjLtGFenE BvXd6SOmFbdJOOZGLLR9d9Qj8jSX X-Google-Smtp-Source: APiQypKKFg5wOxeC9g1yMU0rceRnWjaKvO+FoJqFG9QA9Jq68OPh54BXvdi24napyAdQ4moSNYVw+w== X-Received: by 2002:ac8:4a94:: with SMTP id l20mr11213190qtq.302.1585962729302; Fri, 03 Apr 2020 18:12:09 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:08 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 10/23] sequencer: make apply_rebase() accept a path Date: Fri, 3 Apr 2020 21:11:23 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 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 d1d59867ae..ae9efe5825 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3649,13 +3649,13 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) return -1; } -static int apply_autostash(struct replay_opts *opts) +static int apply_autostash(const char *path) { struct strbuf stash_sha1 = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_sha1, rebase_path_autostash(), + if (!read_oneliner(&stash_sha1, path, READ_ONELINER_SKIP_IF_EMPTY)) { strbuf_release(&stash_sha1); return 0; @@ -3748,7 +3748,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")); } @@ -4061,7 +4061,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) @@ -5070,7 +5070,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")); @@ -5081,12 +5081,12 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla if (res == -1) return -1; else if (res == -2) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); return -1; } else if (res == -3) { - apply_autostash(opts); + apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); todo_list_release(&new_todo); From patchwork Sat Apr 4 01:11:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473945 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 E773192A for ; Sat, 4 Apr 2020 01:12:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C662D2074B for ; Sat, 4 Apr 2020 01:12:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P3b2Om5d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbgDDBMO (ORCPT ); Fri, 3 Apr 2020 21:12:14 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:42698 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726512AbgDDBML (ORCPT ); Fri, 3 Apr 2020 21:12:11 -0400 Received: by mail-qt1-f194.google.com with SMTP id b10so2484113qtt.9 for ; Fri, 03 Apr 2020 18:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o0cVVs4U0C8huOh0K2x4n9ozqCvkQ76WZSM+jWciwC8=; b=P3b2Om5dOdXEIfO2TNXM7njg8ULgHS/K+cMHR1M2Mk02G2t1tEMltisU5o14+byro2 DcwT9Twx+loJUl9MaemkGkq7kxwgJrNoT2cuTR4LUmdE0bVxIpSAfgE4DvMA141qNeLO AC1D24xIMPS86CYpGa9d4oLQ9nM/zBGdCkc3shsfJxVmiI7zrDaGrK+cmPQiR+Eye8qA 7+B9ska1jX4bbtiKrBLcXNtTlAGX90Bt8urWkV5W/RseWgt7TqTRiYCnLNB/6e8sCN6W QhREZmiEGuNSjc5YcnQ4At+Aaik6rr/wO3OkeObQdfJ8M5uQYpD5B89OlvUNiNMd9DOf hILw== 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=o0cVVs4U0C8huOh0K2x4n9ozqCvkQ76WZSM+jWciwC8=; b=nuTHKdYA/q60M8R/93gskL7h6UxhNmIKJ5s/WGDYgbU1ytcZSHYH2+7EaH/uY5PqPJ aoyxoY3m5zno6AMaGNh1tmpghehciaB1zmPy37+FZSPeIxplPhn+TZhkztBjjMdZnMtN HSneMuCozRBXkRSviYSPcnZNiYqRf2Bm19MkV8zMFqj2+UdrjZS0Je67DfKn52wtPbqR mza/Bll666DHDTZ+dxuIQIyX9Mc4AXbua1CfXz0txjIwBnFtf0i9d6SXdEhGr3McwzFy yeOt3eOFW8w2ivfrphtO2qwpNwRM2aJwGNrH9tCl2VGTGfgAoIWlhXf1T9YVaK5QHhVC ET8w== X-Gm-Message-State: AGi0PubJnc33CHrzvxnw0rwFq3pnwlOqzW/lRuGrV1yBkry/N0y5ktZh dGSaMa2OJQ+1Hn3Ndne2E/v8bqy7 X-Google-Smtp-Source: APiQypK97MReIBk0/VrHG/0EoVTl8IaFojp0Ywk5you7tfe1xg1/3J8Hv3r+xHZ7kbBktIHIaLiATA== X-Received: by 2002:ac8:5486:: with SMTP id h6mr11073234qtq.256.1585962730328; Fri, 03 Apr 2020 18:12:10 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:09 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 11/23] sequencer: rename stash_sha1 to stash_oid Date: Fri, 3 Apr 2020 21:11:24 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The preferred terminology is to refer to object identifiers as "OIDs". Rename the `stash_sha1` variable to `stash_oid` in order to conform to this. Signed-off-by: Denton Liu --- sequencer.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sequencer.c b/sequencer.c index ae9efe5825..4b7985942d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3651,23 +3651,23 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) static int apply_autostash(const char *path) { - struct strbuf stash_sha1 = STRBUF_INIT; + struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_sha1, path, + if (!read_oneliner(&stash_oid, path, READ_ONELINER_SKIP_IF_EMPTY)) { - strbuf_release(&stash_sha1); + strbuf_release(&stash_oid); return 0; } - strbuf_trim(&stash_sha1); + strbuf_trim(&stash_oid); child.git_cmd = 1; child.no_stdout = 1; child.no_stderr = 1; argv_array_push(&child.args, "stash"); argv_array_push(&child.args, "apply"); - argv_array_push(&child.args, stash_sha1.buf); + argv_array_push(&child.args, stash_oid.buf); if (!run_command(&child)) fprintf(stderr, _("Applied autostash.\n")); else { @@ -3679,9 +3679,9 @@ static int apply_autostash(const char *path) argv_array_push(&store.args, "-m"); argv_array_push(&store.args, "autostash"); argv_array_push(&store.args, "-q"); - argv_array_push(&store.args, stash_sha1.buf); + argv_array_push(&store.args, stash_oid.buf); if (run_command(&store)) - ret = error(_("cannot store %s"), stash_sha1.buf); + ret = error(_("cannot store %s"), stash_oid.buf); else fprintf(stderr, _("Applying autostash resulted in conflicts.\n" @@ -3690,7 +3690,7 @@ static int apply_autostash(const char *path) " \"git stash drop\" at any time.\n")); } - strbuf_release(&stash_sha1); + strbuf_release(&stash_oid); return ret; } From patchwork Sat Apr 4 01:11:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473943 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 82C4092A for ; Sat, 4 Apr 2020 01:12:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6217C20787 for ; Sat, 4 Apr 2020 01:12:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KjmdPz6Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726380AbgDDBMN (ORCPT ); Fri, 3 Apr 2020 21:12:13 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:42701 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbgDDBMM (ORCPT ); Fri, 3 Apr 2020 21:12:12 -0400 Received: by mail-qt1-f196.google.com with SMTP id b10so2484136qtt.9 for ; Fri, 03 Apr 2020 18:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J2HKOVYzRAu8Mrh4ELprHup9MiSU2rtNWAsFcunWRz4=; b=KjmdPz6YvAY3wlIdlxZQ3oDgrGApIA2Zc41QYsYDhgaRJppX2CYVB4eHttpuIzTHtp VC1/IEnAqkGW+CU3h+fYSsldsCop/1ZT25M5tBGYgTPyh6U752vu5Tv5eBtdIroNzEmf Kob5ixEJDaD+pahKY+lK9T7otOYe5niAfT6MSSTripJjLjajr1WuitcU9nNVS6V+h7wL +aO99eReoWApx95Q2ZSORW0KYpcQrKk6LsjbSMTATesm/zKIR031YXdu2CNjLEQ1auSI nXJ6gzVlZJBHgrHFEhk6KNRSGWuKME3sf32xUE5vV0srfwT8uZcgnnChuNJbdz2tD69K 0I7g== 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=J2HKOVYzRAu8Mrh4ELprHup9MiSU2rtNWAsFcunWRz4=; b=OJePEFmrH+UMBLXaRCdq/1u2712y6hsg5wPyaWVjKsDYJaDk7vg/iZFeWSt0Iockh8 q0RmVpbgxg2BYOvPlHR+MqBvCFMFiR7UyxUutRRveUyv/3+V7JIOEP3sN3aNLYCRBY92 5sZPD1RK8fhgQiQ8BbR4oxLdjLcjpbySubHPlhbRa0Myw5VTiQyQPGq4q/8S7pJYOWG/ AtYtsvB/3c5BY3VcwEqAXCTjdg+CDr4Lhuc8z0guE5uZCcXGNE/gu2Ajok2ThA/2pc+x nCWFVngB1yY555/1cRXFRXp9AKT0XbpzMqegTbLq0dxFwJfJ3VNG2dUW/V4TVDccUicD 321A== X-Gm-Message-State: AGi0Pua3vfs0Y6LlBl7NHoDGTltqmMvaM/hTxaM6v2APICaXzRH+03+J HdeGD0iMwzyQC0S5glpMadPjdKQD X-Google-Smtp-Source: APiQypKTS8UVQR/gJhrpATz9uLcTfxWQ+P3ZWIa3irS8ua1OXmN9DeZqkIbNxPzX6RRMq0dCz6BJSA== X-Received: by 2002:ac8:2a0e:: with SMTP id k14mr11443367qtk.232.1585962731490; Fri, 03 Apr 2020 18:12:11 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:10 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 12/23] rebase: use apply_autostash() from sequencer.c Date: Fri, 3 Apr 2020 21:11:25 -0400 Message-Id: <389b17df334c3d9a8138b5db0ec15c81a8a6ce31.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The apply_autostash() function in builtin/rebase.c is similar enough to the apply_autostash() function in sequencer.c that they are almost interchangeable, except for the type of arg they accept. Make the sequencer.c version extern and use it in rebase. The rebase version was introduced in 6defce2b02 (builtin rebase: support `--autostash` option, 2018-09-04) as part of the shell to C conversion. It opted to duplicate the function because, at the time, there was another in-progress project converting interactive rebase from shell to C as well and they did not want to clash with them by refactoring sequencer.c version of apply_autostash(). Since both efforts are long done, we can freely combine them together now. Signed-off-by: Denton Liu --- builtin/rebase.c | 49 ++---------------------------------------------- sequencer.c | 2 +- sequencer.h | 2 ++ 3 files changed, 5 insertions(+), 48 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 91873fa0b5..29745176cb 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -707,51 +707,6 @@ static int rebase_write_basic_state(struct rebase_options *opts) return 0; } -static int apply_autostash(struct rebase_options *opts) -{ - const char *path = state_dir_path("autostash", opts); - struct strbuf autostash = STRBUF_INIT; - struct child_process stash_apply = CHILD_PROCESS_INIT; - - if (!file_exists(path)) - return 0; - - if (!read_oneliner(&autostash, path, READ_ONELINER_WARN_MISSING)) - return error(_("Could not read '%s'"), path); - /* Ensure that the hash is not mistaken for a number */ - strbuf_addstr(&autostash, "^0"); - argv_array_pushl(&stash_apply.args, - "stash", "apply", autostash.buf, NULL); - stash_apply.git_cmd = 1; - stash_apply.no_stderr = stash_apply.no_stdout = - stash_apply.no_stdin = 1; - if (!run_command(&stash_apply)) - printf(_("Applied autostash.\n")); - else { - struct argv_array args = ARGV_ARRAY_INIT; - int res = 0; - - argv_array_pushl(&args, - "stash", "store", "-m", "autostash", "-q", - autostash.buf, NULL); - if (run_command_v_opt(args.argv, RUN_GIT_CMD)) - res = error(_("Cannot store %s"), autostash.buf); - argv_array_clear(&args); - strbuf_release(&autostash); - if (res) - return res; - - fprintf(stderr, - _("Applying autostash resulted in conflicts.\n" - "Your changes are safe in the stash.\n" - "You can run \"git stash pop\" or \"git stash drop\" " - "at any time.\n")); - } - - strbuf_release(&autostash); - return 0; -} - static int finish_rebase(struct rebase_options *opts) { struct strbuf dir = STRBUF_INIT; @@ -759,7 +714,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 @@ -1204,7 +1159,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 4b7985942d..dde1f6b30f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3649,7 +3649,7 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) return -1; } -static int apply_autostash(const char *path) +int apply_autostash(const char *path) { struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; diff --git a/sequencer.h b/sequencer.h index 1f6eda70b6..d6ba62a089 100644 --- a/sequencer.h +++ b/sequencer.h @@ -191,6 +191,8 @@ void commit_post_rewrite(struct repository *r, const struct commit *current_head, const struct object_id *new_head); +int apply_autostash(const char *path); + #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) void print_commit_summary(struct repository *repo, From patchwork Sat Apr 4 01:11:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473947 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 34A7F912 for ; Sat, 4 Apr 2020 01:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08DE520787 for ; Sat, 4 Apr 2020 01:12:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bKnfq7hU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726595AbgDDBMQ (ORCPT ); Fri, 3 Apr 2020 21:12:16 -0400 Received: from mail-qv1-f68.google.com ([209.85.219.68]:42235 "EHLO mail-qv1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbgDDBMN (ORCPT ); Fri, 3 Apr 2020 21:12:13 -0400 Received: by mail-qv1-f68.google.com with SMTP id ca9so4583858qvb.9 for ; Fri, 03 Apr 2020 18:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bSfI4RaIoissbL4WDRYdrBycXshlTKxbIEm6Sl/3cLY=; b=bKnfq7hUqGE2cpBjiDe7lDg1phcNxFfLMkmrqJaZuh8X5iBa3G/8IdL4PoSNmajRlk 1ov+W0p3WYrOX1h3RwmNj6T3wvoWX3g8PJmgpzHuiP37G/aacnyIyBiOgGcA+8gL3gW1 AejFowNegV7YF53iR8Jr8XD04jYtzrfuHPyocMvw3hN16U1FE+LD4we54wxO8FV1H7bl ahBXEwyjM5Nc7Pv5OgZzIGsxhR8ZhmgHlTjWzSTXWxRBxYip1Jy1x7qJSWdioH6h38ib kqvNHLI5QuoFP89syGYu4JKKfAQB/qL0FG3iXoHF27aKTyfiNYIUdOeHJ1nUEAkeXRPS 9jAg== 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=bSfI4RaIoissbL4WDRYdrBycXshlTKxbIEm6Sl/3cLY=; b=CqSKNlbgkPzfgpWpn7Boyt4FleiQ5lXmgSOWpRyRvJOxWvWhKIf9SZGaiy9T763Rky bVnSoRZfz0cvhAt0YrZT4PJoQhtZ63lm0IExaUNcajfn79xryvJh8XV1aEu5mKSgyheD ij3eNt81HL30A52NB1ybs5JyBDyDwSgNFyCyCTXE8OE4izeFuPTN/6sT9N/M8s8Zgrzg VXVrz1YrpF5he3sCf4PBQGLNdia3TcH2EblOnat+G16KIIub12o5GVEeWCb6KKUpVhO1 Tvo+sVb7UMdQuvBO8GGejab8yvYBFu29iBz2agA/yHC3tvnLPOKjS6TFt2hZHUIx+ZhJ sNQw== X-Gm-Message-State: AGi0PubtskjlCU0OkxzzbsiLSiKwAzaKsw5GVYmYApU05wvDr0tyg+w9 9rUgY57jwSWkZRCLQi3MFnr0HGX2 X-Google-Smtp-Source: APiQypJiHMHxzSMUO5jHRvTmDK3aumth67RSthjBUfNsTm5xLvZ3WWK5hhDjtNINekQeRf7zgg20/Q== X-Received: by 2002:ad4:45ae:: with SMTP id y14mr11291388qvu.119.1585962732643; Fri, 03 Apr 2020 18:12:12 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:12 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 13/23] rebase: generify reset_head() Date: Fri, 3 Apr 2020 21:11:26 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the future, we plan on lib-ifying reset_head() so we need it to be more generic. Make it more generic by making it accept a `struct repository` argument instead of implicitly using the non-repo functions. Also, make it accept a `const char *default_reflog_action` argument so that the default action of "rebase" isn't hardcoded in. Signed-off-by: Denton Liu --- builtin/rebase.c | 64 ++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 29745176cb..0f650a798e 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] [ []]"), @@ -767,9 +769,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; @@ -791,7 +794,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; } @@ -810,26 +813,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; } @@ -840,16 +843,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) { @@ -911,8 +914,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); @@ -1000,8 +1005,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" @@ -1656,8 +1662,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)) @@ -1674,9 +1680,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); @@ -2068,8 +2074,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 || @@ -2109,10 +2116,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&buf, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.switch_to); - if (reset_head(&options.orig_head, "checkout", + if (reset_head(the_repository, + &options.orig_head, "checkout", options.head_name, RESET_HEAD_RUN_POST_CHECKOUT_HOOK, - NULL, buf.buf) < 0) { + NULL, buf.buf, + DEFAULT_REFLOG_ACTION) < 0) { ret = !!error(_("could not switch to " "%s"), options.switch_to); @@ -2184,10 +2193,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); @@ -2202,8 +2211,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "rebase finished: %s onto %s", options.head_name ? options.head_name : "detached HEAD", oid_to_hex(&options.onto->object.oid)); - reset_head(NULL, "Fast-forwarded", options.head_name, - RESET_HEAD_REFS_ONLY, "HEAD", msg.buf); + reset_head(the_repository, NULL, "Fast-forwarded", options.head_name, + RESET_HEAD_REFS_ONLY, "HEAD", msg.buf, + DEFAULT_REFLOG_ACTION); strbuf_release(&msg); ret = !!finish_rebase(&options); goto cleanup; From patchwork Sat Apr 4 01:11:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473959 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 8996692A for ; Sat, 4 Apr 2020 01:12:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5E9A820787 for ; Sat, 4 Apr 2020 01:12:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aSVz80FM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbgDDBMS (ORCPT ); Fri, 3 Apr 2020 21:12:18 -0400 Received: from mail-qv1-f67.google.com ([209.85.219.67]:42235 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbgDDBMP (ORCPT ); Fri, 3 Apr 2020 21:12:15 -0400 Received: by mail-qv1-f67.google.com with SMTP id ca9so4583869qvb.9 for ; Fri, 03 Apr 2020 18:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ICf0wpj7mUiwdzmSpJBeoO9Lw8Eczo0VrcBY43WRqJ8=; b=aSVz80FM1O72ORx3cs+rN2wJKpU/i2ERPXqkoDZhvSnAKCSb1QoYpVNa5tf9kiW+KQ UjksvaQTXntGdbwQSBCObkF81HX5Ofs6rwz765Dq7p1kFdbMXBej2bc5QQ+e6L4w5qWK 4pQaVcDS5SWmCt9vpnYg6KChII53OIAIDN3y4RStgwu/ptDRh+svEaN6hi3daY/h95M0 iFdRRxY5iffOsgNa342/PLRdQpyfSIxE8WxqRg3dBQKbmf5d1uSKUArK+huSfzNdUzHR AknlUa1x7wr+SIkQurAgNeY0Kh0W4uYrrpsu9SqqsjLREnS2DgXDMdzWErxeH3r/gVal bfEw== 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=ICf0wpj7mUiwdzmSpJBeoO9Lw8Eczo0VrcBY43WRqJ8=; b=SeUfW1GwtyWVKi0gdSSZ/gLHoAcHun4QC/EuQg2KS7xJ5bJC/sTsshUnGfx7tanw/l hCRaxExTuLYv4Uc4/l0dnQ0OUQu6UTTVxpPhZILN4PwkLIgOStMQzuo1+MFvHR5WzBE3 NdT8aaKgG/nqaVDwAsmISj9zYijlmKRpUzDY5/NdA7FLupFw1Vd9iYUOM3NXx7hQBIFj 70Xq3O5PXpyqP7yTQCw55C0RHjKEMjMJFjnFIIksI622TTEBJJ+Tc28L8QXIAemOXoGA wdEhFDLHqr0dD2PZDaFp5GiP4CA6FRBGf0IT/ToJyHRmQTJdLA6hZ4KbR4KgRDAFvPdE YVlA== X-Gm-Message-State: AGi0PuYDIUL9gatsCEGs8F3TRrNqgaRl7gGAm2Hx/mlqBqnF+ICV5mgl fte6EkEiYBlHO1dh6KORwJSdpbS7 X-Google-Smtp-Source: APiQypLHU9sRInDpexRXgz+pdpoNkVOfOKFl65QEFf5ZY6u/vYOvEZKafNA/eKGnuBabCN5pf3+YNQ== X-Received: by 2002:ad4:49b2:: with SMTP id u18mr11381798qvx.102.1585962733778; Fri, 03 Apr 2020 18:12:13 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:13 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 14/23] reset: extract reset_head() from rebase Date: Fri, 3 Apr 2020 21:11:27 -0400 Message-Id: <045668620dc5173fddb899f38a976059c84b5465.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Continue the process of lib-ifying the autostash code. In a future commit, this will be used to implement `--autostash` in other builtins. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu --- Makefile | 1 + builtin/rebase.c | 139 +--------------------------------------------- reset.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++ reset.h | 20 +++++++ 4 files changed, 162 insertions(+), 138 deletions(-) create mode 100644 reset.c create mode 100644 reset.h diff --git a/Makefile b/Makefile index f709fc3f77..338fb55b73 100644 --- a/Makefile +++ b/Makefile @@ -970,6 +970,7 @@ LIB_OBJS += replace-object.o LIB_OBJS += repo-settings.o LIB_OBJS += repository.o LIB_OBJS += rerere.o +LIB_OBJS += reset.o LIB_OBJS += resolve-undo.o LIB_OBJS += revision.o LIB_OBJS += run-command.o diff --git a/builtin/rebase.c b/builtin/rebase.c index 0f650a798e..55730f6360 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" @@ -761,144 +762,6 @@ static void add_var(struct strbuf *buf, const char *name, const char *value) } } -#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" - -#define RESET_HEAD_DETACH (1<<0) -#define RESET_HEAD_HARD (1<<1) -#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) -#define RESET_HEAD_REFS_ONLY (1<<3) -#define RESET_ORIG_HEAD (1<<4) - -static int reset_head(struct repository *r, struct object_id *oid, const char *action, - const char *switch_to_branch, unsigned flags, - const char *reflog_orig_head, const char *reflog_head, - const char *default_reflog_action) -{ - unsigned detach_head = flags & RESET_HEAD_DETACH; - unsigned reset_hard = flags & RESET_HEAD_HARD; - unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; - unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; - unsigned update_orig_head = flags & RESET_ORIG_HEAD; - struct object_id head_oid; - struct tree_desc desc[2] = { { NULL }, { NULL } }; - struct lock_file lock = LOCK_INIT; - struct unpack_trees_options unpack_tree_opts; - struct tree *tree; - const char *reflog_action; - struct strbuf msg = STRBUF_INIT; - size_t prefix_len; - struct object_id *orig = NULL, oid_orig, - *old_orig = NULL, oid_old_orig; - int ret = 0, nr = 0; - - if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) - BUG("Not a fully qualified branch: '%s'", switch_to_branch); - - if (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { - ret = -1; - goto leave_reset_head; - } - - if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { - ret = error(_("could not determine HEAD revision")); - goto leave_reset_head; - } - - if (!oid) - oid = &head_oid; - - if (refs_only) - goto reset_head_refs; - - memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); - setup_unpack_trees_porcelain(&unpack_tree_opts, action); - unpack_tree_opts.head_idx = 1; - unpack_tree_opts.src_index = r->index; - unpack_tree_opts.dst_index = r->index; - unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; - unpack_tree_opts.update = 1; - unpack_tree_opts.merge = 1; - if (!detach_head) - unpack_tree_opts.reset = 1; - - if (repo_read_index_unmerged(r) < 0) { - ret = error(_("could not read index")); - goto leave_reset_head; - } - - if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) { - ret = error(_("failed to find tree of %s"), - oid_to_hex(&head_oid)); - goto leave_reset_head; - } - - if (!fill_tree_descriptor(r, &desc[nr++], oid)) { - ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); - goto leave_reset_head; - } - - if (unpack_trees(nr, desc, &unpack_tree_opts)) { - ret = -1; - goto leave_reset_head; - } - - tree = parse_tree_indirect(oid); - prime_cache_tree(r, r->index, tree); - - if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { - ret = error(_("could not write index")); - goto leave_reset_head; - } - -reset_head_refs: - reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); - strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action); - prefix_len = msg.len; - - if (update_orig_head) { - if (!get_oid("ORIG_HEAD", &oid_old_orig)) - old_orig = &oid_old_orig; - if (!get_oid("HEAD", &oid_orig)) { - orig = &oid_orig; - if (!reflog_orig_head) { - strbuf_addstr(&msg, "updating ORIG_HEAD"); - reflog_orig_head = msg.buf; - } - update_ref(reflog_orig_head, "ORIG_HEAD", orig, - old_orig, 0, UPDATE_REFS_MSG_ON_ERR); - } else if (old_orig) - delete_ref(NULL, "ORIG_HEAD", old_orig, 0); - } - - if (!reflog_head) { - strbuf_setlen(&msg, prefix_len); - strbuf_addstr(&msg, "updating HEAD"); - reflog_head = msg.buf; - } - if (!switch_to_branch) - ret = update_ref(reflog_head, "HEAD", oid, orig, - detach_head ? REF_NO_DEREF : 0, - UPDATE_REFS_MSG_ON_ERR); - else { - ret = update_ref(reflog_head, switch_to_branch, oid, - NULL, 0, UPDATE_REFS_MSG_ON_ERR); - if (!ret) - ret = create_symref("HEAD", switch_to_branch, - reflog_head); - } - if (run_hook) - run_hook_le(NULL, "post-checkout", - oid_to_hex(orig ? orig : &null_oid), - oid_to_hex(oid), "1", NULL); - -leave_reset_head: - strbuf_release(&msg); - rollback_lock_file(&lock); - while (nr) - free((void *)desc[--nr].buffer); - return ret; -} - static int move_to_original_branch(struct rebase_options *opts) { struct strbuf orig_head_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT; diff --git a/reset.c b/reset.c new file mode 100644 index 0000000000..79b683bffa --- /dev/null +++ b/reset.c @@ -0,0 +1,140 @@ +#include "git-compat-util.h" +#include "cache-tree.h" +#include "lockfile.h" +#include "refs.h" +#include "reset.h" +#include "run-command.h" +#include "tree-walk.h" +#include "tree.h" +#include "unpack-trees.h" + +int reset_head(struct repository *r, struct object_id *oid, const char *action, + const char *switch_to_branch, unsigned flags, + const char *reflog_orig_head, const char *reflog_head, + const char *default_reflog_action) +{ + unsigned detach_head = flags & RESET_HEAD_DETACH; + unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; + unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; + unsigned update_orig_head = flags & RESET_ORIG_HEAD; + struct object_id head_oid; + struct tree_desc desc[2] = { { NULL }, { NULL } }; + struct lock_file lock = LOCK_INIT; + struct unpack_trees_options unpack_tree_opts; + struct tree *tree; + const char *reflog_action; + struct strbuf msg = STRBUF_INIT; + size_t prefix_len; + struct object_id *orig = NULL, oid_orig, + *old_orig = NULL, oid_old_orig; + int ret = 0, nr = 0; + + if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) + BUG("Not a fully qualified branch: '%s'", switch_to_branch); + + if (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { + ret = -1; + goto leave_reset_head; + } + + if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { + ret = error(_("could not determine HEAD revision")); + goto leave_reset_head; + } + + if (!oid) + oid = &head_oid; + + if (refs_only) + goto reset_head_refs; + + memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); + setup_unpack_trees_porcelain(&unpack_tree_opts, action); + unpack_tree_opts.head_idx = 1; + unpack_tree_opts.src_index = r->index; + unpack_tree_opts.dst_index = r->index; + unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; + unpack_tree_opts.update = 1; + unpack_tree_opts.merge = 1; + if (!detach_head) + unpack_tree_opts.reset = 1; + + if (repo_read_index_unmerged(r) < 0) { + ret = error(_("could not read index")); + goto leave_reset_head; + } + + if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) { + ret = error(_("failed to find tree of %s"), + oid_to_hex(&head_oid)); + goto leave_reset_head; + } + + if (!fill_tree_descriptor(r, &desc[nr++], oid)) { + ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); + goto leave_reset_head; + } + + if (unpack_trees(nr, desc, &unpack_tree_opts)) { + ret = -1; + goto leave_reset_head; + } + + tree = parse_tree_indirect(oid); + prime_cache_tree(r, r->index, tree); + + if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { + ret = error(_("could not write index")); + goto leave_reset_head; + } + +reset_head_refs: + reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); + strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : default_reflog_action); + prefix_len = msg.len; + + if (update_orig_head) { + if (!get_oid("ORIG_HEAD", &oid_old_orig)) + old_orig = &oid_old_orig; + if (!get_oid("HEAD", &oid_orig)) { + orig = &oid_orig; + if (!reflog_orig_head) { + strbuf_addstr(&msg, "updating ORIG_HEAD"); + reflog_orig_head = msg.buf; + } + update_ref(reflog_orig_head, "ORIG_HEAD", orig, + old_orig, 0, UPDATE_REFS_MSG_ON_ERR); + } else if (old_orig) + delete_ref(NULL, "ORIG_HEAD", old_orig, 0); + } + + if (!reflog_head) { + strbuf_setlen(&msg, prefix_len); + strbuf_addstr(&msg, "updating HEAD"); + reflog_head = msg.buf; + } + if (!switch_to_branch) + ret = update_ref(reflog_head, "HEAD", oid, orig, + detach_head ? REF_NO_DEREF : 0, + UPDATE_REFS_MSG_ON_ERR); + else { + ret = update_ref(reflog_head, switch_to_branch, oid, + NULL, 0, UPDATE_REFS_MSG_ON_ERR); + if (!ret) + ret = create_symref("HEAD", switch_to_branch, + reflog_head); + } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); + +leave_reset_head: + strbuf_release(&msg); + rollback_lock_file(&lock); + while (nr) + free((void *)desc[--nr].buffer); + return ret; + +} diff --git a/reset.h b/reset.h new file mode 100644 index 0000000000..12f83c78e2 --- /dev/null +++ b/reset.h @@ -0,0 +1,20 @@ +#ifndef RESET_H +#define RESET_H + +#include "hash.h" +#include "repository.h" + +#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" + +#define RESET_HEAD_DETACH (1<<0) +#define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) +#define RESET_HEAD_REFS_ONLY (1<<3) +#define RESET_ORIG_HEAD (1<<4) + +int reset_head(struct repository *r, struct object_id *oid, const char *action, + const char *switch_to_branch, unsigned flags, + const char *reflog_orig_head, const char *reflog_head, + const char *default_reflog_action); + +#endif From patchwork Sat Apr 4 01:11:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473949 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 A61881668 for ; Sat, 4 Apr 2020 01:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 855CF2080C for ; Sat, 4 Apr 2020 01:12:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DI6P2iVo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgDDBMR (ORCPT ); Fri, 3 Apr 2020 21:12:17 -0400 Received: from mail-qv1-f66.google.com ([209.85.219.66]:46334 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbgDDBMQ (ORCPT ); Fri, 3 Apr 2020 21:12:16 -0400 Received: by mail-qv1-f66.google.com with SMTP id bu9so4574640qvb.13 for ; Fri, 03 Apr 2020 18:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dnSIFpWzrZIhL4coIee8OMYgHWQfDde9r+RYhxzpxa0=; b=DI6P2iVoEzTZSTWPI+53jFO2k3Xk8jVyT3jmr6vbXEsUla/7dTQdD0XpTGgBSQ4qz0 nBGAQ+IZdrBgTk1rVFuiTf0fsEPXgUHI9c33GHRByt1U9zSxaBO85kOURLdwlkT6AxFR 5vKD7Rl7b1T1VCnxiuGWUxHIYjZx84NoNjawVG9YGXEDLlAJuuqdJAm+XoZGNU2QrPqA bwpD5e0XTUCek+BO0I4NMmIGhIOTgxQaaq6x9Xevv+Uq/FGj2L3LVXo/BzcQewnDyWhu fHcwEuZeUlKho8cSDcVRT7zQRJsShU3G5cxJyH5b2Dow5Oh043jU8Ty9phgPpFZYRovd lxzA== 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=dnSIFpWzrZIhL4coIee8OMYgHWQfDde9r+RYhxzpxa0=; b=ItlgDgnmFp04djvsB3wT6l35I7Eujcw6HqaWs+ZFSUhIMlpWnXfF2bvtotmmXKIoc8 q2iJIKPi7Nun9qJhLqaHcNGjxAasVbyY6NCMf6TwRj/IH8vLcGcIHqz9XFi5YLUqQ+ga oqMw5DmApPayWuH8e6PjWe7lnp+IFs6CK2Slr2kV3lGDzNzD39sFzhQzCcDd13Z8kRxe LNrypeXr7ya//opHube03wevfNeJnitigc52vh55hpPM0ASWblg0EF95NDHuw5531UPo oHsBClahZdvn0vJkUHAOQgbLskKSlMwGsR3f0ERqXZ7LGcXN57sNG6rGEA2PSN/Ij0Qp v1CQ== X-Gm-Message-State: AGi0PuZ1vAYGmqo/gFGhh4GAOTusyK3WLkvWq2WXlX5iw91AA8WUO8Tg RAQzeQsw+miSYu/34sS42yAkRg46 X-Google-Smtp-Source: APiQypIvFttcAg7f8e8rPu8qP8IH9x52J8LBNq24DaGapLwH9SM8x5M8tD4Wwc5KoLrycNMxgWM5VQ== X-Received: by 2002:ad4:4581:: with SMTP id x1mr10638221qvu.152.1585962734828; Fri, 03 Apr 2020 18:12:14 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:14 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 15/23] rebase: extract create_autostash() Date: Fri, 3 Apr 2020 21:11:28 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will 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 55730f6360..8349f3a03a 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1269,6 +1269,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) { @@ -1902,50 +1951,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("could not read index")); if (options.autostash) { - struct lock_file lock_file = LOCK_INIT; - int fd; - - fd = hold_locked_index(&lock_file, 0); - refresh_cache(REFRESH_QUIET); - if (0 <= fd) - repo_update_index_if_able(the_repository, &lock_file); - rollback_lock_file(&lock_file); - - if (has_unstaged_changes(the_repository, 1) || - has_uncommitted_changes(the_repository, 1)) { - const char *autostash = - state_dir_path("autostash", &options); - struct child_process stash = CHILD_PROCESS_INIT; - struct object_id oid; - - argv_array_pushl(&stash.args, - "stash", "create", "autostash", NULL); - stash.git_cmd = 1; - stash.no_stdin = 1; - strbuf_reset(&buf); - if (capture_command(&stash, &buf, GIT_MAX_HEXSZ)) - die(_("Cannot autostash")); - strbuf_trim_trailing_newline(&buf); - if (get_oid(buf.buf, &oid)) - die(_("Unexpected stash response: '%s'"), - buf.buf); - strbuf_reset(&buf); - strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); - - if (safe_create_leading_directories_const(autostash)) - die(_("Could not create directory for '%s'"), - options.state_dir); - write_file(autostash, "%s", oid_to_hex(&oid)); - printf(_("Created autostash: %s\n"), buf.buf); - if (reset_head(the_repository, NULL, "reset --hard", - NULL, RESET_HEAD_HARD, NULL, NULL, - DEFAULT_REFLOG_ACTION) < 0) - die(_("could not reset --hard")); - - if (discard_index(the_repository->index) < 0 || - repo_read_index(the_repository) < 0) - die(_("could not read index")); - } + create_autostash(&options); } if (require_clean_work_tree(the_repository, "rebase", From patchwork Sat Apr 4 01:11:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473951 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 0225792A for ; Sat, 4 Apr 2020 01:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D4A6320731 for ; Sat, 4 Apr 2020 01:12:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bj8hGIyv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbgDDBMS (ORCPT ); Fri, 3 Apr 2020 21:12:18 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:38118 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbgDDBMR (ORCPT ); Fri, 3 Apr 2020 21:12:17 -0400 Received: by mail-qk1-f196.google.com with SMTP id h14so10194831qke.5 for ; Fri, 03 Apr 2020 18:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nhhS7eH2znlOIw1OtQOPkWNOz5rVtgDAZc916pl9T5I=; b=Bj8hGIyvSy4hU/Uh8gGfI6aWJ/L4vKvZKf6XN2KrQOBfJ9RORGNPMmmz/KjKY1MtvF wBCS+rZdc924kL3bzg0C2VmFzpco3LOlO/JK9VW3xcwF0UtdGRCZWwZZ59NMn1PKBGMa uIwmiZcwfPvmWvxmL8RfcpEZJ8+us0HPmZfSMN/jJX7L+6yb5LXCj0S23El6v/vRUqHe vhJMGeQA3VmZcSW8Jhp1PJZwzEO5j/BTd3fXMW/68mkKwzlmitSfGT8MHlZHuTR+pYkv nf4S/vIWm+Jtsj8SGutmV2ByaRJhb0GGiY5PhIYqx+7qxQh+wG7cEU92t8jgy0/Xcp5x rLVA== 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=nhhS7eH2znlOIw1OtQOPkWNOz5rVtgDAZc916pl9T5I=; b=b3EAlLS52E3bcmvRvhHY6rpxkeZS0evc6ArCyfM013Re+NHQ30TLd3S+W0TE2uUz8f KwOAxs02Fj8Siha6bZ+1ShLwWDHRGHwJKCCPYxyqhFW/Sx5YMTao+QSzElS3HdW3iNuy iNBS3Fpy0QwG7X1Sr/fo5/eENPaOziqvuNAanQbnfHpQb2SJtr8OBGjlOxuRDRZuq8Oi vL4xHAYTI8KkMHEqnNjLTjgxilG/GaJupTjKCAgBSrUUb4IytBxAxp1cMsq9RjMoE6mu ZXVLEuKPzj7JdPF0vJ19X7ZYyYGR4k5WoYFY8ldhm3xwzYEaBt55EmytXKu/ZZQuePQ+ llBA== X-Gm-Message-State: AGi0PubeVRSGhCC5YpWHuhU5JNzWUfpbolYhZ+ogcgY++HBxYN5orSb9 3DaPaMBGCCjY7XG/YdIR5e2CgrmZ X-Google-Smtp-Source: APiQypLztK8H2Cl+7kxwY0o+e1T/j1g9A+AfRCl9DIX1l/afhhAvW+/vP9BSz5RtT76PhtXQsuSDEw== X-Received: by 2002:a05:620a:48:: with SMTP id t8mr168467qkt.21.1585962736280; Fri, 03 Apr 2020 18:12:16 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:15 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 16/23] rebase: generify create_autostash() Date: Fri, 3 Apr 2020 21:11:29 -0400 Message-Id: <9ab10d23d41a2135a02bf054269a7deb5d07604e.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the future, we plan on lib-ifying 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 8349f3a03a..e9b05a6cd8 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1269,22 +1269,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; @@ -1302,18 +1301,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); @@ -1951,7 +1950,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("could not read index")); if (options.autostash) { - create_autostash(&options); + create_autostash(the_repository, state_dir_path("autostash", &options), + DEFAULT_REFLOG_ACTION); } if (require_clean_work_tree(the_repository, "rebase", From patchwork Sat Apr 4 01:11:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473953 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 DA86292A for ; Sat, 4 Apr 2020 01:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B86692074B for ; Sat, 4 Apr 2020 01:12:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="usB5BWYI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbgDDBMT (ORCPT ); Fri, 3 Apr 2020 21:12:19 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:33990 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726632AbgDDBMS (ORCPT ); Fri, 3 Apr 2020 21:12:18 -0400 Received: by mail-qt1-f194.google.com with SMTP id 14so7904599qtp.1 for ; Fri, 03 Apr 2020 18:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zk9ObUzTQltqhzu6e9Ir2MbkOrMxwNbJFFPR40SA9yw=; b=usB5BWYIfKgWBBilRELcQ65/OuqCXgrsPF9zsD8Ybn1WzFcDjLV5ZaGev0m1JV41Lr m6vOF3kYmJCsLu824lsProue/EVl14BZjE5lNWmRYjzBKTt+lgnpX7E4JfjnwmlRLETO QqsIzXEpXcMVsOK9JuyXjxbRP+08T9BkgN+HcbCeKXkZzJ50sXY1Z5e+FaIi4VrRbmSP NvlYNEhd50Uz5nYGi6/idU1iURSV8JTEX+BL20D0R+aH1zKJWLQecHCV0GHN6Kl5ULHi cze7VGrWaKaKEBMNSOAnUUJtBkEY+K9W8QP78KpNxADZV4pfuG/4imaTm54hxUy+1m3S 13JA== 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=Zk9ObUzTQltqhzu6e9Ir2MbkOrMxwNbJFFPR40SA9yw=; b=nokO5KDZDcAS8KIjm98v/i6xNYAXbDzqnVJGj46/FcpItsTfZM0N+3HJKvjHMiwcgu xx/fWzqrklxezHROS4j3LC2LVEbxKmYeYZ6GQtpPyPjzYQTs+DUhQr/+mFe56lyym2Yt OjwJgo+AtHjuJR0siQc+cSssEXcptkNQhJWimEioAEJXExqkbklfpEn7YV68s+84xAi8 T0datuergnkLbNYonsc8O8nJHSz7xXfPYYS7VHcAjoq+cYD05gV2vMY/iDaWg3hnYFL0 nnd+GY8g7XnOUUxvoBLvPXqoz3qz97vnEk78608+vq9Aa52hzfHQ5uojX8rbx1m0MU1q QIRw== X-Gm-Message-State: AGi0PuYcuEYMUrOwEuHuSfdt0zLzEXxVjd6W6RCoK2iLVLpNhPbXEQjc AGC1fWqNC2FRqhPIAoCTWh+1spJG X-Google-Smtp-Source: APiQypJA3LB1piLFEUVvYH9xPosrvGL7Yz+IUbN4DxRGyybIcMejOB3xGTTrZKwnT0UiFa4K9LOzNg== X-Received: by 2002:aed:2f01:: with SMTP id l1mr11122523qtd.37.1585962737380; Fri, 03 Apr 2020 18:12:17 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:16 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 17/23] sequencer: extract perform_autostash() from rebase Date: Fri, 3 Apr 2020 21:11:30 -0400 Message-Id: <26cca49be6908083382b2209e405e7462cd077a7.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Lib-ify the autostash code by extracting perform_autostash() from rebase into sequencer. In a future commit, this will be used to implement `--autostash` in other builtins. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu --- builtin/rebase.c | 49 ----------------------------------------------- sequencer.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 2 ++ 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index e9b05a6cd8..b800c8bfca 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1269,55 +1269,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 dde1f6b30f..8efe0976fd 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" @@ -3649,6 +3650,55 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset) return -1; } +void create_autostash(struct repository *r, const char *path, + const char *default_reflog_action) +{ + struct strbuf buf = STRBUF_INIT; + struct lock_file lock_file = LOCK_INIT; + int fd; + + fd = repo_hold_locked_index(r, &lock_file, 0); + refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); + if (0 <= fd) + repo_update_index_if_able(r, &lock_file); + rollback_lock_file(&lock_file); + + if (has_unstaged_changes(r, 1) || + has_uncommitted_changes(r, 1)) { + struct child_process stash = CHILD_PROCESS_INIT; + struct object_id oid; + + argv_array_pushl(&stash.args, + "stash", "create", "autostash", NULL); + stash.git_cmd = 1; + stash.no_stdin = 1; + strbuf_reset(&buf); + if (capture_command(&stash, &buf, GIT_MAX_HEXSZ)) + die(_("Cannot autostash")); + strbuf_trim_trailing_newline(&buf); + if (get_oid(buf.buf, &oid)) + die(_("Unexpected stash response: '%s'"), + buf.buf); + strbuf_reset(&buf); + strbuf_add_unique_abbrev(&buf, &oid, DEFAULT_ABBREV); + + if (safe_create_leading_directories_const(path)) + die(_("Could not create directory for '%s'"), + path); + write_file(path, "%s", oid_to_hex(&oid)); + printf(_("Created autostash: %s\n"), buf.buf); + if (reset_head(r, NULL, "reset --hard", + NULL, RESET_HEAD_HARD, NULL, NULL, + default_reflog_action) < 0) + die(_("could not reset --hard")); + + if (discard_index(r->index) < 0 || + repo_read_index(r) < 0) + die(_("could not read index")); + } + strbuf_release(&buf); +} + int apply_autostash(const char *path) { struct strbuf stash_oid = STRBUF_INIT; diff --git a/sequencer.h b/sequencer.h index d6ba62a089..cf1284f9ed 100644 --- a/sequencer.h +++ b/sequencer.h @@ -191,6 +191,8 @@ void commit_post_rewrite(struct repository *r, const struct commit *current_head, const struct object_id *new_head); +void create_autostash(struct repository *r, const char *path, + const char *default_reflog_action); int apply_autostash(const char *path); #define SUMMARY_INITIAL_COMMIT (1 << 0) From patchwork Sat Apr 4 01:11:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473955 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 5A7E8912 for ; Sat, 4 Apr 2020 01:12:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 390B920731 for ; Sat, 4 Apr 2020 01:12:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K9X028VZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726684AbgDDBMV (ORCPT ); Fri, 3 Apr 2020 21:12:21 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:34163 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbgDDBMT (ORCPT ); Fri, 3 Apr 2020 21:12:19 -0400 Received: by mail-qk1-f193.google.com with SMTP id i186so1248965qke.1 for ; Fri, 03 Apr 2020 18:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DUgn9onJnc+CLINd2r5YNxqa38tJ7MrR11cbK6unYBI=; b=K9X028VZaA1p72GY9uRNbKJwx1RI0wbpZ6b+LX4+VibCLb+dwh9ERGh/CALdgxy0LS lXDYMx5dDlHq3Wm+qMLwGKenpSozcO5gtq4UBh8rvV6INAUfPTcMxP/I/wGm6VYywMN0 TEwXzTTikrBlEA9LsuDCcQ3THCebzApXpVhMBAyMej+LXYt4XViDj+w8PjEXICLY5QF2 f6e6gz46sqMeOOl3OMpxZ+q3Cgri56Z+dCJX8uO55ZJY8fsX++/+sECQEC5EhkOCQYbx AGQGH+ga6Vp74rTPChgw7ncYJmQqZav+5FBi5o7fHt34+Jos1lsHtfx91UTPYMBaY37C p3rg== 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=DUgn9onJnc+CLINd2r5YNxqa38tJ7MrR11cbK6unYBI=; b=kAgt+8kHaCZYlmlwobzAgERjQvOZ0sCjHfWoqJvYnp8uMNHLF/3ihQgctBuBuUTKVN LZ+oj54mXkpZNU9tw03m1wHWiwsrgKabvWpGu07yikpjGFBhW/5lu8Slh9lX4h83xWZg kygLf2taN8dBFJcsgVzawz3t8I46ZfFn8Xsdbd7o7v81f6sKaDIfGRmxY7a67aP7doAL Hu7Bw6lKSXoh9+VFKnOrwxi4/qUV7E3S+YrXuQSMosPdSTUXZvpMNyPRHnjcTYZZwitW zxkdp1ColarKACUXyvq6AwUCQ1ZBeKU5yc1r37xNaY8sNLtcZT8g8Ft1+vDa4MZwcbJk CIQw== X-Gm-Message-State: AGi0PuY8bAiVgGnIht8zZ/5FWo9kUogV2acSrjSps1YBiU4syL09BJOy iE96kQY5f67DbajLLMtkbww2S2iN X-Google-Smtp-Source: APiQypKfyq4P7JIPM6c1SezMd9gzhboFSZ+AdeF0yupROKuFrT6+K7B/TxbIiD5/R/ekIsmd/qHXPQ== X-Received: by 2002:a37:317:: with SMTP id 23mr11438535qkd.233.1585962738405; Fri, 03 Apr 2020 18:12:18 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:17 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 18/23] sequencer: unlink autostash in apply_autostash() Date: Fri, 3 Apr 2020 21:11:31 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 8efe0976fd..5dd1c2438e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3740,6 +3740,7 @@ int apply_autostash(const char *path) " \"git stash drop\" at any time.\n")); } + unlink(path); strbuf_release(&stash_oid); return ret; } From patchwork Sat Apr 4 01:11:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473963 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 F1B8692A for ; Sat, 4 Apr 2020 01:12:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF6BC20731 for ; Sat, 4 Apr 2020 01:12:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Lo5qrNJV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726899AbgDDBMZ (ORCPT ); Fri, 3 Apr 2020 21:12:25 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:43103 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbgDDBMX (ORCPT ); Fri, 3 Apr 2020 21:12:23 -0400 Received: by mail-qk1-f196.google.com with SMTP id o10so10136489qki.10 for ; Fri, 03 Apr 2020 18:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l3sXBy9fKrkislpfYTekmI52GIt5QopTZkA0tIscZsE=; b=Lo5qrNJVCWPtU65fCq/vPu3Fg123lVduVv1JBG7+s6k0zNVXyQNFDDf9V79A7OvWx8 y1TGrdd4nWsOiOJAnI+FxQR9wDgBOIvvDNv96HgiPO08erOcxFqJouqSLoqk8kxhrxR3 Ag3qnXSFi3uJQL6NHJQH+Dg+WMS9c4gtHFvQVlx+HW4Cha2qF5sWtB0xiMJKMyhJEaPb tXzUdPMVzWxPviIw4NbIl4lJ7h5oapiMotiG48O5oQrEtpWwUtKZZRF1NGWWQ0Tp+sD3 +b3mGCzPmYWSAAPcmE4i/SXRSg/uwPM3s94poYGX7XL00okD/2S6sV8WNPlTXp6oAHY0 jfXQ== 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=l3sXBy9fKrkislpfYTekmI52GIt5QopTZkA0tIscZsE=; b=Un8I7brSuKK8JEuWzcvYkMBYm3PftCUE5KVFmA7if7I/MEqYgfJAAcwtPOHL2iQrra BJdk4+FmOhLykWsDkTxQV6PLYHSOMundHmgq2YJ+B14sT+mcysJ4SL/Yp7lMlBSyxLiK PWKSxP3nemjRLIzA6sxBhWuMa0RH/qGTB6KJKVJ8aoFx9HK3LkyyNqvwCA8custSbP0g Vc8ZCcYdc56DrepqwsPWT/3LL5gMpEYvZ3hEiTLM0SU1BJTRvA1uPyYuhAuvT0IjaQSS GXbQ7hXB0oPhMgGBvYyZImjigjlmmD+Zrq7mfMWkJdEPuCMZuIAPOuBPwizqtbivdeLn hwsA== X-Gm-Message-State: AGi0PuY96JPAp7+4FA5whH0if2fXj/9m1uovvimopDFoYNSXfa40nUkV ++wGnnbE4KyahRpoiJRjJRxcdbaI X-Google-Smtp-Source: APiQypKUq+++CSoLm2P5pFAY9sZRkDhUpRdAgCYZ9VXilOwW3CjieFeF6gK+kuM/9SwipOjV1av13Q== X-Received: by 2002:a05:620a:9cd:: with SMTP id y13mr10952166qky.488.1585962739361; Fri, 03 Apr 2020 18:12:19 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:18 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 19/23] sequencer: implement save_autostash() Date: Fri, 3 Apr 2020 21:11:32 -0400 Message-Id: <75dc3f10a1aac24007b660a02ce829c8702ffd0e.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Extract common functionality of apply_autostash() into apply_save_autostash() and use it to implement save_autostash(). This function will be used in a future commit. The difference between save_autostash() and apply_autostash() is that the latter does not try to apply the stash. It skips that step and just stores the created entry in the stash reflog. Signed-off-by: Denton Liu --- sequencer.c | 37 +++++++++++++++++++++++++++---------- sequencer.h | 1 + 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/sequencer.c b/sequencer.c index 5dd1c2438e..fb52583bc2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3699,7 +3699,7 @@ void create_autostash(struct repository *r, const char *path, strbuf_release(&buf); } -int apply_autostash(const char *path) +static int apply_save_autostash(const char *path, int attempt_apply) { struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; @@ -3712,13 +3712,17 @@ int apply_autostash(const char *path) } strbuf_trim(&stash_oid); - child.git_cmd = 1; - child.no_stdout = 1; - child.no_stderr = 1; - argv_array_push(&child.args, "stash"); - argv_array_push(&child.args, "apply"); - argv_array_push(&child.args, stash_oid.buf); - if (!run_command(&child)) + if (attempt_apply) { + child.git_cmd = 1; + child.no_stdout = 1; + child.no_stderr = 1; + argv_array_push(&child.args, "stash"); + argv_array_push(&child.args, "apply"); + argv_array_push(&child.args, stash_oid.buf); + ret = run_command(&child); + } + + if (attempt_apply && !ret) fprintf(stderr, _("Applied autostash.\n")); else { struct child_process store = CHILD_PROCESS_INIT; @@ -3734,10 +3738,13 @@ int apply_autostash(const char *path) ret = error(_("cannot store %s"), stash_oid.buf); else fprintf(stderr, - _("Applying autostash resulted in conflicts.\n" + _("%s\n" "Your changes are safe in the stash.\n" "You can run \"git stash pop\" or" - " \"git stash drop\" at any time.\n")); + " \"git stash drop\" at any time.\n"), + attempt_apply ? + _("Applying autostash resulted in conflicts.") : + _("Autostash exists; creating a new stash entry.")); } unlink(path); @@ -3745,6 +3752,16 @@ int apply_autostash(const char *path) return ret; } +int save_autostash(const char *path) +{ + return apply_save_autostash(path, 0); +} + +int apply_autostash(const char *path) +{ + return apply_save_autostash(path, 1); +} + static const char *reflog_message(struct replay_opts *opts, const char *sub_action, const char *fmt, ...) { diff --git a/sequencer.h b/sequencer.h index cf1284f9ed..2d09c1ac0b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -193,6 +193,7 @@ void commit_post_rewrite(struct repository *r, void create_autostash(struct repository *r, const char *path, const char *default_reflog_action); +int save_autostash(const char *path); int apply_autostash(const char *path); #define SUMMARY_INITIAL_COMMIT (1 << 0) From patchwork Sat Apr 4 01:11:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473957 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 B6AB392A for ; Sat, 4 Apr 2020 01:12:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9551820731 for ; Sat, 4 Apr 2020 01:12:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kvCGWO/B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726749AbgDDBMW (ORCPT ); Fri, 3 Apr 2020 21:12:22 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:33399 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbgDDBMV (ORCPT ); Fri, 3 Apr 2020 21:12:21 -0400 Received: by mail-qt1-f196.google.com with SMTP id c14so8197400qtp.0 for ; Fri, 03 Apr 2020 18:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kadXDH/XBsH/eMWSUaU7o3uCzdU2sPSmcuHCC3zx7aI=; b=kvCGWO/Bn4KJLHPVW2HRd50qA0IyhqciVPEgKyfw0MBPUxTsliDigZ9bXXD8oHYXXN ZczhNXOt1AyjAXx4lR9sgCebUkbBtd2l5Q4svf8MzACzQw11OqnrZ9niIUhLUABtsLuo fGTU4zGK564aqsfCAIlnneL1U0HDvXFMjSJi16u/GuTeY596BQsvX1pF6IY/eN/raIQ2 G2jle3+m1Tj4yZpiQQKY/3ECSH68xVkDJ/IRVwPMYe/zWIxJF/tqhTRRnaMMSfWUqjVy YrQJcm0kI7ExSmmEyiL+7Mr2wwPTb1oqDzURWJdP831Scnc/fvmtP5akCWAMnT9Ujuhd FaFg== 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=kadXDH/XBsH/eMWSUaU7o3uCzdU2sPSmcuHCC3zx7aI=; b=mdzRT1T6TVsbcT4tdBa/5jGD4VTWDS6fmjHi+yvD+IpeWHhsIUSlXzryPRtDx7Zhs/ Aa6MqJZKA/sqqVpZV2zt6MIaQwKMZZnE2MW6r1C8GdpdLnWhDnIofq6e6ucerHMF+Byw BqknkfRFKOmsNQ6xSH5WFps6twfp51I8F9hE53dveoRo4f2jY09Tqpud0el9SstZdpCq uahhyISp+Drihq7iyyivEMlFLen105HYEO8V0XWsmKg8MT+AnG9C0znqMcosEhOP7tku rUXjykCZQbjo+R8+B063BQ+rK/tmorqF2DsVC8YBw+44U1PdfAeabjrz91tKvNeOrnLC JxzA== X-Gm-Message-State: AGi0PuZ0SMnkfMP67KhlEkpMvZ7aKuqz0FmWN8gNzLtOgBHYbyCw6MWn OvlLmr9s+2ghuwhK46MU2rsWrxgE X-Google-Smtp-Source: APiQypIci/Sia14yVgOjnlcdccCNTD9FOccDGIU3RgtmD+8nriRcSZj9nQc6C3u7Kurjh16aR5LTfQ== X-Received: by 2002:ac8:4e0e:: with SMTP id c14mr10409018qtw.312.1585962740261; Fri, 03 Apr 2020 18:12:20 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:19 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 20/23] sequencer: implement apply_autostash_oid() Date: Fri, 3 Apr 2020 21:11:33 -0400 Message-Id: <598ddea6c1187d78f876136974822e65bbec146b.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split apply_save_autostash() into apply_autostash_oid() and apply_save_autostash() where the former operates on an OID string and the latter reads the OID from a file before passing it into apply_save_autostash_oid(). This function is required for a future commmit which will rely on being able to apply an autostash whose OID is stored as a string. Signed-off-by: Denton Liu --- sequencer.c | 38 ++++++++++++++++++++++++++------------ sequencer.h | 1 + 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/sequencer.c b/sequencer.c index fb52583bc2..b4cab9632a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3699,26 +3699,18 @@ void create_autostash(struct repository *r, const char *path, strbuf_release(&buf); } -static int apply_save_autostash(const char *path, int attempt_apply) +static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply) { - struct strbuf stash_oid = STRBUF_INIT; struct child_process child = CHILD_PROCESS_INIT; int ret = 0; - if (!read_oneliner(&stash_oid, path, - READ_ONELINER_SKIP_IF_EMPTY)) { - strbuf_release(&stash_oid); - return 0; - } - strbuf_trim(&stash_oid); - if (attempt_apply) { child.git_cmd = 1; child.no_stdout = 1; child.no_stderr = 1; argv_array_push(&child.args, "stash"); argv_array_push(&child.args, "apply"); - argv_array_push(&child.args, stash_oid.buf); + argv_array_push(&child.args, stash_oid); ret = run_command(&child); } @@ -3733,9 +3725,9 @@ static int apply_save_autostash(const char *path, int attempt_apply) argv_array_push(&store.args, "-m"); argv_array_push(&store.args, "autostash"); argv_array_push(&store.args, "-q"); - argv_array_push(&store.args, stash_oid.buf); + argv_array_push(&store.args, stash_oid); if (run_command(&store)) - ret = error(_("cannot store %s"), stash_oid.buf); + ret = error(_("cannot store %s"), stash_oid); else fprintf(stderr, _("%s\n" @@ -3747,6 +3739,23 @@ static int apply_save_autostash(const char *path, int attempt_apply) _("Autostash exists; creating a new stash entry.")); } + return ret; +} + +static int apply_save_autostash(const char *path, int attempt_apply) +{ + struct strbuf stash_oid = STRBUF_INIT; + int ret = 0; + + if (!read_oneliner(&stash_oid, path, + READ_ONELINER_SKIP_IF_EMPTY)) { + strbuf_release(&stash_oid); + return 0; + } + strbuf_trim(&stash_oid); + + ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply); + unlink(path); strbuf_release(&stash_oid); return ret; @@ -3762,6 +3771,11 @@ int apply_autostash(const char *path) return apply_save_autostash(path, 1); } +int apply_autostash_oid(const char *stash_oid) +{ + return apply_save_autostash_oid(stash_oid, 1); +} + static const char *reflog_message(struct replay_opts *opts, const char *sub_action, const char *fmt, ...) { diff --git a/sequencer.h b/sequencer.h index 2d09c1ac0b..a90b768b74 100644 --- a/sequencer.h +++ b/sequencer.h @@ -195,6 +195,7 @@ void create_autostash(struct repository *r, const char *path, const char *default_reflog_action); int save_autostash(const char *path); int apply_autostash(const char *path); +int apply_autostash_oid(const char *stash_oid); #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) From patchwork Sat Apr 4 01:11:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473967 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 5FAD6912 for ; Sat, 4 Apr 2020 01:12:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 298272074B for ; Sat, 4 Apr 2020 01:12:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SxCTVSFJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726841AbgDDBMY (ORCPT ); Fri, 3 Apr 2020 21:12:24 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:33995 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726765AbgDDBMX (ORCPT ); Fri, 3 Apr 2020 21:12:23 -0400 Received: by mail-qt1-f195.google.com with SMTP id 14so7904715qtp.1 for ; Fri, 03 Apr 2020 18:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h40MC6mBNbcIpzQQD5uwq6s+5+65M7z4l7rJIduVMbo=; b=SxCTVSFJAEa9eHSpPLrn/BYPrS3D5GbLigxaF74igX3UJ3jZrLcGz5XTf3nohg2I20 z57y2WzPm3b+ktmrVf+NezT5+K5ej4taaENPSyewgPuH54FwBZuBPtIBgBqedBSMtYm0 b2QR2TZoN5ZCrZ5wwhJ5ytHL3ibCnadRmLCE5LUqcTmBeO3ZGj+nunMfI2sunBYgWJWa kyILmsshRz+RAs3tkKkIOq0DvHLM+FGnNgdShoLXXnuMrJRyVpOilW7/lrkGj3j/w3kd 5eGbBCoezeLb0/9gWK2gO8O3vLK1dQ/khOdhevnAeGqLMLFwerVGhRiJDtYf4zU5A2KU 9P5g== 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=h40MC6mBNbcIpzQQD5uwq6s+5+65M7z4l7rJIduVMbo=; b=uMtMGe8vFgPBgJ++m4Tzbyz1WY4iHtR3TTW51B1/HDtkT/IM5FEmLyahKsBeEUquv2 XIkI8sOIYmzPNzcJs1Rj2koNB4kMY7X+MdMnzL3Ov3BT5EQvpAOxDr9rCpGxLQb8zNuw ANTaydDYLEQ7HUWH3jqQ+XUSDHc9ea5OHk/T4diHD+JWZHO/f0CXCfwNZF3Ic2sBk2HJ O+7RcpQ6pLivuvF2HBA9o1ske0jroBwnW9e9EaCaSg+7glYpZKXRAVJPJ8m23S4GLMdz 56EtZ14G6/RK3A+GdHwoxKPAV9+L6MG1s9gzNTz+5mTrVyeff8YHayHODYV8TetiHQbH aG+Q== X-Gm-Message-State: AGi0Pub+4e+7GQsvpwRl+YQ5XkXhD9v5tle9MUJeoi1cL99eUDuGaWbQ gES9q+8vKgW5wNBR9O13JoNeygbI X-Google-Smtp-Source: APiQypKwhUnYcKbZzEUkYDZR7aYC2w7R7JalXs/ZhDjybSVrlurMJJvsjbzy6S7NSrV9Oxmz1DxzbA== X-Received: by 2002:ac8:fe9:: with SMTP id f38mr11237491qtk.130.1585962741377; Fri, 03 Apr 2020 18:12:21 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:20 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 21/23] merge: teach --autostash option Date: Fri, 3 Apr 2020 21:11:34 -0400 Message-Id: <7adf7941921065fa1a5e68524e2dd3cd28f9a12b.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In rebase, one can pass the `--autostash` option to cause the worktree to be automatically stashed before continuing with the rebase. This option is missing in merge, however. Implement the `--autostash` option and corresponding `merge.autoStash` option in merge which stashes before merging and then pops after. This option is useful when a developer has some local changes on a topic branch but they realize that their work depends on another branch. Previously, they had to run something like git fetch ... git stash push git merge FETCH_HEAD git stash pop but now, that is reduced to git fetch ... git merge --autostash FETCH_HEAD When an autostash is generated, it is automatically reapplied to the worktree only in three explicit situations: 1. An incomplete merge is commit using `git commit`. 2. A merge completes successfully. 3. A merge is aborted using `git merge --abort`. In all other situations where the merge state is removed using remove_merge_branch_state() such as aborting a merge via `git reset --hard`, the autostash is saved into the stash reflog instead keeping the worktree clean. Suggested-by: Alban Gruin Signed-off-by: Denton Liu --- Documentation/config/merge.txt | 10 +++ Documentation/git-merge.txt | 6 +- Documentation/merge-options.txt | 8 +++ branch.c | 1 + builtin/commit.c | 2 + builtin/merge.c | 27 ++++++++ builtin/rebase.c | 3 +- builtin/reset.c | 4 +- parse-options.h | 1 + path.c | 1 + path.h | 4 +- t/t3033-merge-toplevel.sh | 22 ++++++ t/t7600-merge.sh | 118 ++++++++++++++++++++++++++++++++ 13 files changed, 201 insertions(+), 6 deletions(-) diff --git a/Documentation/config/merge.txt b/Documentation/config/merge.txt index 6a313937f8..cb2ed58907 100644 --- a/Documentation/config/merge.txt +++ b/Documentation/config/merge.txt @@ -70,6 +70,16 @@ merge.stat:: Whether to print the diffstat between ORIG_HEAD and the merge result at the end of the merge. True by default. +merge.autoStash:: + When set to true, automatically create a temporary stash entry + before the operation begins, and apply it after the operation + ends. This means that you can run merge on a dirty worktree. + However, use with care: the final stash application after a + successful merge might result in non-trivial conflicts. + This option can be overridden by the `--no-autostash` and + `--autostash` options of linkgit:git-merge[1]. + Defaults to false. + merge.tool:: Controls which merge tool is used by linkgit:git-mergetool[1]. The list below shows the valid built-in values. diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 092529c619..9cb14f0059 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -94,7 +94,8 @@ will be appended to the specified message. --abort:: Abort the current conflict resolution process, and - try to reconstruct the pre-merge state. + try to reconstruct the pre-merge state. If an autostash entry is + present, apply it back to the worktree. + If there were uncommitted worktree changes present when the merge started, 'git merge --abort' will in some cases be unable to @@ -102,7 +103,8 @@ reconstruct these changes. It is therefore recommended to always commit or stash your changes before running 'git merge'. + 'git merge --abort' is equivalent to 'git reset --merge' when -`MERGE_HEAD` is present. +`MERGE_HEAD` is present unless `MERGE_AUTOSTASH` is also present where +the stash entry is applied to the worktree. --quit:: Forget about the current merge in progress. Leave the index diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 40dc4f5e8c..3985e6d4a9 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -155,6 +155,14 @@ ifndef::git-pull[] Note that not all merge strategies may support progress reporting. +--autostash:: +--no-autostash:: + Automatically create a temporary stash entry before the operation + begins, and apply it after the operation ends. This means + that you can run the operation on a dirty worktree. However, use + with care: the final stash application after a successful + merge might result in non-trivial conflicts. + endif::git-pull[] --allow-unrelated-histories:: diff --git a/branch.c b/branch.c index 579494738a..2d9e7675a6 100644 --- a/branch.c +++ b/branch.c @@ -344,6 +344,7 @@ void remove_merge_branch_state(struct repository *r) unlink(git_path_merge_rr(r)); unlink(git_path_merge_msg(r)); unlink(git_path_merge_mode(r)); + save_autostash(git_path_merge_autostash(r)); } void remove_branch_state(struct repository *r, int verbose) diff --git a/builtin/commit.c b/builtin/commit.c index 7ba33a3bec..c1b25d2954 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1713,6 +1713,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) &oid, flags); } + apply_autostash(git_path_merge_autostash(the_repository)); + UNLEAK(err); UNLEAK(sb); return 0; diff --git a/builtin/merge.c b/builtin/merge.c index d127d2225f..f2f8069f85 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -82,6 +82,7 @@ static int show_progress = -1; static int default_to_upstream = 1; static int signoff; static const char *sign_commit; +static int autostash; static int no_verify; static struct strategy all_strategy[] = { @@ -286,6 +287,7 @@ static struct option builtin_merge_options[] = { OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1), { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"), N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, + OPT_AUTOSTASH(&autostash), OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")), OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")), OPT_BOOL(0, "no-verify", &no_verify, N_("bypass pre-merge-commit and commit-msg hooks")), @@ -475,6 +477,7 @@ static void finish(struct commit *head_commit, /* Run a post-merge hook */ run_hook_le(NULL, "post-merge", squash ? "1" : "0", NULL); + apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); } @@ -634,6 +637,9 @@ static int git_merge_config(const char *k, const char *v, void *cb) return 0; } else if (!strcmp(k, "gpg.mintrustlevel")) { check_trust_level = 0; + } else if (!strcmp(k, "merge.autostash")) { + autostash = git_config_bool(k, v); + return 0; } status = fmt_merge_msg_config(k, v, cb); @@ -1281,6 +1287,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (abort_current_merge) { int nargc = 2; const char *nargv[] = {"reset", "--merge", NULL}; + struct strbuf stash_oid = STRBUF_INIT; if (orig_argc != 2) usage_msg_opt(_("--abort expects no arguments"), @@ -1289,8 +1296,19 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (!file_exists(git_path_merge_head(the_repository))) die(_("There is no merge to abort (MERGE_HEAD missing).")); + if (read_oneliner(&stash_oid, git_path_merge_autostash(the_repository), + READ_ONELINER_SKIP_IF_EMPTY)) { + strbuf_trim(&stash_oid); + unlink(git_path_merge_autostash(the_repository)); + } + /* Invoke 'git reset --merge' */ ret = cmd_reset(nargc, nargv, prefix); + + if (stash_oid.len) + apply_autostash_oid(stash_oid.buf); + + strbuf_release(&stash_oid); goto done; } @@ -1513,6 +1531,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } + if (autostash) + create_autostash(the_repository, + git_path_merge_autostash(the_repository), + "merge"); if (checkout_fast_forward(the_repository, &head_commit->object.oid, &commit->object.oid, @@ -1579,6 +1601,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (fast_forward == FF_ONLY) die(_("Not possible to fast-forward, aborting.")); + if (autostash) + create_autostash(the_repository, + git_path_merge_autostash(the_repository), + "merge"); + /* We are going to make a new commit. */ git_committer_info(IDENT_STRICT); diff --git a/builtin/rebase.c b/builtin/rebase.c index b800c8bfca..e681ff58de 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1371,8 +1371,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) { OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"), N_("GPG-sign commits"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, - OPT_BOOL(0, "autostash", &options.autostash, - N_("automatically stash/stash pop before and after")), + OPT_AUTOSTASH(&options.autostash), OPT_STRING_LIST('x', "exec", &exec, N_("exec"), N_("add exec lines after each commit of the " "editable list")), diff --git a/builtin/reset.c b/builtin/reset.c index 18228c312e..0d155101f4 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -25,6 +25,7 @@ #include "cache-tree.h" #include "submodule.h" #include "submodule-config.h" +#include "sequencer.h" #define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000) @@ -437,8 +438,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (reset_type == HARD && !update_ref_status && !quiet) print_new_head_line(lookup_commit_reference(the_repository, &oid)); } - if (!pathspec.nr) + if (!pathspec.nr) { remove_branch_state(the_repository, 0); + } return update_ref_status; } diff --git a/parse-options.h b/parse-options.h index fece5ba628..46af942093 100644 --- a/parse-options.h +++ b/parse-options.h @@ -336,5 +336,6 @@ int parse_opt_passthru_argv(const struct option *, const char *, int); #define OPT_CLEANUP(v) OPT_STRING(0, "cleanup", v, N_("mode"), N_("how to strip spaces and #comments from message")) #define OPT_PATHSPEC_FROM_FILE(v) OPT_FILENAME(0, "pathspec-from-file", v, N_("read pathspec from file")) #define OPT_PATHSPEC_FILE_NUL(v) OPT_BOOL(0, "pathspec-file-nul", v, N_("with --pathspec-from-file, pathspec elements are separated with NUL character")) +#define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after")) #endif diff --git a/path.c b/path.c index 88cf593007..d764738146 100644 --- a/path.c +++ b/path.c @@ -1535,5 +1535,6 @@ REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG") REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR") REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE") REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD") +REPO_GIT_PATH_FUNC(merge_autostash, "MERGE_AUTOSTASH") REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD") REPO_GIT_PATH_FUNC(shallow, "shallow") diff --git a/path.h b/path.h index 14d6dcad16..1f1bf8f87a 100644 --- a/path.h +++ b/path.h @@ -177,11 +177,12 @@ struct path_cache { const char *merge_rr; const char *merge_mode; const char *merge_head; + const char *merge_autostash; const char *fetch_head; const char *shallow; }; -#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } +#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } const char *git_path_cherry_pick_head(struct repository *r); const char *git_path_revert_head(struct repository *r); @@ -190,6 +191,7 @@ const char *git_path_merge_msg(struct repository *r); const char *git_path_merge_rr(struct repository *r); const char *git_path_merge_mode(struct repository *r); const char *git_path_merge_head(struct repository *r); +const char *git_path_merge_autostash(struct repository *r); const char *git_path_fetch_head(struct repository *r); const char *git_path_shallow(struct repository *r); diff --git a/t/t3033-merge-toplevel.sh b/t/t3033-merge-toplevel.sh index d314599428..e29c284b9b 100755 --- a/t/t3033-merge-toplevel.sh +++ b/t/t3033-merge-toplevel.sh @@ -142,6 +142,17 @@ test_expect_success 'refuse two-project merge by default' ' test_must_fail git merge five ' +test_expect_success 'refuse two-project merge by default, quit before --autostash happens' ' + t3033_reset && + git reset --hard four && + echo change >>one.t && + git diff >expect && + test_must_fail git merge --autostash five 2>err && + test_i18ngrep ! "stash" err && + git diff >actual && + test_cmp expect actual +' + test_expect_success 'two-project merge with --allow-unrelated-histories' ' t3033_reset && git reset --hard four && @@ -149,4 +160,15 @@ test_expect_success 'two-project merge with --allow-unrelated-histories' ' git diff --exit-code five ' +test_expect_success 'two-project merge with --allow-unrelated-histories with --autostash' ' + t3033_reset && + git reset --hard four && + echo change >>one.t && + git diff one.t >expect && + git merge --allow-unrelated-histories --autostash five 2>err && + test_i18ngrep "Applied autostash." err && + git diff one.t >actual && + test_cmp expect actual +' + test_done diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 4fa0ef8e3b..d809310df1 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,120 @@ test_expect_success 'refresh the index before merging' ' git merge c3 ' +test_expect_success 'merge with --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git merge --autostash c2 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'merge with merge.autoStash' ' + test_config merge.autoStash true && + git reset --hard c1 && + git merge-file file file.orig file.9 && + git merge c2 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'fast-forward merge with --autostash' ' + git reset --hard c0 && + git merge-file file file.orig file.5 && + git merge --autostash c1 2>err && + test_i18ngrep "Applied autostash." err && + test_cmp result.1-5 file +' + +test_expect_success 'octopus merge with --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.3 && + git merge --autostash c2 c3 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5-9 merge-result && + test_cmp result.1-3-5-9 file +' + +test_expect_success 'conflicted merge with --autostash, --abort restores stash' ' + git reset --hard c3 && + cp file.1 file && + test_must_fail git merge --autostash c7 && + git merge --abort 2>err && + test_i18ngrep "Applied autostash." err && + test_cmp file.1 file +' + +test_expect_success 'completed merge (git commit) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git commit 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'completed merge (git merge --continue) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git merge --continue 2>err && + test_i18ngrep "Applied autostash." err && + git show HEAD:file >merge-result && + test_cmp result.1-5 merge-result && + test_cmp result.1-5-9 file +' + +test_expect_success 'aborted merge (merge --abort) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git merge --abort 2>err && + test_i18ngrep "Applied autostash." err && + git diff >actual && + test_cmp expect actual +' + +test_expect_success 'aborted merge (reset --hard) with --no-commit and --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.9 && + git diff >expect && + git merge --no-commit --autostash c2 && + git stash show -p MERGE_AUTOSTASH >actual && + test_cmp expect actual && + git reset --hard 2>err && + test_i18ngrep "Autostash exists; creating a new stash entry." err && + git diff --exit-code +' + +test_expect_success 'merge with conflicted --autostash changes' ' + git reset --hard c1 && + git merge-file file file.orig file.9y && + git diff >expect && + test_when_finished "test_might_fail git stash drop" && + git merge --autostash c3 2>err && + test_i18ngrep "Applying autostash resulted in conflicts." err && + git show HEAD:file >merge-result && + test_cmp result.1-9 merge-result && + git stash show -p >actual && + test_cmp expect actual +' + cat >expected.branch <<\EOF Merge branch 'c5-branch' (early part) EOF From patchwork Sat Apr 4 01:11:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473961 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 3991E912 for ; Sat, 4 Apr 2020 01:12:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 173DA20731 for ; Sat, 4 Apr 2020 01:12:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q1M05W5+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726887AbgDDBMZ (ORCPT ); Fri, 3 Apr 2020 21:12:25 -0400 Received: from mail-qv1-f65.google.com ([209.85.219.65]:46338 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbgDDBMX (ORCPT ); Fri, 3 Apr 2020 21:12:23 -0400 Received: by mail-qv1-f65.google.com with SMTP id bu9so4574740qvb.13 for ; Fri, 03 Apr 2020 18:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y3JpD1BmGlEgxfNhigHedIBI5YZ1431gBF8qqQU816M=; b=q1M05W5+ZPyxwEs2CAwUMdYonBSe83Th+gflSB846XvdgelJPz7m0X2DOQDK8JC7LY gjPFU3qu6JTLPpNnUC/MTJzekOTHMAVXwUg8LtA8xcvCtz/JmpqG2l+xZdV/kAahz93a jKrDtecdGOQZkxMXC/hMKP7eiJ3vOpDyIgSvThDsLLa/NXzz4gXw0c3ss3aUdhDnntZ2 RJAtE+bQ/A/MnhzwnQeEc7DSPnE/777Xv9qNmtzh4/TKQ3Syj0h3ZjTZRLPDMFWiv8gk WVpRip4szhZA2LFoe9IG95kZGkyRwwzDjoBYs5e+Kca3kkE1P4lXKjbnnuIG7djrXh1W CAgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y3JpD1BmGlEgxfNhigHedIBI5YZ1431gBF8qqQU816M=; b=kX00MfFCCy/9poWcuAi1Eqmf7jTIjpsJtlW4NtsMkRqnmw/4Mn2TslDr3dsX5W7CNr M1chtTRYX9YF5+E1teKfPUiyJ0CdgsDtJiANmrXjqeXsjUr/xnJGUTjtxtuZCNPlq4Bk 75M+DBUI2zUqd5m6GLERl6dcKUCCB/utHSx+hzH/+dEVA4SXwaoLgpRPPbsRFhJtCq/8 TZJGfKlNru7z0F0+3arV4Iz/pGSKHqIU9lLuEBB+PJUPasp1JdGYCtyAGZVOWw/3e9uI OmlW7gZYmC1LWaW/kRU5gx2u1r8JI+eEKWQxKG2hIz7LRGi/2XqVpx/m0YThnRBFB6OC QqgA== X-Gm-Message-State: AGi0Pual+uyF94ODoBlRqjSUW85fAyA3Z9sCwzJ+NRyA8NOpUSBqZWnd zFLr2JAWtxGgLi5gdv+OiKNkPJ5f X-Google-Smtp-Source: APiQypILVaMO44g35dnaREs/IBwZTdQtuVlqYmrm+r4UuOWBEQE0CIvX/IWvPIk0UK7E5EVDF/DPnA== X-Received: by 2002:a05:6214:1e5:: with SMTP id c5mr11172489qvu.233.1585962742200; Fri, 03 Apr 2020 18:12:22 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:21 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 22/23] t5520: make test_pull_autostash() accept expect_parent_num Date: Fri, 3 Apr 2020 21:11:35 -0400 Message-Id: X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Before, test_pull_autostash() was hardcoded to run `test_cmp_rev HEAD^ copy` to test that a rebase happened. However, in a future patch, we plan on testing merging as well. Make test_pull_autostash() accept a parent number as an argument so that, in the future, we can test if a merge happened in addition to a rebase. Signed-off-by: Denton Liu --- t/t5520-pull.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 2f86fca042..f610dc14de 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -10,11 +10,13 @@ modify () { } test_pull_autostash () { + expect_parent_num="$1" && + shift && git reset --hard before-rebase && echo dirty >new_file && git add new_file && git pull "$@" . copy && - test_cmp_rev HEAD^ copy && + test_cmp_rev HEAD^"$expect_parent_num" copy && echo dirty >expect && test_cmp expect new_file && echo "modified again" >expect && @@ -369,22 +371,22 @@ test_expect_success '--rebase fails with multiple branches' ' test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' ' test_config rebase.autostash true && - test_pull_autostash --rebase + test_pull_autostash 1 --rebase ' test_expect_success 'pull --rebase --autostash & rebase.autostash=true' ' test_config rebase.autostash true && - test_pull_autostash --rebase --autostash + test_pull_autostash 1 --rebase --autostash ' test_expect_success 'pull --rebase --autostash & rebase.autostash=false' ' test_config rebase.autostash false && - test_pull_autostash --rebase --autostash + test_pull_autostash 1 --rebase --autostash ' test_expect_success 'pull --rebase --autostash & rebase.autostash unset' ' test_unconfig rebase.autostash && - test_pull_autostash --rebase --autostash + test_pull_autostash 1 --rebase --autostash ' test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' ' @@ -422,7 +424,7 @@ test_expect_success 'pull.rebase' ' test_expect_success 'pull --autostash & pull.rebase=true' ' test_config pull.rebase true && - test_pull_autostash --autostash + test_pull_autostash 1 --autostash ' test_expect_success 'pull --no-autostash & pull.rebase=true' ' From patchwork Sat Apr 4 01:11:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11473965 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 D6E6492A for ; Sat, 4 Apr 2020 01:12:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ABF8020787 for ; Sat, 4 Apr 2020 01:12:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gbnNV0n7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbgDDBM1 (ORCPT ); Fri, 3 Apr 2020 21:12:27 -0400 Received: from mail-qv1-f67.google.com ([209.85.219.67]:40234 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726788AbgDDBMY (ORCPT ); Fri, 3 Apr 2020 21:12:24 -0400 Received: by mail-qv1-f67.google.com with SMTP id bp12so4595805qvb.7 for ; Fri, 03 Apr 2020 18:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SfqKQCJxrbAI7q9qgz7feSm3n/yolzfRqw44OcRExYc=; b=gbnNV0n7q01HKhDIXfN+TiqAjCaMgvg0w1XkBEdJYpLhV6i1fa6JR3aE3Vt1RpNgk9 CF8NPT3HFraBfbjgVR0oGYmj3FGz0a1bxevpxtPXaVFGcHjY9PfLOCuoof0lOCOiWbsc agiK/BvytVV4P6gC7+1rYaCO63KCDUdK+V80a5ZkZQyRe8hk0yBI/OxQfuImfczwBLWn 5d9KgOCziraIqCCvIrvGVPW8rY+lA7TX7j52fmsimKEcC5A1HSWKyK5mgLoTsl3uHs1H QoLOd9doXoKjrW5C2p5RO4ZIJ838QKcKOAV7i9lCwnZwW4goeGuAzguvE2IaREwPtU6m nhiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SfqKQCJxrbAI7q9qgz7feSm3n/yolzfRqw44OcRExYc=; b=X3ADd2QnBR6fiKvR+eHuAtI6z43QDOuoAj3pircyXEifvgFcpHZc70IUh43m2GxRJ3 gQ8lXxYEEuEST063XNsPEAYeGYkg0YT8c+cfeLk5uc/HZKBGXOQ7B/Istm9XOAGL3MPx +xasi0W6kqFselbUjujy8kTB25W1nl66myWc0irmP1mAP6HetuMgZwpOX5mqmTFvRS8U d6cFxDJYSRtjspcds3chCHkHePDZKh3+VNThQZ5T1Yc5YKYn4m0AqmyldJT7jp19VaGT Q5mhFFBSvpZFkm4J6qWyTG1Bp6Bc+KkhSPOtR8AnWMiSezcFjwNx5CIBELL9MrJL4TPD 1l4Q== X-Gm-Message-State: AGi0PuYXWkcC9hnBX24ZdugXjtCjQp4w7nCxMWeF6K0C+lBfUEDVp2MO MF+IHmSshkAfmv87uUiH7UgvrzeB X-Google-Smtp-Source: APiQypJkPv8vNIwPHycAv3mkF2KHPu1f85oVyOBRWEEE1F4vWZmaR/LpxktrybRA0R/5y9KhEGBK+g== X-Received: by 2002:ad4:5610:: with SMTP id ca16mr11321999qvb.104.1585962743478; Fri, 03 Apr 2020 18:12:23 -0700 (PDT) Received: from localhost.localdomain (ktnron0919w-grc-01-76-68-143-128.dsl.bell.ca. [76.68.143.128]) by smtp.gmail.com with ESMTPSA id a136sm3297503qkc.75.2020.04.03.18.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 18:12:22 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v4 23/23] pull: pass --autostash to merge Date: Fri, 3 Apr 2020 21:11:36 -0400 Message-Id: <177c7e537b1d853f34719882702e1f39d06e5a16.1585962673.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Before, `--autostash` only worked with `git pull --rebase`. However, in the last patch, merge learned `--autostash` as well so there's no reason why we should have this restriction anymore. Teach pull to pass `--autostash` to merge, just like it did for rebase. Signed-off-by: Denton Liu --- Documentation/git-pull.txt | 9 ------- Documentation/merge-options.txt | 4 +-- builtin/pull.c | 9 ++++--- t/t5520-pull.sh | 43 +++++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index dfb901f8b8..ba3772de9f 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -133,15 +133,6 @@ unless you have read linkgit:git-rebase[1] carefully. --no-rebase:: Override earlier --rebase. ---autostash:: ---no-autostash:: - Before starting rebase, stash local modifications away (see - linkgit:git-stash[1]) if needed, and apply the stash entry when - done. `--no-autostash` is useful to override the `rebase.autoStash` - configuration variable (see linkgit:git-config[1]). -+ -This option is only valid when "--rebase" is used. - Options related to fetching ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 3985e6d4a9..48bfcda084 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -155,6 +155,8 @@ ifndef::git-pull[] Note that not all merge strategies may support progress reporting. +endif::git-pull[] + --autostash:: --no-autostash:: Automatically create a temporary stash entry before the operation @@ -163,8 +165,6 @@ ifndef::git-pull[] with care: the final stash application after a successful merge might result in non-trivial conflicts. -endif::git-pull[] - --allow-unrelated-histories:: By default, `git merge` command refuses to merge histories that do not share a common ancestor. This option can be diff --git a/builtin/pull.c b/builtin/pull.c index 3e624d1e00..9beb4841d1 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -163,7 +163,7 @@ static struct option pull_options[] = { N_("verify that the named commit has a valid GPG signature"), PARSE_OPT_NOARG), OPT_BOOL(0, "autostash", &opt_autostash, - N_("automatically stash/stash pop before and after rebase")), + N_("automatically stash/stash pop before and after")), OPT_PASSTHRU_ARGV('s', "strategy", &opt_strategies, N_("strategy"), N_("merge strategy to use"), 0), @@ -661,6 +661,10 @@ static int run_merge(void) argv_array_pushv(&args, opt_strategy_opts.argv); if (opt_gpg_sign) argv_array_push(&args, opt_gpg_sign); + if (opt_autostash == 0) + argv_array_push(&args, "--no-autostash"); + else if (opt_autostash == 1) + argv_array_push(&args, "--autostash"); if (opt_allow_unrelated_histories > 0) argv_array_push(&args, "--allow-unrelated-histories"); @@ -908,9 +912,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (get_oid("HEAD", &orig_head)) oidclr(&orig_head); - if (!opt_rebase && opt_autostash != -1) - die(_("--[no-]autostash option is only valid with --rebase.")); - autostash = config_autostash; if (opt_rebase) { if (opt_autostash != -1) diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index f610dc14de..37535d63a9 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -28,7 +28,7 @@ test_pull_autostash_fail () { echo dirty >new_file && git add new_file && test_must_fail git pull "$@" . copy 2>err && - test_i18ngrep "uncommitted changes." err + test_i18ngrep "\(uncommitted changes.\)\|\(overwritten by merge:\)" err } test_expect_success setup ' @@ -404,13 +404,40 @@ test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' ' test_pull_autostash_fail --rebase --no-autostash ' -for i in --autostash --no-autostash -do - test_expect_success "pull $i (without --rebase) is illegal" ' - test_must_fail git pull $i . copy 2>err && - test_i18ngrep "only valid with --rebase" err - ' -done +test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' ' + test_config merge.autostash true && + test_pull_autostash 2 +' + +test_expect_success 'pull --autostash & merge.autostash=true' ' + test_config merge.autostash true && + test_pull_autostash 2 --autostash +' + +test_expect_success 'pull --autostash & merge.autostash=false' ' + test_config merge.autostash false && + test_pull_autostash 2 --autostash +' + +test_expect_success 'pull --autostash & merge.autostash unset' ' + test_unconfig merge.autostash && + test_pull_autostash 2 --autostash +' + +test_expect_success 'pull --no-autostash & merge.autostash=true' ' + test_config merge.autostash true && + test_pull_autostash_fail --no-autostash +' + +test_expect_success 'pull --no-autostash & merge.autostash=false' ' + test_config merge.autostash false && + test_pull_autostash_fail --no-autostash +' + +test_expect_success 'pull --no-autostash & merge.autostash unset' ' + test_unconfig merge.autostash && + test_pull_autostash_fail --no-autostash +' test_expect_success 'pull.rebase' ' git reset --hard before-rebase &&