git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ben Keene via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ben Keene <seraphire@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v3 0/4] git-p4: Usability enhancements
Date: Thu, 12 Dec 2019 19:46:23 +0000	[thread overview]
Message-ID: <pull.675.v3.git.git.1576179987.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.675.v2.git.git.1575991374.gitgitgadget@gmail.com>

Some user interaction with git-p4 is not as user-friendly as the rest of the
Git ecosystem. Here are three areas that can be improved on:

1) When a patch fails and the user is prompted, there is no sanitization of
the user input so for a "yes/no" question, if the user enters "YES" instead
of a lowercase "y", they will be re-prompted to enter their answer. 

Commit 1 addresses this by sanitizing the user text by trimming and
lowercasing their input before testing. Now "YES" will succeed!

2) Git can handle scraping the RCS Keyword expansions out of source files
when it is preparing to submit them to P4. However, if the config value
"git-p4.attemptRCSCleanup" isn't set, it will just report that it fails.

Commit 2 adds a helpful suggestion, that the user might want to set
git-p4.attemptRCSCleanup.

3) If the command line arguments are incorrect for git-p4, the program
reports that there was a syntax error, but doesn't show what the correct
syntax is.

Commit 3 displays the context help for the failed command.

Ben Keene (4):
  git-p4: yes/no prompts should sanitize user text
  git-p4: show detailed help when parsing options fail
  git-p4: wrap patchRCSKeywords test to revert changes on failure
  git-p4: failure because of RCS keywords should show help

 git-p4.py | 94 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 34 deletions(-)


base-commit: ad05a3d8e5a6a06443836b5e40434262d992889a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-675%2Fseraphire%2Fseraphire%2Fp4-usability-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-675/seraphire/seraphire/p4-usability-v3
Pull-Request: https://github.com/git/git/pull/675

Range-diff vs v2:

 1:  527b7b8f8a ! 1:  fff93acf44 git-p4: yes/no prompts should sanitize user text
     @@ -9,9 +9,12 @@
          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
     +    Create a new function, prompt(prompt_text) where
            * promt_text is the text prompt for the user
     -      * is a list of lower-case, single letter choices.
     +      * choices are extracted from the prompt text [.]
     +          a single letter surrounded by square brackets
     +          is selected as a valid choice.
     +
          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
     @@ -19,6 +22,10 @@
      
          Change the current references to raw_input() to use this new function.
      
     +    Since the method requires the returned text to be one of the available
     +    choices, remove the loop from the calling code that handles response
     +    verification.
     +
          Signed-off-by: Ben Keene <seraphire@gmail.com>
      
       diff --git a/git-p4.py b/git-p4.py
     @@ -28,12 +35,16 @@
               sys.stderr.write(msg + "\n")
               sys.exit(1)
       
     -+def prompt(prompt_text, choices = []):
     ++def prompt(prompt_text):
      +    """ Prompt the user to choose one of the choices
     ++
     ++    Choices are identified in the prompt_text by square brackets around
     ++    a single letter option.
      +    """
     ++    choices = set(m.group(1) for m in re.finditer(r"\[(.)\]", prompt_text))
      +    while True:
      +        response = raw_input(prompt_text).strip().lower()
     -+        if len(response) == 0:
     ++        if not response:
      +            continue
      +        response = response[0]
      +        if response in choices:
     @@ -43,22 +54,73 @@
           if verbose:
               sys.stderr.write('Writing pipe: %s\n' % str(c))
      @@
     +         if os.stat(template_file).st_mtime > mtime:
                   return True
       
     -         while 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':
     +-            if response == 'y':
     +-                return True
     +-            if response == 'n':
     +-                return False
     ++        response = prompt("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
     ++        if response == 'y':
     ++            return True
     ++        if response == 'n':
     ++            return False
     + 
     +     def get_diff_description(self, editedFiles, filesToAdd, symlinks):
     +         # diff
      @@
     -                         # prompt for what to do, or use the option/variable
     -                         if self.conflict_behavior == "ask":
     -                             print("What do you want to do?")
     +                           " --prepare-p4-only")
     +                     break
     +                 if i < last:
     +-                    quit = False
     +-                    while True:
     +-                        # 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":
     +-                            if not response:
     +-                                continue
     +-                        elif self.conflict_behavior == "skip":
     +-                            response = "s"
     +-                        elif self.conflict_behavior == "quit":
     +-                            response = "q"
     +-                        else:
     +-                            die("Unknown conflict_behavior '%s'" %
     +-                                self.conflict_behavior)
     +-
     +-                        if response[0] == "s":
     +-                            print("Skipping this commit, but applying the rest")
     +-                            break
     +-                        if response[0] == "q":
     +-                            print("Quitting")
     +-                            quit = True
     +-                            break
     +-                    if quit:
     ++                    # prompt for what to do, or use the option/variable
     ++                    if self.conflict_behavior == "ask":
     ++                        print("What do you want to do?")
     ++                        response = prompt("[s]kip this commit but apply the rest, or [q]uit? ")
     ++                    elif self.conflict_behavior == "skip":
     ++                        response = "s"
     ++                    elif self.conflict_behavior == "quit":
     ++                        response = "q"
     ++                    else:
     ++                        die("Unknown conflict_behavior '%s'" %
     ++                            self.conflict_behavior)
     ++
     ++                    if response == "s":
     ++                        print("Skipping this commit, but applying the rest")
     ++                    if response == "q":
     ++                        print("Quitting")
     +                         break
     + 
     +         chdir(self.oldWorkingDirectory)
     +@@
     + 
     + if __name__ == '__main__':
     +     main()
     ++
 2:  1d4f4e210b = 2:  5c5c981632 git-p4: show detailed help when parsing options fail
 3:  20aa557193 = 3:  c466e79148 git-p4: wrap patchRCSKeywords test to revert changes on failure
 4:  50e9a175c3 ! 4:  00307c3951 git-p4: failure because of RCS keywords should show help
     @@ -23,7 +23,7 @@
      +                # 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:
     ++                    if p4_keywords_regexp_for_file(file) is not 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

