Patchwork [3,of,3,main-line-of-work] changelog: register changelog.i.a as a temporary file

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 13, 2014, 5:05 p.m.
Message ID <0dca9f044cecb79a4ad8.1415898301@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6710/
State Accepted
Commit e44399c494ab23cefb8c99087529f9b4b06d398e
Headers show

Comments

Pierre-Yves David - Nov. 13, 2014, 5:05 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1415466489 0
#      Sat Nov 08 17:08:09 2014 +0000
# Node ID 0dca9f044cecb79a4ad88e11c94b4bd35eb19527
# Parent  979d2d237821deea966ed077d2c2d42e44927990
changelog: register changelog.i.a as a temporary file

The file is registered to make sure the transaction is cleaned up in all cases.
Matt Mackall - Nov. 13, 2014, 10:46 p.m.
On Thu, 2014-11-13 at 17:05 +0000, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1415466489 0
> #      Sat Nov 08 17:08:09 2014 +0000
> # Node ID 0dca9f044cecb79a4ad88e11c94b4bd35eb19527
> # Parent  979d2d237821deea966ed077d2c2d42e44927990
> changelog: register changelog.i.a as a temporary file

These are queued for default, thanks.

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -271,11 +271,15 @@  class changelog(revlog.revlog):
     def _writepending(self, tr):
         "create a file containing the unfinalized state for pretxnchangegroup"
         if self._delaybuf:
             # make a temporary copy of the index
             fp1 = self._realopener(self.indexfile)
-            fp2 = self._realopener(self.indexfile + ".a", "w")
+            pendingfilename = self.indexfile + ".a"
+            # register as a temp file to ensure cleanup on failure
+            tr.registertmp(pendingfilename)
+            # write existing data
+            fp2 = self._realopener(pendingfilename, "w")
             fp2.write(fp1.read())
             # add pending data
             fp2.write("".join(self._delaybuf))
             fp2.close()
             # switch modes so finalize can simply rename
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -146,10 +146,23 @@  more there after
   abort: pretxncommit.forbid1 hook exited with status 1
   [255]
   $ hg -q tip
   4:539e4b31b6dc
 
+(Check that no 'changelog.i.a' file were left behind)
+
+  $ ls -1 .hg/store/
+  00changelog.i
+  00manifest.i
+  data
+  fncache
+  journal.phaseroots
+  phaseroots
+  undo
+  undo.phaseroots
+
+
 precommit hook can prevent commit
 
   $ echo "precommit.forbid = python \"$TESTDIR/printenv.py\" precommit.forbid 1" >> .hg/hgrc
   $ hg commit -m 'fail' -d '4 0'
   precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10