예제 #1
0
파일: shelve.py 프로젝트: mitrandir77/eden
def listcmd(ui, repo, pats, opts):
    """subcommand that displays the list of shelves"""
    pats = set(pats)
    width = 80
    if not ui.plain():
        width = ui.termwidth()
    namelabel = "shelve.newest"
    ui.pager("shelve")
    for mtime, name in listshelves(repo):
        sname = util.split(name)[1]
        if pats and sname not in pats:
            continue
        ui.write(sname, label=namelabel)
        namelabel = "shelve.name"
        if ui.quiet:
            ui.write("\n")
            continue
        ui.write(" " * (16 - len(sname)))
        used = 16
        age = "(%s)" % templatefilters.age(util.makedate(mtime), abbrev=True)
        ui.write(age, label="shelve.age")
        ui.write(" " * (12 - len(age)))
        used += 12
        with open(name + "." + patchextension, "rb") as fp:
            while True:
                line = fp.readline()
                if not line:
                    break
                if not line.startswith(b"#"):
                    desc = pycompat.decodeutf8(line.rstrip())
                    if ui.formatted:
                        desc = util.ellipsis(desc, width - used)
                    ui.write(desc)
                    break
            ui.write("\n")
            if not (opts["patch"] or opts["stat"]):
                continue
            difflines = fp.readlines()
            if opts["patch"]:
                for chunk, label in patch.difflabel(iter, difflines):
                    ui.writebytes(chunk, label=label)
            if opts["stat"]:
                for chunk, label in patch.diffstatui(difflines, width=width):
                    ui.write(chunk, label=label)
예제 #2
0
파일: shelve.py 프로젝트: mitrandir77/eden
def _docreatecmd(ui, repo, pats, opts):
    wctx = repo[None]
    parents = wctx.parents()
    if len(parents) > 1:
        raise error.Abort(_("cannot shelve while merging"))
    parent = parents[0]
    origbranch = wctx.branch()

    if parent.node() != nodemod.nullid:
        desc = "shelve changes to: %s" % parent.description().split("\n", 1)[0]
    else:
        desc = "(changes in empty repository)"

    if not opts.get("message"):
        opts["message"] = desc

    activebookmark = None
    try:
        with repo.lock(), repo.transaction("commit", report=None):

            interactive = opts.get("interactive", False)
            includeunknown = opts.get(
                "unknown", False) and not opts.get("addremove", False)

            name = getshelvename(repo, parent, opts)
            activebookmark = _backupactivebookmark(repo)
            extra = {}
            if includeunknown:
                _includeunknownfiles(repo, pats, opts, extra)

            if _iswctxonnewbranch(repo) and not _isbareshelve(pats, opts):
                # In non-bare shelve we don't store newly created branch
                # at bundled commit
                repo.dirstate.setbranch(repo["."].branch())

            commitfunc = getcommitfunc(extra, interactive, editor=True)
            if not interactive:
                node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
            else:
                node = cmdutil.dorecord(ui, repo, commitfunc, None, False,
                                        cmdutil.recordfilter, *pats, **opts)
            if not node:
                _nothingtoshelvemessaging(ui, repo, pats, opts)
                return 1

            _hidenodes(repo, [node])
    except (KeyboardInterrupt, Exception):
        if activebookmark:
            bookmarks.activate(repo, activebookmark)
        raise

    _shelvecreatedcommit(ui, repo, node, name)

    if ui.formatted:
        desc = util.ellipsis(desc, ui.termwidth())
    ui.status(_("shelved as %s\n") % name)

    # current wc parent may be already obsolete because
    # it might have been created previously and shelve just
    # reuses it
    try:
        hg.update(repo, parent.node())
    except (KeyboardInterrupt, Exception):
        # failed to update to the original revision, which has left us on the
        # (hidden) shelve commit.  Move directly to the original commit by
        # updating the dirstate parents.
        repo.setparents(parent.node())
        raise
    finally:
        if origbranch != repo["."].branch() and not _isbareshelve(pats, opts):
            repo.dirstate.setbranch(origbranch)
        if activebookmark:
            bookmarks.activate(repo, activebookmark)
예제 #3
0
    def _parse(self, ui, path):
        "Prepare list of P4 filenames and revisions to import"
        p4changes = {}
        changeset = {}
        files_map = {}
        copies_map = {}
        localname = {}
        depotname = {}
        heads = []

        ui.status(_("reading p4 views\n"))

        # read client spec or view
        if "/" in path:
            p4changes.update(self._parse_view(path))
            if path.startswith("//") and path.endswith("/..."):
                views = {path[:-3]: ""}
            else:
                views = {"//": ""}
        else:
            cmd = "p4 -G client -o %s" % util.shellquote(path)
            clientspec = marshal.load(util.popen(cmd, mode="rb"))

            views = {}
            for client in clientspec:
                if client.startswith("View"):
                    sview, cview = clientspec[client].split()
                    p4changes.update(self._parse_view(sview))
                    if sview.endswith("...") and cview.endswith("..."):
                        sview = sview[:-3]
                        cview = cview[:-3]
                    cview = cview[2:]
                    cview = cview[cview.find("/") + 1:]
                    views[sview] = cview

        # list of changes that affect our source files
        p4changes = p4changes.keys()
        p4changes.sort(key=int)

        # list with depot pathnames, longest first
        vieworder = views.keys()
        vieworder.sort(key=len, reverse=True)

        # handle revision limiting
        startrev = self.ui.config("convert", "p4.startrev")

        # now read the full changelists to get the list of file revisions
        ui.status(_("collecting p4 changelists\n"))
        lastid = None
        for change in p4changes:
            if startrev and int(change) < int(startrev):
                continue
            if self.revs and int(change) > int(self.revs[0]):
                continue
            if change in self.revmap:
                # Ignore already present revisions, but set the parent pointer.
                lastid = change
                continue

            if lastid:
                parents = [lastid]
            else:
                parents = []

            d = self._fetch_revision(change)
            c = self._construct_commit(d, parents)

            descarr = c.desc.splitlines(True)
            if len(descarr) > 0:
                shortdesc = descarr[0].rstrip("\r\n")
            else:
                shortdesc = "**empty changelist description**"

            t = "%s %s" % (c.rev, repr(shortdesc)[1:-1])
            ui.status(util.ellipsis(t, 80) + "\n")

            files = []
            copies = {}
            copiedfiles = []
            i = 0
            while ("depotFile%d" % i) in d and ("rev%d" % i) in d:
                oldname = d["depotFile%d" % i]
                filename = None
                for v in vieworder:
                    if oldname.lower().startswith(v.lower()):
                        filename = decodefilename(views[v] + oldname[len(v):])
                        break
                if filename:
                    files.append((filename, d["rev%d" % i]))
                    depotname[filename] = oldname
                    if d.get("action%d" % i) == "move/add":
                        copiedfiles.append(filename)
                    localname[oldname] = filename
                i += 1

            # Collect information about copied files
            for filename in copiedfiles:
                oldname = depotname[filename]

                flcmd = "p4 -G filelog %s" % util.shellquote(oldname)
                flstdout = util.popen(flcmd, mode="rb")

                copiedfilename = None
                for d in loaditer(flstdout):
                    copiedoldname = None

                    i = 0
                    while ("change%d" % i) in d:
                        if (d["change%d" % i] == change
                                and d["action%d" % i] == "move/add"):
                            j = 0
                            while ("file%d,%d" % (i, j)) in d:
                                if d["how%d,%d" % (i, j)] == "moved from":
                                    copiedoldname = d["file%d,%d" % (i, j)]
                                    break
                                j += 1
                        i += 1

                    if copiedoldname and copiedoldname in localname:
                        copiedfilename = localname[copiedoldname]
                        break

                if copiedfilename:
                    copies[filename] = copiedfilename
                else:
                    ui.warn(
                        _("cannot find source for copied file: %s@%s\n") %
                        (filename, change))

            changeset[change] = c
            files_map[change] = files
            copies_map[change] = copies
            lastid = change

        if lastid and len(changeset) > 0:
            heads = [lastid]

        return {
            "changeset": changeset,
            "files": files_map,
            "copies": copies_map,
            "heads": heads,
            "depotname": depotname,
        }