Skip to content

Commit

Permalink
Support cross workspace amend
Browse files Browse the repository at this point in the history
Change: ws-amend
  • Loading branch information
christian-schilling committed Jul 31, 2024
1 parent 2dde605 commit bbd14b6
Show file tree
Hide file tree
Showing 59 changed files with 344 additions and 69 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tempfile = "3.10.1"

[workspace.dependencies.git2]
default-features = false
version = "0.19"
version = "0.18.3"

[workspace.dependencies.juniper]
version = "0.15.11"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ history, taking a filter specification as argument.

It can be installed with the following Cargo command, assuming Rust is installed:
```shell
cargo install josh-filter --git https://github.com/josh-project/josh.git
cargo install josh --git https://github.com/josh-project/josh.git
```

git-sync
Expand Down
2 changes: 1 addition & 1 deletion josh-core/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use std::collections::HashMap;

const CACHE_VERSION: u64 = 20;
const CACHE_VERSION: u64 = 19;

lazy_static! {
static ref DB: std::sync::Mutex<Option<sled::Db>> = std::sync::Mutex::new(None);
Expand Down
17 changes: 16 additions & 1 deletion josh-core/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,22 @@ pub fn unapply_filter(
let tree = module_commit.tree()?;
let commit_message = module_commit.summary().unwrap_or("NO COMMIT MESSAGE");

let new_trees: JoshResult<Vec<_>> = {
let mut nt = None;
if let Some(change_ids) = change_ids {
for c in change_ids.iter() {
let cid = get_change_id(&module_commit, ret);

if c.id == cid.id {
let x = transaction.repo().find_commit(c.commit)?;
nt = Some(filter::unapply(transaction, filter, tree.clone(), x.tree()?)?.id());
break;
}
}
}

let new_trees: JoshResult<Vec<_>> = if let Some(nt) = nt {
Ok(vec![nt])
} else {
let span = tracing::span!(
tracing::Level::TRACE,
"unapply filter",
Expand Down
2 changes: 1 addition & 1 deletion josh-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Change {
}

impl Change {
fn new(commit: git2::Oid) -> Self {
pub fn new(commit: git2::Oid) -> Self {
Self {
author: Default::default(),
id: Default::default(),
Expand Down
4 changes: 1 addition & 3 deletions josh-proxy/src/bin/josh-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,9 +1185,7 @@ async fn call_service(
while path.contains("//") {
path = path.replace("//", "/");
}
percent_encoding::percent_decode_str(&path)
.decode_utf8_lossy()
.to_string()
path
};

if let Some(resource_path) = path.strip_prefix("/~/ui") {
Expand Down
52 changes: 46 additions & 6 deletions josh-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ pub fn process_repo_update(repo_update: RepoUpdate) -> josh::JoshResult<String>
None
};

if changes.is_some() && push_mode == PushMode::Review {
changes = Some(refs_to_changes(
&transaction_mirror,
&baseref.replacen("refs/heads/", "", 1),
&author,
));
}

let filter = josh::filter::parse(&repo_update.filter_spec)?;
let new_oid = git2::Oid::from_str(new)?;
let backward_new_oid = {
Expand Down Expand Up @@ -868,6 +876,38 @@ impl Drop for TmpGitNamespace {
}
}

fn refs_to_changes(
transaction: &josh::cache::Transaction,
baseref: &str,
change_author: &str,
) -> Vec<josh::Change> {
let mut changes = vec![];
let glob = transaction.refname(&format!(
"refs/heads/@changes/{}/{}/*",
baseref, change_author
));

for r in transaction.repo().references_glob(&glob).unwrap() {
let r = r.unwrap();
let mut change = josh::Change::new(r.target().unwrap());
change.author = change_author.to_string();

let id = r.name().unwrap().replacen(
&transaction.refname(&format!(
"refs/heads/@changes/{}/{}/",
baseref, change_author
)),
"",
1,
);
change.id = Some(id);

changes.push(change);
}

return changes;
}

fn changes_to_refs(
baseref: &str,
change_author: &str,
Expand All @@ -887,12 +927,12 @@ fn changes_to_refs(
if id.contains('@') {
return Err(josh::josh_error("Change id must not contain '@'"));
}
if seen.contains(&id) {
return Err(josh::josh_error(&format!(
"rejecting to push {:?} with duplicate label",
change.commit
)));
}
//if seen.contains(&id) {
// return Err(josh::josh_error(&format!(
// "rejecting to push {:?} with duplicate label",
// change.commit
// )));
//}
seen.push(id);
} else {
return Err(josh::josh_error(&format!(
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/amend_patchset.t
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/authentication.t
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"real_repo.git" = ["::sub1/"]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
4 changes: 2 additions & 2 deletions tests/proxy/caching.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down Expand Up @@ -162,7 +162,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_absent_head.t
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_all.t
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"real_repo.git" = ["::sub1/"]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_blocked.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_invalid_url.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_locked_refs.t
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_prefix.t
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_sha.t
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Check (2) and (3) but with a branch ref
"real_repo.git" = ["::sub1/"]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subsubtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subtree_no_master.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"real_repo.git" = [":/sub1"]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subtree_tags.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_with_meta.t
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/empty_commit.t
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ should still be included.
"real_repo.git" = ["::sub1/"]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/get_version.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/import_export.t
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Flushed credential cache
"repo2.git" = [":prefix=repo2"]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/join_with_merge.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"real_repo.git" = [":prefix=sub1"]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/markers.t
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
]
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/no_proxy.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/no_proxy_lfs.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 20
| `-- 19
| `-- sled
| |-- blobs
| |-- conf
Expand Down
Loading

0 comments on commit bbd14b6

Please sign in to comment.