Пример #1
0
    def _verifyfile(self, cctx, cset, contents, standin, verified):
        filename = bfutil.splitstandin(standin)
        if not filename:
            return False
        fctx = cctx[standin]
        key = (filename, fctx.filenode())
        if key in verified:
            return False

        expecthash = fctx.data()[0:40]
        verified.add(key)
        if not bfutil.insystemcache(self.ui, expecthash):
            self.ui.warn(
                _('changeset %s: %s missing\n'
                  '  (%s: %s)\n')
                % (cset, filename, expecthash, err.strerror))
            return True                 # failed

        if contents:
            storepath = bfutil.systemcachepath(self.ui, expecthash)
            actualhash = bfutil.hashfile(storepath)
            if actualhash != expecthash:
                self.ui.warn(
                    _('changeset %s: %s: contents differ\n'
                      '  (%s:\n'
                      '  expected hash %s,\n'
                      '  but got %s)\n')
                    % (cset, filename, storepath, expecthash, actualhash))
                return True             # failed
        return False
Пример #2
0
    def _verifyfile(self, cctx, cset, contents, standin, verified):
        filename = bfutil.split_standin(standin)
        if not filename:
            return False
        fctx = cctx[standin]
        key = (filename, fctx.filenode())
        if key in verified:
            return False

        expect_hash = fctx.data()[0:40]
        verified.add(key)
        if not bfutil.in_system_cache(self.ui, expect_hash):
            self.ui.warn(
                _('changeset %s: %s missing\n'
                  '  (%s: %s)\n') %
                (cset, filename, expect_hash, err.strerror))
            return True  # failed

        if contents:
            store_path = bfutil.system_cache_path(self.ui, expect_hash)
            actual_hash = bfutil.hashfile(store_path)
            if actual_hash != expect_hash:
                self.ui.warn(
                    _('changeset %s: %s: contents differ\n'
                      '  (%s:\n'
                      '  expected hash %s,\n'
                      '  but got %s)\n') %
                    (cset, filename, store_path, expect_hash, actual_hash))
                return True  # failed
        return False
Пример #3
0
def override_update(orig, ui, repo, *pats, **opts):
    bfdirstate = bfutil.open_bfdirstate(ui, repo)
    s = bfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False, False, False)
    (unsure, modified, added, removed, missing, unknown, ignored, clean) = s

    # Need to lock between the standins getting updated and their bfiles getting updated
    wlock = repo.wlock()
    try:
        if opts['check']:
            mod = len(modified) > 0
            for bfile in unsure:
                standin = bfutil.standin(bfile)
                if repo['.'][standin].data().strip() != bfutil.hashfile(repo.wjoin(bfile)):
                    mod = True
                else:
                    bfdirstate.normal(bfutil.unixpath(bfile))
            bfdirstate.write()
            if mod:
                raise util.Abort(_('uncommitted local changes'))
        # XXX handle removed differently
        if not opts['clean']:
            for bfile in unsure + modified + added:
                bfutil.update_standin(repo, bfutil.standin(bfile))
    finally:
        wlock.release()
    return orig(ui, repo, *pats, **opts)
Пример #4
0
def update_bfiles(ui, repo):
    wlock = repo.wlock()
    try:
        bfdirstate = bfutil.open_bfdirstate(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.list_bfiles(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.find_file(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._open_store(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
                    bfdirstate.forget(bfutil.unixpath(bfile))

        bfdirstate.write()
        if printed:
            ui.status(
                _('%d big files updated, %d removed\n') % (updated, removed))
    finally:
        wlock.release()
Пример #5
0
def revert_bfiles(ui, repo):
    wlock = repo.wlock()
    try:
        bfdirstate = bfutil.open_bfdirstate(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.list_bfiles(repo)
        toget = []
        at = 0
        updated = 0
        for bfile in bfiles:
            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.find_file(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._open_store(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 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 == '?':
                    bfdirstate.forget(bfile)
        bfdirstate.write()
    finally:
        wlock.release()
Пример #6
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()
Пример #7
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()
Пример #8
0
        def status(self, node1='.', node2=None, match=None, ignored=False, clean=False, unknown=False, subrepos=None):
            listignored, listclean, listunknown = ignored, clean, unknown
            if not self.bfstatus:
                try:
                    return super(bfiles_repo, self).status(node1, node2, match, listignored, listclean, listunknown, subrepos)
                except TypeError:
                    return super(bfiles_repo, self).status(node1, node2, match, listignored, listclean, listunknown)
            else:
                # some calls in this function rely on the old version of status
                self.bfstatus = False
                if isinstance(node1, context.changectx):
                    ctx1 = node1
                else:
                    ctx1 = repo[node1]
                if isinstance(node2, context.changectx):
                    ctx2 = node2
                else:
                    ctx2 = repo[node2]
                working = ctx2.rev() is None
                parentworking = working and ctx1 == self['.']

                def inctx(file, ctx):
                    try:
                        if ctx.rev() is None:
                            return file in ctx.manifest()
                        ctx[file]
                        return True
                    except:
                        return False

                # create a copy of match that matches standins instead of bfiles
                # if matcher not set then it is the always matcher so overwrite that
                if match is None:
                    match = match_.always(self.root, self.getcwd())

                def tostandin(file):
                    if inctx(bfutil.standin(file), ctx2):
                        return bfutil.standin(file)
                    return file

                m = copy.copy(match)
                m._files = [tostandin(f) for f in m._files]

                # get ignored clean and unknown but remove them later if they were not asked for
                try:
                    result = super(bfiles_repo, self).status(node1, node2, m, True, True, True, subrepos)
                except TypeError:
                    result = super(bfiles_repo, self).status(node1, node2, m, True, True, True)
                if working:
                    # Hold the wlock while we read bfiles and update the bfdirstate
                    wlock = repo.wlock()
                    try:
                        # Any non bfiles that were explicitly listed must be taken out or
                        # bfdirstate.status will report an error. The status of these files
                        # was already computed using super's status.
                        bfdirstate = bfutil.open_bfdirstate(ui, self)
                        match._files = [f for f in match._files if f in bfdirstate]
                        s = bfdirstate.status(match, [], listignored, listclean, listunknown)
                        (unsure, modified, added, removed, missing, unknown, ignored, clean) = s
                        if parentworking:
                            for bfile in unsure:
                                if ctx1[bfutil.standin(bfile)].data().strip() != bfutil.hashfile(self.wjoin(bfile)):
                                    modified.append(bfile)
                                else:
                                    clean.append(bfile)
                                    bfdirstate.normal(bfutil.unixpath(bfile))
                            bfdirstate.write()
                        else:
                            tocheck = unsure + modified + added + clean
                            modified, added, clean = [], [], []

                            for bfile in tocheck:
                                standin = bfutil.standin(bfile)
                                if inctx(standin, ctx1):
                                    if ctx1[standin].data().strip() != bfutil.hashfile(self.wjoin(bfile)):
                                        modified.append(bfile)
                                    else:
                                        clean.append(bfile)
                                else:
                                    added.append(bfile)
                    finally:
                        wlock.release()

                    for standin in ctx1.manifest():
                        if not bfutil.is_standin(standin):
                            continue
                        bfile = bfutil.split_standin(standin)
                        if not match(bfile):
                            continue
                        if bfile not in bfdirstate:
                            removed.append(bfile)
                    # Handle unknown and ignored differently
                    bfiles = (modified, added, removed, missing, [], [], clean)
                    result = list(result)
                    # Unknown files
                    result[4] = [f for f in unknown if repo.dirstate[f] == '?' and not bfutil.is_standin(f)]
                    # Ignored files must be ignored by both the dirstate and bfdirstate
                    result[5] = set(ignored).intersection(set(result[5]))
                    # combine normal files and bfiles
                    normals = [[fn for fn in filelist if not bfutil.is_standin(fn)] for filelist in result]
                    result = [sorted(list1 + list2) for (list1, list2) in zip(normals, bfiles)]
                else:
                    def toname(f):
                        if bfutil.is_standin(f):
                            return bfutil.split_standin(f)
                        return f
                    result = [[toname(f) for f in items] for items in result]

                if not listunknown:
                    result[4] = []
                if not listignored:
                    result[5] = []
                if not listclean:
                    result[6] = []
                self.bfstatus = True
                return result