Пример #1
0
def addbranchrevs(lrepo, repo, branches, revs):
    hashbranch, branches = branches
    if not hashbranch and not branches:
        return revs or None, revs and revs[0] or None
    revs = revs and list(revs) or []
    if not repo.capable('branchmap'):
        if branches:
            raise util.Abort(_("remote branch lookup not supported"))
        revs.append(hashbranch)
        return revs, revs[0]
    branchmap = repo.branchmap()

    def primary(butf8):
        if butf8 == '.':
            if not lrepo or not lrepo.local():
                raise util.Abort(_("dirstate branch not accessible"))
            butf8 = lrepo.dirstate.branch()
        if butf8 in branchmap:
            revs.extend(node.hex(r) for r in reversed(branchmap[butf8]))
            return True
        else:
            return False

    for branch in branches:
        butf8 = encoding.fromlocal(branch)
        if not primary(butf8):
            raise error.RepoLookupError(_("unknown branch '%s'") % branch)
    if hashbranch:
        butf8 = encoding.fromlocal(hashbranch)
        if not primary(butf8):
            revs.append(hashbranch)
    return revs, revs[0]
Пример #2
0
    def add(self, manifest, files, desc, transaction, p1, p2,
                  user, date=None, extra={}):
        user = user.strip()
        # An empty username or a username with a "\n" will make the
        # revision text contain two "\n\n" sequences -> corrupt
        # repository since read cannot unpack the revision.
        if not user:
            raise error.RevlogError(_("empty username"))
        if "\n" in user:
            raise error.RevlogError(_("username %s contains a newline")
                                    % repr(user))

        # strip trailing whitespace and leading and trailing empty lines
        desc = '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')

        user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)

        if date:
            parseddate = "%d %d" % util.parsedate(date)
        else:
            parseddate = "%d %d" % util.makedate()
        if extra and extra.get("branch") in ("default", ""):
            del extra["branch"]
        if extra:
            extra = encodeextra(extra)
            parseddate = "%s %s" % (parseddate, extra)
        l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
        text = "\n".join(l)
        return self.addrevision(text, transaction, len(self), p1, p2)
def addbranchrevs(lrepo, repo, branches, revs):
    hashbranch, branches = branches
    if not hashbranch and not branches:
        return revs or None, revs and revs[0] or None
    revs = revs and list(revs) or []
    if not repo.capable('branchmap'):
        if branches:
            raise util.Abort(_("remote branch lookup not supported"))
        revs.append(hashbranch)
        return revs, revs[0]
    branchmap = repo.branchmap()

    def primary(butf8):
        if butf8 == '.':
            if not lrepo or not lrepo.local():
                raise util.Abort(_("dirstate branch not accessible"))
            butf8 = lrepo.dirstate.branch()
        if butf8 in branchmap:
            revs.extend(node.hex(r) for r in reversed(branchmap[butf8]))
            return True
        else:
            return False

    for branch in branches:
        butf8 = encoding.fromlocal(branch)
        if not primary(butf8):
            raise error.RepoLookupError(_("unknown branch '%s'") % branch)
    if hashbranch:
        butf8 = encoding.fromlocal(hashbranch)
        if not primary(butf8):
            revs.append(hashbranch)
    return revs, revs[0]
Пример #4
0
 def pushkey(self, namespace, key, old, new):
     if not self.capable('pushkey'):
         return False
     d = self._call("pushkey",
                    namespace=encoding.fromlocal(namespace),
                    key=encoding.fromlocal(key),
                    old=encoding.fromlocal(old),
                    new=encoding.fromlocal(new))
     try:
         d = bool(int(d))
     except ValueError:
         raise error.ResponseError(
             _('push failed (unexpected response):'), d)
     return d
Пример #5
0
 def pushkey(self, namespace, key, old, new):
     if not self.capable('pushkey'):
         yield False, None
     f = future()
     yield todict(namespace=encoding.fromlocal(namespace),
                  key=encoding.fromlocal(key),
                  old=encoding.fromlocal(old),
                  new=encoding.fromlocal(new)), f
     d = f.value
     try:
         d = bool(int(d))
     except ValueError:
         raise error.ResponseError(_('push failed (unexpected response):'),
                                   d)
     yield d
Пример #6
0
 def pushkey(self, namespace, key, old, new):
     if not self.capable('pushkey'):
         yield False, None
     f = future()
     yield todict(namespace=encoding.fromlocal(namespace),
                  key=encoding.fromlocal(key),
                  old=encoding.fromlocal(old),
                  new=encoding.fromlocal(new)), f
     d = f.value
     try:
         d = bool(int(d))
     except ValueError:
         raise error.ResponseError(
             _('push failed (unexpected response):'), d)
     yield d
