Skip to content

Commit

Permalink
List mutable renames by dst changeset
Browse files Browse the repository at this point in the history
Summary: This option prints out all renames of a given dst commit

Reviewed By: markbt

Differential Revision: D69530922

fbshipit-source-id: d8576b440992efe8d6a32b62c354d83eaf4f2846
  • Loading branch information
Liu Yang authored and facebook-github-bot committed Feb 13, 2025
1 parent 54ff777 commit 47c207a
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ CREATE TABLE IF NOT EXISTS `mutable_renames`(
UNIQUE (`repo_id`, `dst_path_hash`, `dst_cs_id`)
);

CREATE INDEX IF NOT EXISTS `dst_cs_id` ON `mutable_renames` (`repo_id`, `dst_cs_id`);

CREATE TABLE IF NOT EXISTS `mutable_renames_paths`(
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`path_hash` VARBINARY(32) NOT NULL,
Expand Down
57 changes: 57 additions & 0 deletions eden/mononoke/mutable_renames/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,38 @@ impl MutableRenames {
}
}
}

pub async fn list_renames_by_dst_cs_uncached(
&self,
ctx: &CoreContext,
dst_cs_id: ChangesetId,
) -> Result<Vec<MutableRenameEntry>, Error> {
let rows = ListRenamesByDstChangeset::maybe_traced_query(
&self.store.read_connection,
ctx.client_request_info(),
&self.repo_id,
&dst_cs_id,
)
.await?;

Ok(rows
.into_iter()
.map(
|(src_cs_id, dst_path_bytes, src_path_bytes, src_unode, is_tree)| {
let dst_path = MPath::new(dst_path_bytes)?;
let src_path = MPath::new(src_path_bytes)?;
let src_unode = if is_tree == 1 {
Entry::Tree(ManifestUnodeId::new(src_unode))
} else {
Entry::Leaf(FileUnodeId::new(src_unode))
};

MutableRenameEntry::new(dst_cs_id, dst_path, src_cs_id, src_path, src_unode)
},
)
.filter_map(|r| r.ok())
.collect())
}
}

