Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
mononoke: use visited_pruner
Browse files Browse the repository at this point in the history
Summary: See previous diff for the movitvation

Reviewed By: jsgf

Differential Revision: D8207273

fbshipit-source-id: 527c1d97546afedf36f84059ccb7c740bd412907
  • Loading branch information
StanislavGlebik authored and facebook-github-bot committed Jun 4, 2018
1 parent bc5276a commit 171a456
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 41 deletions.
13 changes: 8 additions & 5 deletions server/src/repo.rs
Expand Up @@ -41,7 +41,8 @@ use mercurial::{self, HgBlobNode, HgManifestId, HgNodeHash, HgParents, NodeHashC
use mercurial_bundles::{parts, Bundle2EncodeBuilder, Bundle2Item};
use mercurial_types::{percent_encode, Changeset, DChangesetId, DManifestId, DNodeHash, DParents,
Entry, MPath, RepoPath, RepositoryId, Type, D_NULL_HASH};
use mercurial_types::manifest_utils::{changed_entry_stream, EntryStatus};
use mercurial_types::manifest_utils::{changed_entry_stream_with_pruner, visited_pruner,
ChangedEntry, EntryStatus};
use metaconfig::repoconfig::RepoType;

use hgproto::{self, GetbundleArgs, GettreepackArgs, HgCommandRes, HgCommands};
Expand Down Expand Up @@ -500,16 +501,17 @@ impl RepoClient {
// TODO: possibly enable compression support once this is fixed.
bundle.set_compressor_type(None);

// TODO(stash): T25850889 same entries will be generated over and over again.
// Potentially it can be very inefficient.
let pruner = visited_pruner();

let changed_entries = params.mfnodes.iter().map(|h| h.into_mononoke()).fold(
stream::empty().boxify(),
|cur_stream, manifest_id| {
move |cur_stream, manifest_id| {
let new_stream = get_changed_entry_stream(
self.repo.blobrepo.clone(),
&manifest_id,
&basemfnode,
rootpath.clone(),
pruner.clone(),
);
cur_stream.select(new_stream).boxify()
},
Expand Down Expand Up @@ -866,6 +868,7 @@ fn get_changed_entry_stream(
mfid: &DNodeHash,
basemfid: &DNodeHash,
rootpath: Option<MPath>,
pruner: impl FnMut(&ChangedEntry) -> bool + Send + Clone + 'static,
) -> BoxStream<(Box<Entry + Sync>, Option<MPath>), Error> {
let manifest = repo.get_manifest_by_nodeid(mfid)
.traced_global("fetch rootmf", trace_args!());
Expand All @@ -876,7 +879,7 @@ fn get_changed_entry_stream(
.join(basemanifest)
.map({
let rootpath = rootpath.clone();
|(mf, basemf)| changed_entry_stream(&mf, &basemf, rootpath)
move |(mf, basemf)| changed_entry_stream_with_pruner(&mf, &basemf, rootpath, pruner)
})
.flatten_stream();

Expand Down
47 changes: 11 additions & 36 deletions tests/integration/test-gettreepack.t
Expand Up @@ -49,53 +49,28 @@ Make sure that cache is empty
$ [[ -a $TESTTMP/cachepath/repo/packs/manifests ]]
[1]
Small extension to call gettreepack method with a few nodes. At the time of writing this test
hg prefetch failed for treeonly repos. We can use it instead when it's fixed
$ cat >> $TESTTMP/gettreepack.py <<EOF
> from mercurial import registrar
> from mercurial import (bundle2, extensions)
> cmdtable = {}
> command = registrar.command(cmdtable)
> @command('gettreepack', [
> ('r', 'rev', [], 'specify the revision', 'REV'),
> ('', 'baserev', [], 'specify the base revision', 'REV'),
> ], '[-r REV]')
> def _gettreepack(ui, repo, **opts):
> treemanifestext = extensions.find('treemanifest')
> fallbackpath = treemanifestext.getfallbackpath(repo)
> ctxs = [repo[r] for r in opts.get('rev')]
> basectxs = [repo[r] for r in opts.get('baserev')]
> with repo.connectionpool.get(fallbackpath) as conn:
> remote = conn.peer
> mfnodes = [ctx.manifestnode() for ctx in ctxs]
> basemfnodes = [ctx.manifestnode() for ctx in basectxs]
> bundle = remote.gettreepack('', mfnodes, basemfnodes, [])
> bundle2.processbundle(repo, bundle, None)
> EOF
$ hgmn --config extensions.gettreepack=$TESTTMP/gettreepack.py gettreepack -r 0 -r 1
$ hgmn --config extensions.gettreepack=$TESTTMP/gettreepack.py gettreepack -r 2 --baserev 1 --baserev 0
$ hgmn prefetch -r 0 -r1
$ hgmn prefetch -r 2
$ cat $TESTTMP/mononoke.out | grep 'Got request: Gettreepack'
* Got request: Gettreepack(GettreepackArgs { rootdir: b"", mfnodes: [HgNodeHash(Sha1(41b34f08c1356f6ad068e9ab9b43d984245111aa)), HgNodeHash(Sha1(eb79886383871977bccdb3000c275a279f0d4c99))], basemfnodes: [], directories: [] }), repo: $TESTTMP/repo (glob)
* Got request: Gettreepack(GettreepackArgs { rootdir: b"", mfnodes: [HgNodeHash(Sha1(7c9b4fd8b49377e2fead2e9610bb8db910a98c53))], basemfnodes: [HgNodeHash(Sha1(eb79886383871977bccdb3000c275a279f0d4c99))], directories: [] }), repo: $TESTTMP/repo (glob)
Make sure that new entries were downloaded
$ [[ -a $TESTTMP/cachepath/repo/packs/manifests ]]
$ ls $TESTTMP/cachepath/repo/packs/manifests | wc -l
8
Update to the revisions. Make sure that gettreepack command is not sent because
we've already downloaded all the trees
$ hgmn up 2 --debug | grep 'sending .* command'
sending hello command
sending between command
sending getfiles command
Update to the revisions. Change the path to make sure that gettreepack command is
not sent because we've already downloaded all the trees
$ hgmn up 2 --config paths.default=ssh://brokenpath -q
$ ls
A
B
C
No wireproto commands should be sent at all, because everything has been already
downloaded
$ hgmn up 1 --debug | grep 'sending .* command'
[1]
Change the path to make sure that no wireproto commands should be sent at all,
because everything has been already downloaded.
$ hgmn up 1 --config paths.default=ssh://brokenpath -q
$ ls
A
B

0 comments on commit 171a456

Please sign in to comment.