Пример #7
0
def buildmetadata(ctx):
    '''build content of .hg_archival.txt'''
    repo = ctx.repo()
    hex = ctx.hex()
    if ctx.rev() is None:
        hex = ctx.p1().hex()
        if ctx.dirty():
            hex += '+'

    base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
        _rootctx(repo).hex(), hex, encoding.fromlocal(ctx.branch()))

    tags = ''.join('tag: %s\n' % t for t in ctx.tags()
                   if repo.tagtype(t) == 'global')
    if not tags:
        repo.ui.pushbuffer()
        opts = {
            'template': '{latesttag}\n{latesttagdistance}',
            'style': '',
            'patch': None,
            'git': None
        }
        cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
        ltags, dist = repo.ui.popbuffer().split('\n')
        ltags = ltags.split(':')
        if ctx.rev() is None:
            changessince = len(repo.revs('only(%d,%s)', ctx.p1(),
                                         ltags[0])) + 1
        else:
            changessince = len(repo.revs('only(%d,%s)', ctx.rev(), ltags[0]))
        tags = ''.join('latesttag: %s\n' % t for t in ltags)
        tags += 'latesttagdistance: %s\n' % dist
        tags += 'changessincelatesttag: %s\n' % changessince

    return base + tags
 def write(self, tr=None):
     """Save branch cache if it is dirty."""
     repo = self._repo
     if self._rbcnamescount < len(self._names):
         try:
             if self._rbcnamescount != 0:
                 f = repo.vfs.open(_rbcnames, 'ab')
                 if f.tell() == self._rbcsnameslen:
                     f.write('\0')
                 else:
                     f.close()
                     repo.ui.debug("%s changed - rewriting it\n" %
                                   _rbcnames)
                     self._rbcnamescount = 0
                     self._rbcrevslen = 0
             if self._rbcnamescount == 0:
                 f = repo.vfs.open(_rbcnames, 'wb')
             f.write('\0'.join(
                 encoding.fromlocal(b)
                 for b in self._names[self._rbcnamescount:]))
             self._rbcsnameslen = f.tell()
             f.close()
         except (IOError, OSError, util.Abort), inst:
             repo.ui.debug("couldn't write revision branch cache names: "
                           "%s\n" % inst)
             return
         self._rbcnamescount = len(self._names)
Пример #9
0
 def write(self, repo):
     """Save branch cache if it is dirty."""
     if self._rbcnamescount < len(self._names):
         try:
             if self._rbcnamescount != 0:
                 f = repo.vfs.open(_rbcnames, 'ab')
                 # The position after open(x, 'a') is implementation defined-
                 # see issue3543.  SEEK_END was added in 2.5
                 f.seek(0, 2) #os.SEEK_END
                 if f.tell() == self._rbcsnameslen:
                     f.write('\0')
                 else:
                     f.close()
                     repo.ui.debug("%s changed - rewriting it\n" % _rbcnames)
                     self._rbcnamescount = 0
                     self._rbcrevslen = 0
             if self._rbcnamescount == 0:
                 f = repo.vfs.open(_rbcnames, 'wb')
             f.write('\0'.join(encoding.fromlocal(b)
                               for b in self._names[self._rbcnamescount:]))
             self._rbcsnameslen = f.tell()
             f.close()
         except (IOError, OSError, util.Abort), inst:
             repo.ui.debug("couldn't write revision branch cache names: "
                           "%s\n" % inst)
             return
         self._rbcnamescount = len(self._names)
Пример #10
0
 def write(self, repo):
     try:
         f = repo.vfs(_filename(repo), "w", atomictemp=True)
         cachekey = [hex(self.tipnode), str(self.tiprev)]
         if self.filteredhash is not None:
             cachekey.append(hex(self.filteredhash))
         f.write(" ".join(cachekey) + '\n')
         nodecount = 0
         for label, nodes in sorted(self.iteritems()):
             for node in nodes:
                 nodecount += 1
                 if node in self._closednodes:
                     state = 'c'
                 else:
                     state = 'o'
                 f.write("%s %s %s\n" % (hex(node), state,
                                         encoding.fromlocal(label)))
         f.close()
         repo.ui.log('branchcache',
                     'wrote %s branch cache with %d labels and %d nodes\n',
                     repo.filtername, len(self), nodecount)
     except (IOError, OSError, util.Abort), inst:
         repo.ui.debug("couldn't write branch cache: %s\n" % inst)
         # Abort may be raise by read only opener
         pass
Пример #11
0
 def write(self, tr=None):
     """Save branch cache if it is dirty."""
     repo = self._repo
     if self._rbcnamescount < len(self._names):
         try:
             if self._rbcnamescount != 0:
                 f = repo.vfs.open(_rbcnames, 'ab')
                 if f.tell() == self._rbcsnameslen:
                     f.write('\0')
                 else:
                     f.close()
                     repo.ui.debug("%s changed - rewriting it\n" % _rbcnames)
                     self._rbcnamescount = 0
                     self._rbcrevslen = 0
             if self._rbcnamescount == 0:
                 f = repo.vfs.open(_rbcnames, 'wb')
             f.write('\0'.join(encoding.fromlocal(b)
                               for b in self._names[self._rbcnamescount:]))
             self._rbcsnameslen = f.tell()
             f.close()
         except (IOError, OSError, util.Abort), inst:
             repo.ui.debug("couldn't write revision branch cache names: "
                           "%s\n" % inst)
             return
         self._rbcnamescount = len(self._names)
Пример #12
0
    def __init__(self, repo, text="", user=None, date=None, extra=None, changes=None):
        self._repo = repo
        self._rev = None
        self._node = None
        self._text = text
        if date:
            self._date = util.parsedate(date)
        if user:
            self._user = user
        if changes:
            self._status = list(changes[:4])
            self._unknown = changes[4]
            self._ignored = changes[5]
            self._clean = changes[6]
        else:
            self._unknown = None
            self._ignored = None
            self._clean = None

        self._extra = {}
        if extra:
            self._extra = extra.copy()
        if "branch" not in self._extra:
            try:
                branch = encoding.fromlocal(self._repo.dirstate.branch())
            except UnicodeDecodeError:
                raise util.Abort(_("branch name not in UTF-8!"))
            self._extra["branch"] = branch
        if self._extra["branch"] == "":
            self._extra["branch"] = "default"
Пример #13
0
def buildmetadata(ctx):
    '''build content of .hg_archival.txt'''
    repo = ctx.repo()
    hex = ctx.hex()
    if ctx.rev() is None:
        hex = ctx.p1().hex()
        if ctx.dirty():
            hex += '+'

    base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
        _rootctx(repo).hex(), hex, encoding.fromlocal(ctx.branch()))

    tags = ''.join('tag: %s\n' % t for t in ctx.tags()
                   if repo.tagtype(t) == 'global')
    if not tags:
        repo.ui.pushbuffer()
        opts = {'template': '{latesttag}\n{latesttagdistance}',
                'style': '', 'patch': None, 'git': None}
        cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
        ltags, dist = repo.ui.popbuffer().split('\n')
        ltags = ltags.split(':')
        if ctx.rev() is None:
            changessince = len(repo.revs('only(%d,%s)', ctx.p1(),
                                         ltags[0])) + 1
        else:
            changessince = len(repo.revs('only(%d,%s)', ctx.rev(), ltags[0]))
        tags = ''.join('latesttag: %s\n' % t for t in ltags)
        tags += 'latesttagdistance: %s\n' % dist
        tags += 'changessincelatesttag: %s\n' % changessince

    return base + tags
Пример #14
0
 def lookup(self, key):
     self.requirecap('lookup', _('look up remote revision'))
     d = self._call("lookup", key=encoding.fromlocal(key))
     success, data = d[:-1].split(" ", 1)
     if int(success):
         return bin(data)
     self._abort(error.RepoError(data))
Пример #15
0
 def write(self, repo):
     """Save branch cache if it is dirty."""
     if self._rbcnamescount < len(self._names):
         try:
             if self._rbcnamescount != 0:
                 f = repo.vfs.open(_rbcnames, 'ab')
                 # The position after open(x, 'a') is implementation defined-
                 # see issue3543.  SEEK_END was added in 2.5
                 f.seek(0, 2) #os.SEEK_END
                 if f.tell() == self._rbcsnameslen:
                     f.write('\0')
                 else:
                     f.close()
                     repo.ui.debug("%s changed - rewriting it\n" % _rbcnames)
                     self._rbcnamescount = 0
                     self._rbcrevslen = 0
             if self._rbcnamescount == 0:
                 f = repo.vfs.open(_rbcnames, 'wb')
             f.write('\0'.join(encoding.fromlocal(b)
                               for b in self._names[self._rbcnamescount:]))
             self._rbcsnameslen = f.tell()
             f.close()
         except (IOError, OSError, util.Abort), inst:
             repo.ui.debug("couldn't write revision branch cache names: "
                           "%s\n" % inst)
             return
         self._rbcnamescount = len(self._names)
Пример #16
0
 def write(self, repo):
     try:
         f = repo.vfs(_filename(repo), "w", atomictemp=True)
         cachekey = [hex(self.tipnode), str(self.tiprev)]
         if self.filteredhash is not None:
             cachekey.append(hex(self.filteredhash))
         f.write(" ".join(cachekey) + '\n')
         nodecount = 0
         for label, nodes in sorted(self.iteritems()):
             for node in nodes:
                 nodecount += 1
                 if node in self._closednodes:
                     state = 'c'
                 else:
                     state = 'o'
                 f.write("%s %s %s\n" % (hex(node), state,
                                         encoding.fromlocal(label)))
         f.close()
         repo.ui.log('branchcache',
                     'wrote %s branch cache with %d labels and %d nodes\n',
                     repo.filtername, len(self), nodecount)
     except (IOError, OSError, util.Abort), inst:
         repo.ui.debug("couldn't write branch cache: %s\n" % inst)
         # Abort may be raise by read only opener
         pass
Пример #17
0
 def listkeys(self, namespace):
     if not self.capable('pushkey'):
         yield {}, None
     f = future()
     self.ui.debug('preparing listkeys for "%s"\n' % namespace)
     yield {'namespace': encoding.fromlocal(namespace)}, f
     d = f.value
     yield pushkeymod.decodekeys(d)
Пример #18
0
def branchmap(repo, proto):
    branchmap = repo.branchmap()
    heads = []
    for branch, nodes in branchmap.iteritems():
        branchname = urllib.quote(encoding.fromlocal(branch))
        branchnodes = encodelist(nodes)
        heads.append('%s %s' % (branchname, branchnodes))
    return '\n'.join(heads)
Пример #19
0
def branchmap(repo, proto):
    branchmap = repo.branchmap()
    heads = []
    for branch, nodes in branchmap.iteritems():
        branchname = urllib.quote(encoding.fromlocal(branch))
        branchnodes = encodelist(nodes)
        heads.append('%s %s' % (branchname, branchnodes))
    return '\n'.join(heads)
Пример #20
0
    def add(self,
            manifest,
            files,
            desc,
            transaction,
            p1,
            p2,
            user,
            date=None,
            extra=None):
        # Convert to UTF-8 encoded bytestrings as the very first
        # thing: calling any method on a localstr object will turn it
        # into a str object and the cached UTF-8 string is thus lost.
        user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)

        user = user.strip()
        # An empty username or a username with a "\n" will make the
        # revision text contain two "\n\n" sequences -> corrupt
        # repository since read cannot unpack the revision.
        if not user:
            raise error.RevlogError(_("empty username"))
        if "\n" in user:
            raise error.RevlogError(
                _("username %s contains a newline") % repr(user))

        # strip trailing whitespace and leading and trailing empty lines
        desc = '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')

        if date:
            parseddate = "%d %d" % util.parsedate(date)
        else:
            parseddate = "%d %d" % util.makedate()
        if extra:
            branch = extra.get("branch")
            if branch in ("default", ""):
                del extra["branch"]
            elif branch in (".", "null", "tip"):
                raise error.RevlogError(
                    _('the name \'%s\' is reserved') % branch)
        if extra:
            extra = encodeextra(extra)
            parseddate = "%s %s" % (parseddate, extra)
        l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
        text = "\n".join(l)
        return self.addrevision(text, transaction, len(self), p1, p2)
Пример #21
0
 def pushkey(self, namespace, key, old, new):
     if not self.capable('pushkey'):
         yield False, None
     f = future()
     yield todict(namespace=encoding.fromlocal(namespace),
                  key=encoding.fromlocal(key),
                  old=encoding.fromlocal(old),
                  new=encoding.fromlocal(new)), f
     d = f.value
     d, output = d.split('\n', 1)
     try:
         d = bool(int(d))
     except ValueError:
         raise error.ResponseError(_('push failed (unexpected response):'),
                                   d)
     for l in output.splitlines(True):
         self.ui.status(_('remote: '), l)
     yield d
Пример #22
0
 def lookup(self, key):
     self.requirecap('lookup', _('look up remote revision'))
     f = future()
     yield todict(key=encoding.fromlocal(key)), f
     d = f.value
     success, data = d[:-1].split(" ", 1)
     if int(success):
         yield bin(data)
     self._abort(error.RepoError(data))
Пример #23
0
 def pushkey(self, namespace, key, old, new):
     if not self.capable('pushkey'):
         yield False, None
     f = future()
     yield todict(namespace=encoding.fromlocal(namespace),
                  key=encoding.fromlocal(key),
                  old=encoding.fromlocal(old),
                  new=encoding.fromlocal(new)), f
     d = f.value
     d, output = d.split('\n', 1)
     try:
         d = bool(int(d))
     except ValueError:
         raise error.ResponseError(
             _('push failed (unexpected response):'), d)
     for l in output.splitlines(True):
         self.ui.status(_('remote: '), l)
     yield d