mononoke_queries! {
Expand Down Expand Up @@ -443,6 +475,31 @@ mononoke_queries! {
"
}

read ListRenamesByDstChangeset(repo_id: RepositoryId, dst_cs_id: ChangesetId) -> (
ChangesetId,
Vec<u8>,
Vec<u8>,
Blake2,
i8
) {
"
SELECT
m.src_cs_id,
dst_p.path as dst_path,
src_p.path as src_path,
m.src_unode_id,
m.is_tree
FROM mutable_renames AS m
JOIN mutable_renames_paths AS dst_p
ON m.dst_path_hash = dst_p.path_hash
JOIN mutable_renames_paths AS src_p
ON m.src_path_hash = src_p.path_hash
WHERE
m.repo_id = {repo_id}
AND m.dst_cs_id = {dst_cs_id}
"
}

read HasRenameCheck(repo_id: RepositoryId, dst_cs_id: ChangesetId) -> (ChangesetId) {
"
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Check that D and E lack mutable rename information
$ mononoke_admin mutable-renames -R repo check-commit $E
No mutable renames associated with this commit

List should return the same output as check when it's empty
$ mononoke_admin mutable-renames -R repo list $D
No mutable renames associated with this commit

Copy immutable to mutable on D, and check it
$ mononoke_admin mutable-renames -R repo copy-immutable $D
Creating entry for `c_file` copied to `c_prime`
Expand All @@ -53,6 +57,10 @@ Copy immutable to mutable on D, and check it
$ mononoke_admin mutable-renames -R repo get $D --path c_prime
Source path `c_file`, source bonsai CS 74a33dfc64c14f4fc8ca6150b8bc565431403302b99c2a1dc14fc83eeb7a8938, source unode Leaf(FileUnodeId(Blake2(48f83239679afb0c0207fc2bf510bc61b5e39db53f9eba1dc795a79c3422085a)))

List all renames on D
$ mononoke_admin mutable-renames -R repo list $D
Destination path MPath("c_prime"), destination bonsai CS 37567336930d36d383a4ed0058077657e4a5b4bea1c6f7cb98ce41aa21eaa13d, source path MPath("c_file"), source bonsai CS 74a33dfc64c14f4fc8ca6150b8bc565431403302b99c2a1dc14fc83eeb7a8938, source unode Leaf(FileUnodeId(Blake2(48f83239679afb0c0207fc2bf510bc61b5e39db53f9eba1dc795a79c3422085a)))

Confirm that this didn't change E
$ mononoke_admin mutable-renames -R repo check-commit $E
No mutable renames associated with this commit
Expand All @@ -68,10 +76,19 @@ Add a mutable change on E, and check that the immutable changes and this change
$ mononoke_admin mutable-renames -R repo get $E --path d_prime
Source path `c_prime`, source bonsai CS 37567336930d36d383a4ed0058077657e4a5b4bea1c6f7cb98ce41aa21eaa13d, source unode Leaf(FileUnodeId(Blake2(f6fc8af942343b8de8fbea05804113bfc45e34670a84cfa2272fc5ef606598ae)))

List all renames on E
$ mononoke_admin mutable-renames -R repo list $E
Destination path MPath("d_prime"), destination bonsai CS f0249abfb89eb2db2b4ffd4ad0334c25d2b6d96183823127f79688852e6194af, source path MPath("c_prime"), source bonsai CS 37567336930d36d383a4ed0058077657e4a5b4bea1c6f7cb98ce41aa21eaa13d, source unode Leaf(FileUnodeId(Blake2(f6fc8af942343b8de8fbea05804113bfc45e34670a84cfa2272fc5ef606598ae)))
Destination path MPath("a_file"), destination bonsai CS f0249abfb89eb2db2b4ffd4ad0334c25d2b6d96183823127f79688852e6194af, source path MPath("a_file"), source bonsai CS 1a21e175bd7b7537dee83095eeccf66dea393e734eeb35f93bea530c9dc7e528, source unode Leaf(FileUnodeId(Blake2(2c50f7bb2096b424b82e1c7ebfad7d2361dddf3c1d09ce2dba20e2baa3d388f2)))

Confirm that we can add a rename of a file in G to A
$ mononoke_admin mutable-renames -R repo add --src-commit-id $A --src-path a_file --dst-commit-id $G --dst-path g_file
Creating entry for source file `a_file` to destination file `g_file`

List all renames on G
$ mononoke_admin mutable-renames -R repo list $G
Destination path MPath("g_file"), destination bonsai CS 074c10beddc42f9e0e41f1adea1dbecf76e01dbe015a5b656205b1245ac7b7fc, source path MPath("a_file"), source bonsai CS 1a21e175bd7b7537dee83095eeccf66dea393e734eeb35f93bea530c9dc7e528, source unode Leaf(FileUnodeId(Blake2(2c50f7bb2096b424b82e1c7ebfad7d2361dddf3c1d09ce2dba20e2baa3d388f2)))

This must *never* work - if it does, we create a cycle where G's "ancestor" is H, whose ancestor is G...
$ mononoke_admin mutable-renames -R repo add --src-commit-id $H --src-path h_file --dst-commit-id $G --dst-path g_file
Creating entry for source file `h_file` to destination file `g_file`
Expand Down
5 changes: 5 additions & 0 deletions eden/mononoke/tools/admin/src/commands/mutable_renames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod add;
mod check_commit;
mod copy_immutable;
mod get;
mod list;

use add::AddArgs;
use anyhow::Context;
Expand All @@ -23,6 +24,7 @@ use clap::Subcommand;
use commit_graph::CommitGraph;
use copy_immutable::CopyImmutableArgs;
use get::GetArgs;
use list::ListArgs;
use mononoke_app::args::RepoArgs;
use mononoke_app::MononokeApp;
use mutable_renames::MutableRenames;
Expand Down Expand Up @@ -72,6 +74,8 @@ pub enum MutableRenamesSubcommand {
CheckCommit(CheckCommitArgs),
/// Get mutable rename information for a given commit, path pair
Get(GetArgs),
/// List mutable renames for a given commit
List(ListArgs),
/// Add new mutable renames to your repo
Add(AddArgs),
/// Copy immutable renames to mutable renames
Expand All @@ -91,6 +95,7 @@ pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> {
check_commit::check_commit(&ctx, &repo, args).await?
}
MutableRenamesSubcommand::Get(args) => get::get(&ctx, &repo, args).await?,
MutableRenamesSubcommand::List(args) => list::list(&ctx, &repo, args).await?,
MutableRenamesSubcommand::Add(args) => add::add(&ctx, &repo, args).await?,
MutableRenamesSubcommand::CopyImmutable(args) => {
copy_immutable::copy_immutable(&ctx, &repo, args).await?
Expand Down
48 changes: 48 additions & 0 deletions eden/mononoke/tools/admin/src/commands/mutable_renames/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/

use anyhow::Result;
use clap::Args;
use commit_id::parse_commit_id;
use context::CoreContext;
use mutable_renames::MutableRenamesRef;

use super::Repo;

#[derive(Args)]
pub struct ListArgs {
/// Commit ID to fetch renames from
///
/// This can be any commit id type. Specify 'scheme=id' to disambiguate
/// commit identity scheme (e.g. 'hg=HASH', 'globalrev=REV').
commit_id: String,
}

pub async fn list(ctx: &CoreContext, repo: &Repo, list_args: ListArgs) -> Result<()> {
let target_commit = parse_commit_id(ctx, repo, &list_args.commit_id).await?;

let entries = repo
.mutable_renames()
.list_renames_by_dst_cs_uncached(ctx, target_commit)
.await?;

if entries.is_empty() {
println!("No mutable renames associated with this commit");
} else {
for entry in entries {
println!(
"Destination path {:?}, destination bonsai CS {}, source path {:?}, source bonsai CS {}, source unode {:?}",
entry.dst_path(),
target_commit,
entry.src_path(),
entry.src_cs_id(),
entry.src_unode()
);
}
}
Ok(())
}

0 comments on commit 47c207a

Please sign in to comment.