All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bug fix: ensure P4 "err" is displayed when exception is raised.
@ 2024-05-04  5:57 Fahad Alrashed via GitGitGadget
  2024-05-06 12:01 ` Karthik Nayak
  2024-05-08 11:46 ` [PATCH v2] " Fahad Alrashed via GitGitGadget
  0 siblings, 2 replies; 6+ messages in thread
From: Fahad Alrashed via GitGitGadget @ 2024-05-04  5:57 UTC (permalink / raw
  To: git; +Cc: Fahad Alrashed, Fahad Alrashed

From: Fahad Alrashed <fahad@keylock.net>

Bug fix: During "git p4 clone" if p4 process returns
an error from the server, it will store it in variable
"err". The it will send a text command "die-now" to
git-fast-import. However, git-fast-import raises an
exception: "fatal: Unsupported command: die-now"
and err is never displayed. This patch ensures that
err is dispayed using "finally:"

Signed-off-by: Fahad Alrashed <fahad@keylock.net>
---
    In git p4, git fast-import fails from die-now command and err (from
    Perforce) is not shown
    
    When importing from Perforce using git p4 clone <depot location>,
    cloning works fine until Perforce command p4 raises an error. This error
    message is stored in err variable then git-fast-import is sent a die-now
    command to kill it. An exception is raised fatal: Unsupported command:
    die-now.
    
    This patch forces python to call die() with the err message returned
    from Perforce.
    
    This commit fixes the root cause of a bug that took me hours to find.
    I'm sure many faced the cryptic error and declared that git-p4 is not
    working for them.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1668%2Falrashedf%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1668/alrashedf/master-v1
Pull-Request: https://github.com/git/git/pull/1668

 git-p4.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index 28ab12c72b6..f1ab31d5403 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3253,17 +3253,19 @@ def streamP4FilesCb(self, marshalled):
             if self.stream_have_file_info:
                 if "depotFile" in self.stream_file:
                     f = self.stream_file["depotFile"]
-            # force a failure in fast-import, else an empty
-            # commit will be made
-            self.gitStream.write("\n")
-            self.gitStream.write("die-now\n")
-            self.gitStream.close()
-            # ignore errors, but make sure it exits first
-            self.importProcess.wait()
-            if f:
-                die("Error from p4 print for %s: %s" % (f, err))
-            else:
-                die("Error from p4 print: %s" % err)
+            try:
+                # force a failure in fast-import, else an empty
+                # commit will be made
+                self.gitStream.write("\n")
+                self.gitStream.write("die-now\n")
+                self.gitStream.close()
+                # ignore errors, but make sure it exits first
+                self.importProcess.wait()
+            finally:
+                if f:
+                    die("Error from p4 print for %s: %s" % (f, err))
+                else:
+                    die("Error from p4 print: %s" % err)
 
         if 'depotFile' in marshalled and self.stream_have_file_info:
             # start of a new file - output the old one first

base-commit: 235986be822c9f8689be2e9a0b7804d0b1b6d821
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Bug fix: ensure P4 "err" is displayed when exception is raised.
  2024-05-04  5:57 [PATCH] Bug fix: ensure P4 "err" is displayed when exception is raised Fahad Alrashed via GitGitGadget
@ 2024-05-06 12:01 ` Karthik Nayak
  2024-05-08 11:46 ` [PATCH v2] " Fahad Alrashed via GitGitGadget
  1 sibling, 0 replies; 6+ messages in thread
From: Karthik Nayak @ 2024-05-06 12:01 UTC (permalink / raw
  To: Fahad Alrashed via GitGitGadget, git; +Cc: Fahad Alrashed

[-- Attachment #1: Type: text/plain, Size: 3544 bytes --]

Hello Fahad,

"Fahad Alrashed via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Fahad Alrashed <fahad@keylock.net>
>
> Bug fix: During "git p4 clone" if p4 process returns

Nit: I haven't seen us use a prefix for the commit message. Also we use
a max line length of 72 characters (see .editorconfig). The commit
message seems to be wrapped at a much lower threshold.

> an error from the server, it will store it in variable

perhaps `in the 'err' variable` or `in a variable 'err'`.

> "err". The it will send a text command "die-now" to

s/The/Then

> git-fast-import. However, git-fast-import raises an
> exception: "fatal: Unsupported command: die-now"
> and err is never displayed. This patch ensures that
> err is dispayed using "finally:"
>
> Signed-off-by: Fahad Alrashed <fahad@keylock.net>
> ---
>     In git p4, git fast-import fails from die-now command and err (from
>     Perforce) is not shown
>
>     When importing from Perforce using git p4 clone <depot location>,
>     cloning works fine until Perforce command p4 raises an error. This error
>     message is stored in err variable then git-fast-import is sent a die-now
>     command to kill it. An exception is raised fatal: Unsupported command:
>     die-now.
>
>     This patch forces python to call die() with the err message returned
>     from Perforce.
>
>     This commit fixes the root cause of a bug that took me hours to find.
>     I'm sure many faced the cryptic error and declared that git-p4 is not
>     working for them.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1668%2Falrashedf%2Fmaster-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1668/alrashedf/master-v1
> Pull-Request: https://github.com/git/git/pull/1668
>
>  git-p4.py | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 28ab12c72b6..f1ab31d5403 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -3253,17 +3253,19 @@ def streamP4FilesCb(self, marshalled):
>              if self.stream_have_file_info:
>                  if "depotFile" in self.stream_file:
>                      f = self.stream_file["depotFile"]
> -            # force a failure in fast-import, else an empty
> -            # commit will be made
> -            self.gitStream.write("\n")
> -            self.gitStream.write("die-now\n")
> -            self.gitStream.close()
> -            # ignore errors, but make sure it exits first
> -            self.importProcess.wait()
> -            if f:
> -                die("Error from p4 print for %s: %s" % (f, err))
> -            else:
> -                die("Error from p4 print: %s" % err)
> +            try:
> +                # force a failure in fast-import, else an empty
> +                # commit will be made
> +                self.gitStream.write("\n")
> +                self.gitStream.write("die-now\n")
> +                self.gitStream.close()
> +                # ignore errors, but make sure it exits first
> +                self.importProcess.wait()
> +            finally:
> +                if f:
> +                    die("Error from p4 print for %s: %s" % (f, err))
> +                else:
> +                    die("Error from p4 print: %s" % err)
>

This part looks good.

>          if 'depotFile' in marshalled and self.stream_have_file_info:
>              # start of a new file - output the old one first
>
> base-commit: 235986be822c9f8689be2e9a0b7804d0b1b6d821
> --
> gitgitgadget

Thanks,
Karthik

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Bug fix: ensure P4 "err" is displayed when exception is raised.
  2024-05-04  5:57 [PATCH] Bug fix: ensure P4 "err" is displayed when exception is raised Fahad Alrashed via GitGitGadget
  2024-05-06 12:01 ` Karthik Nayak
@ 2024-05-08 11:46 ` Fahad Alrashed via GitGitGadget
  2024-05-08 16:53   ` Junio C Hamano
  2024-05-08 22:11   ` [PATCH v3] git-p4: show Perforce error to the user Fahad Alrashed via GitGitGadget
  1 sibling, 2 replies; 6+ messages in thread
From: Fahad Alrashed via GitGitGadget @ 2024-05-08 11:46 UTC (permalink / raw
  To: git; +Cc: Karthik Nayak, Fahad Alrashed, Fahad Alrashed

From: Fahad Alrashed <fahad@keylock.net>

During "git p4 clone" if p4 process returns an error from the server,
it will store the message in the 'err' variable. Then it will send a
text command "die-now" to git-fast-import. However, git-fast-import
raises an exception: "fatal: Unsupported command: die-now" and err is
never displayed. This patch ensures that err is dispayed using
"finally:".

Signed-off-by: Fahad Alrashed <fahad@keylock.net>
---
    In git p4, git fast-import fails from die-now command and err (from
    Perforce) is not shown
    
    When importing from Perforce using git p4 clone <depot location>,
    cloning works fine until Perforce command p4 raises an error. This error
    message is stored in err variable then git-fast-import is sent a die-now
    command to kill it. An exception is raised fatal: Unsupported command:
    die-now.
    
    This patch forces python to call die() with the err message returned
    from Perforce.
    
    This commit fixes the root cause of a bug that took me hours to find.
    I'm sure many faced the cryptic error and declared that git-p4 is not
    working for them.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1668%2Falrashedf%2Fmaster-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1668/alrashedf/master-v2
Pull-Request: https://github.com/git/git/pull/1668

Range-diff vs v1:

 1:  8dd2c730128 ! 1:  8d5b982bd08 Bug fix: ensure P4 "err" is displayed when exception is raised.
     @@ Metadata
       ## Commit message ##
          Bug fix: ensure P4 "err" is displayed when exception is raised.
      
     -    Bug fix: During "git p4 clone" if p4 process returns
     -    an error from the server, it will store it in variable
     -    "err". The it will send a text command "die-now" to
     -    git-fast-import. However, git-fast-import raises an
     -    exception: "fatal: Unsupported command: die-now"
     -    and err is never displayed. This patch ensures that
     -    err is dispayed using "finally:"
     +    During "git p4 clone" if p4 process returns an error from the server,
     +    it will store the message in the 'err' variable. Then it will send a
     +    text command "die-now" to git-fast-import. However, git-fast-import
     +    raises an exception: "fatal: Unsupported command: die-now" and err is
     +    never displayed. This patch ensures that err is dispayed using
     +    "finally:".
      
          Signed-off-by: Fahad Alrashed <fahad@keylock.net>
      


 git-p4.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index 28ab12c72b6..f1ab31d5403 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3253,17 +3253,19 @@ def streamP4FilesCb(self, marshalled):
             if self.stream_have_file_info:
                 if "depotFile" in self.stream_file:
                     f = self.stream_file["depotFile"]
-            # force a failure in fast-import, else an empty
-            # commit will be made
-            self.gitStream.write("\n")
-            self.gitStream.write("die-now\n")
-            self.gitStream.close()
-            # ignore errors, but make sure it exits first
-            self.importProcess.wait()
-            if f:
-                die("Error from p4 print for %s: %s" % (f, err))
-            else:
-                die("Error from p4 print: %s" % err)
+            try:
+                # force a failure in fast-import, else an empty
+                # commit will be made
+                self.gitStream.write("\n")
+                self.gitStream.write("die-now\n")
+                self.gitStream.close()
+                # ignore errors, but make sure it exits first
+                self.importProcess.wait()
+            finally:
+                if f:
+                    die("Error from p4 print for %s: %s" % (f, err))
+                else:
+                    die("Error from p4 print: %s" % err)
 
         if 'depotFile' in marshalled and self.stream_have_file_info:
             # start of a new file - output the old one first

base-commit: 235986be822c9f8689be2e9a0b7804d0b1b6d821
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Bug fix: ensure P4 "err" is displayed when exception is raised.
  2024-05-08 11:46 ` [PATCH v2] " Fahad Alrashed via GitGitGadget
@ 2024-05-08 16:53   ` Junio C Hamano
  2024-05-08 22:11   ` [PATCH v3] git-p4: show Perforce error to the user Fahad Alrashed via GitGitGadget
  1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2024-05-08 16:53 UTC (permalink / raw
  To: Fahad Alrashed via GitGitGadget; +Cc: git, Karthik Nayak, Fahad Alrashed

"Fahad Alrashed via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Fahad Alrashed <fahad@keylock.net>
> Subject: Re: [PATCH v2] Bug fix: ensure P4 "err" is displayed when exception is raised.

Our convention is to use the name of the area as the prefix, e.g.,

	git-p4: show Perforce error to the user

in the title.  Documentation/SubmittingPatches has more guidance on
the title, like omitting the full-stop at the end, and on the
proposed log message in general.

> During "git p4 clone" if p4 process returns an error from the server,
> it will store the message in the 'err' variable. Then it will send a
> text command "die-now" to git-fast-import. However, git-fast-import
> raises an exception: "fatal: Unsupported command: die-now" and err is
> never displayed.

Nicely explained.

> This patch ensures that err is dispayed using
> "finally:".

Instead, we write it more like

	Ensure that err is shown to the end user.

The implementation (i.e., catching an error with try/finally) can be
seen from the patch text.  What is more important to capture in the
proposed log message is what _effect_ the commit wanted to make,
which is a good way to show _why_ we are making the change.

The intent of the original code being to always die at this point.
Even though it is necessary to enclose the earlier part up to
.wait() inside a try block to catch an exception, the two calls to
die() do not have to be inside finally block (in other words,
finally block could be just a no-op, and the die() calls can be done
after the whole try/finally block that kills the fast-import by
sending die-now and makes sure .wait() sees the process go), which
may have made the intent of the fix even more clear, which is "we
use the try/finally construct only to work around an exception
thrown by killing the fast-import process".

The patch posted as-is is not wrong per-se, though.

Thanks.

> diff --git a/git-p4.py b/git-p4.py
> index 28ab12c72b6..f1ab31d5403 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -3253,17 +3253,19 @@ def streamP4FilesCb(self, marshalled):
>              if self.stream_have_file_info:
>                  if "depotFile" in self.stream_file:
>                      f = self.stream_file["depotFile"]
> -            # force a failure in fast-import, else an empty
> -            # commit will be made
> -            self.gitStream.write("\n")
> -            self.gitStream.write("die-now\n")
> -            self.gitStream.close()
> -            # ignore errors, but make sure it exits first
> -            self.importProcess.wait()
> -            if f:
> -                die("Error from p4 print for %s: %s" % (f, err))
> -            else:
> -                die("Error from p4 print: %s" % err)
> +            try:
> +                # force a failure in fast-import, else an empty
> +                # commit will be made
> +                self.gitStream.write("\n")
> +                self.gitStream.write("die-now\n")
> +                self.gitStream.close()
> +                # ignore errors, but make sure it exits first
> +                self.importProcess.wait()
> +            finally:
> +                if f:
> +                    die("Error from p4 print for %s: %s" % (f, err))
> +                else:
> +                    die("Error from p4 print: %s" % err)
>  
>          if 'depotFile' in marshalled and self.stream_have_file_info:
>              # start of a new file - output the old one first
>
> base-commit: 235986be822c9f8689be2e9a0b7804d0b1b6d821

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3] git-p4: show Perforce error to the user
  2024-05-08 11:46 ` [PATCH v2] " Fahad Alrashed via GitGitGadget
  2024-05-08 16:53   ` Junio C Hamano
@ 2024-05-08 22:11   ` Fahad Alrashed via GitGitGadget
  2024-05-09 15:30     ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Fahad Alrashed via GitGitGadget @ 2024-05-08 22:11 UTC (permalink / raw
  To: git; +Cc: Karthik Nayak, Fahad Alrashed, Fahad Alrashed

From: Fahad Alrashed <fahad@keylock.net>

During "git p4 clone" if p4 process returns an error from the server,
it will store the message in the 'err' variable. Then it will send a
text command "die-now" to git-fast-import. However, git-fast-import
raises an exception: "fatal: Unsupported command: die-now" and err is
never displayed. This patch ensures that err is shown to the end user.

Signed-off-by: Fahad Alrashed <fahad@keylock.net>
---
    In git p4, git fast-import fails from die-now command and err (from
    Perforce) is not shown
    
    When importing from Perforce using git p4 clone <depot location>,
    cloning works fine until Perforce command p4 raises an error. This error
    message is stored in err variable then git-fast-import is sent a die-now
    command to kill it. An exception is raised fatal: Unsupported command:
    die-now.
    
    This patch forces python to call die() with the err message returned
    from Perforce.
    
    This commit fixes the root cause of a bug that took me hours to find.
    I'm sure many faced the cryptic error and declared that git-p4 is not
    working for them.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1668%2Falrashedf%2Fmaster-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1668/alrashedf/master-v3
Pull-Request: https://github.com/git/git/pull/1668

Range-diff vs v2:

 1:  8d5b982bd08 ! 1:  16a0693b932 Bug fix: ensure P4 "err" is displayed when exception is raised.
     @@ Metadata
      Author: Fahad Alrashed <fahad@keylock.net>
      
       ## Commit message ##
     -    Bug fix: ensure P4 "err" is displayed when exception is raised.
     +    git-p4: show Perforce error to the user
      
          During "git p4 clone" if p4 process returns an error from the server,
          it will store the message in the 'err' variable. Then it will send a
          text command "die-now" to git-fast-import. However, git-fast-import
          raises an exception: "fatal: Unsupported command: die-now" and err is
     -    never displayed. This patch ensures that err is dispayed using
     -    "finally:".
     +    never displayed. This patch ensures that err is shown to the end user.
      
          Signed-off-by: Fahad Alrashed <fahad@keylock.net>
      


 git-p4.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index 28ab12c72b6..f1ab31d5403 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3253,17 +3253,19 @@ def streamP4FilesCb(self, marshalled):
             if self.stream_have_file_info:
                 if "depotFile" in self.stream_file:
                     f = self.stream_file["depotFile"]
-            # force a failure in fast-import, else an empty
-            # commit will be made
-            self.gitStream.write("\n")
-            self.gitStream.write("die-now\n")
-            self.gitStream.close()
-            # ignore errors, but make sure it exits first
-            self.importProcess.wait()
-            if f:
-                die("Error from p4 print for %s: %s" % (f, err))
-            else:
-                die("Error from p4 print: %s" % err)
+            try:
+                # force a failure in fast-import, else an empty
+                # commit will be made
+                self.gitStream.write("\n")
+                self.gitStream.write("die-now\n")
+                self.gitStream.close()
+                # ignore errors, but make sure it exits first
+                self.importProcess.wait()
+            finally:
+                if f:
+                    die("Error from p4 print for %s: %s" % (f, err))
+                else:
+                    die("Error from p4 print: %s" % err)
 
         if 'depotFile' in marshalled and self.stream_have_file_info:
             # start of a new file - output the old one first

base-commit: 235986be822c9f8689be2e9a0b7804d0b1b6d821
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] git-p4: show Perforce error to the user
  2024-05-08 22:11   ` [PATCH v3] git-p4: show Perforce error to the user Fahad Alrashed via GitGitGadget
@ 2024-05-09 15:30     ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2024-05-09 15:30 UTC (permalink / raw
  To: Fahad Alrashed via GitGitGadget; +Cc: git, Karthik Nayak, Fahad Alrashed

"Fahad Alrashed via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Fahad Alrashed <fahad@keylock.net>
>
> During "git p4 clone" if p4 process returns an error from the server,
> it will store the message in the 'err' variable. Then it will send a
> text command "die-now" to git-fast-import. However, git-fast-import
> raises an exception: "fatal: Unsupported command: die-now" and err is
> never displayed. This patch ensures that err is shown to the end user.
>
> Signed-off-by: Fahad Alrashed <fahad@keylock.net>
> ---

Looking good.  Queued.  Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-09 15:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-04  5:57 [PATCH] Bug fix: ensure P4 "err" is displayed when exception is raised Fahad Alrashed via GitGitGadget
2024-05-06 12:01 ` Karthik Nayak
2024-05-08 11:46 ` [PATCH v2] " Fahad Alrashed via GitGitGadget
2024-05-08 16:53   ` Junio C Hamano
2024-05-08 22:11   ` [PATCH v3] git-p4: show Perforce error to the user Fahad Alrashed via GitGitGadget
2024-05-09 15:30     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.