Ejemplo n.º 1
0
def updatebfiles(ui, repo):
    wlock = repo.wlock()
    try:
        bfdirstate = bfutil.openbfdirstate(ui, repo)
        s = bfdirstate.status(match_.always(repo.root, repo.getcwd()), [],
            False, False, False)
        unsure, modified, added, removed, missing, unknown, ignored, clean = s

        bfiles = bfutil.listbfiles(repo)
        toget = []
        at = 0
        updated = 0
        removed = 0
        printed = False
        if bfiles:
            ui.status(_('getting changed bfiles\n'))
            printed = True

        for bfile in bfiles:
            at += 1
            if os.path.exists(repo.wjoin(bfile)) and not \
                    os.path.exists(repo.wjoin(bfutil.standin(bfile))):
                os.unlink(repo.wjoin(bfile))
                removed += 1
                bfdirstate.forget(bfutil.unixpath(bfile))
                continue
            expectedhash = repo[None][bfutil.standin(bfile)].data().strip()
            mode = os.stat(repo.wjoin(bfutil.standin(bfile))).st_mode
            if not os.path.exists(repo.wjoin(bfile)) or expectedhash != \
                    bfutil.hashfile(repo.wjoin(bfile)):
                path = bfutil.findfile(repo, expectedhash)
                if not path:
                    toget.append((bfile, expectedhash))
                else:
                    util.makedirs(os.path.dirname(repo.wjoin(bfile)))
                    shutil.copy(path,  repo.wjoin(bfile))
                    os.chmod(repo.wjoin(bfile), mode)
                    updated += 1
                    bfdirstate.normal(bfutil.unixpath(bfile))
            elif os.path.exists(repo.wjoin(bfile)) and mode != \
                    os.stat(repo.wjoin(bfile)).st_mode:
                os.chmod(repo.wjoin(bfile), mode)
                updated += 1
                bfdirstate.normal(bfutil.unixpath(bfile))

        if toget:
            store = basestore._openstore(repo)
            (success, missing) = store.get(toget)
        else:
            success, missing = [],[]

        for (filename, hash) in success:
            mode = os.stat(repo.wjoin(bfutil.standin(filename))).st_mode
            os.chmod(repo.wjoin(filename), mode)
            updated += 1
            bfdirstate.normal(bfutil.unixpath(filename))

        for bfile in bfdirstate:
            if bfile not in bfiles:
                if os.path.exists(repo.wjoin(bfile)):
                    if not printed:
                        ui.status(_('getting changed bfiles\n'))
                        printed = True
                    os.unlink(repo.wjoin(bfile))
                    removed += 1
                    path = bfutil.unixpath(bfile)
                    try:
                        # Mercurial >= 1.9
                        bfdirstate.drop(path)
                    except AttributeError:
                        # Mercurial <= 1.8
                        bfdirstate.forget(path)

        bfdirstate.write()
        if printed:
            ui.status(_('%d big files updated, %d removed\n') % (updated,
                removed))
    finally:
        wlock.release()
Ejemplo n.º 2
0
def revertbfiles(ui, repo, filelist=None):
    wlock = repo.wlock()
    try:
        bfdirstate = bfutil.openbfdirstate(ui, repo)
        s = bfdirstate.status(match_.always(repo.root, repo.getcwd()), [],
            False, False, False)
        unsure, modified, added, removed, missing, unknown, ignored, clean = s

        bfiles = bfutil.listbfiles(repo)
        toget = []
        at = 0
        updated = 0
        for bfile in bfiles:
            if filelist is None or bfile in filelist:
                if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):
                    bfdirstate.remove(bfile)
                    continue
                if os.path.exists(repo.wjoin(bfutil.standin(os.path.join(bfile\
                    + '.orig')))):
                    shutil.copyfile(repo.wjoin(bfile), repo.wjoin(bfile + \
                        '.orig'))
                at += 1
                expectedhash = repo[None][bfutil.standin(bfile)].data().strip()
                mode = os.stat(repo.wjoin(bfutil.standin(bfile))).st_mode
                if not os.path.exists(repo.wjoin(bfile)) or expectedhash != \
                        bfutil.hashfile(repo.wjoin(bfile)):
                    path = bfutil.findfile(repo, expectedhash)
                    if path is None:
                        toget.append((bfile, expectedhash))
                    else:
                        util.makedirs(os.path.dirname(repo.wjoin(bfile)))
                        shutil.copy(path, repo.wjoin(bfile))
                        os.chmod(repo.wjoin(bfile), mode)
                        updated += 1
                        if bfutil.standin(bfile) not in repo['.']:
                            bfdirstate.add(bfutil.unixpath(bfile))
                        elif expectedhash == repo['.'][bfutil.standin(bfile)] \
                                .data().strip():
                            bfdirstate.normal(bfutil.unixpath(bfile))
                        else:
                            bfutil.dirstate_normaldirty(bfdirstate,
                                bfutil.unixpath(bfile))
                elif os.path.exists(repo.wjoin(bfile)) and mode != \
                        os.stat(repo.wjoin(bfile)).st_mode:
                    os.chmod(repo.wjoin(bfile), mode)
                    updated += 1
                    if bfutil.standin(bfile) not in repo['.']:
                        bfdirstate.add(bfutil.unixpath(bfile))
                    elif expectedhash == \
                            repo['.'][bfutil.standin(bfile)].data().strip():
                        bfdirstate.normal(bfutil.unixpath(bfile))
                    else:
                        bfutil.dirstate_normaldirty(bfdirstate,
                            bfutil.unixpath(bfile))

        if toget:
            store = basestore._openstore(repo)
            success, missing = store.get(toget)
        else:
            success, missing = [], []

        for (filename, hash) in success:
            mode = os.stat(repo.wjoin(bfutil.standin(filename))).st_mode
            os.chmod(repo.wjoin(filename), mode)
            updated += 1
            if bfutil.standin(filename) not in repo['.']:
                bfdirstate.add(bfutil.unixpath(filename))
            elif hash == repo['.'][bfutil.standin(filename)].data().strip():
                bfdirstate.normal(bfutil.unixpath(filename))
            else:
                bfutil.dirstate_normaldirty(bfdirstate,
                    bfutil.unixpath(filename))

        removed = 0
        for bfile in bfdirstate:
            if filelist is None or bfile in filelist:
                if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):
                    if os.path.exists(repo.wjoin(bfile)):
                        os.unlink(repo.wjoin(bfile))
                        removed += 1
                        if bfutil.standin(bfile) in repo['.']:
                            bfdirstate.remove(bfutil.unixpath(bfile))
                        else:
                            bfdirstate.forget(bfutil.unixpath(bfile))
                else:
                    state = repo.dirstate[bfutil.standin(bfile)]
                    if state == 'n':
                        bfdirstate.normal(bfile)
                    elif state == 'r':
                        bfdirstate.remove(bfile)
                    elif state == 'a':
                        bfdirstate.add(bfile)
                    elif state == '?':
                        try:
                            # Mercurial >= 1.9
                            bfdirstate.drop(bfile)
                        except AttributeError:
                            # Mercurial <= 1.8
                            bfdirstate.forget(bfile)
        bfdirstate.write()
    finally:
        wlock.release()