Пример #24
0
 def setbranch(self, branch):
     if branch in ['tip', '.', 'null']:
         raise util.Abort(_('the name \'%s\' is reserved') % branch)
     self._branch = encoding.fromlocal(branch)
     f = self._opener('branch', 'w', atomictemp=True)
     try:
         f.write(self._branch + '\n')
     finally:
         f.close()
Пример #25
0
 def lookup(self, key):
     self.requirecap('lookup', _('look up remote revision'))
     f = future()
     yield todict(key=encoding.fromlocal(key)), f
     d = f.value
     success, data = d[:-1].split(" ", 1)
     if int(success):
         yield bin(data)
     self._abort(error.RepoError(data))
Пример #26
0
 def listkeys(self, namespace):
     if not self.capable('pushkey'):
         return {}
     d = self._call("listkeys", namespace=encoding.fromlocal(namespace))
     r = {}
     for l in d.splitlines():
         k, v = l.split('\t')
         r[encoding.tolocal(k)] = encoding.tolocal(v)
     return r
Пример #27
0
 def listkeys(self, namespace):
     if not self.capable("pushkey"):
         yield {}, None
     f = future()
     self.ui.debug('preparing listkeys for "%s"\n' % namespace)
     yield {"namespace": encoding.fromlocal(namespace)}, f
     d = f.value
     self.ui.debug('received listkey for "%s": %i bytes\n' % (namespace, len(d)))
     yield pushkeymod.decodekeys(d)
Пример #28
0
 def setbranch(self, branch):
     if branch in ['tip', '.', 'null']:
         raise util.Abort(_('the name \'%s\' is reserved') % branch)
     self._branch = encoding.fromlocal(branch)
     f = self._opener('branch', 'w', atomictemp=True)
     try:
         f.write(self._branch + '\n')
     finally:
         f.close()
Пример #29
0
 def lookup(self, key):
     self.requirecap("lookup", _("look up remote revision"))
     f = future()
     yield {"key": encoding.fromlocal(key)}, f
     d = f.value
     success, data = d[:-1].split(" ", 1)
     if int(success):
         yield bin(data)
     self._abort(error.RepoError(data))
Пример #30
0
 def pushkey(self, namespace, key, old, new):
     if not self.capable('pushkey'):
         yield False, None
     f = future()
     self.ui.debug('preparing pushkey for "%s:%s"\n' % (namespace, key))
     yield {'namespace': encoding.fromlocal(namespace),
            'key': encoding.fromlocal(key),
            'old': encoding.fromlocal(old),
            'new': encoding.fromlocal(new)}, f
     d = f.value
     d, output = d.split('\n', 1)
     try:
         d = bool(int(d))
     except ValueError:
         raise error.ResponseError(
             _('push failed (unexpected response):'), d)
     for l in output.splitlines(True):
         self.ui.status(_('remote: '), l)
     yield d
Пример #31
0
 def pushkey(self, namespace, key, old, new):
     if not self.capable("pushkey"):
         yield False, None
     f = future()
     self.ui.debug('preparing pushkey for "%s:%s"\n' % (namespace, key))
     yield {
         "namespace": encoding.fromlocal(namespace),
         "key": encoding.fromlocal(key),
         "old": encoding.fromlocal(old),
         "new": encoding.fromlocal(new),
     }, f
     d = f.value
     d, output = d.split("\n", 1)
     try:
         d = bool(int(d))
     except ValueError:
         raise error.ResponseError(_("push failed (unexpected response):"), d)
     for l in output.splitlines(True):
         self.ui.status(_("remote: "), l)
     yield d
Пример #32
0
 def listkeys(self, namespace):
     if not self.capable('pushkey'):
         yield {}, None
     f = future()
     yield todict(namespace=encoding.fromlocal(namespace)), f
     d = f.value
     r = {}
     for l in d.splitlines():
         k, v = l.split('\t')
         r[encoding.tolocal(k)] = encoding.tolocal(v)
     yield r
Пример #33
0
 def listkeys(self, namespace):
     if not self.capable('pushkey'):
         yield {}, None
     f = future()
     yield todict(namespace=encoding.fromlocal(namespace)), f
     d = f.value
     r = {}
     for l in d.splitlines():
         k, v = l.split('\t')
         r[encoding.tolocal(k)] = encoding.tolocal(v)
     yield r
