Skip to content

Commit

Permalink
Add an experimental feature that puts the git commit in the mercurial…
Browse files Browse the repository at this point in the history
… changeset `extras`
  • Loading branch information
glandium committed Jun 28, 2024
1 parent 6679c5f commit 8be6fd0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4864,6 +4864,8 @@ pub fn has_compat(c: Compat) -> bool {
bitflags! {
pub struct Experiments: i32 {
const MERGE = 0x1;
// Add git commit as extra metadata in mercurial changesets.
const GIT_COMMIT = 0x2;
}
}
pub struct AllExperiments {
Expand All @@ -4883,6 +4885,9 @@ static EXPERIMENTS: Lazy<AllExperiments> = Lazy::new(|| {
b"merge" => {
flags |= Experiments::MERGE;
}
b"git_commit" => {
flags |= Experiments::GIT_COMMIT;
}
s if s.starts_with(b"similarity") => {
if let Some(value) = s[b"similarity".len()..].strip_prefix(b"=") {
match u8::from_bytes(value) {
Expand Down
12 changes: 10 additions & 2 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use crate::util::{
SliceExt, ToBoxed, Transpose,
};
use crate::xdiff::{apply, textdiff, PatchInfo};
use crate::{check_enabled, has_compat, Checks, Compat};
use crate::{check_enabled, experiment, has_compat, Checks, Compat, Experiments};

pub const REFS_PREFIX: &str = "refs/cinnabar/";
pub const REPLACE_REFS_PREFIX: &str = "refs/cinnabar/replace/";
Expand Down Expand Up @@ -1873,9 +1873,17 @@ pub fn create_changeset(
.extra()
.and_then(|e| e.get(b"branch").map(ToBoxed::to_boxed))
});
let mut extra = None;
if let Some(branch) = &branch {
let mut extra = ChangesetExtra::new();
let extra = extra.get_or_insert_with(ChangesetExtra::new);
extra.set(b"branch", branch);
}
let git_commit_extra = experiment(Experiments::GIT_COMMIT).then(|| commit_id.to_string());
if let Some(git_commit_extra) = &git_commit_extra {
let extra = extra.get_or_insert_with(ChangesetExtra::new);
extra.set(b"git_commit", git_commit_extra.as_bytes());
}
if let Some(extra) = extra {
let mut buf = Vec::new();
extra.dump_into(&mut buf);
cs_metadata.extra = Some(buf.into_boxed_slice());
Expand Down
27 changes: 27 additions & 0 deletions tests/push.t
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,30 @@ In that corner case, we don't store metadata.

$ git -C uvw-git cinnabar rollback --candidates
2836e453f32b1ecccd3acca412f75b07c88176bf (current)

$ rm -rf $REPO/.hg
$ hg init $REPO
$ git -C abc-git cinnabar rollback 0000000000000000000000000000000000000000
$ git -C abc-git push origin 8b86a58578d5270969543e287634e3a2f122a338:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
To hg::.*/push.t/repo (re)
* [new branch] 8b86a58578d5270969543e287634e3a2f122a338 -> branches/default/tip

$ git -c cinnabar.experiments=git_commit -C abc-git push origin 687e015f9f646bb19797d991f2f53087297fbe14:branches/default/tip
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 2 changesets with 2 changes to 2 files
To hg::.*/push.t/repo (re)
8b86a58..687e015 687e015f9f646bb19797d991f2f53087297fbe14 -> branches/default/tip

$ hg -R $REPO log -G --template '{node} {branch} {desc} {extras.git_commit}'
o c70941aaa15aa6e5feae28164438f13dc3cd7b8e default c 687e015f9f646bb19797d991f2f53087297fbe14
|
o 29872b591f8d41c613bbfad38722824ab0457f17 default b d04f6df4abe2870ceb759263ee6aaa9241c4f93c
|
o f92470d7f6966a39dfbced6a525fe81ebf5c37b9 default a

0 comments on commit 8be6fd0

Please sign in to comment.