Skip to content

Commit bbd14b6

Browse files
Support cross workspace amend
Change: ws-amend
1 parent 2dde605 commit bbd14b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+344
-69
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tempfile = "3.10.1"
3737

3838
[workspace.dependencies.git2]
3939
default-features = false
40-
version = "0.19"
40+
version = "0.18.3"
4141

4242
[workspace.dependencies.juniper]
4343
version = "0.15.11"

docs/src/reference/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ history, taking a filter specification as argument.
99

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

1515
git-sync

josh-core/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use std::collections::HashMap;
33

4-
const CACHE_VERSION: u64 = 20;
4+
const CACHE_VERSION: u64 = 19;
55

66
lazy_static! {
77
static ref DB: std::sync::Mutex<Option<sled::Db>> = std::sync::Mutex::new(None);

josh-core/src/history.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,22 @@ pub fn unapply_filter(
441441
let tree = module_commit.tree()?;
442442
let commit_message = module_commit.summary().unwrap_or("NO COMMIT MESSAGE");
443443

444-
let new_trees: JoshResult<Vec<_>> = {
444+
let mut nt = None;
445+
if let Some(change_ids) = change_ids {
446+
for c in change_ids.iter() {
447+
let cid = get_change_id(&module_commit, ret);
448+
449+
if c.id == cid.id {
450+
let x = transaction.repo().find_commit(c.commit)?;
451+
nt = Some(filter::unapply(transaction, filter, tree.clone(), x.tree()?)?.id());
452+
break;
453+
}
454+
}
455+
}
456+
457+
let new_trees: JoshResult<Vec<_>> = if let Some(nt) = nt {
458+
Ok(vec![nt])
459+
} else {
445460
let span = tracing::span!(
446461
tracing::Level::TRACE,
447462
"unapply filter",

josh-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct Change {
3838
}
3939

4040
impl Change {
41-
fn new(commit: git2::Oid) -> Self {
41+
pub fn new(commit: git2::Oid) -> Self {
4242
Self {
4343
author: Default::default(),
4444
id: Default::default(),

josh-proxy/src/bin/josh-proxy.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,7 @@ async fn call_service(
11851185
while path.contains("//") {
11861186
path = path.replace("//", "/");
11871187
}
1188-
percent_encoding::percent_decode_str(&path)
1189-
.decode_utf8_lossy()
1190-
.to_string()
1188+
path
11911189
};
11921190

11931191
if let Some(resource_path) = path.strip_prefix("/~/ui") {

josh-proxy/src/lib.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ pub fn process_repo_update(repo_update: RepoUpdate) -> josh::JoshResult<String>
259259
None
260260
};
261261

262+
if changes.is_some() && push_mode == PushMode::Review {
263+
changes = Some(refs_to_changes(
264+
&transaction_mirror,
265+
&baseref.replacen("refs/heads/", "", 1),
266+
&author,
267+
));
268+
}
269+
262270
let filter = josh::filter::parse(&repo_update.filter_spec)?;
263271
let new_oid = git2::Oid::from_str(new)?;
264272
let backward_new_oid = {
@@ -868,6 +876,38 @@ impl Drop for TmpGitNamespace {
868876
}
869877
}
870878

879+
fn refs_to_changes(
880+
transaction: &josh::cache::Transaction,
881+
baseref: &str,
882+
change_author: &str,
883+
) -> Vec<josh::Change> {
884+
let mut changes = vec![];
885+
let glob = transaction.refname(&format!(
886+
"refs/heads/@changes/{}/{}/*",
887+
baseref, change_author
888+
));
889+
890+
for r in transaction.repo().references_glob(&glob).unwrap() {
891+
let r = r.unwrap();
892+
let mut change = josh::Change::new(r.target().unwrap());
893+
change.author = change_author.to_string();
894+
895+
let id = r.name().unwrap().replacen(
896+
&transaction.refname(&format!(
897+
"refs/heads/@changes/{}/{}/",
898+
baseref, change_author
899+
)),
900+
"",
901+
1,
902+
);
903+
change.id = Some(id);
904+
905+
changes.push(change);
906+
}
907+
908+
return changes;
909+
}
910+
871911
fn changes_to_refs(
872912
baseref: &str,
873913
change_author: &str,
@@ -887,12 +927,12 @@ fn changes_to_refs(
887927
if id.contains('@') {
888928
return Err(josh::josh_error("Change id must not contain '@'"));
889929
}
890-
if seen.contains(&id) {
891-
return Err(josh::josh_error(&format!(
892-
"rejecting to push {:?} with duplicate label",
893-
change.commit
894-
)));
895-
}
930+
//if seen.contains(&id) {
931+
// return Err(josh::josh_error(&format!(
932+
// "rejecting to push {:?} with duplicate label",
933+
// change.commit
934+
// )));
935+
//}
896936
seen.push(id);
897937
} else {
898938
return Err(josh::josh_error(&format!(

tests/proxy/amend_patchset.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
]
125125
.
126126
|-- josh
127-
| `-- 20
127+
| `-- 19
128128
| `-- sled
129129
| |-- blobs
130130
| |-- conf

tests/proxy/authentication.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"real_repo.git" = ["::sub1/"]
125125
.
126126
|-- josh
127-
| `-- 20
127+
| `-- 19
128128
| `-- sled
129129
| |-- blobs
130130
| |-- conf

0 commit comments

Comments
 (0)