##// END OF EJS Templates
localrepo.commit: normalize commit message even for rawcommit....
localrepo.commit: normalize commit message even for rawcommit. This normalization consists of: - stripping trailing whitespace - always using "\n" as the line separator I think the main reason rawcommit was skipping this normalization was an attempt to preserve hashes during an hg->hg conversion. While this is a nice goal, it's not particularly interesting in practice. Since SHA-1 is so strong, the only safe way to do it is to have absolutely identical revisions. But: - if the original revision was created with a recent version of hg, the commit message will be the same, with or without that normalization - if it was created with an ancient version of hg that didn't do any normalization, even if the commit message is identical, the file list in the changelog is likely to be different (e.g. no removed files), and there were some old issues with e.g. extra file merging, which will end up changing the hash anyway - in any case, if one *really* has to preserve hashes, it's easier (and faster) to fake a partial conversion using something like: hg clone -U -r rev orig-repo new-repo hg -R new-repo log --template '#node# #node#\n' > new-repo/.hg/shamap Additionally, we've had some reports of problems arising from this lack of normalization - e.g. issue871, and a user that was wondering why hg export/hg import was not preserving hashes when there was nothing unusual going on (it was just import doing the normalization that had been skipped). This also means that it's even more unlikely to get identical revisions when going $VCS->hg->$VCS.

File last commit:

r6065:53ed9b40 default
r6254:3667b6e4 default
Show More
transaction.py
104 lines | 2.9 KiB | text/x-python | PythonLexer
# transaction.py - simple journalling scheme for mercurial
#
# This transaction scheme is intended to gracefully handle program
# errors and interruptions. More serious failures like system crashes
# can be recovered with an fsck-like tool. As the whole repository is
# effectively log-structured, this should amount to simply truncating
# anything that isn't referenced in the changelog.
#
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
from i18n import _
import os
class transaction(object):
def __init__(self, report, opener, journal, after=None, createmode=None):
self.journal = None
self.count = 1
self.report = report
self.opener = opener
self.after = after
self.entries = []
self.map = {}
self.journal = journal
self.file = open(self.journal, "w")
if createmode is not None:
os.chmod(self.journal, createmode & 0666)
def __del__(self):
if self.journal:
if self.entries: self.abort()
self.file.close()
try: os.unlink(self.journal)
except: pass
def add(self, file, offset, data=None):
if file in self.map: return
self.entries.append((file, offset, data))
self.map[file] = len(self.entries) - 1
# add enough data to the journal to do the truncate
self.file.write("%s\0%d\n" % (file, offset))
self.file.flush()
def find(self, file):
if file in self.map:
return self.entries[self.map[file]]
return None
def replace(self, file, offset, data=None):
if file not in self.map:
raise KeyError(file)
index = self.map[file]
self.entries[index] = (file, offset, data)
self.file.write("%s\0%d\n" % (file, offset))
self.file.flush()
def nest(self):
self.count += 1
return self
def running(self):
return self.count > 0
def close(self):
self.count -= 1
if self.count != 0:
return
self.file.close()
self.entries = []
if self.after:
self.after()
else:
os.unlink(self.journal)
self.journal = None
def abort(self):
if not self.entries: return
self.report(_("transaction abort!\n"))
for f, o, ignore in self.entries:
try:
self.opener(f, "a").truncate(o)
except:
self.report(_("failed to truncate %s\n") % f)
self.entries = []
self.report(_("rollback completed\n"))
def rollback(opener, file):
files = {}
for l in open(file).readlines():
f, o = l.split('\0')
files[f] = o
for f in files:
o = files[f]
opener(f, "a").truncate(int(o))
os.unlink(file)