Commit Graph

133 Commits

Author SHA1 Message Date
Pierre-Yves David
92bf4dcbdc transaction: pass the transaction to 'pending' callback
The callback will likely need to perform some operation related to the
transaction (eg: backing files up). So we better pass the current transaction as
the callback argument. Otherwise callback that needs it has to rely on horrible
weak reference trick.

The first foreseen user of this is changelog._writepending. We would like it to
register the temporary file it create for cleanup purpose.
2014-11-08 16:27:50 +00:00
Pierre-Yves David
6ab03ec965 transaction: gather backupjournal logic together in the __init__
The initialisation of file-backup related variable were a bit scattered, we
gather them together.
2014-11-05 10:22:17 +00:00
Pierre-Yves David
b91f1df8cd transaction: handle missing file in backupentries (instead of using entries)
The case where a backup of a missing file was requested was previously
handled by the 'entries' list. As the 'backupentries' is about to gain
ability to backup files outside of '.hg/store', we want it to be able
to handle the missing file too.

Reminder: using 'addbackup' on a missing file means that such file needs to be
deleted if we rollback the transaction.
2014-11-05 01:38:48 +00:00
Pierre-Yves David
1d1e3a5b9c transaction: factorise append-only file registration
The addition is done in two different places but differs slightly. We factorise
this addition to ensure it is consistent in all places.
2014-11-05 10:13:01 +00:00
Pierre-Yves David
b9cd014175 transaction: document tr.add 2014-11-05 13:00:48 +00:00
Pierre-Yves David
9a1f491fee transaction: drop backupentries logic from startgroup and endgroup
The `startgroup` and `endgroup` methods are used in a very specific
context to wrap a very specific operation (revlog truncation). It does
not make sense to perform any other operations during such a "group"
(eg:file backup). There is currently no user of backupfile during a
"group" so we drop the group-specific code and restrict authorized
operations during "group".
2014-11-05 10:05:38 +00:00
Pierre-Yves David
483eb136e7 transaction: document startgroup and endgroup
These enigmatic methods are only used in repair. We document them to clarify
there purpose and user.
2014-11-05 10:00:15 +00:00
Pierre-Yves David
36a4f98617 transaction: mark backup-related attributes private
As the transaction is gaining more functions and attributes, it is important to clarify
what is part of the public API.
2014-11-05 09:31:57 +00:00
Pierre-Yves David
63c82fbc8a transaction: document the contents of tr.backupentries
Now that all items are known we can document it.
2014-11-05 01:30:29 +00:00
Pierre-Yves David
9d5b590e75 transaction: drop the third item in tr.backupentries
This third item is always None and never used.
2014-11-05 01:33:16 +00:00
Pierre-Yves David
bff90c5de3 transaction: allow registering a post-close callback
The addchangegroup code considers the transaction done after a 'tr.close()' call
and schedules the hook's execution for after lock release. In the nested transaction
case, the transaction is not yet committed and we must delay this scheduling.
We add an 'addpostclose' method (like the 'addpending' and 'addfinalize' ones) that
registers code to be run if the transaction is successfully committed.
2014-10-28 14:24:43 +01:00
Pierre-Yves David
7ae09eecbb transaction: allow registering a finalization callback
The new 'addfinalize' method allows people to register a callback to
be triggered when the transaction is closed. This aims to get rid of
explicit calls to 'changelog.finalize'. This also obsoletes the
'onclose' function but removing it is not in the scope of this series.
2014-10-17 22:28:09 -07:00
Pierre-Yves David
16a2a58b80 transaction: add 'writepending' logic
The contents of the transaction must be flushed to disk before running
a hook. But it must be flushed to a special file so that the normal
reader does not use it. This logic is currently in the changelog only.
We add some facility to register such operations in the transaction
itself.
2014-10-17 21:19:54 -07:00
Pierre-Yves David
34fb3a3cdd transaction: only generate file when we actually close the transaction
Before this change, the file were written for every call to `tr.close()`
exposing data to reader far too early.
2014-10-17 21:25:48 -07:00
Pierre-Yves David
245e001eb5 transaction: extract file generation into its own function
We extract the code generating files into its own function. We are
about to move this code around to fix a bug. We'll need it in a
function soon to reuse it for "pending" logic. So we move the code
into a function instead of moving it twice.
2014-09-29 00:59:25 -07:00
Durham Goode
fd796ba36d transactions: change backupfiles format to use newlines
Previously the journal.backupfiles file was delimited by \0. Now we delimit it
using \n (same as the journal file). This allows us to change the number of
values in each line more easily, rather than relying on the count of \0's.
2014-10-21 12:38:28 -07:00
Durham Goode
646f35dbec transactions: add version number to journal.backupfiles
The transaction format will be changing a bit over the next releases, so let's
go ahead and add a version number to make backwards compatibility easier. This
whole file format was broken prior to 3.2 (see previous patch), so changing it
now is pretty low risk.
2014-10-21 11:37:29 -07:00
Durham Goode
faf9d65282 transactions: fix hg recover with fncache backups
The transaction backupfiles logic was broken for 'hg recover'.  The file format
is XXX\0XXX\0YYY\0YYY\0 but the parser did a couple things wrong. 1) It went one
step beyond the final \0 and tried to read past the end of the array. 2)
array[i:i+1] returns a single item, instead of two items as intended.

Added a test to catch it, which turns out to be the first actual 'hg recover'
test.
2014-10-20 16:53:56 -07:00
Pierre-Yves David
12b0405a08 transaction: allow generating file outside of store
We allow a vfs argument to `addfilegenerator`. This allows generating files outside
of the store directory like bookmarks. However, this is not really working since
we do not have the infrastructure to backup and restore files outside of store.
By chance, the bookmark file is already backed up by another mechanism so we can
restrict this new feature to bookmarks (which is our only interest here) and
proceed.
2014-09-28 00:36:42 -07:00
Pierre-Yves David
a80cda9824 transaction: work around and document issue with file backup
The backup restoration is actually hard-coded for the main file. And this
hard-coded list is the only one used when repairing an interrupted transaction
from another process.

Solving this problem is out of the scope of this series so we document it and
work around its implications.
2014-10-01 21:40:44 -05:00
Mads Kiilerich
440a607ef9 cleanup: name unused variables using convention of leading _
This helps checker tools ... and readability for those who knows and follows
the convention.
2014-08-15 04:37:46 +02:00
Mads Kiilerich
23da6c1d98 cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
_ is usually used for i18n markup but we also used it for I-don't-care
variables.

Instead, name don't-care variables in a slightly descriptive way but use the _
prefix to designate unused variable.

This will mute some pyflakes "import '_' ... shadowed by loop variable"
warnings.
2014-08-15 16:20:47 +02:00
Pierre-Yves David
3f8b890149 transaction: add a file generation mechanism
A new `transaction.addfilegenerator` function is added. It allows external code
to register files to be generated. See inline documentation for details.

It is important to gather all file creation logic on the transaction
as at some point we'll want to mimic the "pre-transaction-commit"
logic that we use for revlog. I'm refering to the logic that lets
hooks see the result of the transaction before it actually gets
committed.
2014-08-07 14:40:02 -07:00
Pierre-Yves David
98693f71e9 transaction: backup file in a dedicated "namespace"
File backup may conflict with other "journal.*" file. We add a fixed part in the
backup name file to prevent it.
2014-08-07 10:54:17 -07:00
Pierre-Yves David
c81f99d5f9 transaction: use self.journal to create backup file
Transaction journal name is "journal" in most case, but it can be something else.
We use the appropriate attribute to create the file.
2014-08-07 11:56:32 -07:00
Durham Goode
340117ecce transaction: fix file descriptor leak for journal.backupfiles
The journal.backupfiles descriptor wasn't being closed. This resulted in
hgsubversion test runs having a bagillion descriptors open, which crashed on
platforms with low open file limits (like OSX).
2014-04-30 15:36:38 -07:00
Pierre-Yves David
18d2864e3c transaction: add a notion of hook arguments
It is now possible to register parameters to be used when invoking hooks in this
transaction. This will cope with the fact that bundle2 adds multiple data types
in a single transaction.

Do not expect any wide and consistent usages of this in the next release. This
will be used by bundle2 experiments first. It will be made better for the release
after.
2014-04-17 17:04:59 -04:00
Matt Mackall
2cef67b922 transaction: drop extra import caught by pyflakes 2014-04-02 13:41:23 -05:00
Durham Goode
1fd6146a66 transaction: add support for non-append files
This adds support for normal, non-append-only files in transactions.  For
example, .hg/store/fncache and .hg/store/phaseroots should be written as part of
the transaction, but are not append only files.

This adds a journal.backupfiles along side the normal journal. This tracks which
files have been backed up as part of the transaction.  transaction.addbackup()
creates a backup of the file (using a hardlink), which is later used to recover
in the event of the transaction failing.

Using a seperate journal allows the repository to still be used by older
versions of Mercurial. A future patch will use this functionality and add tests
for it.
2014-03-24 15:21:51 -07:00
Durham Goode
503655f175 transaction: add onclose/onabort hook for pre-close logic
Adds an optional onclose parameter to transactions that gets called just before
the transaction is committed. This allows things that build up data over the
course of the transaction (like the fncache) to commit their data.

Also adds onabort. It's not used, but will allow extensions to hook into onclose
and onabort to provide transaction support.
2014-03-24 15:57:47 -07:00
Matt Mackall
0122021cb0 journal: report parsing errors on recover/rollback (issue4172) 2014-02-17 14:49:56 -06:00
FUJIWARA Katsunori
ed122f7175 transaction: take journal file path relative to vfs to use file API via vfs 2013-11-12 16:23:52 +09:00
FUJIWARA Katsunori
cf2ceb0ac9 transaction: unlink target file via vfs
Before this patch, unlink target file is once opened before unlinking,
because "opener" before vfs migration doesn't have "unlink()"
function.

This patch uses "vfs.unlink()" instead of "open()" and "fp.name".
2013-11-12 16:23:52 +09:00
Mads Kiilerich
2f4504e446 fix trivial spelling errors 2012-08-15 22:38:42 +02:00
Brodie Rao
a706d64a2c cleanup: replace naked excepts with except Exception: ... 2012-05-12 16:02:46 +02:00
Adrian Buehlmann
76e8469c0d transaction: use posixfile and unlink from util
instead of open() and os.unlink()

Avoids potential issues with file access on Windows (e.g. AV-scanners).
2011-02-15 14:41:49 +01:00
Dan Villiom Podlaski Christiansen
ec590d5cd4 explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
2010-12-24 15:23:01 +01:00
Patrick Mezard
3153012325 cleanup: typos 2010-07-26 22:29:49 +02:00
Ronny Pfannschmidt
4362059a98 make transactions work on non-refcounted python implementations 2010-05-27 17:47:40 +02:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Benoit Boissinot
8265d7b666 transaction: initialize self.journal to None after deletion
This avoid a warning when having an empty transaction, where hg would try to
delete the journal twice.
2010-01-11 21:40:19 +01:00
Sune Foldager
46c649736d transaction: always remove empty journal on abort
When transactions without entries were aborted, the journal (of size 0) was not
unlinked, which prevents subsequent operations until hg recover is run on the
repository.

We also make sure the journal is unlinked when committing, even if the provided
hook doesn't do so.
2009-11-02 10:19:14 +01:00
Benoit Boissinot
864f95d532 transaction: more specific exceptions, os.unlink can raise OSError 2009-10-31 18:17:59 +01:00
Greg Ward
b42121b634 transaction: document close(), abort() methods 2009-07-21 20:31:45 -04:00
Henrik Stuart
2108f47c49 transaction: fix uncaught ENOENT (issue1724)
The opener raises an IOError on errors where transaction expects an
OSError.
2009-07-07 19:24:52 +02:00
Henrik Stuart
ec8d726ba0 transaction: add atomic groups to transaction logic
When performing a strip operation on a repository, it is vital that all the
truncations are performed, or that none of them are. This is done by adding
support for writing a number of entries in a single operation.

Co-contributor: Sune Foldager <cryo@cyanite.org>
2009-05-11 21:12:40 +02:00
Henrik Stuart
d0b7d204d4 transaction: refactor transaction.abort and rollback to use the same code
This adds a change to the way that abort is processed, as it will not continue
truncating files beyond the first failure, otherwise the respective
functionality is maintained, i.e. abort will not unlink files, but rollback
will.