Пример #34
0
 def listkeys(self, namespace):
     if not self.capable('pushkey'):
         yield {}, None
     f = future()
     self.ui.debug('preparing listkeys for "%s"\n' % namespace)
     yield {'namespace': encoding.fromlocal(namespace)}, f
     d = f.value
     r = {}
     for l in d.splitlines():
         k, v = l.split('\t')
         r[encoding.tolocal(k)] = encoding.tolocal(v)
     yield r
Пример #35
0
 def listkeys(self, namespace):
     if not self.capable('pushkey'):
         yield {}, None
     f = future()
     self.ui.debug('preparing listkeys for "%s"\n' % namespace)
     yield {'namespace': encoding.fromlocal(namespace)}, f
     d = f.value
     r = {}
     for l in d.splitlines():
         k, v = l.split('\t')
         r[encoding.tolocal(k)] = encoding.tolocal(v)
     yield r
Пример #36
0
        def metadata():
            base = "repo: %s\nnode: %s\nbranch: %s\n" % (repo[0].hex(), hex(node), encoding.fromlocal(ctx.branch()))

            tags = "".join("tag: %s\n" % t for t in ctx.tags() if repo.tagtype(t) == "global")
            if not tags:
                repo.ui.pushbuffer()
                opts = {"template": "{latesttag}\n{latesttagdistance}", "style": "", "patch": None, "git": None}
                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
                ltags, dist = repo.ui.popbuffer().split("\n")
                tags = "".join("latesttag: %s\n" % t for t in ltags.split(":"))
                tags += "latesttagdistance: %s\n" % dist

            return base + tags
Пример #37
0
 def write(self, repo):
     try:
         f = repo.opener(_filename(repo), "w", atomictemp=True)
         cachekey = [hex(self.tipnode), str(self.tiprev)]
         if self.filteredhash is not None:
             cachekey.append(hex(self.filteredhash))
         f.write(" ".join(cachekey) + '\n')
         for label, nodes in sorted(self.iteritems()):
             for node in nodes:
                 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
         f.close()
     except (IOError, OSError, util.Abort):
         # Abort may be raise by read only opener
         pass
Пример #38
0
def makememctx(repo, parents, text, user, date, branch, files, store,
               editor=None):
    def getfilectx(repo, memctx, path):
        data, (islink, isexec), copied = store.getfile(path)
        return memfilectx(path, data, islink=islink, isexec=isexec,
                                  copied=copied)
    extra = {}
    if branch:
        extra['branch'] = encoding.fromlocal(branch)
    ctx =  memctx(repo, parents, text, files, getfilectx, user,
                          date, extra)
    if editor:
        ctx._text = editor(repo, ctx, [])
    return ctx
Пример #39
0
 def write(self, repo):
     try:
         f = repo.opener(_filename(repo), "w", atomictemp=True)
         cachekey = [hex(self.tipnode), str(self.tiprev)]
         if self.filteredhash is not None:
             cachekey.append(hex(self.filteredhash))
         f.write(" ".join(cachekey) + '\n')
         for label, nodes in sorted(self.iteritems()):
             for node in nodes:
                 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
         f.close()
     except (IOError, OSError, util.Abort):
         # Abort may be raise by read only opener
         pass
Пример #40
0
    def add(self, manifest, files, desc, transaction, p1, p2,
                  user, date=None, extra=None):
        # Convert to UTF-8 encoded bytestrings as the very first
        # thing: calling any method on a localstr object will turn it
        # into a str object and the cached UTF-8 string is thus lost.
        user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)

        user = user.strip()
        # An empty username or a username with a "\n" will make the
        # revision text contain two "\n\n" sequences -> corrupt
        # repository since read cannot unpack the revision.
        if not user:
            raise error.RevlogError(_("empty username"))
        if "\n" in user:
            raise error.RevlogError(_("username %s contains a newline")
                                    % repr(user))

        # strip trailing whitespace and leading and trailing empty lines
        desc = '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')

        if date:
            parseddate = "%d %d" % util.parsedate(date)
        else:
            parseddate = "%d %d" % util.makedate()
        if extra:
            branch = extra.get("branch")
            if branch in ("default", ""):
                del extra["branch"]
            elif branch in (".", "null", "tip"):
                raise error.RevlogError(_('the name \'%s\' is reserved')
                                        % branch)
        if extra:
            extra = encodeextra(extra)
            parseddate = "%s %s" % (parseddate, extra)
        l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
        text = "\n".join(l)
        return self.addrevision(text, transaction, len(self), p1, p2)
Пример #41
0
    def setbranch(self, branch):
        self._branch = encoding.fromlocal(branch)
        f = self._opener('branch', 'w', atomictemp=True)
        try:
            f.write(self._branch + '\n')
            f.close()

            # make sure filecache has the correct stat info for _branch after
            # replacing the underlying file
            ce = self._filecache['_branch']
            if ce:
                ce.refresh()
        except:  # re-raises
            f.discard()
            raise
