From patchwork Fri Feb 14 14:44:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11382331 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 0CC1F1800 for ; Fri, 14 Feb 2020 14:44:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E063B22314 for ; Fri, 14 Feb 2020 14:44:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PVnOxs2o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387397AbgBNOov (ORCPT ); Fri, 14 Feb 2020 09:44:51 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33939 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729278AbgBNOou (ORCPT ); Fri, 14 Feb 2020 09:44:50 -0500 Received: by mail-wr1-f66.google.com with SMTP id n10so9244017wrm.1 for ; Fri, 14 Feb 2020 06:44:49 -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=3vHz707grPFrlVodQLLVK0XDj5wFTqWjLd0CoJDuBFc=; b=PVnOxs2oVkZx0jedPGMim9hMb3YGMYaLFMUaBYwkuqiLqPE2LXm3XKhG0h24T5lnEL x74TR4cpXFi18RUvIHl2ib7CpHpRfcfGRTXvPmPkCvr6xj6uHyVDj/XI8PE5hQVhvvQ2 O1kYsXg0qFf4vLve78YV2xSuXxBD0fBBGFPyN/7+dE1asjiblVWWyjbakHkwsXxTgODQ 2/tmiJ9ArdaSjixfZRRc1tJrq1GsOSTq25BEQMsTtNljk2xLQ9Gy+5Em2gU1r/G0a1be qPfW4C9/qOLhnXnHaInyD+mk3Im6f9x/w44K9xFTEKI77ylRlY+I9ykfF0n7Aln4qdCS B7Rw== 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=3vHz707grPFrlVodQLLVK0XDj5wFTqWjLd0CoJDuBFc=; b=oJJMdvbxZTumlvGcXWOZODrcJNfAVpEKOuL3+ug85OI5HY1g51doCOnIl/IERUUS/5 zGXnqobK/w/jXW/n4Fx7GlXz4edYQ7qkSOuQubhEAowqvkXURH9xi91hyu34JqDp6TYp jcv8sbyxvMsX6MEJuJpvSoz4A0+K/C/SNf2UhsLEc058eHfG6OMre1qDi8IR6Fb0pfdr dQJ4VfQKa7fDrgkSbNAny72l1Fe6H+JPX5BdkqD9EahCwYXLtoai9l6kM9ORC6WmkET5 oyL1iyrEeW210sBq+FWUeWDaBcQFzbMIUmy194rQZgJscWVb+WJxhDPwbz+x/5HEc298 g01A== X-Gm-Message-State: APjAAAXi309n+7aJZtn0OtZKV+kxY9RKhTgST+dQ4UuQl2/MqoHeVCsB LU03dDd9kR/qK84/o9zEXUk9o1Mq X-Google-Smtp-Source: APXvYqwLsJRatRYejJ8ubKVqO1ufmjt8i11pYhl1wM4Ziy0dCGUJZbFy8YMep3jQg7L2vZDi1jea7A== X-Received: by 2002:adf:df8f:: with SMTP id z15mr4283500wrl.282.1581691488355; Fri, 14 Feb 2020 06:44:48 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 21sm7779297wmo.8.2020.02.14.06.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 06:44:47 -0800 (PST) Message-Id: <013b27760a0372a2a30e380c29919a5ca12ca135.1581691486.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Fri, 14 Feb 2020 14:44:40 +0000 Subject: [PATCH v6 1/7] git-p4: rewrite prompt to be Windows compatible Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene The existing function prompt(prompt_text) does not work correctly when run on Windows 10 bash terminal when launched from the sourcetree GUI application. The stdout is not flushed properly so the prompt text is not displayed to the user until the next flush of stdout, which is quite confusing. Change this method by: * Adding flush to stderr, stdout, and stdin * Use readline from sys.stdin instead of raw_input. The existing strip().lower() are retained. Signed-off-by: Ben Keene --- git-p4.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-p4.py b/git-p4.py index 40d9e7c594e..65b6d4dca08 100755 --- a/git-p4.py +++ b/git-p4.py @@ -175,7 +175,10 @@ def prompt(prompt_text): """ choices = set(m.group(1) for m in re.finditer(r"\[(.)\]", prompt_text)) while True: - response = raw_input(prompt_text).strip().lower() + sys.stderr.flush() + sys.stdout.write(prompt_text) + sys.stdout.flush() + response=sys.stdin.readline().strip().lower() if not response: continue response = response[0] From patchwork Fri Feb 14 14:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11382333 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 5769A1580 for ; Fri, 14 Feb 2020 14:44:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E9D824649 for ; Fri, 14 Feb 2020 14:44:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LSkpPmT+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387401AbgBNOow (ORCPT ); Fri, 14 Feb 2020 09:44:52 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42613 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729399AbgBNOov (ORCPT ); Fri, 14 Feb 2020 09:44:51 -0500 Received: by mail-wr1-f65.google.com with SMTP id k11so11171648wrd.9 for ; Fri, 14 Feb 2020 06:44:50 -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=uUqGfofknPcEAQ5nvTP1fA2W60P4i7uhCRCHfpO2L5s=; b=LSkpPmT+Abr5kKt4FsQ9Y7KeQHf1P6aeyzuBkuF40HaS3ICkdgYRtCEl/6Vm7MhHBp AGQU3gdESHOJOSASUDdjtvLHOYFC8UA39JfiFYfUGp3rI3wmvn0+QdVAH/46RTXcsyTd 4zTiAlIZdPnoNRTulQjdwf+/t3dATg1tlNmk10GHKSwuCvRCZx94ocI+dOqH5vetniJx k+yJwUmQPeKqgNzZey57u5L5tO6jSbaMTOCdU0Q13jsFAXROTi3PzHWF6YTDQNaU9nCN es90jnpu7ec7+XUM4IFeDoaGMqazIuWvp7IaXHcsfx4yhwYPxxP8kJFFBmAnFxhqYCSu pQNg== 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=uUqGfofknPcEAQ5nvTP1fA2W60P4i7uhCRCHfpO2L5s=; b=Pu9zKvDsBd2kuB3rY+hIRVpCXZUhzxtI90MAveon1+TtHXGhNXJ2zTa2DYb/e2/Ao7 a405M1RfwcLRDNSEC0uXapIzIvU58MVbxzKd1bJC36CAHkUIWDRqk7KEudEzhuJ28o9P xvDAidTuLt7OZbshV01dyKSRya37b/ubBypCxivcWK6xt5630J1sicJsk3JKNIczqjmG fwYpCguDJ237bbUjlBelYMYtwVUK62UcweldXFIVuUUPuNMRNTfBFCrfMAwRJRzVWEUl DVFFcsyqH9tkLYQbVxhdGzvXgUHkt9ESAGERP2CUgEfXr5r6Wg1omX2lES0ev3sEctxq Urhg== X-Gm-Message-State: APjAAAX6hLkMYQbUnM0pBywZUNsx0v5Plhhg+0u3TRJqLzzl7fRaL2jo XLWM/C9Ysk8JGupNN94I0YXAaa+W X-Google-Smtp-Source: APXvYqxE0qKvavcp01iVEHQOhMz682Kx0AQQmFHAnbvF+JvLhKMkh4vY5Q2SOj7ZQMYq+d55VnSV+Q== X-Received: by 2002:adf:cd92:: with SMTP id q18mr4314399wrj.261.1581691489187; Fri, 14 Feb 2020 06:44:49 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x11sm7446748wmg.46.2020.02.14.06.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 06:44:48 -0800 (PST) Message-Id: <72c3d642a9749fa0072bf1dbd5c652c8866d30b1.1581691486.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Fri, 14 Feb 2020 14:44:41 +0000 Subject: [PATCH v6 2/7] git-p4: create new function run_git_hook Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene This commit is in preparation of introducing new p4 submit hooks. The current code in the python script git-p4.py makes the assumption that the git hooks can be executed by subprocess.call() function. However, when git is run on Windows, this may not work as expected. The subprocess.call() does not cover all the use cases for properly executing the various types of executable files on Windows. Prepare for remediation by adding a new function, run_git_hook, that takes 2 parameters: * the short filename of an optionally registered git hook * an optional list of parameters The run_git_hook function will honor the existing behavior seen in the current code for executing the p4-pre-submit hook: * Hooks are looked for in core.hooksPath directory. * If core.hooksPath is not set, then the current .git/hooks directory is checked. * If the hook does not exist, the function returns True. * If the hook file is not accessible, the function returns True. * If the hook returns a zero exit code when executed, the function return True. * If the hook returns a non-zero exit code, the function returns False. Add the following additional functionality if git-p4.py is run on Windows. * If hook file is not located without an extension, search for any file in the associated hook directory (from the list above) that has the same name but with an extension. * If the file is still not found, return True (the hook is missing) Add a new function run_hook_command() that wraps the OS dependent functionality for actually running the subprocess.call() with OS dependent behavior: If a hook file exists on Windows: * If there is no extension, set the launch executable to be SH.EXE - Look for SH.EXE under the environmental variable EXEPATH in the bin/ directory. - If %EXEPATH%/bin/sh.exe exists, use this as the actual executable. - If %EXEPATH%/bin/sh.exe does not exist, use sh.exe - Execute subprocess.call() without the shell (shell=False) * If there is an extension, execute subprocess.call() with teh shell (shell=True) and consider the file to be the executable. The return value from run_hook_command() is the subprocess.call() return value. These functions are added in this commit, but are only staged and not yet used. Signed-off-by: Ben Keene --- git-p4.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/git-p4.py b/git-p4.py index 65b6d4dca08..4eccea3fa58 100755 --- a/git-p4.py +++ b/git-p4.py @@ -26,6 +26,7 @@ import zlib import ctypes import errno +import glob # support basestring in python3 try: @@ -185,6 +186,73 @@ def prompt(prompt_text): if response in choices: return response +def run_git_hook(cmd, param=[]): + """Execute a hook if the hook exists.""" + if verbose: + sys.stderr.write("Looking for hook: %s\n" % cmd) + sys.stderr.flush() + + hooks_path = gitConfig("core.hooksPath") + if len(hooks_path) <= 0: + hooks_path = os.path.join(os.environ["GIT_DIR"], "hooks") + + if not isinstance(param, list): + param=[param] + + # resolve hook file name, OS depdenent + hook_file = os.path.join(hooks_path, cmd) + if platform.system() == 'Windows': + if not os.path.isfile(hook_file): + # look for the file with an extension + files = glob.glob(hook_file + ".*") + if not files: + return True + files.sort() + hook_file = files.pop() + while hook_file.upper().endswith(".SAMPLE"): + # The file is a sample hook. We don't want it + if len(files) > 0: + hook_file = files.pop() + else: + return True + + if not os.path.isfile(hook_file) or not os.access(hook_file, os.X_OK): + return True + + return run_hook_command(hook_file, param) == 0 + +def run_hook_command(cmd, param): + """Executes a git hook command + cmd = the command line file to be executed. This can be + a file that is run by OS association. + + param = a list of parameters to pass to the cmd command + + On windows, the extension is checked to see if it should + be run with the Git for Windows Bash shell. If there + is no file extension, the file is deemed a bash shell + and will be handed off to sh.exe. Otherwise, Windows + will be called with the shell to handle the file assocation. + + For non Windows operating systems, the file is called + as an executable. + """ + cli = [cmd] + param + use_shell = False + if platform.system() == 'Windows': + (root,ext) = os.path.splitext(cmd) + if ext == "": + exe_path = os.environ.get("EXEPATH") + if exe_path is None: + exe_path = "" + else: + exe_path = os.path.join(exe_path, "bin") + cli = [os.path.join(exe_path, "SH.EXE")] + cli + else: + use_shell = True + return subprocess.call(cli, shell=use_shell) + + def write_pipe(c, stdin): if verbose: sys.stderr.write('Writing pipe: %s\n' % str(c)) @@ -2337,12 +2405,7 @@ def run(self, args): sys.exit("number of commits (%d) must match number of shelved changelist (%d)" % (len(commits), num_shelves)) - hooks_path = gitConfig("core.hooksPath") - if len(hooks_path) <= 0: - hooks_path = os.path.join(os.environ.get("GIT_DIR", ".git"), "hooks") - - hook_file = os.path.join(hooks_path, "p4-pre-submit") - if os.path.isfile(hook_file) and os.access(hook_file, os.X_OK) and subprocess.call([hook_file]) != 0: + if not run_git_hook("p4-pre-submit"): sys.exit(1) # @@ -4124,7 +4187,6 @@ def printUsage(commands): "unshelve" : P4Unshelve, } - def main(): if len(sys.argv[1:]) == 0: printUsage(commands.keys()) From patchwork Fri Feb 14 14:44:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11382337 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 DB04A1580 for ; Fri, 14 Feb 2020 14:44:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B9A4A24649 for ; Fri, 14 Feb 2020 14:44:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YGtO3VYt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387433AbgBNOoy (ORCPT ); Fri, 14 Feb 2020 09:44:54 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50253 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbgBNOow (ORCPT ); Fri, 14 Feb 2020 09:44:52 -0500 Received: by mail-wm1-f68.google.com with SMTP id a5so10199135wmb.0 for ; Fri, 14 Feb 2020 06:44:50 -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=5kC8PpjlwM8iMZkewDBjrt2v33GjpYgn3pFe6ohOsls=; b=YGtO3VYtKzUtEqzW7jD7DHYRHEi/33Mqk6mL4g7Sdy7dKxv5c2YsHZU2eFJtfKXxVB T7pgeV6AaO5EH6cQ8A54+3HCJ8hnDWt5C8B0dN57o0kOuuF0cPerUaZZU3RiQRjtflrf 4EVtUNUDONbFYdc7kM2J5uF07gm0yrf9KuctXplBs0auNC4m/qtylPYJyLb4TJSx7ks/ BWafpdScVcGhQguvZ6s6fUtAbBv88WXDhp+fR/NaNIEBe2ifnbcfXDU5wQaytPK4/oWH fyWbQZSKwXPfQB0HFyeePhB+O4PLD50Soz6OLvszZ6zGOGPC5RG8QX9h6PULmmTqv2+x ZBQQ== 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=5kC8PpjlwM8iMZkewDBjrt2v33GjpYgn3pFe6ohOsls=; b=BjEpZozhb17NQK271iCwu97NC+tahxfbWVlyT3BrfdHfou9zVZRp0T77YsDJTQeDK1 Spm3vHUiuQ+EmYj5dWQwwPDaZWh3bVT3SP+wOz46Jia7k4i8RlVMGtbGEOf3Cdl0KdFU /0LndK0Z43nfBN6pskmeuU+Jc3Np36/oF3wDVtlCMZjpKbkhi0+Bn4l3yDyPQ0L2bqgM DaDaYXf0tohM+GcQ8IbJ5QQY2G0Sr43UaoebTWkWMcdvimTyFtxVQyNxAv0B9Lnc3N1Z ma0Bd+dP9qxvP2LwIiK/swUbV36aiD+iqijB8X8WpTYH3WMGzmlASc8IoRxHJB/G3QSr morQ== X-Gm-Message-State: APjAAAUNrr0aCa33O5cr7DN+KPbjKtcIMps6mt0lRY4mJB4WWD7pMqvC cwCG4IOfdnblXkhY0EJZfjGvqWLQ X-Google-Smtp-Source: APXvYqzI+ZkQUXWfJ7w44X4egRU8HI6KQhISM1LkUGqVlPHGWhNifO+Is5GNInbaxuiLHRukH22YZQ== X-Received: by 2002:a1c:5445:: with SMTP id p5mr5014531wmi.75.1581691490183; Fri, 14 Feb 2020 06:44:50 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e22sm7852503wme.45.2020.02.14.06.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 06:44:49 -0800 (PST) Message-Id: In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Fri, 14 Feb 2020 14:44:42 +0000 Subject: [PATCH v6 3/7] git-p4: add p4-pre-submit exit text Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene When the p4-pre-submit exits with a non-zero exit code, the application will abort the process with no additional information presented to the user. This can be confusing for new users as it may not be clear that the p4-pre-submit action caused the error. Add text to explain why the program aborted the submit action. Signed-off-by: Ben Keene --- git-p4.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/git-p4.py b/git-p4.py index 4eccea3fa58..b1c86678fc6 100755 --- a/git-p4.py +++ b/git-p4.py @@ -2405,7 +2405,15 @@ def run(self, args): sys.exit("number of commits (%d) must match number of shelved changelist (%d)" % (len(commits), num_shelves)) - if not run_git_hook("p4-pre-submit"): + try: + if not run_git_hook("p4-pre-submit"): + print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nYou can skip " \ + "this pre-submission check by adding\nthe command line option '--no-verify', " \ + "however,\nthis will also skip the p4-changelist hook as well.") + sys.exit(1) + except Exception as e: + print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nThe hook failed "\ + "with the error '{0}'".format(e.message) ) sys.exit(1) # From patchwork Fri Feb 14 14:44:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11382341 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 1A98413A4 for ; Fri, 14 Feb 2020 14:44:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E0D482187F for ; Fri, 14 Feb 2020 14:44:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ilt+04Vb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387454AbgBNOo4 (ORCPT ); Fri, 14 Feb 2020 09:44:56 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37718 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387421AbgBNOoz (ORCPT ); Fri, 14 Feb 2020 09:44:55 -0500 Received: by mail-wm1-f67.google.com with SMTP id a6so10903548wme.2 for ; Fri, 14 Feb 2020 06:44: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=Nn8NEkjsKQAY7KAdevbPz0Qu2jcUWo6F6jKeN/6cKNs=; b=Ilt+04VbwJZN4xyJcJqusdUaRGuruzVET0giOQOQdVDIHylkCgKFcROTulkeE3IjKg Es9O0WDvqpnv3ng5fdBU5WmUEPFjc70PKocjWabMasDSrnLqtPoP+0aOX4Yk8Gu6ZFmf PwDVT6fvIqlyMlmvkfc6mdcSVU/4zoaRckeO67LwWzmREItPEp7X+vjRlHgwSMbKldGb LQT1WpcNcfBhSkbebq0u0Rfn4oVcTKsEW7hiDlC3PH3lBF36btM3fmQDRsi6jTuowMZN waqfCQtB09cqEMO/1OPE7uA2mbNUyz1/krsV0uQdOCEaBs+xiS8jg6QRddmO48roBkkp fizQ== 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=Nn8NEkjsKQAY7KAdevbPz0Qu2jcUWo6F6jKeN/6cKNs=; b=EkCK5XEhp3nPeg1Ufjog1nOin+5wv5SVkU/vlrQTlmHPJnK7yxQ+4cR1a+CuYoquGS dAGG454Fintt1L2/euWsAGauCK542BEa0RPKEeIqR+bEgiyMLrYtwST8vnfu5TC6ExsG fM4UMRvkgCQBsaX9TjBangi4QCFjiChjHUouCWj7fkNe2YvwMOU3L0d6kwFtX9lzzcq/ 1dqK+KPtss2i8iqsFZEObyB/yQ0ECh0jCI82wJHKtHLyJNGKixRxITguB6KsVH5L0hoc 5bZLqqO0z1euDdmBL8BPJYuXb3Vtva7YxXT04jtM21pKtIWMdcyUxFsikB2+fDWw4/E8 6qFA== X-Gm-Message-State: APjAAAXeNB71RBhS9gp9npIGsqh8la7PkJ+W88zDKkB4pB9sEYsnkWWb jkfspQ/LrpECimIdZZwU0MspUbb8 X-Google-Smtp-Source: APXvYqz53HzSczbA/ltBl4s7Jx04yfg1Ja/ebyd2amy7/5ck6enewLQEFc+d52jiZZ0juJJDWBH79Q== X-Received: by 2002:a05:600c:2406:: with SMTP id 6mr5084889wmp.30.1581691491148; Fri, 14 Feb 2020 06:44:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y1sm7404519wrq.16.2020.02.14.06.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 06:44:50 -0800 (PST) Message-Id: In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Fri, 14 Feb 2020 14:44:43 +0000 Subject: [PATCH v6 4/7] git-p4: add --no-verify option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene Add new command line option --no-verify: Add a new command line option "--no-verify" to the Submit command of git-p4.py. This option will function in the spirit of the existing --no-verify command line option found in git commit. It will cause the P4 Submit function to ignore the existing p4-pre-submit. Change the execution of the existing trigger p4-pre-submit to honor the --no-verify option. Before exiting on failure of this hook, display text to the user explaining which hook has failed and the impact of using the --no-verify option. Change the call of the p4-pre-submit hook to use the new run_git_hook function. This is in preparation of additional hooks to be added. Signed-off-by: Ben Keene --- Documentation/git-p4.txt | 10 ++++++++-- Documentation/githooks.txt | 5 ++++- git-p4.py | 32 +++++++++++++++++++------------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 3494a1db3eb..362b50eb212 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -374,14 +374,20 @@ These options can be used to modify 'git p4 submit' behavior. been submitted. Implies --disable-rebase. Can also be set with git-p4.disableP4Sync. Sync with origin/master still goes ahead if possible. -Hook for submit -~~~~~~~~~~~~~~~ +Hooks for submit +---------------- + +p4-pre-submit +~~~~~~~~~~~~~ + The `p4-pre-submit` hook is executed if it exists and is executable. The hook takes no parameters and nothing from standard input. Exiting with non-zero status from this script prevents `git-p4 submit` from launching. +It can be bypassed with the `--no-verify` command line option. One usage scenario is to run unit tests in the hook. + Rebase options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 rebase' behavior. diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 50365f2914e..8cf6b08b55b 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -520,7 +520,10 @@ p4-pre-submit This hook is invoked by `git-p4 submit`. It takes no parameters and nothing from standard input. Exiting with non-zero status from this script prevent -`git-p4 submit` from launching. Run `git-p4 submit --help` for details. +`git-p4 submit` from launching. It can be bypassed with the `--no-verify` +command line option. Run `git-p4 submit --help` for details. + + post-index-change ~~~~~~~~~~~~~~~~~ diff --git a/git-p4.py b/git-p4.py index b1c86678fc6..c969d9235b1 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1588,13 +1588,17 @@ def __init__(self): "work from a local git branch that is not master"), optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true", help="Skip Perforce sync of p4/master after submit or shelve"), + optparse.make_option("--no-verify", dest="no_verify", action="store_true", + help="Bypass p4-pre-submit"), ] self.description = """Submit changes from git to the perforce depot.\n - The `p4-pre-submit` hook is executed if it exists and is executable. - The hook takes no parameters and nothing from standard input. Exiting with - non-zero status from this script prevents `git-p4 submit` from launching. + The `p4-pre-submit` hook is executed if it exists and is executable. It + can be bypassed with the `--no-verify` command line option. The hook takes + no parameters and nothing from standard input. Exiting with a non-zero status + from this script prevents `git-p4 submit` from launching. - One usage scenario is to run unit tests in the hook.""" + One usage scenario is to run unit tests in the hook. + """ self.usage += " [name of git branch to submit into perforce depot]" self.origin = "" @@ -1612,6 +1616,7 @@ def __init__(self): self.exportLabels = False self.p4HasMoveCommand = p4_has_move_command() self.branch = None + self.no_verify = False if gitConfig('git-p4.largeFileSystem'): die("Large file system not supported for git-p4 submit command. Please remove it from config.") @@ -2405,16 +2410,17 @@ def run(self, args): sys.exit("number of commits (%d) must match number of shelved changelist (%d)" % (len(commits), num_shelves)) - try: - if not run_git_hook("p4-pre-submit"): - print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nYou can skip " \ - "this pre-submission check by adding\nthe command line option '--no-verify', " \ - "however,\nthis will also skip the p4-changelist hook as well.") + if not self.no_verify: + try: + if not run_git_hook("p4-pre-submit"): + print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nYou can skip " \ + "this pre-submission check by adding\nthe command line option '--no-verify', " \ + "however,\nthis will also skip the p4-changelist hook as well.") + sys.exit(1) + except Exception as e: + print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nThe hook failed "\ + "with the error '{0}'".format(e.message) ) sys.exit(1) - except Exception as e: - print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nThe hook failed "\ - "with the error '{0}'".format(e.message) ) - sys.exit(1) # # Apply the commits, one at a time. On failure, ask if should From patchwork Fri Feb 14 14:44:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11382339 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 D380B13A4 for ; Fri, 14 Feb 2020 14:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A849E22314 for ; Fri, 14 Feb 2020 14:44:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vJwsEMPV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387445AbgBNOoz (ORCPT ); Fri, 14 Feb 2020 09:44:55 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39533 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387427AbgBNOoy (ORCPT ); Fri, 14 Feb 2020 09:44:54 -0500 Received: by mail-wr1-f65.google.com with SMTP id y11so11178709wrt.6 for ; Fri, 14 Feb 2020 06:44: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=sGRNsxuyHRz+riv06aTjXiqn20BEbLaF2huS2hqI0+M=; b=vJwsEMPVAThtE9WjlIRtK3C5bP4YjnR2mzkldaD/XrII6j6ckn+EBJaTtc/GsRHExO igmaONISYSTY92m+bzZnK6EU0OX2AFo5LpHlso+V/6YP5pUFn44E3++3FbUqwwCORCcK HBLTv2n/4X68IBcOwPN7JgFxVTEjk2ZDWS38cQSVfvJ0QBlzJW1AS1l7uWt7kO75w9PC Y0bxqN4tKyF+i7XhLoJHVzAY4E73JylIyt2iGtMszGZZA8EQr6zANN+NRzHevkW/Io3G BGkmatawMmwqE9eBW7iPcZaKLyrhV0Y0cjMAFp++nBIiWRs0A3z54UANMjm9n18LjZHE XXvw== 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=sGRNsxuyHRz+riv06aTjXiqn20BEbLaF2huS2hqI0+M=; b=oKRNGUMINdPcKc/frpGqcIODjd2IqtE5+8ruMJJTlwmbvdQoMyMjjrRCYQaU0wYjiG Y9sZToFeWBS1fTz0lBB9jp9foVa5S+p7iyioZ4dZ+EneRQMY/QoQqFTqkmCsqsienIwh LRRrchBSY99TepVEsb4QJ7VP427KkWvKdYCgWWD4ppacFwtL/PXAfuWfiP5bsLM4xSJS m+q4KnGnaMlgsXBzpveYaznFwNesmnCYSnkd1BHXlo5wN/w36a9tdTPREatUCKIuHbM7 mNZxb5rQEn4oRHLJMCn4KaOVn/0z8T2X8GFBvZIzKL5o99ZCqcabWH9wCKfoQ/4hIpq/ pJ9w== X-Gm-Message-State: APjAAAVdvN7COn85r09d9eoESMCeBIx9YQ6KUUFA2APVzZ+bf/wLLX1H Q+D8IzvxNDG+/8mKLeqg6D8mE7yO X-Google-Smtp-Source: APXvYqyKKLG876SdQuM2q3DvRbZMMGuNwzxzpEF//6g9e1WXXm5M1JrfCORlFlF8Nfy9QWerEO+XWQ== X-Received: by 2002:a5d:61d1:: with SMTP id q17mr4547503wrv.156.1581691491885; Fri, 14 Feb 2020 06:44:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d4sm4233294wra.14.2020.02.14.06.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 06:44:51 -0800 (PST) Message-Id: <22ac4384bd5e68709ee03ac0beaaff7e3d39fe51.1581691486.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Fri, 14 Feb 2020 14:44:44 +0000 Subject: [PATCH v6 5/7] git-p4: restructure code in submit Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene In preparation for adding new hooks to the submit method of git-p4, restructure the applyCommit function in the P4Submit class. Make the following changes: * Move all the code after the definition of submitted = False into the Try-Finally block. This ensures that any error that occurs will properly recover. This is not necessary with the current code because none of it should throw an exception, however the next set of changes will introduce exceptional code. Existing flow control can remain as defined - the if-block for prepare-p4-only sets the local variable "submitted" to True and exits the function. New early exits, leave submitted set to False so the Finally block will undo changes to the P4 workspace. * Make the small usability change of adding an empty string to the print statements displayed to the user when the prepare-p4-only option is selected. On Windows, the command print() may display a set of parentheses "()" to the user when the print() function is called with no parameters. By supplying an empty string, the intended blank line will print as expected. * Fix a small bug when the submittedTemplate is edited by the user and all content in the file is removed. The existing code will throw an exception if the separateLine is not found in the file. Change this code to test for the separator line using a find() test first and only split on the separator if it is found. * Additionally, add the new behavior that if the changelist file has been completely emptied that the Submit action for this changelist will be aborted. Signed-off-by: Ben Keene --- git-p4.py | 92 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/git-p4.py b/git-p4.py index c969d9235b1..4ae6aa30f06 100755 --- a/git-p4.py +++ b/git-p4.py @@ -2102,47 +2102,47 @@ def applyCommit(self, id): tmpFile.write(submitTemplate) tmpFile.close() - if self.prepare_p4_only: - # - # Leave the p4 tree prepared, and the submit template around - # and let the user decide what to do next - # - print() - print("P4 workspace prepared for submission.") - print("To submit or revert, go to client workspace") - print(" " + self.clientPath) - print() - print("To submit, use \"p4 submit\" to write a new description,") - print("or \"p4 submit -i <%s\" to use the one prepared by" \ - " \"git p4\"." % fileName) - print("You can delete the file \"%s\" when finished." % fileName) - - if self.preserveUser and p4User and not self.p4UserIsMe(p4User): - print("To preserve change ownership by user %s, you must\n" \ - "do \"p4 change -f \" after submitting and\n" \ - "edit the User field.") - if pureRenameCopy: - print("After submitting, renamed files must be re-synced.") - print("Invoke \"p4 sync -f\" on each of these files:") - for f in pureRenameCopy: - print(" " + f) - - print() - print("To revert the changes, use \"p4 revert ...\", and delete") - print("the submit template file \"%s\"" % fileName) - if filesToAdd: - print("Since the commit adds new files, they must be deleted:") - for f in filesToAdd: - print(" " + f) - print() - return True - - # - # Let the user edit the change description, then submit it. - # submitted = False try: + + if self.prepare_p4_only: + # + # Leave the p4 tree prepared, and the submit template around + # and let the user decide what to do next + # + submitted = True + print("") + print("P4 workspace prepared for submission.") + print("To submit or revert, go to client workspace") + print(" " + self.clientPath) + print("") + print("To submit, use \"p4 submit\" to write a new description,") + print("or \"p4 submit -i <%s\" to use the one prepared by" \ + " \"git p4\"." % fileName) + print("You can delete the file \"%s\" when finished." % fileName) + + if self.preserveUser and p4User and not self.p4UserIsMe(p4User): + print("To preserve change ownership by user %s, you must\n" \ + "do \"p4 change -f \" after submitting and\n" \ + "edit the User field.") + if pureRenameCopy: + print("After submitting, renamed files must be re-synced.") + print("Invoke \"p4 sync -f\" on each of these files:") + for f in pureRenameCopy: + print(" " + f) + + print("") + print("To revert the changes, use \"p4 revert ...\", and delete") + print("the submit template file \"%s\"" % fileName) + if filesToAdd: + print("Since the commit adds new files, they must be deleted:") + for f in filesToAdd: + print(" " + f) + print("") + sys.stdout.flush() + return True + if self.edit_template(fileName): # read the edited message and submit tmpFile = open(fileName, "rb") @@ -2150,7 +2150,15 @@ def applyCommit(self, id): tmpFile.close() if self.isWindows: message = message.replace("\r\n", "\n") - submitTemplate = message[:message.index(separatorLine)] + if message.find(separatorLine) != -1: + submitTemplate = message[:message.index(separatorLine)] + else: + submitTemplate = message + + if len(submitTemplate.strip()) == 0: + print("Changelist is empty, aborting this changelist.") + sys.stdout.flush() + return False if update_shelve: p4_write_pipe(['shelve', '-r', '-i'], submitTemplate) @@ -2174,19 +2182,21 @@ def applyCommit(self, id): submitted = True finally: - # skip this patch + # Revert changes if we skip this patch if not submitted or self.shelve: if self.shelve: print ("Reverting shelved files.") else: print ("Submission cancelled, undoing p4 changes.") + sys.stdout.flush() for f in editedFiles | filesToDelete: p4_revert(f) for f in filesToAdd: p4_revert(f) os.remove(f) - os.remove(fileName) + if not self.prepare_p4_only: + os.remove(fileName) return submitted # Export git tags as p4 labels. Create a p4 label and then tag From patchwork Fri Feb 14 14:44:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11382343 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 B4A831800 for ; Fri, 14 Feb 2020 14:44:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A23E24649 for ; Fri, 14 Feb 2020 14:44:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b1Ktnmz9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387458AbgBNOo5 (ORCPT ); Fri, 14 Feb 2020 09:44:57 -0500 Received: from mail-wr1-f44.google.com ([209.85.221.44]:33767 "EHLO mail-wr1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387429AbgBNOo4 (ORCPT ); Fri, 14 Feb 2020 09:44:56 -0500 Received: by mail-wr1-f44.google.com with SMTP id u6so11234126wrt.0 for ; Fri, 14 Feb 2020 06:44: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=81/AIgqyRuFiV3HO2Icul1sGV/JwegTwet9uDfguys4=; b=b1Ktnmz9Ec+Dtowa+A9lfFqHOnWPUKvO0gLpKwSdL9gLyWr5g7ztVL32ZA5XRlT4iB h+Ka37tiufW/lG9mDOzV7Vqw1w8kdnXCHEmssur6Zc7OaDvXHP54YENtQ622xcphbWVi iX4twi3JI/M8fTrBHTk4yDdWZ8MGNYwUVLAOXuFcdz3G+xMj83lqJnDuLBjUV3SyW4Ig c7Ufnu4SB8klIxNBRO9tOc+jO88LIuljWpvx59dAHxB0aImpVslKUL6kGmy9TTUd2ui7 p83nMlD4Ho/DKPbqBTM9CUn9FjcBYGVNdJPmKvutKu6mjy8668giiT7mQC3mUzl0dwWb wYFA== 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=81/AIgqyRuFiV3HO2Icul1sGV/JwegTwet9uDfguys4=; b=svTJZqH/4vEA6TpSEV1SZCGV38/r1evS5ig1c2cfKsk7+m5vvOJOmY7KllXdstROZY 5GSOuTm0mTnn+5h63i38svyfoQXP1gqk0YP3NlP8KU8RxRgl3Y+MjrnLiZStjXGLjiep dkdZLG8Om53Tu8t8kzO4eJLbKMpwA3f7sb8tWFG4S+YQbAE5L4i1QV9ob8llExLZjxTH kK3r1oEXA81LRm0O6cO9oDLBiyRF/0roo/7YLv0wu4F9pNLdMr40Wqso0zd86QU4Ijss DBvzN4S1eQTHfPNvmgc0YLaD1OOqe8Wz76VU0crKPXrwYDUhazwH4Y0fKFz/A1W9cqvB SjIQ== X-Gm-Message-State: APjAAAUxRwvaq9dZHmt0qOEXDBKBk/jH2sHTxJd704sTJU6SXfTImmMU Sd3sKjgTL5ZlI04DQ0bqOBvZw9YB X-Google-Smtp-Source: APXvYqxXLNwMm2Pc8QZesVPvvD4k14fmbIczj6eE3li/xrqja0FmdCJEBugJXiA/PecWVJLmVORAtg== X-Received: by 2002:adf:ce0f:: with SMTP id p15mr4638343wrn.342.1581691493512; Fri, 14 Feb 2020 06:44:53 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a9sm7853762wrn.3.2020.02.14.06.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 06:44:52 -0800 (PST) Message-Id: In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Fri, 14 Feb 2020 14:44:45 +0000 Subject: [PATCH v6 6/7] git-p4: add p4 submit hooks Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene The git command "commit" supports a number of hooks that support changing the behavior of the commit command. The git-p4.py program only has one existing hook, "p4-pre-submit". This command occurs early in the process. There are no hooks in the process flow for modifying the P4 changelist text programmatically. Adds 3 new hooks to git-p4.py to the submit option. The new hooks are: * p4-prepare-changelist - Execute this hook after the changelist file has been created. The hook will be executed even if the --prepare-p4-only option is set. This hook ignores the --no-verify option in keeping with the existing behavior of git commit. * p4-changelist - Execute this hook after the user has edited the changelist. Do not execute this hook if the user has selected the --prepare-p4-only option. This hook will honor the --no-verify, following the conventions of git commit. * p4-post-changelist - Execute this hook after the P4 submission process has completed successfully. This hook takes no parameters and is executed regardless of the --no-verify option. It's return value will not be checked. The calls to the new hooks: p4-prepare-changelist, p4-changelist, and p4-post-changelist should all be called inside the try-finally block. Signed-off-by: Ben Keene --- Documentation/git-p4.txt | 35 +++++++++++++++++++++++++++++ Documentation/githooks.txt | 46 ++++++++++++++++++++++++++++++++++++++ git-p4.py | 35 ++++++++++++++++++++++++++++- 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 362b50eb212..dab9609013f 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -387,6 +387,41 @@ It can be bypassed with the `--no-verify` command line option. One usage scenario is to run unit tests in the hook. +p4-prepare-changelist +~~~~~~~~~~~~~~~~~~~~~ + +The `p4-prepare-changelist` hook is executed right after preparing +the default changelist message and before the editor is started. +It takes one parameter, the name of the file that contains the +changelist text. Exiting with a non-zero status from the script +will abort the process. + +The purpose of the hook is to edit the message file in place, +and it is not supressed by the `--no-verify` option. This hook +is called even if `--prepare-p4-only` is set. + +p4-changelist +~~~~~~~~~~~~~ + +The `p4-changelist` hook is executed after the changelist +message has been edited by the user. It can be bypassed with the +`--no-verify` option. It takes a single parameter, the name +of the file that holds the proposed changelist text. Exiting +with a non-zero status causes the command to abort. + +The hook is allowed to edit the changelist file and can be used +to normalize the text into some project standard format. It can +also be used to refuse the Submit after inspect the message file. + +p4-post-changelist +~~~~~~~~~~~~~~~~~~ + +The `p4-post-changelist` hook is invoked after the submit has +successfully occured in P4. It takes no parameters and is meant +primarily for notification and cannot affect the outcome of the +git p4 submit action. + + Rebase options ~~~~~~~~~~~~~~ diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 8cf6b08b55b..8aa9c2176c6 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -515,6 +515,52 @@ The exit status determines whether git will use the data from the hook to limit its search. On error, it will fall back to verifying all files and folders. +p4-changelist +~~~~~~~~~~~~~ + +This hook is invoked by `git-p4 submit`. + +The `p4-changelist` hook is executed after the changelist +message has been edited by the user. It can be bypassed with the +`--no-verify` option. It takes a single parameter, the name +of the file that holds the proposed changelist text. Exiting +with a non-zero status causes the command to abort. + +The hook is allowed to edit the changelist file and can be used +to normalize the text into some project standard format. It can +also be used to refuse the Submit after inspect the message file. + +Run `git-p4 submit --help` for details. + +p4-prepare-changelist +~~~~~~~~~~~~~~~~~~~~~ + +This hook is invoked by `git-p4 submit`. + +The `p4-prepare-changelist` hook is executed right after preparing +the default changelist message and before the editor is started. +It takes one parameter, the name of the file that contains the +changelist text. Exiting with a non-zero status from the script +will abort the process. + +The purpose of the hook is to edit the message file in place, +and it is not supressed by the `--no-verify` option. This hook +is called even if `--prepare-p4-only` is set. + +Run `git-p4 submit --help` for details. + +p4-post-changelist +~~~~~~~~~~~~~~~~~~ + +This hook is invoked by `git-p4 submit`. + +The `p4-post-changelist` hook is invoked after the submit has +successfully occured in P4. It takes no parameters and is meant +primarily for notification and cannot affect the outcome of the +git p4 submit action. + +Run `git-p4 submit --help` for details. + p4-pre-submit ~~~~~~~~~~~~~ diff --git a/git-p4.py b/git-p4.py index 4ae6aa30f06..8761c70e1c6 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1589,7 +1589,7 @@ def __init__(self): optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true", help="Skip Perforce sync of p4/master after submit or shelve"), optparse.make_option("--no-verify", dest="no_verify", action="store_true", - help="Bypass p4-pre-submit"), + help="Bypass p4-pre-submit and p4-changelist hooks"), ] self.description = """Submit changes from git to the perforce depot.\n The `p4-pre-submit` hook is executed if it exists and is executable. It @@ -1598,6 +1598,28 @@ def __init__(self): from this script prevents `git-p4 submit` from launching. One usage scenario is to run unit tests in the hook. + + The `p4-prepare-changelist` hook is executed right after preparing the default + changelist message and before the editor is started. It takes one parameter, + the name of the file that contains the changelist text. Exiting with a non-zero + status from the script will abort the process. + + The purpose of the hook is to edit the message file in place, and it is not + supressed by the `--no-verify` option. This hook is called even if + `--prepare-p4-only` is set. + + The `p4-changelist` hook is executed after the changelist message has been + edited by the user. It can be bypassed with the `--no-verify` option. It + takes a single parameter, the name of the file that holds the proposed + changelist text. Exiting with a non-zero status causes the command to abort. + + The hook is allowed to edit the changelist file and can be used to normalize + the text into some project standard format. It can also be used to refuse the + Submit after inspect the message file. + + The `p4-post-changelist` hook is invoked after the submit has successfully + occured in P4. It takes no parameters and is meant primarily for notification + and cannot affect the outcome of the git p4 submit action. """ self.usage += " [name of git branch to submit into perforce depot]" @@ -2105,6 +2127,10 @@ def applyCommit(self, id): submitted = False try: + # Allow the hook to edit the changelist text before presenting it + # to the user. + if not run_git_hook("p4-prepare-changelist", [fileName]): + return False if self.prepare_p4_only: # @@ -2144,6 +2170,12 @@ def applyCommit(self, id): return True if self.edit_template(fileName): + if not self.no_verify: + if not run_git_hook("p4-changelist", [fileName]): + print("The p4-changelist hook failed.") + sys.stdout.flush() + return False + # read the edited message and submit tmpFile = open(fileName, "rb") message = tmpFile.read() @@ -2181,6 +2213,7 @@ def applyCommit(self, id): submitted = True + run_git_hook("p4-post-changelist") finally: # Revert changes if we skip this patch if not submitted or self.shelve: From patchwork Fri Feb 14 14:44:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11382345 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 4797B13A4 for ; Fri, 14 Feb 2020 14:45:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 24C5D2187F for ; Fri, 14 Feb 2020 14:45:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WqSrvnxl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387466AbgBNOo7 (ORCPT ); Fri, 14 Feb 2020 09:44:59 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40395 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387435AbgBNOo4 (ORCPT ); Fri, 14 Feb 2020 09:44:56 -0500 Received: by mail-wr1-f67.google.com with SMTP id t3so11185964wru.7 for ; Fri, 14 Feb 2020 06:44:55 -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=XZZUve2ddD5J23QBrcjCZHW5emJqSKctaadnUg1LmzM=; b=WqSrvnxlhEegWYtKoaFQGrIofhq+V55MlmzDN6IxzpPRiS2nBxtQLBYmgTHCHutlmU hG0bv19SCw0JM6NjhuvQnfllk8PJMSk1YEPnOAdQPjv3p84j9hDL6QJ9T+VG7oFLcxlb v7oVP3WHM+/vN74XwfHML3igpVAswwCql+zMchyp2MmL0m7RCVYNAqnHjLhW9MhHOWk7 gGRx9hy5FDrrWjpRKyky5xVc3NgnA91kbczpxBkecnuO4+e2wEdq3tiNNzQTMfZAIV+A VwobJm2XMY0mq2o4ZrMkfGfEysNVRr5WHrixNykbFEMX6UDQZCfapdCNx9F4MB2uX9mz bPxw== 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=XZZUve2ddD5J23QBrcjCZHW5emJqSKctaadnUg1LmzM=; b=NmXa2I8okmsKoPYRGEKHZ5g7KsRA3rpzSoSSLKcnOnMqw0XBGvEqdjWV0bxSw8xWEy 7tmM7PFrfIUDExLbEgi6bqVxBXbdpdBR6fhXL6IzMgEP2qhVUSXPdExARRL20xr02j79 muf6NjDf7PYf3Vh2jLA4IJcefKwZMKC5PkChPq31iscqEpLR6PAzDUMtTv/pOcY2HfTu LDxxKu7jwlgCpBsPzBzGJTx6rxXy/z8REknIcGUbstuPB1FxVY3r0Em2qtsk/Ybkui9q KGRTX3JOnsx14tQh4wj+a3aSSoO0lRrlq2ddqd4xf2dHvFyjOot4u7N1f1A7+zKHhJhc CNSA== X-Gm-Message-State: APjAAAUU8XOtkFXzDFOKORUmi0Ggw0OrHMzbpCiNw5jgi7YEvaw0HgvS p3U7xqWxXFoWXtckZXzC0vgjCWRl X-Google-Smtp-Source: APXvYqzlKipi59vhXnHm7OhoWv7tRJcIJzMWErBeGAXKmQR3+VTaDmKD2s7IvxhcYWIl09uYEPh2CA== X-Received: by 2002:adf:dd4d:: with SMTP id u13mr4669344wrm.394.1581691494595; Fri, 14 Feb 2020 06:44:54 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c13sm7302504wrn.46.2020.02.14.06.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 06:44:53 -0800 (PST) Message-Id: In-Reply-To: References: From: "Ben Keene via GitGitGadget" Date: Fri, 14 Feb 2020 14:44:46 +0000 Subject: [PATCH v6 7/7] git-p4: add RCS keyword status message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Keene , Ben Keene Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ben Keene During the p4 submit process, git-p4 will attempt to apply a patch to the files found in the p4 workspace. However, if P4 uses RCS keyword expansion, this patch may fail. When the patch fails, the user is alerted to the failure and that git-p4 will attempt to clear the expanded text from the files and re-apply the patch. The current version of git-p4 does not tell the user the result of the re-apply attempt after the RCS expansion has been removed which can be confusing. Add a new print statement after the git patch has been successfully applied when the RCS keywords have been cleansed. Signed-off-by: Ben Keene --- git-p4.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-p4.py b/git-p4.py index 8761c70e1c6..258b9b98b93 100755 --- a/git-p4.py +++ b/git-p4.py @@ -2025,6 +2025,9 @@ def applyCommit(self, id): applyPatchCmd = patchcmd + "--check --apply -" patch_succeeded = True + if verbose: + print("TryPatch: %s" % tryPatchCmd) + if os.system(tryPatchCmd) != 0: fixed_rcs_keywords = False patch_succeeded = False @@ -2064,6 +2067,7 @@ def applyCommit(self, id): print("Retrying the patch with RCS keywords cleaned up") if os.system(tryPatchCmd) == 0: patch_succeeded = True + print("Patch succeesed this time with RCS keywords cleaned") if not patch_succeeded: for f in editedFiles: