mononoke: always create bookmark if doesn't exist

Summary: The behaviour was changed in mercurial and we need to match it

Reviewed By: ikostia

Differential Revision: D14743136

fbshipit-source-id: 8f0184e0fc1fbf666323e5d3f1e2f0c85a1e3dc6
This commit is contained in:
Stanislau Hlebik 2019-04-03 06:07:55 -07:00 committed by Facebook Github Bot
parent bbad5e0955
commit bb52969617
3 changed files with 31 additions and 54 deletions

View File

@ -132,7 +132,6 @@ pub struct PushrebaseSuccessResult {
#[derive(Clone)]
pub struct OntoBookmarkParams {
pub bookmark: Bookmark,
pub create_if_not_exists: bool,
}
/// Does a pushrebase of a list of commits `pushed_set` onto `onto_bookmark`
@ -388,26 +387,22 @@ fn find_closest_root(
find_closest_ancestor_root(ctx.clone(), repo, config, bookmark.bookmark, roots, id)
}
None => {
if bookmark.create_if_not_exists {
join_all(roots.into_iter().map(move |root| {
repo.get_generation_number_by_bonsai(ctx.clone(), root)
.and_then(move |maybe_gen_num| {
maybe_gen_num.ok_or(ErrorKind::RootNotFound(root).into())
})
.map(move |gen_num| (root, gen_num))
}))
.and_then(|roots_with_gen_nums| {
roots_with_gen_nums
.into_iter()
.max_by_key(|(_, gen_num)| gen_num.clone())
.ok_or(ErrorKind::NoRoots.into())
})
.map(|(cs_id, _)| cs_id)
.from_err()
.boxify()
} else {
err(ErrorKind::PushrebaseBookmarkNotFound(bookmark.bookmark).into()).boxify()
}
join_all(roots.into_iter().map(move |root| {
repo.get_generation_number_by_bonsai(ctx.clone(), root)
.and_then(move |maybe_gen_num| {
maybe_gen_num.ok_or(ErrorKind::RootNotFound(root).into())
})
.map(move |gen_num| (root, gen_num))
}))
.and_then(|roots_with_gen_nums| {
roots_with_gen_nums
.into_iter()
.max_by_key(|(_, gen_num)| gen_num.clone())
.ok_or(ErrorKind::NoRoots.into())
})
.map(|(cs_id, _)| cs_id)
.from_err()
.boxify()
}
}
})
@ -660,7 +655,7 @@ fn intersect_changed_files(
}
/// Returns Some(ChangesetId) if bookmarks exists.
/// Returns None if bookmarks does not exists, but create_if_not_exists is set to true
/// Returns None if bookmarks does not exists
fn get_onto_bookmark_value(
ctx: CoreContext,
repo: &BlobRepo,
@ -668,15 +663,8 @@ fn get_onto_bookmark_value(
) -> impl Future<Item = Option<ChangesetId>, Error = PushrebaseError> {
get_bookmark_value(ctx.clone(), &repo, &onto_bookmark.bookmark).and_then(
move |maybe_bookmark_value| match maybe_bookmark_value {
Some(bookmark_value) => ok(Some(bookmark_value)).left_future(),
None => {
if onto_bookmark.create_if_not_exists {
ok(None).left_future()
} else {
err(ErrorKind::PushrebaseBookmarkNotFound(onto_bookmark.bookmark).into())
.right_future()
}
}
Some(bookmark_value) => ok(Some(bookmark_value)),
None => ok(None),
},
)
}
@ -978,7 +966,6 @@ mod tests {
let book = Bookmark::new("master").unwrap();
let book = OntoBookmarkParams {
bookmark: book,
create_if_not_exists: false,
};
book
}
@ -2021,25 +2008,6 @@ mod tests {
let book = Bookmark::new("newbook").unwrap();
let book = OntoBookmarkParams {
bookmark: book,
create_if_not_exists: false,
};
assert!(run_future(
&mut runtime,
do_pushrebase(
ctx.clone(),
repo.clone(),
Default::default(),
book,
vec![hg_cs],
None
),
)
.is_err());
let book = Bookmark::new("newbook").unwrap();
let book = OntoBookmarkParams {
bookmark: book,
create_if_not_exists: true,
};
assert!(run_future(
&mut runtime,
@ -2065,7 +2033,6 @@ mod tests {
let book = Bookmark::new("newbook").unwrap();
let book = OntoBookmarkParams {
bookmark: book,
create_if_not_exists: true,
};
let num_pushes = 10;

View File

@ -303,10 +303,8 @@ fn resolve_pushrebase(
let v = Vec::from(onto_bookmark.as_ref());
let onto_bookmark = String::from_utf8(v)?;
let onto_bookmark = Bookmark::new(onto_bookmark)?;
let create_if_not_exists = cg_push.mparams.get("newhead").is_some();
let onto_bookmark = pushrebase::OntoBookmarkParams {
bookmark: onto_bookmark,
create_if_not_exists,
};
Ok((onto_bookmark, cg_push, manifests, bundle2))
}

View File

@ -466,3 +466,15 @@ Test deleting a bookmark
o 9 [public;rev=20;2f7cc50dc4e5]
|
~
Test creating a bookmark and new head
$ echo draft > draft && hg add draft && hg ci -m draft
$ hgmn push -r . --to newbook --create
remote: * DEBG Session with Mononoke started with uuid: * (glob)
pushing rev 7a037594e202 to destination ssh://user@dummy/repo bookmark newbook
searching for changes
adding changesets
adding manifests
adding file changes
added 0 changesets with 0 changes to 0 files
exporting bookmark newbook