Co-contributor: Sune Foldager <cryo@cyanite.org>
2009-05-04 15:31:57 +02:00
Henrik Stuart
206e98a6fb transaction: reset transaction on abort
Prevent the use of the transaction after it has been aborted.

Co-contributor: Sune Foldager <cryo@cyanite.org>
2009-04-19 20:02:32 +02:00
Henrik Stuart
db9b1644e1 transaction: ensure finished transactions are not reused
All transactional methods on the transaction class have had a decorator
added that ensures the transaction is running.

Co-contributor: Sune Foldager <cryo@cyanite.org>
2009-04-24 09:56:53 +02:00
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Henrik Stuart
c57f2e28ee transaction: only delete journal on successful abort/commit
This solves that the journal file was always deleted when the transaction
was deleted, no matter whether the abort (rollback) succeeded or not.
Thus, never supporting a hg recover. The journal file is now only deleted
on close (commit) or a successful abort.
2009-04-16 15:41:25 +02:00
Benoit Boissinot
becc8b09ae add missing import from d329ec89ce55 2008-11-07 18:42:43 +01:00
Benoit Boissinot
a95f4bd10d fix restart of interrupted recover
Ignore missing files if they are already removed.
Thanks maelcum on IRC for reporting it.
2008-11-07 18:41:22 +01:00
Brendan Cully
9d21508cbe rollback: unlink files truncated to length 0 2008-03-31 23:02:25 -07:00
Alexis S. L. Carvalho
6b4c649e55 make the journal/undo files from transactions inherit the mode from .hg/store 2008-02-09 18:38:54 -02:00
Matt Mackall
a68910fcf1 transactions: don't show a backtrace when journal exists
Now we simply print a message on how to recover.
2008-01-16 11:32:25 -06:00
Matt Mackall
296d6a7cb8 Simplify i18n imports 2006-12-14 20:25:19 -06:00
Matt Mackall
f17a4e1934 Replace demandload with new demandimport 2006-12-13 13:27:09 -06:00
Vadim Gelfer
dc377b58c1 update copyrights. 2006-08-12 12:30:02 -07:00
Vadim Gelfer
9a0c813fdc use demandload more. 2006-06-20 23:58:21 -07:00
Chris Mason
4841dc10da Fix transaction handling during interleaved file split. 2006-04-17 13:19:58 -04:00
mason@suse.com
9090463607 Automatic nesting into running transactions in the same repository.
This associates a transaction handle with a given repository object, and
any additional calls to start new transactions reuse that transaction.

For the 2700 patch import run, this brings the system time down from
1m20s to 50s, mostly by skipping backups of the dirstate file.

(note, this patch does not change hg import to use the nested transaction,
mq is the only user right now)
2006-02-28 12:24:54 -06:00
Eric Hopper
dd6718fc31 Convert all classes to new-style classes by deriving them from object. 2005-11-18 22:48:47 -08:00
twaldmann@thinkmo.de
55d74a6b77 fixed some stuff pychecker shows, marked unclear/wrong stuff with XXX 2005-11-14 03:59:35 +02:00
Benoit Boissinot
06e39e559b i18n part2: use '_' for all strings who are part of the user interface 2005-10-18 18:38:39 -07:00
Benoit Boissinot
e38e94088a i18n first part: make '_' available for files who need it 2005-10-18 18:37:48 -07:00
Bart Trojanowski
3529a29a40 [PATCH] raise exceptions with Exception subclasses
Fixed the patch.  Using Exception subclasses.

(tweaked by mpm)
2005-08-26 19:08:25 -07:00
benoit.boissinot@ens-lyon.fr
95b97f01ed pep-0008 cleanup
- Don't use spaces around the '=' sign when used to indicate a
      keyword argument or a default parameter value.
2005-08-26 13:06:58 +02:00
mpm@selenic.com
e4d910ab82 Fix undo after aborted commit bug
Commit would overwrite undo.dirstate unconditionally, so an undo after
an aborted commit would restore the dirstate from the aborted commit
and not the prior transaction.

This copies dirstate to journal.dirstate and moves it after a
successful transaction.
2005-07-27 18:16:20 -08:00
mpm@selenic.com
4394004b4a Remove all remaining print statements
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Remove all remaining print statements

Convert most prints to ui.warn or ui.write
Pass a write function into transactions

manifest hash: d1b0af7a344fc087a5acfe3ae87b782c20d043e0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCx1Q3ywK+sNU5EO8RAqSTAJwM5t/m+JOlf2ZXOjuItCSdFiubcwCdFm3G
HoicikSYpTgfCj2pIRfyLjo=
=Loqo
-----END PGP SIGNATURE-----
2005-07-02 18:57:59 -08:00
mpm@selenic.com
0420d357e1 transaction: nullify journal after close()
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

transaction: nullify journal after close()

This keeps us from trying to cleanup in __del__.

bug spotted by K Thananchayan <thananck@yahoo.com>

manifest hash: 1f4c5fa43d2458cdcb6ec0f0a7066b3c3e699f33
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCxwQ6ywK+sNU5EO8RAuGhAJ9+BnKILwRCF9EKlPTz2zptiysQ/QCgsB3s
VKIehiStv+ibWQQi15k4mwk=
=nZD1
-----END PGP SIGNATURE-----
2005-07-02 13:16:42 -08:00
mpm@selenic.com
b292364b4f transaction: __del__ should do nothing if the journal already exists
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

transaction: __del__ should do nothing if the journal already exists

manifest hash: c85f747ca762b7c446d306cbd7a20f8e566557fb
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCxXbTywK+sNU5EO8RAvjsAKCcTSzN9OjtoAdaZgtjDs9380ia7ACfcXsx
FcNESqr4nX9b97WTGszJs48=
=C2sL
-----END PGP SIGNATURE-----
2005-07-01 09:01:07 -08:00
mpm@selenic.com
0fb5db6915 Whitespace cleanups
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whitespace cleanups

manifest hash: ac954bc3a4f034c12638a259ecd65841f5b63c5c
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCwuubywK+sNU5EO8RAluIAJ98XQpNdZUpSmYKgDmrMRlbL76ZzQCfes0t
rknNUN/PhtyA4bzL646dOz4=
=UyCE
-----END PGP SIGNATURE-----
2005-06-29 10:42:35 -08:00
mpm@selenic.com
5e62f2ce10 [PATCH] rename under the other OS
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[PATCH] rename under the other OS

From: K Thananchayan <thananck@yahoo.com>

Rename fails under windows if dest file exists. This
patch add a rename method to util module that removes
the dest file and retries if initial attempt fails.

manifest hash: 2744d9fd1717e15133b411a269df909fa8ec0faf
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCuNzDywK+sNU5EO8RAsPBAJ9NQN3bTuJvTem5x+utGnoMkhYc0QCbBFSJ
PoMP69H1UnVE6drFlnlFE0s=
=pePw
-----END PGP SIGNATURE-----
2005-06-21 19:36:35 -08:00
mpm@selenic.com
683f21be6a Implement recover and undo commands
This adds an interface to transaction to rollback with a given journal file
and commands to rollback an existing .hg/journal or .hg/undo.
2005-05-26 09:04:54 -08:00
mpm@selenic.com
7a540c10d5 Warn if we fail to truncate something 2005-05-20 17:20:39 -08:00
mpm@selenic.com
2bbb8b5a72 Beginnings of transaction undo support 2005-05-18 16:31:51 -08:00
mpm@selenic.com
60afa3551c Attempt to recover journal automatically 2005-05-10 00:32:05 -08:00
mpm@selenic.com
97820ba3c6 Fix multiple changes to file per transaction 2005-05-10 00:31:00 -08:00
mpm@selenic.com
89e337b327 Fix empty transaction destruction 2005-05-04 09:32:39 -08:00
mpm@selenic.com
78a55d241c Delete journal on destruction even if there are no entries to replay. 2005-05-04 09:30:56 -08:00
mpm@selenic.com
ca8cb8ba67 Add back links from file revisions to changeset revisions
Add simple transaction support
Add hg verify
Improve caching in revlog
Fix a bunch of bugs
Self-hosting now that the metadata is close to finalized
2005-05-03 13:16:10 -08:00