##// END OF EJS Templates
monotone: replace %s interpolation with appropriate numeric specifiers...
monotone: replace %s interpolation with appropriate numeric specifiers The length is an int, and the version is a float. Neither work with bytes on py3. This was noticed when looking at nearby code after updating pytype changed some signatures.

File last commit:

r52707:f1ef512e default
r52707:f1ef512e default
Show More
monotone.py
410 lines | 13.5 KiB | text/x-python | PythonLexer
Martin Geisler
convert: add copyright and license headers to back-ends
r8250 # monotone.py - monotone support for the convert extension
#
# Copyright 2008, 2009 Mikkel Fahnoe Jorgensen <mikkel@dvide.com> and
# others
#
# This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
timeless
convert: monotone use absolute_import
r28372 import os
import re
Yuya Nishihara
py3: move up symbol imports to enforce import-checker rules...
r29205 from mercurial.i18n import _
Gregory Szorc
py3: manually import pycompat.open into files that need it...
r43355 from mercurial.pycompat import open
timeless
convert: monotone use absolute_import
r28372 from mercurial import (
error,
Pulkit Goyal
py3: use pycompat.byteskwargs in hgext/convert/...
r36347 pycompat,
timeless
convert: monotone use absolute_import
r28372 )
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 from mercurial.utils import dateutil
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
timeless
convert: monotone use absolute_import
r28372 from . import common
Augie Fackler
formatting: blacken the codebase...
r43346
timeless
convert: monotone use absolute_import
r28372 class monotone_source(common.converter_source, common.commandline):
Matt Harbison
convert: save an indicator of the repo type for sources and sinks...
r35168 def __init__(self, ui, repotype, path=None, revs=None):
common.converter_source.__init__(self, ui, repotype, path, revs)
Durham Goode
convert: add support for specifying multiple revs...
r25748 if revs and len(revs) > 1:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'monotone source does not support specifying '
b'multiple revs'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 common.commandline.__init__(self, ui, b'mtn')
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 self.ui = ui
self.path = path
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 self.automatestdio = False
Durham Goode
convert: add support for specifying multiple revs...
r25748 self.revs = revs
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
Augie Fackler
formatting: blacken the codebase...
r43346 norepo = common.NoRepo(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"%s does not look like a monotone repository") % path
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not os.path.exists(os.path.join(path, b'_MTN')):
Patrick Mezard
convert/mtn: allow monotone database files as sources
r8052 # Could be a monotone repository (SQLite db file)
try:
Matt Harbison
convert: fix various leaked file descriptors...
r52580 with open(path, b'rb') as f:
header = f.read(16)
Brodie Rao
cleanup: replace naked excepts with more specific ones
r16688 except IOError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 header = b''
if header != b'SQLite format 3\x00':
Patrick Mezard
convert/mtn: allow monotone database files as sources
r8052 raise norepo
Matt Mackall
convert: attempt to check repo type before checking for tool
r7973
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 # regular expressions for parsing monotone output
Augie Fackler
formatting: blacken the codebase...
r43346 space = br'\s*'
name = br'\s+"((?:\\"|[^"])*)"\s*'
value = name
Pulkit Goyal
py3: make sure regexes are bytes...
r36411 revision = br'\s+\[(\w+)\]\s*'
Augie Fackler
formatting: blacken the codebase...
r43346 lines = br'(?:.|\n)+'
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.dir_re = re.compile(space + b"dir" + name)
self.file_re = re.compile(
space + b"file" + name + b"content" + revision
)
Augie Fackler
formatting: blacken the codebase...
r43346 self.add_file_re = re.compile(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 space + b"add_file" + name + b"content" + revision
Augie Fackler
formatting: blacken the codebase...
r43346 )
self.patch_re = re.compile(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 space + b"patch" + name + b"from" + revision + b"to" + revision
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.rename_re = re.compile(space + b"rename" + name + b"to" + name)
self.delete_re = re.compile(space + b"delete" + name)
self.tag_re = re.compile(space + b"tag" + name + b"revision" + revision)
Augie Fackler
formatting: blacken the codebase...
r43346 self.cert_re = re.compile(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lines + space + b"name" + name + b"value" + value
Augie Fackler
formatting: blacken the codebase...
r43346 )
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 attr = space + b"file" + lines + space + b"attr" + space
Augie Fackler
formatting: blacken the codebase...
r43346 self.attr_execute_re = re.compile(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 attr + b'"mtn:execute"' + space + b'"true"'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
# cached data
self.manifest_rev = None
self.manifest = None
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307 self.files = None
Augie Fackler
formatting: blacken the codebase...
r43346 self.dirs = None
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 common.checktool(b'mtn', abort=False)
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
def mtnrun(self, *args, **kwargs):
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 if self.automatestdio:
return self.mtnrunstdio(*args, **kwargs)
else:
return self.mtnrunsingle(*args, **kwargs)
def mtnrunsingle(self, *args, **kwargs):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 kwargs['d'] = self.path
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return self.run0(b'automate', *args, **kwargs)
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 def mtnrunstdio(self, *args, **kwargs):
# Prepare the command in automate stdio format
Pulkit Goyal
py3: use pycompat.byteskwargs in hgext/convert/...
r36347 kwargs = pycompat.byteskwargs(kwargs)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 command = []
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for k, v in kwargs.items():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 command.append(b"%d:%s" % (len(k), k))
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 if v:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 command.append(b"%d:%s" % (len(v), v))
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 if command:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 command.insert(0, b'o')
command.append(b'e')
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 command.append(b'l')
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 for arg in args:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 command.append(b"%d:%s" % (len(arg), arg))
command.append(b'e')
command = b''.join(command)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.debug(b"mtn: sending '%s'\n" % command)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 self.mtnwritefp.write(command)
self.mtnwritefp.flush()
return self.mtnstdioreadcommandoutput(command)
def mtnstdioreadpacket(self):
read = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 commandnbr = b''
while read != b':':
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 read = self.mtnreadfp.read(1)
if not read:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'bad mtn packet - no end of commandnbr'))
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 commandnbr += read
commandnbr = commandnbr[:-1]
stream = self.mtnreadfp.read(1)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if stream not in b'mewptl':
raise error.Abort(
_(b'bad mtn packet - bad stream type %s') % stream
)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
read = self.mtnreadfp.read(1)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if read != b':':
raise error.Abort(_(b'bad mtn packet - no divider before size'))
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
read = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lengthstr = b''
while read != b':':
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 read = self.mtnreadfp.read(1)
if not read:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'bad mtn packet - no end of packet size'))
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 lengthstr += read
try:
Gregory Szorc
py3: use int instead of pycompat.long...
r49787 length = int(lengthstr[:-1])
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 except TypeError:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'bad mtn packet - bad packet size %s') % lengthstr
Augie Fackler
formatting: blacken the codebase...
r43346 )
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
read = self.mtnreadfp.read(length)
if len(read) != length:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"bad mtn packet - unable to read full packet "
Matt Harbison
monotone: replace %s interpolation with appropriate numeric specifiers...
r52707 b"read %s of %d"
Augie Fackler
formatting: blacken the codebase...
r43346 )
% (len(read), length)
)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
return (commandnbr, stream, length, read)
def mtnstdioreadcommandoutput(self, command):
Daniel Atallah
convert/mtn: Fix conversion of large files from mtn (broken in ed97955e0c04)...
r13792 retval = []
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 while True:
commandnbr, stream, length, output = self.mtnstdioreadpacket()
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.debug(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'mtn: read packet %s:%s:%d\n' % (commandnbr, stream, length)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if stream == b'l':
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 # End of command
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if output != b'0':
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"mtn command '%s' returned %s") % (command, output)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 break
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif stream in b'ew':
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 # Error, warning output
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.warn(_(b'%s error:\n') % self.command)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 self.ui.warn(output)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif stream == b'p':
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 # Progress messages
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.debug(b'mtn: ' + output)
elif stream == b'm':
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 # Main stream - command output
Daniel Atallah
convert/mtn: Fix conversion of large files from mtn (broken in ed97955e0c04)...
r13792 retval.append(output)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(retval)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 def mtnloadmanifest(self, rev):
if self.manifest_rev == rev:
return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.manifest = self.mtnrun(b"get_manifest_of", rev).split(b"\n\n")
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 self.manifest_rev = rev
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307 self.files = {}
self.dirs = {}
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307 for e in self.manifest:
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 m = self.file_re.match(e)
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307 if m:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 attr = b""
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 name = m.group(1)
node = m.group(2)
if self.attr_execute_re.match(e):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 attr += b"x"
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307 self.files[name] = (node, attr)
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 m = self.dir_re.match(e)
if m:
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307 self.dirs[m.group(1)] = True
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
def mtnisfile(self, name, rev):
# a non-file could be a directory or a deleted or renamed file
self.mtnloadmanifest(rev)
Benoit Boissinot
convert: cleanups in monotone converter
r8458 return name in self.files
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 def mtnisdir(self, name, rev):
self.mtnloadmanifest(rev)
Benoit Boissinot
convert: cleanups in monotone converter
r8458 return name in self.dirs
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 def mtngetcerts(self, rev):
Augie Fackler
formatting: blacken the codebase...
r43346 certs = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"author": b"<missing>",
b"date": b"<missing>",
b"changelog": b"<missing>",
b"branch": b"<missing>",
Augie Fackler
formatting: blacken the codebase...
r43346 }
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 certlist = self.mtnrun(b"certs", rev)
Patrick Mezard
convert/mtn: handle change in mtn 0.45 certs output
r9823 # mtn < 0.45:
# key "test@selenic.com"
# mtn >= 0.45:
# key [ff58a7ffb771907c4ff68995eada1c4da068d328]
Matt Harbison
cleanup: replace contiguous spaces in regex patterns with an explicit count...
r44472 certlist = re.split(br'\n\n {6}key ["\[]', certlist)
Patrick Mezard
convert/mtn: handle change in mtn 0.45 certs output
r9823 for e in certlist:
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 m = self.cert_re.match(e)
if m:
David Reiss
convert.monotone: fix quotes and backslashes in change descriptions.
r6632 name, value = m.groups()
Matt Harbison
typing: add some assertions that a variable isn't None...
r50748 assert value is not None # help pytype
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 value = value.replace(br'\"', b'"')
value = value.replace(br'\\', b'\\')
David Reiss
convert.monotone: fix quotes and backslashes in change descriptions.
r6632 certs[name] = value
Paul Aurich
convert/mtn: handle subsecond commit dates (issue1616)
r8101 # Monotone may have subsecond dates: 2005-02-05T09:39:12.364306
Paul Aurich
convert/mtn: mtn does not record timezones, mark dates as UTC (issue1624)
r8125 # and all times are stored in UTC
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 certs[b"date"] = certs[b"date"].split(b'.')[0] + b" UTC"
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 return certs
# implement the converter_source interface:
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 def getheads(self):
Durham Goode
convert: add support for specifying multiple revs...
r25748 if not self.revs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return self.mtnrun(b"leaves").splitlines()
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 else:
Durham Goode
convert: add support for specifying multiple revs...
r25748 return self.revs
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
Mads Kiilerich
convert: introduce --full for converting all files...
r22300 def getchanges(self, rev, full):
if full:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b"convert from monotone does not support --full")
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revision = self.mtnrun(b"get_revision", rev).split(b"\n\n")
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 files = {}
Patrick Mezard
convert/mtn: handle files moved in a moved directory (issue1619/2)
r8123 ignoremove = {}
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 renameddirs = []
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 copies = {}
for e in revision:
m = self.add_file_re.match(e)
if m:
files[m.group(1)] = rev
Patrick Mezard
convert/mtn: handle files moved in a moved directory (issue1619/2)
r8123 ignoremove[m.group(1)] = rev
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 m = self.patch_re.match(e)
if m:
files[m.group(1)] = rev
# Delete/rename is handled later when the convert engine
# discovers an IOError exception from getfile,
# but only if we add the "from" file to the list of changes.
Patrick Mezard
convert: record deleted files in monotone source
r6376 m = self.delete_re.match(e)
if m:
files[m.group(1)] = rev
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 m = self.rename_re.match(e)
if m:
toname = m.group(2)
fromname = m.group(1)
if self.mtnisfile(toname, rev):
Patrick Mezard
convert/mtn: handle files moved in a moved directory (issue1619/2)
r8123 ignoremove[toname] = 1
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 copies[toname] = fromname
files[toname] = rev
files[fromname] = rev
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 elif self.mtnisdir(toname, rev):
renameddirs.append((fromname, toname))
# Directory renames can be handled only once we have recorded
# all new files
for fromdir, todir in renameddirs:
renamed = {}
for tofile in self.files:
Patrick Mezard
convert/mtn: handle files moved in a moved directory (issue1619/2)
r8123 if tofile in ignoremove:
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if tofile.startswith(todir + b'/'):
Augie Fackler
formatting: blacken the codebase...
r43346 renamed[tofile] = fromdir + tofile[len(todir) :]
Patrick Mezard
convert/mtn: handle directory move into moved directory (issue1619/3)
r8124 # Avoid chained moves like:
# d1(/a) => d3/d1(/a)
# d2 => d3
ignoremove[tofile] = 1
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 for tofile, fromfile in renamed.items():
Augie Fackler
monotone: fix a bogus _() wrapper that was caught when formatting code...
r42431 self.ui.debug(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"copying file in renamed directory from '%s' to '%s'"
Augie Fackler
formatting: blacken the codebase...
r43346 % (fromfile, tofile),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'\n',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 files[tofile] = rev
copies[tofile] = fromfile
for fromfile in renamed.values():
files[fromfile] = rev
Mads Kiilerich
convert: optimize convert of files that are unmodified from p2 in merges...
r24395 return (files.items(), copies, set())
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
def getfile(self, name, rev):
if not self.mtnisfile(name, rev):
Mads Kiilerich
convert: use None value for missing files instead of overloading IOError...
r22296 return None, None
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 data = self.mtnrun(b"get_file_of", name, r=rev)
Brodie Rao
cleanup: replace naked excepts with except Exception: ...
r16689 except Exception:
Mads Kiilerich
convert: use None value for missing files instead of overloading IOError...
r22296 return None, None
Patrick Mezard
convert: merge sources getmode() into getfile()
r11134 self.mtnloadmanifest(rev)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 node, attr = self.files.get(name, (None, b""))
Patrick Mezard
convert: merge sources getmode() into getfile()
r11134 return data, attr
Mikkel Fahnøe Jørgensen
cleanup monotone conversion and use commandline class
r6307
def getcommit(self, rev):
Daniel Atallah
convert/mtn: convert suspended branches as closed branches...
r13779 extra = {}
certs = self.mtngetcerts(rev)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if certs.get(b'suspend') == certs[b"branch"]:
Manuel Jacob
convert: use bytes for value in extra dict...
r45652 extra[b'close'] = b'1'
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 dateformat = b"%Y-%m-%dT%H:%M:%S"
timeless
convert: monotone use absolute_import
r28372 return common.commit(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 author=certs[b"author"],
date=dateutil.datestr(dateutil.strdate(certs[b"date"], dateformat)),
desc=certs[b"changelog"],
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 rev=rev,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 parents=self.mtnrun(b"parents", rev).splitlines(),
branch=certs[b"branch"],
Augie Fackler
formatting: blacken the codebase...
r43346 extra=extra,
)
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306
def gettags(self):
tags = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for e in self.mtnrun(b"tags").split(b"\n\n"):
Mikkel Fahnøe Jørgensen
initial version of monotone source for convert extension
r6306 m = self.tag_re.match(e)
if m:
tags[m.group(1)] = m.group(2)
return tags
def getchangedfiles(self, rev, i):
# This function is only needed to support --filemap
# ... and we don't support that
Brodie Rao
cleanup: "raise SomeException()" -> "raise SomeException"
r16687 raise NotImplementedError
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
def before(self):
# Check if we have a new enough version to use automate stdio
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 versionstr = self.mtnrunsingle(b"interface_version")
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 version = float(versionstr)
except Exception:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b"unable to determine mtn automate interface version")
Augie Fackler
formatting: blacken the codebase...
r43346 )
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
if version >= 12.0:
self.automatestdio = True
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.debug(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"mtn automate version %f - using automate stdio\n" % version
Augie Fackler
formatting: blacken the codebase...
r43346 )
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
# launch the long-running automate stdio process
Augie Fackler
formatting: blacken the codebase...
r43346 self.mtnwritefp, self.mtnreadfp = self._run2(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'automate', b'stdio', b'-d', self.path
Augie Fackler
formatting: blacken the codebase...
r43346 )
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 # read the headers
read = self.mtnreadfp.readline()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if read != b'format-version: 2\n':
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'mtn automate stdio header unexpected: %s') % read
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 while read != b'\n':
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 read = self.mtnreadfp.readline()
if not read:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"failed to reach end of mtn automate "
b"stdio headers"
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760 else:
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.debug(
Matt Harbison
monotone: replace %s interpolation with appropriate numeric specifiers...
r52707 b"mtn automate version %f - not using automate stdio "
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"(automate >= 12.0 - mtn >= 0.46 is needed)\n" % version
Augie Fackler
formatting: blacken the codebase...
r43346 )
Daniel Atallah
convert/mtn: add support for using monotone's "automate stdio" when available...
r13760
def after(self):
if self.automatestdio:
self.mtnwritefp.close()
self.mtnwritefp = None
self.mtnreadfp.close()
self.mtnreadfp = None