changeset 13104:5dac0d04b838

merge with stable
author Matt Mackall <mpm@selenic.com>
date Wed, 08 Dec 2010 13:12:12 -0600
parents 37d0fe7a14da (current diff) 6e79a3bb8c79 (diff)
children c869bd9e1193 4a13ca2c21ce 122f8a5e02db
files hgext/bookmarks.py mercurial/archival.py mercurial/patch.py
diffstat 4 files changed, 86 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/bookmarks.py	Wed Dec 08 11:18:26 2010 -0600
+++ b/hgext/bookmarks.py	Wed Dec 08 13:12:12 2010 -0600
@@ -44,8 +44,14 @@
     can be copied back on rollback.
     '''
     refs = repo._bookmarks
-    if os.path.exists(repo.join('bookmarks')):
-        util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
+
+    try:
+        bms = repo.opener('bookmarks').read()
+    except IOError:
+        bms = None
+    if bms is not None:
+        repo.opener('undo.bookmarks', 'w').write(bms)
+
     if repo._bookmarkcurrent not in refs:
         setcurrent(repo, None)
     wlock = repo.wlock()
--- a/mercurial/archival.py	Wed Dec 08 11:18:26 2010 -0600
+++ b/mercurial/archival.py	Wed Dec 08 13:12:12 2010 -0600
@@ -70,6 +70,8 @@
             self.fileobj.write('\010')                 # compression method
             # Python 2.6 deprecates self.filename
             fname = getattr(self, 'name', None) or self.filename
+            if fname and fname.endswith('.gz'):
+                fname = fname[:-3]
             flags = 0
             if fname:
                 flags = gzip.FNAME
--- a/mercurial/patch.py	Wed Dec 08 11:18:26 2010 -0600
+++ b/mercurial/patch.py	Wed Dec 08 13:12:12 2010 -0600
@@ -485,6 +485,15 @@
         for x, s in enumerate(self.lines):
             self.hash.setdefault(s, []).append(x)
 
+    def makerejlines(self, fname):
+        base = os.path.basename(fname)
+        yield "--- %s\n+++ %s\n" % (base, base)
+        for x in self.rej:
+            for l in x.hunk:
+                yield l
+                if l[-1] != '\n':
+                    yield "\n\ No newline at end of file\n"
+
     def write_rej(self):
         # our rejects are a little different from patch(1).  This always
         # creates rejects in the same form as the original patch.  A file
@@ -499,16 +508,9 @@
             _("%d out of %d hunks FAILED -- saving rejects to file %s\n") %
             (len(self.rej), self.hunks, fname))
 
-        def rejlines():
-            base = os.path.basename(self.fname)
-            yield "--- %s\n+++ %s\n" % (base, base)
-            for x in self.rej:
-                for l in x.hunk:
-                    yield l
-                    if l[-1] != '\n':
-                        yield "\n\ No newline at end of file\n"
-
-        self.writelines(fname, rejlines())
+        fp = self.opener(fname, 'w')
+        fp.writelines(self.makerejlines(self.fname))
+        fp.close()
 
     def apply(self, h):
         if not h.complete():
--- a/tests/test-mq-eol.t	Wed Dec 08 11:18:26 2010 -0600
+++ b/tests/test-mq-eol.t	Wed Dec 08 13:12:12 2010 -0600
@@ -141,3 +141,67 @@
   $ hg qpop
   popping eol.diff
   patch queue now empty
+  $ cd ..
+
+
+Test .rej file EOL are left unchanged
+
+  $ hg init testeol
+  $ cd testeol
+  $ python -c "file('a', 'wb').write('1\r\n2\r\n3\r\n4')"
+  $ hg ci -Am adda
+  adding a
+  $ python -c "file('a', 'wb').write('1\r\n2\r\n33\r\n4')"
+  $ hg qnew patch1
+  $ hg qpop
+  popping patch1
+  patch queue now empty
+  $ python -c "file('a', 'wb').write('1\r\n22\r\n33\r\n4')"
+  $ hg ci -m changea
+
+  $ hg --config 'patch.eol=LF' qpush
+  applying patch1
+  patching file a
+  Hunk #1 FAILED at 0
+  1 out of 1 hunks FAILED -- saving rejects to file a.rej
+  patch failed, unable to continue (try -v)
+  patch failed, rejects left in working dir
+  errors during apply, please fix and refresh patch1
+  [2]
+  $ hg qpop
+  popping patch1
+  patch queue now empty
+  $ cat a.rej
+  --- a
+  +++ a
+  @@ -1,4 +1,4 @@
+   1\r (esc)
+   2\r (esc)
+  -3\r (esc)
+  +33\r (esc)
+   4
+  \ No newline at end of file
+
+  $ hg --config 'patch.eol=auto' qpush
+  applying patch1
+  patching file a
+  Hunk #1 FAILED at 0
+  1 out of 1 hunks FAILED -- saving rejects to file a.rej
+  patch failed, unable to continue (try -v)
+  patch failed, rejects left in working dir
+  errors during apply, please fix and refresh patch1
+  [2]
+  $ hg qpop
+  popping patch1
+  patch queue now empty
+  $ cat a.rej
+  --- a
+  +++ a
+  @@ -1,4 +1,4 @@
+   1\r (esc)
+   2\r (esc)
+  -3\r (esc)
+  +33\r (esc)
+   4
+  \ No newline at end of file
+  $ cd ..