diff --git a/mercurial/patch.py b/mercurial/patch.py
index 557a083453c968c288bb22e531740e9478f656b0_bWVyY3VyaWFsL3BhdGNoLnB5..4e2fb0ad00a97eaff8bc34d82606afa99a67cfda_bWVyY3VyaWFsL3BhdGNoLnB5 100644
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1859,7 +1859,7 @@
             # set numbers to 0 anyway when starting new file
             adds, removes, isbinary = 0, 0, False
             if line.startswith('diff --git a/'):
-                filename = gitre.search(line).group(1)
+                filename = gitre.search(line).group(2)
             elif line.startswith('diff -r'):
                 # format: "diff -r ... -r ... filename"
                 filename = diffre.search(line).group(1)
diff --git a/tests/test-glog.t b/tests/test-glog.t
index 557a083453c968c288bb22e531740e9478f656b0_dGVzdHMvdGVzdC1nbG9nLnQ=..4e2fb0ad00a97eaff8bc34d82606afa99a67cfda_dGVzdHMvdGVzdC1nbG9nLnQ= 100644
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1853,7 +1853,7 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     copy a b
   |
-  |   a |  0
+  |   b |  0
   |   1 files changed, 0 insertions(+), 0 deletions(-)
   |
 
@@ -1886,7 +1886,7 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     copy a b
   |
-  |   a |  0
+  |   b |  0
   |   1 files changed, 0 insertions(+), 0 deletions(-)
   |
   o  changeset:   0:f8035bb17114