Patchwork [V2] extdata: show debug message if external command exits with non-zero status

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 4, 2017, 2:12 p.m.
Message ID <82606a8703b6f3b297fd.1507126367@mimosa>
Download mbox | patch
Permalink /patch/24483/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 4, 2017, 2:12 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1506856910 -3600
#      Sun Oct 01 12:21:50 2017 +0100
# Node ID 82606a8703b6f3b297fd0ed6d3e45e43ecd548de
# Parent  b3a36705720f5ed1e7cc5129b27450ca59c7952b
extdata: show debug message if external command exits with non-zero status

This isn't fatal because it's quite common for grep to exit with 1. Thanks to
Foozy for spotting this.
Augie Fackler - Oct. 10, 2017, 1:02 a.m.
On Wed, Oct 04, 2017 at 11:12:47PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1506856910 -3600
> #      Sun Oct 01 12:21:50 2017 +0100
> # Node ID 82606a8703b6f3b297fd0ed6d3e45e43ecd548de
> # Parent  b3a36705720f5ed1e7cc5129b27450ca59c7952b
> extdata: show debug message if external command exits with non-zero status

queued, thanks

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1065,6 +1065,10 @@  def extdatasource(repo, source):
     finally:
         if proc:
             proc.communicate()
+            if proc.returncode != 0:
+                # not an error so 'cmd | grep' can be empty
+                repo.ui.debug("extdata command '%s' %s\n"
+                              % (cmd, util.explainexit(proc.returncode)[0]))
         if src:
             src.close()
 
diff --git a/tests/test-extdata.t b/tests/test-extdata.t
--- a/tests/test-extdata.t
+++ b/tests/test-extdata.t
@@ -12,6 +12,7 @@  test revset support
   > filedata = file:extdata.txt
   > notes = notes.txt
   > shelldata = shell:cat extdata.txt | grep 2
+  > emptygrep = shell:cat extdata.txt | grep empty
   > EOF
   $ cat <<'EOF' > extdata.txt
   > 2 another comment on 2
@@ -42,6 +43,12 @@  test weight of extdata() revset
     (symbol '3'))
   3
 
+test non-zero exit of shell command
+
+  $ hg log -qr "extdata(emptygrep)"
+  $ hg log -qr "extdata(emptygrep)" --debug
+  extdata command 'cat extdata.txt | grep empty' exited with status * (glob)
+
 test bad extdata() revset source
 
   $ hg log -qr "extdata()"