From patchwork Mon Dec 9 14:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11279433 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 D525A930 for ; Mon, 9 Dec 2019 14:16:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4A0F207FD for ; Mon, 9 Dec 2019 14:16:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q/sivd8q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727918AbfLIOQ4 (ORCPT ); Mon, 9 Dec 2019 09:16:56 -0500 Received: from mail-wr1-f52.google.com ([209.85.221.52]:40227 "EHLO mail-wr1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727684AbfLIOQx (ORCPT ); Mon, 9 Dec 2019 09:16:53 -0500 Received: by mail-wr1-f52.google.com with SMTP id c14so16371893wrn.7 for ; Mon, 09 Dec 2019 06:16:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=I8b8jus+gL9qTMtX2MUVL0s1hihf58yRSrMe9WY6y50=; b=q/sivd8qjHP/ZVNGyZvN721VIEhifgmpu4p7hjzp8tCoy9equppCyOGPEu+gLXkjco 8+XNaR/kQnbLFCtPd+CDtq7YPgTIE/G51iT9L27RSv7PJ5QEgb4thS1AmxA8s8dGiv14 K/saBDh+sJKQF+CyXqNrBPk3ZpUzkCoBgjzHqSB8D/KqyFIEQ+X8PZ7ueYRO7O6ivR0b NCfZoSAIdQmuHV6ReQixUL5arLO/XUEys5G/cH1CYSGWrSpSHfY7xMn7NxkiaOofLNBy LrNVXcBAY8wAtEZM3/8YepcmvNF2kLFboej6AtIN/YkVq/safyK8CFtaAFTsMIOC5ybh wt8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=I8b8jus+gL9qTMtX2MUVL0s1hihf58yRSrMe9WY6y50=; b=YmDGY/5tVPluBCF5WPjNUtbOPeAbLXTTMJaGc/OaBRt2Gmwx3j4mq///vPGznygt/z 2eltQyQ9UsmjhGYI9jHxYSHJ5uw+PwNsKGWpMT4Rgbgoy0P0Qjw+M9mPc2m5zHeVqMd/ MRpbMtLqdvD7AHoOZGyJq4XBVKbdeukuTyWVk8/HwpEZ8my8BDTirQWbJK7aSIzkPsJ5 Nhh+GHDy4J0rHPtjwY8qlMAANAA/c2+0cbeyKzpdzujlHiCV0KuaFYqFqLzNl6nArgxA g+P1v9bTWcx37aqpwOVMcJC7LdjBZTqs/+m71iLT9+gBJAiOy1PkB2IfcqGRsRyKvOC4 LImg== X-Gm-Message-State: APjAAAULH9bB75pDsO1tJUzqKUm6GOZ2QEAeGbLYxTbypVGBMeEMLtpr SLtusYarRCJ6kN8I574TQJKYr9UR X-Google-Smtp-Source: APXvYqzjEgmDQsJNb7g3ZoQviAugZugx+QPOjzk950fiOsNp7lvJu4/IbasWI1BxHLzMznCFLwkn5w== X-Received: by 2002:a5d:4392:: with SMTP id i18mr2495595wrq.199.1575901011648; Mon, 09 Dec 2019 06:16:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z13sm14129536wmi.18.2019.12.09.06.16.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Dec 2019 06:16:51 -0800 (PST) Message-Id: In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Mon, 09 Dec 2019 14:16:47 +0000 Subject: [PATCH 1/3] git-p4: [usability] yes/no prompts should sanitize user text Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Junio C Hamano , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene When prompting the user interactively for direction, the tests are not forgiving of user input format. For example, the first query asks for a yes/no response. If the user enters the full word "yes" or "no" or enters a capital "Y" the test will fail. Create a new function, prompt(prompt_text, choices) where * promt_text is the text prompt for the user * is a list of lower-case, single letter choices. This new function must prompt the user for input and sanitize it by converting the response to a lower case string, trimming leading and trailing spaces, and checking if the first character is in the list of choices. If it is, return the first letter. Change the current references to raw_input() to use this new function. Signed-off-by: Ben Keene --- git-p4.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/git-p4.py b/git-p4.py index 60c73b6a37..0fa562fac9 100755 --- a/git-p4.py +++ b/git-p4.py @@ -167,6 +167,17 @@ def die(msg): sys.stderr.write(msg + "\n") sys.exit(1) +def prompt(prompt_text, choices = []): + """ Prompt the user to choose one of the choices + """ + while True: + response = raw_input(prompt_text).strip().lower() + if len(response) == 0: + continue + response = response[0] + if response in choices: + return response + def write_pipe(c, stdin): if verbose: sys.stderr.write('Writing pipe: %s\n' % str(c)) @@ -1779,7 +1790,7 @@ def edit_template(self, template_file): return True while True: - response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ") + response = prompt("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ", ["y", "n"]) if response == 'y': return True if response == 'n': @@ -2350,8 +2361,8 @@ def run(self, args): # prompt for what to do, or use the option/variable if self.conflict_behavior == "ask": print("What do you want to do?") - response = raw_input("[s]kip this commit but apply" - " the rest, or [q]uit? ") + response = prompt("[s]kip this commit but apply" + " the rest, or [q]uit? ", ["s", "q"]) if not response: continue elif self.conflict_behavior == "skip": From patchwork Mon Dec 9 14:16:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11279435 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 38D9C112B for ; Mon, 9 Dec 2019 14:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18FF7207FD for ; Mon, 9 Dec 2019 14:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M2UeWZjQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727872AbfLIOQ4 (ORCPT ); Mon, 9 Dec 2019 09:16:56 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42870 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfLIOQy (ORCPT ); Mon, 9 Dec 2019 09:16:54 -0500 Received: by mail-wr1-f67.google.com with SMTP id a15so16345052wrf.9 for ; Mon, 09 Dec 2019 06:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2OWtz1ywBrk5hySH2j3HtFlNv2/6yPxzpHRoB9xHYA8=; b=M2UeWZjQWqJKM7jj8lFmHmFymrLvMV5tVEL+VoaC23DoIv+6seiFBDLrOtqEt8UyLg WPNhAUlXGDKX6a8QHzG0z+rHmDPMUHjFRqtpqaIDv5/QkRV9qtqc0Zm3I1caCADLcJQL XCPbM+NZuesOvInJ9uBp9Hbl66yp6yxYpewJ6pxPbDGubHUUlbegrUmVRJR7tRbDCUIk K+A+wi69pGTgBQ5G3fMruJ0dimRS+MbzvSFtTT9zi7QML7ZrhWo78a6BHFElm4oX5wfT XfxmpA0+X2yk8K2osV72+KyoZcZ0onzSmyJdJZsNd9ZTUioF9DjCoZxZbsqEExdG4plw Np2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2OWtz1ywBrk5hySH2j3HtFlNv2/6yPxzpHRoB9xHYA8=; b=YPAqFt+yEcUHp1IY4LRfaVtMP0AWaW7C23NgieFLXGPukVZ9u54pA5ltj6GR5mozSU nWHrpx0+eXJkYPGWqgWUJVC6/mrySyFADErDttbDDkQVZ+cJj1mNO/2fKZS7Ik2Ymotn 7sSXBh7lTs/CecksiiJ6xq/jI8cTXmPMyPKhYC2iCJpB4vC5ml/szKu5P7S7snED2VKT RgaJVLib2aA87jIOwLEQUoWUTGtBc6/ktRKLeRgHVwuRabBzD2ogR8BVgainlDK897nh nuA3e0LOHpHp7KZw0IIiRidLudUTlgFbljg8LgLvSwcd0myeeDQj2vwROOlFaLH4AGe+ 3riA== X-Gm-Message-State: APjAAAV9aSEBrEe/yp76R5IXpjn/5zOIlakZXCi7Eq20K6UMQ8z8D2cv LahKiw3rGfB/I164Omq7MZ62UH0i X-Google-Smtp-Source: APXvYqyG8s1QvyyU83IqnnzjWEjJfWefELEIEtojcfohD7GUa17NJNHSZHZeBdFM0edKiVLGiw6AHA== X-Received: by 2002:a05:6000:11c3:: with SMTP id i3mr2406994wrx.244.1575901012629; Mon, 09 Dec 2019 06:16:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o15sm28954513wra.83.2019.12.09.06.16.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Dec 2019 06:16:52 -0800 (PST) Message-Id: In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Mon, 09 Dec 2019 14:16:48 +0000 Subject: [PATCH 2/3] git-p4: [usability] RCS Keyword failure should suggest help Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Junio C Hamano , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene When applying a commit fails because of RCS keywords, Git will fail the P4 submit. It would help the user if Git suggested that the user set git-p4.attemptRCSCleanup to true. Change the applyCommit() method that when applying a commit fails becasue of the P4 RCS Keywords, the user should consider setting git-p4.attemptRCSCleanup to true. Signed-off-by: Ben Keene --- git-p4.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/git-p4.py b/git-p4.py index 0fa562fac9..856fe82079 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1950,8 +1950,23 @@ def applyCommit(self, id): # disable the read-only bit on windows. if self.isWindows and file not in editedFiles: os.chmod(file, stat.S_IWRITE) - self.patchRCSKeywords(file, kwfiles[file]) - fixed_rcs_keywords = True + + try: + self.patchRCSKeywords(file, kwfiles[file]) + fixed_rcs_keywords = True + except: + # We are throwing an exception, undo all open edits + for f in editedFiles: + p4_revert(f) + raise + else: + # They do not have attemptRCSCleanup set, this might be the fail point + # Check to see if the file has RCS keywords and suggest setting the property. + for file in editedFiles | filesToDelete: + if p4_keywords_regexp_for_file(file) != None: + print("At least one file in this commit has RCS Keywords that may be causing problems. ") + print("Consider:\ngit config git-p4.attemptRCSCleanup true") + break if fixed_rcs_keywords: print("Retrying the patch with RCS keywords cleaned up") From patchwork Mon Dec 9 14:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11279437 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 B6D901593 for ; Mon, 9 Dec 2019 14:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9635E207FD for ; Mon, 9 Dec 2019 14:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZPIA0iV5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727837AbfLIOQ4 (ORCPT ); Mon, 9 Dec 2019 09:16:56 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38219 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727788AbfLIOQz (ORCPT ); Mon, 9 Dec 2019 09:16:55 -0500 Received: by mail-wr1-f67.google.com with SMTP id y17so16392011wrh.5 for ; Mon, 09 Dec 2019 06:16:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Z6cfkpy0XYOK6kEsOlgEccbPfpxqqKqR4uKSe3tKNCw=; b=ZPIA0iV5aNKth6DglbKX0S8yDUQFCLu4MtCIQ/9uyENZr2tiLxsmKBlRG94EIuhNFN hn04BTxYLg8hKhmcNlMqhKeUynp/BY4b6gyqHzYSn1uO1MHr6l+3xUVNKN7uAd1HOZTY ksDcm+NifTUHY6UqoV+wROpv9bfhvhS+DzaGixgCIfBoTm2uPITcMxfYgoH0Q7nVp+kW 8vAVlIqwfFhMh1qHpdVXNGgExntzn9A7V8bOl+S2WnsNgBC2zURDCWaDgStH3Ubzbv2v wFDwTy7LPvMcklq4hpCZ3YwZ9YPPmFJue3CVoCxqRUl882QlrtCBAFwUJ0VlkZistejx 4L4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Z6cfkpy0XYOK6kEsOlgEccbPfpxqqKqR4uKSe3tKNCw=; b=Zb7rB5/WSIt/OuIuEj+ydA4ZfNlr58r5N5HRy82g8TioTCO96cHYH2fwgZSuoZbYMy zmpBGmlJDOCKOK6IhBZ1naFjtt6pGzlRIA+1qZ5NdqJD3mD5aLIatLFJnPFQvCavTM3k zoz7v2GxsT3lgnNnxQIyxIJnl1ZFkIogYOLIqyB8xqemTwc6rO+FYVXZHJ2wsKKCI9FR ionR2JHNVAXSk6OnuMy4JfgNUUsYff68K4QaOYIM0tb1x9E85kHx0N3/ILla9bzynZqH Pmhhnz0x3gmN7KYMgc95bMBaQuIu93+ypjyVpVqCFFwU668WSn6b2YZIf+DRgfY18DAP dBYg== X-Gm-Message-State: APjAAAVG/zEfSVx/jLZN2M34IKY+tM9XyytKiIuKksPLyapQ9Owcg06K rEvJoGzJRMOm9YvG2Iz2CsCfRlIO X-Google-Smtp-Source: APXvYqxOhHx+PiPzrTWXTXzsEVuRxhG9xQS9f3pmuxW5sAkqVkUF7AMiL7CYfY3fzLmJe4Aoutf6eg== X-Received: by 2002:a05:6000:1142:: with SMTP id d2mr2259979wrx.253.1575901013319; Mon, 09 Dec 2019 06:16:53 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i81sm9025373wma.10.2019.12.09.06.16.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Dec 2019 06:16:52 -0800 (PST) Message-Id: <2a10890ef76697dbdd67b4c416077726100f88be.1575901009.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Mon, 09 Dec 2019 14:16:49 +0000 Subject: [PATCH 3/3] git-p4: [usability] Show detailed help when parsing options fail Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Junio C Hamano , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene When a user provides invalid parameters to git-p4, the program reports the failure but does not provide the correct command syntax. Add an exception handler to the command-line argument parser to display the command's specific command line parameter syntax when an exception is thrown. Rethrow the exception so the current behavior is retained. Signed-off-by: Ben Keene --- git-p4.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/git-p4.py b/git-p4.py index 856fe82079..cb594baeef 100755 --- a/git-p4.py +++ b/git-p4.py @@ -4166,7 +4166,12 @@ def main(): description = cmd.description, formatter = HelpFormatter()) - (cmd, args) = parser.parse_args(sys.argv[2:], cmd); + try: + (cmd, args) = parser.parse_args(sys.argv[2:], cmd); + except: + parser.print_help() + raise + global verbose verbose = cmd.verbose if cmd.needsGit: