Add transaction hooks and attempt to get .d working

This commit is contained in:
Durham Goode 2013-10-17 16:47:34 -07:00
parent cedf7a6d6e
commit ec4bd7e3d9

View File

@ -22,7 +22,7 @@ testedwith = 'internal'
from mercurial.node import bin, hex, nullid, nullrev from mercurial.node import bin, hex, nullid, nullrev
from mercurial.i18n import _ from mercurial.i18n import _
from mercurial.extensions import wrapfunction from mercurial.extensions import wrapfunction
from mercurial import changelog, error, cmdutil, revlog, localrepo from mercurial import changelog, error, cmdutil, revlog, localrepo, transaction
import MySQLdb, struct, time import MySQLdb, struct, time
from MySQLdb import cursors from MySQLdb import cursors
@ -30,23 +30,28 @@ cmdtable = {}
command = cmdutil.command(cmdtable) command = cmdutil.command(cmdtable)
testedwith = 'internal' testedwith = 'internal'
dbargs = {
}
def uisetup(ui): def uisetup(ui):
wrapfunction(revlog.revlog, '_addrevision', addrevision) wrapfunction(revlog.revlog, '_addrevision', addrevision)
#extensions.wrapcommand(commands.table, 'server', serve)
wrapfunction(localrepo, 'instance', repoinstance) wrapfunction(localrepo, 'instance', repoinstance)
wrapfunction(transaction.transaction, '_abort', transactionclose)
wrapfunction(transaction.transaction, 'close', transactionclose)
def repoinstance(orig, *args): def repoinstance(orig, *args):
repo = orig(*args) repo = orig(*args)
pulldb(repo) if repo.ui.configbool("hgsql", "enabled"):
pulldb(repo)
return repo return repo
def reposetup(ui, repo): def reposetup(ui, repo):
ui.setconfig("hooks", "pretxnchangegroup.remotefilelog", pretxnchangegroup) if repo.ui.configbool("hgsql", "enabled"):
ui.setconfig("hooks", "pretxncommit.remotefilelog", pretxnchangegroup) ui.setconfig("hooks", "pretxnchangegroup.remotefilelog", pretxnchangegroup)
ui.setconfig("hooks", "pretxncommit.remotefilelog", pretxnchangegroup)
# Handle pulls # Sync with db
def pulldb(repo): def pulldb(repo):
conn = MySQLdb.connect(**dbargs) conn = MySQLdb.connect(**dbargs)
@ -140,17 +145,18 @@ def addentries(repo, revisions, transaction, revlogs):
if link > latest: if link > latest:
latest = link latest = link
count += 1 count += 1
if path in revlogs: revlog = revlogs.get('path')
revlog = revlogs[path] if not revlog:
else:
revlog = EntryRevlog(opener, path) revlog = EntryRevlog(opener, path)
revlogs[path] = revlog
if not hasattr(revlog, 'ifh') or revlog.ifh.closed:
dfh = None dfh = None
if not revlog._inline: if not revlog._inline:
dfh = opener(revlog.datafile, "a") dfh = opener(revlog.datafile, "a")
ifh = opener(revlog.indexfile, "a+") ifh = opener(revlog.indexfile, "a+")
revlog.ifh = ifh revlog.ifh = ifh
revlog.dfh = dfh revlog.dfh = dfh
revlogs[path] = revlog
revlog.addentry(transaction, revlog.ifh, revlog.dfh, entry, revlog.addentry(transaction, revlog.ifh, revlog.dfh, entry,
data0, data1) data0, data1)
@ -167,24 +173,25 @@ class EntryRevlog(revlog.revlog):
self.index.insert(-1, e) self.index.insert(-1, e)
self.nodemap[e[7]] = len(self) - 1 self.nodemap[e[7]] = len(self) - 1
# TODO: verify entry rev number matches the current rev curr = len(self) - 1
# TODO: verify entry offset matches current d file offset offset = self.end(curr - 1)
if not self._inline: if not self._inline:
#transaction.add(revlog.datafile, offset) transaction.add(self.datafile, offset)
#transaction.add(revlog.indexfile, curr * len(entry)) transaction.add(self.indexfile, curr * len(entry))
if data0: if data0:
dfh.write(data0) dfh.write(data0)
dfh.write(data1) dfh.write(data1)
ifh.write(entry) ifh.write(entry)
else: else:
#offset += curr * revlog._io.size offset += curr * self._io.size
#transaction.add(revlog.indexfile, offset, curr) transaction.add(self.indexfile, offset, curr)
ifh.write(entry) ifh.write(entry)
ifh.write(data0) ifh.write(data0)
ifh.write(data1) ifh.write(data1)
#self.checkinlinesize(transaction, ifh) #self.checkinlinesize(transaction, ifh)
# Handle pushed commits # Handle incoming commits
pending = [] pending = []
@ -261,3 +268,7 @@ def pretxnchangegroup(ui, repo, *args, **kwargs):
conn.close() conn.close()
del pending[:] del pending[:]
def transactionclose(orig, self):
del pending[:]
return orig(self)