From patchwork Tue Jan 24 11:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13113836 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAE3BC38142 for ; Tue, 24 Jan 2023 11:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233226AbjAXLX0 (ORCPT ); Tue, 24 Jan 2023 06:23:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233817AbjAXLXZ (ORCPT ); Tue, 24 Jan 2023 06:23:25 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D85F65B6 for ; Tue, 24 Jan 2023 03:23:23 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id o17-20020a05600c511100b003db021ef437so10668308wms.4 for ; Tue, 24 Jan 2023 03:23:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=GnCzvczZAyQXJIi0Ueuiqk8/+5AhTp5dyI+rRNCUP9U=; b=QrMXAdm8KF6t/+g/6gReXgwUtL1U6ge6eWLF+kdhC9smwG2ppNyDrpB4huXmvu4BeF ccP2P+c6HKNftGlpzVoRJnWdWw4nCInED31mfnvAZGEQK7Ldk5BqV+cAlOhOhD9i4UEE R2jt1Bmzqa8+aAMcCmyQrq4UiybvC3qYNo5MSfJmI9k6iqe8iSkUvNgYr3BlnORt/EWD yKZDBuS/toeL2iKvadcIirjpvI63ql3ZSfNSRtbHn58dW3/qJQuYIm2kNI/5tbePVfLY +uyN3BDzjvic1N1ks6EXw1VWPXp2jvUdxx3llrt/chw8bhMSX/lpazbOIbYDnrjbRi0n EGbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GnCzvczZAyQXJIi0Ueuiqk8/+5AhTp5dyI+rRNCUP9U=; b=3PIisOikxVTRn+Qps8H/naYnpsYkNbKs9lAsdXcVRJg9u5FbtKAqqz0ipBUBEOX7jE b47iklOCnlRIWG+TZOBDohAl4OtYzONbo6WqNvhWzNxSNFXoxc+TgI5F+nv4bDq678Om sHk8HkRSGgvihu4WFATPHiA22RrVmZVnQ/XYg2WSlZ/7OsztSy9fpFRminzUSxVaWJ6t 4Zve79NZUDWu5u7UJCwWFc7gm2KWCDE3HpBd0u1ur+BkHVo0PKB0Ii9ae2Q6H4C9Bc0m JYPVao7VoupT2gtFLJwBCsdEV3sKiWmUOrtFMASirWBDduzibBuL0jR/qPQd7GRYcpL/ 0kGg== X-Gm-Message-State: AFqh2kqf6K2LsS7MnZVUcgRoum7OANG/Gu/cpD6JNvICx59qivP7sIrS HnGAOt0cG034GvratfoBysS1gqsa5pQ= X-Google-Smtp-Source: AMrXdXt9JAZcrv1+DDysf5NfyrDtsy75CbcT05lHNrqju8skHuRRUFv/Kkqzxaj3D2o4f6knKzWGDw== X-Received: by 2002:a05:600c:4d98:b0:3d3:5c7d:a5f3 with SMTP id v24-20020a05600c4d9800b003d35c7da5f3mr35310151wmp.37.1674559401415; Tue, 24 Jan 2023 03:23:21 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p15-20020a5d4e0f000000b002bdc39849d1sm1660411wrt.44.2023.01.24.03.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 03:23:20 -0800 (PST) Message-Id: <89fe0380cd3a373e7e23d663b506466fd6cb5fb6.1674559397.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Jan 2023 11:23:16 +0000 Subject: [PATCH 1/2] gitk: prevent overly long command lines Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Paul Mackerras , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin To avoid running into command line limitations, some of Git's commands support the `--stdin` option. Let's use exactly this option in the three rev-list/log invocations in gitk that would otherwise possibly run the danger of trying to invoke a too-long command line. While it is easy to redirect either stdin or stdout in Tcl/Tk scripts, what we need here is both. We need to capture the output, yet we also need to pipe in the revs/files arguments via stdin (because stdin does not have any limit, unlike the command line). To help this, we use the neat Tcl feature where you can capture stdout and at the same time feed a fixed string as stdin to the spawned process. One non-obvious aspect about this change is that the `--stdin` option allows to specify revs, the double-dash, and files, but *no* other options such as `--not`. This is addressed by prefixing the "negative" revs with `^` explicitly rather than relying on the `--not` option (thanks for coming up with that idea, Max!). This fixes https://github.com/git-for-windows/git/issues/1987 Analysis-and-initial-patch-by: Max Kirillov Signed-off-by: Johannes Schindelin --- gitk | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/gitk b/gitk index 0ae7d685904..92375ca6a2a 100755 --- a/gitk +++ b/gitk @@ -405,14 +405,16 @@ proc start_rev_list {view} { if {$revs eq {}} { return 0 } - set args [concat $vflags($view) $revs] + set args $vflags($view) } else { + set revs {} set args $vorigargs($view) } if {[catch { set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \ - --parents --boundary $args "--" $files] r] + --parents --boundary $args --stdin \ + "<<[join [concat $revs "--" $files] "\\n"]"] r] } err]} { error_popup "[mc "Error executing git log:"] $err" return 0 @@ -554,13 +556,19 @@ proc updatecommits {} { set revs $newrevs set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]] } - set args [concat $vflags($view) $revs --not $oldpos] + set args $vflags($view) + foreach r $oldpos { + lappend revs "^$r" + } } else { + set revs {} set args $vorigargs($view) } if {[catch { set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \ - --parents --boundary $args "--" $vfilelimit($view)] r] + --parents --boundary $args --stdin \ + "<<[join [concat $revs "--" \ + $vfilelimit($view)] "\\n"]"] r] } err]} { error_popup "[mc "Error executing git log:"] $err" return @@ -10231,10 +10239,16 @@ proc getallcommits {} { foreach id $seeds { lappend ids "^$id" } + lappend ids "--" } } if {$ids ne {}} { - set fd [open [concat $cmd $ids] r] + if {$ids eq "--all"} { + set cmd [concat $cmd "--all"] + } else { + set cmd [concat $cmd --stdin "<<[join $ids "\\n"]"] + } + set fd [open $cmd r] fconfigure $fd -blocking 0 incr allcommits nowbusy allcommits From patchwork Tue Jan 24 11:23:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Rieck X-Patchwork-Id: 13113837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48B02C25B4E for ; Tue, 24 Jan 2023 11:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233924AbjAXLX1 (ORCPT ); Tue, 24 Jan 2023 06:23:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233897AbjAXLXZ (ORCPT ); Tue, 24 Jan 2023 06:23:25 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3264330B29 for ; Tue, 24 Jan 2023 03:23:24 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id fl11-20020a05600c0b8b00b003daf72fc844so12606941wmb.0 for ; Tue, 24 Jan 2023 03:23:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=xgRiLqjfVWE05Ob4hhY8FHeK/8h4bNIU2GMvmGOMisQ=; b=INiFHo8+nORxldOCIg/4XpuM/iTMFpfaD5+bdRFEXmLyUyh2tOalp+4vfP59dD0LEq 80s9Kt7cxU04FIDa83kf+pZq/hIqtXVlOoKijcS5BXhp/6jPxcAJyvjHzfpEsNTlZymi 2sMsWQ3AMawvdKJHi9s/Zss9uCrGiv4Y5eztlhUT5YMDKtLWslbzmcx2qAiPk3/B9Ji7 6yhCeQ5VkWnOkKHZ0jtvruFTRK+XjFWD8oBrDXkQ/5AFsaZV2NLRGkFguGDs3BuC3STw JDS0usbK0O3nDDx4PV899cklzEmP6gAPygwKocpPaH5IUpp1p/5dMZHvvUddKZaFfB5d d/Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xgRiLqjfVWE05Ob4hhY8FHeK/8h4bNIU2GMvmGOMisQ=; b=z/aRETomP5//shZMhCziGluaaprT+4HKcNYFm+uKD8nLBdAQ6aUkimmlqDZaP98c8m BCnARAW1ITgb+fawajVkoVx9QVLo1G7FObwR8GiGukkd26PmeyxuCckZzxZxsoX2mEmf YSx0sM3fr8BNmgcPnVut1Dxk3MLo15c/vfHZ3Q69czS+RyJrHB1QbBzzFe3JmvNATj2P 27apwwNH+he6CYGZzZN5UYUlKTBrlR+XaC0zw6mAkNmxtLV58i1p5UpqziYt8T0XDTdL oazlZik/ITiHdxwPxQezy0j8ynQUQmxckTvWxry48Qdp8cOeempXRtU8lLIPB22nr8D0 M+KQ== X-Gm-Message-State: AFqh2ko1BUfG5GvRbzsaHO9uGAcKHfZWdy8dCjKLMW4iI4nDmD7mKyv8 JfYOmeKHj/gmjVQz/e7MYaFIZD0+8MM= X-Google-Smtp-Source: AMrXdXuLV9h6fcUSzSrpk7cNjJIHewu9wmz3eoxsBK6k3KJwgEF3AmwDIM9wGBSHf4Uj3W3OdwLbmw== X-Received: by 2002:a05:600c:b8a:b0:3d9:f806:2f89 with SMTP id fl10-20020a05600c0b8a00b003d9f8062f89mr27407241wmb.41.1674559402547; Tue, 24 Jan 2023 03:23:22 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bg24-20020a05600c3c9800b003d9ed40a512sm18211936wmb.45.2023.01.24.03.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 03:23:22 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 24 Jan 2023 11:23:17 +0000 Subject: [PATCH 2/2] gitk: escape file paths before piping to git log Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Paul Mackerras , Johannes Schindelin , Nico Rieck Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Nico Rieck From: Nico Rieck We just started piping the file paths via `stdin` instead of passing them via the command-line, to avoid running into command-line limitations. However, since we now pipe the file paths, we need to take care of special characters. This fixes https://github.com/git-for-windows/git/issues/2293 Signed-off-by: Nico Rieck Signed-off-by: Johannes Schindelin --- gitk | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index 92375ca6a2a..df3ba2ea99b 100755 --- a/gitk +++ b/gitk @@ -353,6 +353,16 @@ proc parseviewrevs {view revs} { return $ret } +# Escapes a list of filter paths to be passed to git log via stdin. Note that +# paths must not be quoted. +proc escape_filter_paths {paths} { + set escaped [list] + foreach path $paths { + lappend escaped [string map {\\ \\\\ "\ " "\\\ "} $path] + } + return $escaped +} + # Start off a git log process and arrange to read its output proc start_rev_list {view} { global startmsecs commitidx viewcomplete curview @@ -414,7 +424,8 @@ proc start_rev_list {view} { if {[catch { set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \ --parents --boundary $args --stdin \ - "<<[join [concat $revs "--" $files] "\\n"]"] r] + "<<[join [concat $revs "--" \ + [escape_filter_paths $files]] "\\n"]"] r] } err]} { error_popup "[mc "Error executing git log:"] $err" return 0 @@ -568,7 +579,8 @@ proc updatecommits {} { set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \ --parents --boundary $args --stdin \ "<<[join [concat $revs "--" \ - $vfilelimit($view)] "\\n"]"] r] + [escape_filter_paths \ + $vfilelimit($view)]] "\\n"]"] r] } err]} { error_popup "[mc "Error executing git log:"] $err" return