Пример #42
0
    def setbranch(self, branch):
        self._branch = encoding.fromlocal(branch)
        f = self._opener('branch', 'w', atomictemp=True)
        try:
            f.write(self._branch + '\n')
            f.close()

            # make sure filecache has the correct stat info for _branch after
            # replacing the underlying file
            ce = self._filecache['_branch']
            if ce:
                ce.refresh()
        except: # re-raises
            f.discard()
            raise
Пример #43
0
        def metadata():
            base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
                repo[0].hex(), hex(node), encoding.fromlocal(ctx.branch()))

            tags = ''.join('tag: %s\n' % t for t in ctx.tags()
                           if repo.tagtype(t) == 'global')
            if not tags:
                repo.ui.pushbuffer()
                opts = {'template': '{latesttag}\n{latesttagdistance}',
                        'style': '', 'patch': None, 'git': None}
                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
                ltags, dist = repo.ui.popbuffer().split('\n')
                tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':'))
                tags += 'latesttagdistance: %s\n' % dist

            return base + tags
Пример #44
0
    def write(self, tr=None):
        """Save branch cache if it is dirty."""
        repo = self._repo
        if self._rbcnamescount < len(self._names):
            try:
                if self._rbcnamescount != 0:
                    f = repo.vfs.open(_rbcnames, 'ab')
                    if f.tell() == self._rbcsnameslen:
                        f.write('\0')
                    else:
                        f.close()
                        repo.ui.debug("%s changed - rewriting it\n" %
                                      _rbcnames)
                        self._rbcnamescount = 0
                        self._rbcrevslen = 0
                if self._rbcnamescount == 0:
                    f = repo.vfs.open(_rbcnames, 'wb')
                f.write('\0'.join(
                    encoding.fromlocal(b)
                    for b in self._names[self._rbcnamescount:]))
                self._rbcsnameslen = f.tell()
                f.close()
            except (IOError, OSError, util.Abort) as inst:
                repo.ui.debug("couldn't write revision branch cache names: "
                              "%s\n" % inst)
                return
            self._rbcnamescount = len(self._names)

        start = self._rbcrevslen * _rbcrecsize
        if start != len(self._rbcrevs):
            revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize)
            try:
                f = repo.vfs.open(_rbcrevs, 'ab')
                if f.tell() != start:
                    repo.ui.debug("truncating %s to %s\n" % (_rbcrevs, start))
                    f.seek(start)
                    f.truncate()
                end = revs * _rbcrecsize
                f.write(self._rbcrevs[start:end])
                f.close()
            except (IOError, OSError, util.Abort) as inst:
                repo.ui.debug("couldn't write revision branch cache: %s\n" %
                              inst)
                return
            self._rbcrevslen = revs
Пример #45
0
 def branchmap(self):
     d = self.do_read("branchmap")
     try:
         branchmap = {}
         for branchpart in d.splitlines():
             branchheads = branchpart.split(' ')
             branchname = urllib.unquote(branchheads[0])
             # Earlier servers (1.3.x) send branch names in (their) local
             # charset. The best we can do is assume it's identical to our
             # own local charset, in case it's not utf-8.
             try:
                 branchname.decode('utf-8')
             except UnicodeDecodeError:
                 branchname = encoding.fromlocal(branchname)
             branchheads = [bin(x) for x in branchheads[1:]]
             branchmap[branchname] = branchheads
         return branchmap
     except:
         raise error.ResponseError(_("unexpected response:"), d)
 def branchmap(self):
     d = self._call("branchmap")
     try:
         branchmap = {}
         for branchpart in d.splitlines():
             branchname, branchheads = branchpart.split(' ', 1)
             branchname = urllib.unquote(branchname)
             # Earlier servers (1.3.x) send branch names in (their) local
             # charset. The best we can do is assume it's identical to our
             # own local charset, in case it's not utf-8.
             try:
                 branchname.decode('utf-8')
             except UnicodeDecodeError:
                 branchname = encoding.fromlocal(branchname)
             branchheads = decodelist(branchheads)
             branchmap[branchname] = branchheads
         return branchmap
     except TypeError:
         self._abort(error.ResponseError(_("unexpected response:"), d))
