From abd11ad6ae1e3ee433b1d5bc14d93966ba99e435 Mon Sep 17 00:00:00 2001 From: Zhaolong Zhu Date: Mon, 21 Oct 2024 13:01:54 -0700 Subject: [PATCH] eagerepo: land_stack supports multiple commits Summary: This diff uses pushrebase_one() to support pushrebasing a diff stack with multiple commits. Currently, it does not support concurrent land_stack calls. We will handle it in a later diff. The wireproto does not work for this test case, it seems didn't do the rebase first. I will fix it in a separate diff. Reviewed By: quark-zju Differential Revision: D64540084 fbshipit-source-id: 915bbce72da23a3075d6c87cb4afd124e590c9fd --- eden/scm/lib/eagerepo/src/api.rs | 22 ++++++++++++++++++-- eden/scm/tests/test-pushrebase-eagerepo.t | 25 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/eden/scm/lib/eagerepo/src/api.rs b/eden/scm/lib/eagerepo/src/api.rs index d1ceb0f524822..6cfb57a0adaed 100644 --- a/eden/scm/lib/eagerepo/src/api.rs +++ b/eden/scm/lib/eagerepo/src/api.rs @@ -1276,10 +1276,27 @@ impl SaplingRemoteApi for EagerRepo { return Ok(LandStackResponse { data: Err(e) }); } - panic!("not implemented"); + let mut old_to_new_hgids = HashMap::new(); + let mut base_commit = base; + let mut dest_commit = latest_bookmark_id; + for commit in commits { + let new_commit = pushrebase_one(self, base_commit, commit, dest_commit).await?; + old_to_new_hgids.insert(commit, new_commit); + + base_commit = commit; + dest_commit = new_commit; + } + + let new_head = old_to_new_hgids[&head]; + EagerRepo::set_bookmark(self, &bookmark, Some(new_head)).map_err(map_crate_err)?; + let data = LandStackData { + new_head, + old_to_new_hgids, + }; + self.flush_for_api("land_stack").await?; + return Ok(LandStackResponse { data: Ok(data) }); } - #[allow(dead_code)] async fn pushrebase_one( repo: &EagerRepo, base_commit: HgId, @@ -1292,6 +1309,7 @@ impl SaplingRemoteApi for EagerRepo { let mut new_manifest = dest_manifest.clone(); let matcher = AlwaysMatcher::new(); + // generate new manifest for e in base_manifest.diff(&source_manifest, &matcher)? { let e = e?; diff --git a/eden/scm/tests/test-pushrebase-eagerepo.t b/eden/scm/tests/test-pushrebase-eagerepo.t index b02270709263d..eaba712cda9c3 100644 --- a/eden/scm/tests/test-pushrebase-eagerepo.t +++ b/eden/scm/tests/test-pushrebase-eagerepo.t @@ -6,7 +6,7 @@ > hg log -G -r 'all()' -T '{node|short} {desc} {remotebookmarks} {bookmarks}' > } -#testcases slapi wireproto +#testcases slapi #if wireproto $ setconfig push.edenapi=false @@ -78,3 +78,26 @@ test pushrebase conflicts abort: Server error: Conflicts while pushrebasing: [(RepoPathBuf("a"), RepoPathBuf("a"))] [255] #endif + +Test pushrebase a diff stack + $ newclientrepo client3 test:server + $ hg go -q 2bb9d20e471c + $ echo 1 >> c && hg ci -qAm "add c" + $ echo 2 >> c && hg ci -qm "update c" + $ log + @ adb87132efa9 update c + │ + o f46b94d12452 add c + │ + │ o ea98a8f95390 changed message remote/master + ├─╯ + o 2bb9d20e471c initial + $ hg push --to master -q + $ log + @ 0359afffc631 update c remote/master + │ + o bc98034e098e add c + │ + o ea98a8f95390 changed message + │ + o 2bb9d20e471c initial