Beispiel #1
0
def do_list(parser):
    repo = parser.repo
    for bmark, node in bookmarks.listbookmarks(repo).iteritems():
        bmarks[bmark] = repo[node]

    cur = repo.dirstate.branch()
    orig = peer if peer else repo

    for branch, heads in orig.branchmap().iteritems():
        # only open heads
        heads = [h for h in heads if 'close' not in repo.changelog.read(h)[5]]
        if heads:
            branches[branch] = heads

    list_head(repo, cur)

    if track_branches:
        for branch in branches:
            print "? refs/heads/branches/%s" % gitref(branch)

    for bmark in bmarks:
        print "? refs/heads/%s" % gitref(bmark)

    for tag, node in repo.tagslist():
        if tag == 'tip':
            continue
        print "? refs/tags/%s" % gitref(tag)

    print
Beispiel #2
0
    def do_list(self, parser):
        '''List all references in the mercurial repository. This includes
        the current head, all branches, tags, and bookmarks.'''

        current_branch = self.repo.dirstate.branch()

        # Update the head reference
        head = readcurrent(self.repo)
        if head:
            node = self.repo[head]
        else:
            # If there is no bookmark for head, mock one
            head = current_branch
            node = self.repo['.']
            # I think this means an initial clone occured and we haven't
            # hg updated yet in the local clone
            if not node:
                if 'default' in self.repo:
                    node = self.repo['default']
                else:  # empty repository or head is at 0 commit
                    output()
                    return
            head = head if head != 'default' else 'master'
            #self.bookmarks[head] = node

        self.headnode = (head, node)

        # Update the bookmark references
        for bookmark, node in listbookmarks(self.repo).iteritems():
            self.bookmarks[bookmark] = self.repo[node]

        # update the named branch references
        for branch in self.repo.branchmap():
            heads = self.repo.branchheads(branch, closed=True)
            if heads:
                self.branches[branch] = heads

        # list the head reference
        output("@refs/heads/%s HEAD" % self.headnode[0])

        # list the named branch references
        for branch in self.branches:
            if branch != "default":
                output("? refs/heads/branches/%s" % hg_to_git_spaces(branch))
            else:
                output("? refs/heads/master")

        # list the bookmark references
        for bookmark in self.bookmarks:
            if bookmark != "master":
                output("? refs/heads/%s" % hg_to_git_spaces(bookmark))

        # list the tags
        for tag, node in self.repo.tagslist():
            if tag != "tip":
                output("? refs/tags/%s" % hg_to_git_spaces(tag))

        output()
Beispiel #3
0
def kpull(ui, repo, bookmark=None):
    """Pull the changes from the specified remote bookmark into the local
    repository.
    """
    if bookmarks.listbookmarks(repo):
        raise util.Abort("local repo must not have any bookmarks")

    bookmark = _read_bookmark(repo) if bookmark is None else bookmark
    return commands.pull(ui, repo, source='default', rev=[bookmark])
def firefoxtrees(repo, proto):
    lines = []

    if repo.ui.configbool('firefoxtree', 'servetagsfrombookmarks'):
        for name, hnode in sorted(bookmarks.listbookmarks(repo).items()):
            tree, uri = resolve_trees_to_uris([name])[0]
            if not uri:
                continue

            lines.append('%s %s' % (tree.encode('ascii'), hnode))
    else:
        for tag, node, tree, uri in get_firefoxtrees(repo):
            lines.append('%s %s' % (tag, hex(node)))

    return '\n'.join(lines)
def firefoxtrees(repo, proto):
    lines = []

    if repo.ui.configbool('firefoxtree', 'servetagsfrombookmarks', False):
        for name, hnode in sorted(bookmarks.listbookmarks(repo).items()):
            tree, uri = resolve_trees_to_uris([name])[0]
            if not uri:
                continue

            lines.append('%s %s' % (tree.encode('ascii'), hnode))
    else:
        for tag, node, tree, uri in get_firefoxtrees(repo):
            lines.append('%s %s' % (tag, hex(node)))

    return '\n'.join(lines)
Beispiel #6
0
 def getbookmarks(self):
     return bookmarks.listbookmarks(self.repo)
Beispiel #7
0
 def getbookmarks(self):
     return bookmarks.listbookmarks(self.repo)
Beispiel #8
0
def branching_info(repo: hg.localrepo, ignored: Set[int]) -> BranchingInfo:
    """Lists all relevant information about branch heads and bookmarks, grouped by type.

    `ignored`: Revisions that we ignore during loading because they are corrupted or
    have a corrupted ancestor.

    Categories may have overlapping nodes: a branch tip can be a closed branch head
    and have a bookmark on it, for example.
    """
    branch_tips: Dict[bytes, HgNodeId] = {}
    branch_open_heads = defaultdict(list)
    branch_closed_heads = defaultdict(list)
    all_bookmarks = bookmarks.listbookmarks(repo)

    for branch_name, heads in repo.branchmap().items():
        # Sort the heads by node id since it's stable and doesn't depend on local
        # topology like cloning order.
        for head in sorted(heads):
            head = repo[head]
            if head.rev() in ignored:
                # This revision or one of its ancestors is corrupted, ignore it
                continue
            node_id = head.node()
            if head.closesbranch():
                branch_closed_heads[branch_name].append(node_id)
            else:
                if not branch_tips.get(branch_name):
                    branch_tips[branch_name] = node_id
                branch_open_heads[branch_name].append(node_id)

    # The default revision is where the "@" bookmark is, or failing that the tip of the
    # `default` branch. For our purposes we're trying to find a branch tip to alias to,
    # so only return those if they are branch tips, otherwise don't bother.
    default_rev_alias = None
    at_bookmark = all_bookmarks.get(b"@")
    if at_bookmark is not None:
        bookmark_at_branch = repo[at_bookmark].branch()
        if branch_tips.get(bookmark_at_branch) is not None:
            default_rev_alias = b"bookmarks/@"
    if default_rev_alias is None and branch_tips.get(b"default") is not None:
        default_rev_alias = b"branch-tip/default"

    branches_with_one_head = set()
    for branch, heads in branch_open_heads.items():
        if len(heads) == 1:
            branches_with_one_head.add(branch)

    # The most common case is one head per branch. Simplifying this means we have
    # less duplicate data, because open heads are the same as open branch tips.
    # We don't do more complex deduplication, this is just a simple optimization.
    for branch in branches_with_one_head:
        del branch_open_heads[branch]

    # for bookmarks, the ids listed are not aligned with the rest, it's human
    # readable id as bytes string instead of bytes string. Hence the extra mapping.
    branch_bookmarks = {
        branch: HgNodeId(bytes.fromhex(node_id.decode()))
        for branch, node_id in all_bookmarks.items()
    }

    return BranchingInfo(
        tips=branch_tips,
        bookmarks=branch_bookmarks,
        open_heads=branch_open_heads,
        closed_heads=branch_closed_heads,
        default_branch_alias=default_rev_alias,
    )
Beispiel #9
0
    def do_list(self, parser):
        """List all references in the mercurial repository. This includes
        the current head, all branches, tags, and bookmarks."""

        current_branch = self.repo.dirstate.branch()

        # Update the head reference
        if hg_version() >= "4.0.1":
            head = _readactive(self.repo, self.repo._bookmarks)
        else:
            head = readcurrent(self.repo)

        if head:
            node = self.repo[head]
        else:
            # If there is no bookmark for head, mock one
            head = current_branch
            node = self.repo["."]
            # I think this means an initial clone occured and we haven't
            # hg updated yet in the local clone
            if not node:
                if "default" in self.repo:
                    node = self.repo["default"]
                else:  # empty repository or head is at 0 commit
                    output()
                    return
            head = head if head != "default" else "master"
            # self.bookmarks[head] = node

        self.headnode = (head, node)

        # Update the bookmark references
        for bookmark, node in listbookmarks(self.repo).iteritems():
            self.bookmarks[bookmark] = self.repo[node]

        # update the named branch references
        for branch in self.repo.branchmap():
            # FIXME: Probably a git config instead of an env var would make
            # people happier here.
            clone_closed = os.environ.get("GITIFYHG_ALLOW_CLOSED_BRANCHES") != None
            heads = self.repo.branchheads(branch, closed=clone_closed)
            if heads:
                self.branches[branch] = heads

        # list the head reference
        output("@refs/heads/%s HEAD" % self.headnode[0])

        # list the named branch references
        for branch in self.branches:
            output(
                "%s %s"
                % (self._change_hash(branch_head(self, branch)), name_reftype_to_ref(hg_to_git_spaces(branch), BRANCH))
            )

        # list the bookmark references
        for bookmark, changectx in self.bookmarks.items():
            if bookmark != "master":
                output(
                    "%s %s" % (self._change_hash(changectx), name_reftype_to_ref(hg_to_git_spaces(bookmark), BOOKMARK))
                )

        # list the tags
        for tag, node in self.repo.tagslist():
            if tag != "tip":
                output("%s %s" % (self._change_hash(self.repo[node]), name_reftype_to_ref(hg_to_git_spaces(tag), TAG)))

        output()
Beispiel #10
0
    def do_list(self, parser):
        '''List all references in the mercurial repository. This includes
        the current head, all branches, tags, and bookmarks.'''

        current_branch = self.repo.dirstate.branch()

        # Update the head reference
        head = readcurrent(self.repo)
        if head:
            node = self.repo[head]
        else:
            # If there is no bookmark for head, mock one
            head = current_branch
            node = self.repo['.']
            # I think this means an initial clone occured and we haven't
            # hg updated yet in the local clone
            if not node:
                if 'default' in self.repo:
                    node = self.repo['default']
                else:  # empty repository or head is at 0 commit
                    output()
                    return
            head = head if head != 'default' else 'master'
            #self.bookmarks[head] = node

        self.headnode = (head, node)

        # Update the bookmark references
        for bookmark, node in listbookmarks(self.repo).iteritems():
            self.bookmarks[bookmark] = self.repo[node]

        # update the named branch references
        for branch in self.repo.branchmap():
            # FIXME: Probably a git config instead of an env var would make
            # people happier here.
            clone_closed = os.environ.get(
                "GITIFYHG_ALLOW_CLOSED_BRANCHES") != None
            heads = self.repo.branchheads(branch, closed=clone_closed)
            if heads:
                self.branches[branch] = heads

        # list the head reference
        output("@refs/heads/%s HEAD" % self.headnode[0])

        # list the named branch references
        for branch in self.branches:
            output("%s %s" %
                   (self._change_hash(branch_head(self, branch)),
                    name_reftype_to_ref(hg_to_git_spaces(branch), BRANCH)))

        # list the bookmark references
        for bookmark, changectx in self.bookmarks.items():
            if bookmark != "master":
                output("%s %s" % (self._change_hash(changectx),
                                  name_reftype_to_ref(
                                      hg_to_git_spaces(bookmark), BOOKMARK)))

        # list the tags
        for tag, node in self.repo.tagslist():
            if tag != "tip":
                output("%s %s" %
                       (self._change_hash(self.repo[node]),
                        name_reftype_to_ref(hg_to_git_spaces(tag), TAG)))

        output()
Beispiel #11
0
def kpush(ui, repo, bookmark=None, force=False, new_bookmark=False, **opts):
    """Push the current changeset (.) to the specified bookmark on the default
    push remote.

    Returns 0 if push was successful, 1 on error.
    """
    if bookmarks.listbookmarks(repo):
        raise util.Abort("local repo must not have any bookmarks")

    # First, push the changeset
    dest = ui.expandpath('default-push', 'default')
    dest, _ = hg.parseurl(dest)
    ui.status("pushing to %s\n" % util.hidepassword(dest))

    remote = hg.peer(repo, opts, dest)
    head = repo['.']

    # Push subrepos, copied from commands.push
    # TODO(alpert): What is this _subtoppath craziness?
    repo._subtoppath = dest
    try:
        # Push subrepos depth-first for coherent ordering
        subs = head.substate  # Only repos that are committed
        for s in sorted(subs):
            if head.sub(s).push(opts) == 0:
                return False
    finally:
        del repo._subtoppath

    result = repo.push(remote, force, revs=[head.node()])
    result = not result  # Uh, okay...

    # Then, update the bookmark
    bookmark = _read_bookmark(repo) if bookmark is None else bookmark
    remote_books = remote.listkeys('bookmarks')
    new_node = node.hex(repo.lookup('.'))

    if bookmark in remote_books:
        old_node = remote_books[bookmark]
        if new_node == old_node:
            ui.status("nothing to update\n")
            return 0
        elif repo[new_node] in repo[old_node].descendants():
            ui.status("updating bookmark %s\n" % bookmark)
        elif force:
            ui.status("force-updating bookmark %s\n" % bookmark)
        else:
            ui.warn("skipping non-fast-forward update of bookmark %s\n" %
                    bookmark)
            return 1
    elif new_bookmark:
        old_node = ''
        ui.status("creating bookmark %s\n" % bookmark)
    else:
        ui.warn('remote bookmark %r not found: did you want --new-bookmark?\n'
                % bookmark)
        return 1

    r = remote.pushkey('bookmarks', bookmark, old_node, new_node)
    if not r:
        # Either someone else pushed at the same time as us or new_node doesn't
        # exist in the remote repo (see bookmarks.pushbookmark).
        ui.warn("updating bookmark %s failed!\n" % bookmark)
        return 1

    return 0