Пример #47
0
 def branchmap(self):
     d = self._call("branchmap")
     try:
         branchmap = {}
         for branchpart in d.splitlines():
             branchname, branchheads = branchpart.split(" ", 1)
             branchname = urllib.unquote(branchname)
             # Earlier servers (1.3.x) send branch names in (their) local
             # charset. The best we can do is assume it's identical to our
             # own local charset, in case it's not utf-8.
             try:
                 branchname.decode("utf-8")
             except UnicodeDecodeError:
                 branchname = encoding.fromlocal(branchname)
             branchheads = decodelist(branchheads)
             branchmap[branchname] = branchheads
         return branchmap
     except TypeError:
         self._abort(error.ResponseError(_("unexpected response:"), d))
Пример #48
0
 def branchmap(self):
     d = self.do_read("branchmap")
     try:
         branchmap = {}
         for branchpart in d.splitlines():
             branchheads = branchpart.split(' ')
             branchname = urllib.unquote(branchheads[0])
             # Earlier servers (1.3.x) send branch names in (their) local
             # charset. The best we can do is assume it's identical to our
             # own local charset, in case it's not utf-8.
             try:
                 branchname.decode('utf-8')
             except UnicodeDecodeError:
                 branchname = encoding.fromlocal(branchname)
             branchheads = [bin(x) for x in branchheads[1:]]
             branchmap[branchname] = branchheads
         return branchmap
     except:
         raise error.ResponseError(_("unexpected response:"), d)
Пример #49
0
def addbranchrevs(lrepo, repo, branches, revs):
    if not branches:
        return revs or None, revs and revs[0] or None
    revs = revs and list(revs) or []
    if not repo.capable('branchmap'):
        revs.extend(branches)
        return revs, revs[0]
    branchmap = repo.branchmap()
    for branch in branches:
        if branch == '.':
            if not lrepo or not lrepo.local():
                raise util.Abort(_("dirstate branch not accessible"))
            revs.append(lrepo.dirstate.branch())
        else:
            butf8 = encoding.fromlocal(branch)
            if butf8 in branchmap:
                revs.extend(node.hex(r) for r in reversed(branchmap[butf8]))
            else:
                revs.append(branch)
    return revs, revs[0]
Пример #50
0
        def metadata():
            base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
                repo[0].hex(), hex(node), encoding.fromlocal(ctx.branch()))

            tags = ''.join('tag: %s\n' % t for t in ctx.tags()
                           if repo.tagtype(t) == 'global')
            if not tags:
                repo.ui.pushbuffer()
                opts = {
                    'template': '{latesttag}\n{latesttagdistance}',
                    'style': '',
                    'patch': None,
                    'git': None
                }
                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
                ltags, dist = repo.ui.popbuffer().split('\n')
                tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':'))
                tags += 'latesttagdistance: %s\n' % dist

            return base + tags
Пример #51
0
def makememctx(repo,
               parents,
               text,
               user,
               date,
               branch,
               files,
               store,
               editor=None):
    def getfilectx(repo, memctx, path):
        data, (islink, isexec), copied = store.getfile(path)
        return memfilectx(path,
                          data,
                          islink=islink,
                          isexec=isexec,
                          copied=copied)

    extra = {}
    if branch:
        extra['branch'] = encoding.fromlocal(branch)
    ctx = memctx(repo, parents, text, files, getfilectx, user, date, extra)
    if editor:
        ctx._text = editor(repo, ctx, [])
    return ctx
Пример #52
0
    def __init__(self,
                 repo,
                 text="",
                 user=None,
                 date=None,
                 extra=None,
                 changes=None):
        self._repo = repo
        self._rev = None
        self._node = None
        self._text = text
        if date:
            self._date = util.parsedate(date)
        if user:
            self._user = user
        if changes:
            self._status = list(changes[:4])
            self._unknown = changes[4]
            self._ignored = changes[5]
            self._clean = changes[6]
        else:
            self._unknown = None
            self._ignored = None
            self._clean = None

        self._extra = {}
        if extra:
            self._extra = extra.copy()
        if 'branch' not in self._extra:
            try:
                branch = encoding.fromlocal(self._repo.dirstate.branch())
            except UnicodeDecodeError:
                raise util.Abort(_('branch name not in UTF-8!'))
            self._extra['branch'] = branch
        if self._extra['branch'] == '':
            self._extra['branch'] = 'default'
Пример #53
0
def listkeys(repo, proto, namespace):
    d = pushkeymod.list(repo, encoding.tolocal(namespace)).items()
    t = '\n'.join(['%s\t%s' % (encoding.fromlocal(k), encoding.fromlocal(v))
                   for k, v in d])
    return t
Пример #54
0
 def setbranch(self, branch):
     if branch in ['tip', '.', 'null']:
         raise util.Abort(_('the name \'%s\' is reserved') % branch)
     self._branch = encoding.fromlocal(branch)
     self._opener("branch", "w").write(self._branch + '\n')