-- 
gitgitgadget

  parent reply	other threads:[~2019-12-12 19:46 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-09 14:16 [PATCH 0/3] git-p4: Usability enhancements Ben Keene via GitGitGadget
2019-12-09 14:16 ` [PATCH 1/3] git-p4: [usability] yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-09 22:00   ` Junio C Hamano
2019-12-10 14:26     ` Ben Keene
2019-12-09 14:16 ` [PATCH 2/3] git-p4: [usability] RCS Keyword failure should suggest help Ben Keene via GitGitGadget
2019-12-09 22:22   ` Junio C Hamano
2019-12-09 14:16 ` [PATCH 3/3] git-p4: [usability] Show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-09 22:24   ` Junio C Hamano
2019-12-09 22:06 ` [PATCH 0/3] git-p4: Usability enhancements Junio C Hamano
2019-12-10 15:22 ` [PATCH v2 0/4] " Ben Keene via GitGitGadget
2019-12-10 15:22   ` [PATCH v2 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-11 11:52     ` Denton Liu
2019-12-11 11:59     ` Denton Liu
2019-12-10 15:22   ` [PATCH v2 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-10 15:22   ` [PATCH v2 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-10 15:22   ` [PATCH v2 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-11 11:29     ` Denton Liu
2019-12-11  9:43   ` [PATCH v2 0/4] git-p4: Usability enhancements Luke Diamand
2019-12-12 19:46   ` Ben Keene via GitGitGadget [this message]
2019-12-12 19:46     ` [PATCH v3 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-13  1:45       ` Denton Liu
2019-12-13 13:42         ` Ben Keene
2019-12-13 19:46         ` Junio C Hamano
2019-12-15 20:30           ` Johannes Schindelin
2019-12-16 17:54             ` Junio C Hamano
2019-12-16 19:11             ` Ben Keene
2019-12-12 19:46     ` [PATCH v3 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-12 19:46     ` [PATCH v3 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-12 19:46     ` [PATCH v3 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-13 13:57     ` [PATCH v4 0/4] git-p4: Usability enhancements Ben Keene via GitGitGadget
2019-12-13 13:57       ` [PATCH v4 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-13 22:54         ` Denton Liu
2019-12-16 13:53           ` Ben Keene
2019-12-13 13:57       ` [PATCH v4 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-13 13:58       ` [PATCH v4 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-13 13:58       ` [PATCH v4 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-16 14:02       ` [PATCH v5 0/4] git-p4: Usability enhancements Ben Keene via GitGitGadget
2019-12-16 14:02         ` [PATCH v5 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-16 14:02         ` [PATCH v5 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-16 14:02         ` [PATCH v5 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-16 14:02         ` [PATCH v5 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-16 20:39         ` [PATCH v5 0/4] git-p4: Usability enhancements Junio C Hamano
2019-12-21 10:19           ` Luke Diamand
2019-12-25 19:13             ` Junio C Hamano
2020-01-02 13:50               ` Ben Keene
2020-01-02 21:44                 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.675.v3.git.git.1576179987.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=seraphire@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).