Skip to content

Commit

Permalink
Introduce :committer filter (#1352)
Browse files Browse the repository at this point in the history
Previously `:author` would rewrite both the author
and commiter fields. Now there are seperate filters
for that.

Change: committer-filter
  • Loading branch information
christian-schilling authored Aug 8, 2024
1 parent 4ef5d2c commit daf9b4c
Show file tree
Hide file tree
Showing 56 changed files with 137 additions and 79 deletions.
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 = 21;
const CACHE_VERSION: u64 = 22;

lazy_static! {
static ref DB: std::sync::Mutex<Option<sled::Db>> = std::sync::Mutex::new(None);
Expand Down
15 changes: 15 additions & 0 deletions josh-core/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ enum Op {
// converting to Filter
Squash(Option<std::collections::BTreeMap<LazyRef, Filter>>),
Author(String, String),
Committer(String, String),

// We use BTreeMap rather than HashMap to guarantee deterministic results when
// converting to Filter
Expand Down Expand Up @@ -492,6 +493,13 @@ fn spec2(op: &Op) -> String {
Op::Author(author, email) => {
format!(":author={};{}", parse::quote(author), parse::quote(email))
}
Op::Committer(author, email) => {
format!(
":committer={};{}",
parse::quote(author),
parse::quote(email)
)
}
Op::Message(m) => {
format!(":{}", parse::quote(m))
}
Expand Down Expand Up @@ -926,6 +934,12 @@ fn apply_to_commit2(
Op::Author(author, email) => RewriteData {
tree: commit.tree()?,
author: Some((author.clone(), email.clone())),
committer: None,
message: None,
},
Op::Committer(author, email) => RewriteData {
tree: commit.tree()?,
author: None,
committer: Some((author.clone(), email.clone())),
message: None,
},
Expand Down Expand Up @@ -989,6 +1003,7 @@ fn apply2<'a>(
Op::Squash(None) => Ok(tree),
Op::Message(_) => Ok(tree),
Op::Author(_, _) => Ok(tree),
Op::Committer(_, _) => Ok(tree),
Op::Squash(Some(_)) => Err(josh_error("not applicable to tree")),
Op::Linear => Ok(tree),
Op::Unsign => Ok(tree),
Expand Down
1 change: 1 addition & 0 deletions josh-core/src/filter/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn make_op(args: &[&str]) -> JoshResult<Op> {
["empty"] => Ok(Op::Empty),
["prefix", arg] => Ok(Op::Prefix(Path::new(arg).to_owned())),
["author", author, email] => Ok(Op::Author(author.to_string(), email.to_string())),
["committer", author, email] => Ok(Op::Committer(author.to_string(), email.to_string())),
["workspace", arg] => Ok(Op::Workspace(Path::new(arg).to_owned())),
["prefix"] => Err(josh_error(indoc!(
r#"
Expand Down
92 changes: 67 additions & 25 deletions tests/filter/squash.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This one tag is an annotated tag, to make sure those are handled as well
)
$ git log --graph --decorate --pretty=oneline refs/heads/filtered
* d8aa5a9937f4f0bd645dbc0b591bae5cd6b6d91b (tag: filtered/tag_a, filtered) refs/tags/tag_a
* 977cc3ee14c0d6163ba63bd96f4aeedd43916ba7 (tag: filtered/tag_a, filtered) refs/tags/tag_a
$ git tag tag_b 0b4cf6c
Expand All @@ -70,55 +70,87 @@ This one tag is an annotated tag, to make sure those are handled as well
[3] :squash(
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:"refs/tags/tag_b"
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
d8aa5a9937f4f0bd645dbc0b591bae5cd6b6d91b:"refs/tags/filtered/tag_a"
977cc3ee14c0d6163ba63bd96f4aeedd43916ba7:"refs/tags/filtered/tag_a"
)
[4] :author="New Author";"new@e.mail"
$ git log --graph --decorate --pretty=oneline refs/heads/filtered
* 5b1a753860ca124024f6dfb4fd018fe7df8beae4 (tag: filtered/tag_a, filtered) refs/tags/tag_a
* be41caf35896090033cfd103e06aae721a3ce541 (tag: filtered/tag_a, filtered) refs/tags/tag_a
|\
* 96a731a4d64a8928e6af7abb2d425df3812b4197 (tag: filtered/tag_b) refs/tags/tag_b
* 64f712c4615dbf5e9e0a1c4cdf65b2da2138f4be (tag: filtered/tag_b) refs/tags/tag_b
$ git log --graph --pretty=%an:%ae refs/heads/master
* Josh:josh@example.com
$ git log --graph --pretty=%an:%ae-%cn:%ce refs/heads/master
* Josh:josh@example.com-Josh:josh@example.com
|\
| * Josh:josh@example.com
| * Josh:josh@example.com
* | Josh:josh@example.com
| * Josh:josh@example.com-Josh:josh@example.com
| * Josh:josh@example.com-Josh:josh@example.com
* | Josh:josh@example.com-Josh:josh@example.com
|/
* Josh:josh@example.com
$ git log --graph --pretty=%an:%ae refs/heads/filtered
* New Author:new@e.mail
* Josh:josh@example.com-Josh:josh@example.com
$ git log --graph --pretty=%an:%ae-%cn:%ce refs/heads/filtered
* New Author:new@e.mail-Josh:josh@example.com
|\
* New Author:new@e.mail
* New Author:new@e.mail-Josh:josh@example.com
$ josh-filter -s --squash-pattern "refs/tags/*" :committer=\"New\ Author\"\;\"new@e.mail\" --update refs/heads/filtered
[1] :"refs/tags/filtered/filtered/tag_a"
[1] :"refs/tags/filtered/tag_a"
[1] :"refs/tags/filtered/tag_b"
[1] :"refs/tags/tag_a"
[1] :"refs/tags/tag_b"
[1] :squash(
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
)
[3] :squash(
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:"refs/tags/tag_b"
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
977cc3ee14c0d6163ba63bd96f4aeedd43916ba7:"refs/tags/filtered/tag_a"
)
[4] :author="New Author";"new@e.mail"
[5] :committer="New Author";"new@e.mail"
[5] :squash(
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:"refs/tags/tag_b"
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
64f712c4615dbf5e9e0a1c4cdf65b2da2138f4be:"refs/tags/filtered/tag_b"
a68763bdf2f45a44304067954855749e366a5533:"refs/tags/filtered/filtered/tag_a"
be41caf35896090033cfd103e06aae721a3ce541:"refs/tags/filtered/tag_a"
)
$ git log --graph --pretty=%an:%ae-%cn:%ce refs/heads/filtered
* Josh:josh@example.com-New Author:new@e.mail
|\
* Josh:josh@example.com-New Author:new@e.mail
$ git tag tag_c 975d4c4
$ git show-ref | grep refs/heads > squashlist
$ cat squashlist
86871b8775ad3baca86484337d1072aa1d386f7e refs/heads/branch2
5b1a753860ca124024f6dfb4fd018fe7df8beae4 refs/heads/filtered
97c6007771c497c9530d61aa89af663daebb1625 refs/heads/filtered
1d69b7d2651f744be3416f2ad526aeccefb99310 refs/heads/master
$ josh-filter -s --squash-file squashlist :author=\"John\ Doe\"\;\"new@e.mail\" --update refs/heads/filtered -p > filter.josh
$ cat filter.josh
:squash(
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/heads/master"
5b1a753860ca124024f6dfb4fd018fe7df8beae4:"refs/heads/filtered"
86871b8775ad3baca86484337d1072aa1d386f7e:"refs/heads/branch2"
97c6007771c497c9530d61aa89af663daebb1625:"refs/heads/filtered"
):author="John Doe";"new@e.mail"
$ josh-filter -s --squash-pattern "refs/tags/*" :author=\"New\ Author\"\;\"new@e.mail\" --update refs/heads/filtered -p > filter.josh
$ cat filter.josh
:squash(
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:"refs/tags/tag_b"
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
5b1a753860ca124024f6dfb4fd018fe7df8beae4:"refs/tags/filtered/tag_a"
68dc45079334d83e5b61d2ceeda035b96da4c838:"refs/tags/filtered/filtered/tag_a"
96a731a4d64a8928e6af7abb2d425df3812b4197:"refs/tags/filtered/tag_b"
1dd879133bc80f7d180bd98268412f8ee61226f2:"refs/tags/filtered/tag_b"
975d4c4975912729482cc864d321c5196a969271:"refs/tags/tag_c"
97c6007771c497c9530d61aa89af663daebb1625:"refs/tags/filtered/tag_a"
a91f2e4061d13b9adcb6d8ca63e17c8bbc5bed55:"refs/tags/filtered/filtered/tag_a"
b7e3b7815c4d7c8738545526b20308b1240137c7:"refs/tags/filtered/filtered/filtered/tag_a"
c4215db39f3cd96f07fe4c1f701dad39d5f5dec3:"refs/tags/filtered/filtered/tag_b"
):author="New Author";"new@e.mail"
$ josh-filter -s --file filter.josh --update refs/heads/filtered
[1] :"refs/tags/filtered/filtered/tag_a"
[1] :"refs/tags/filtered/tag_a"
[1] :"refs/tags/filtered/tag_b"
[1] :"refs/tags/tag_a"
[1] :"refs/tags/tag_b"
[1] :"refs/tags/tag_c"
Expand All @@ -128,22 +160,32 @@ This one tag is an annotated tag, to make sure those are handled as well
[3] :squash(
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:"refs/tags/tag_b"
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
5b1a753860ca124024f6dfb4fd018fe7df8beae4:"refs/tags/filtered/tag_a"
68dc45079334d83e5b61d2ceeda035b96da4c838:"refs/tags/filtered/filtered/tag_a"
96a731a4d64a8928e6af7abb2d425df3812b4197:"refs/tags/filtered/tag_b"
1dd879133bc80f7d180bd98268412f8ee61226f2:"refs/tags/filtered/tag_b"
975d4c4975912729482cc864d321c5196a969271:"refs/tags/tag_c"
97c6007771c497c9530d61aa89af663daebb1625:"refs/tags/filtered/tag_a"
a91f2e4061d13b9adcb6d8ca63e17c8bbc5bed55:"refs/tags/filtered/filtered/tag_a"
b7e3b7815c4d7c8738545526b20308b1240137c7:"refs/tags/filtered/filtered/filtered/tag_a"
c4215db39f3cd96f07fe4c1f701dad39d5f5dec3:"refs/tags/filtered/filtered/tag_b"
)
[3] :squash(
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:"refs/tags/tag_b"
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
d8aa5a9937f4f0bd645dbc0b591bae5cd6b6d91b:"refs/tags/filtered/tag_a"
977cc3ee14c0d6163ba63bd96f4aeedd43916ba7:"refs/tags/filtered/tag_a"
)
[5] :committer="New Author";"new@e.mail"
[5] :squash(
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:"refs/tags/tag_b"
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
64f712c4615dbf5e9e0a1c4cdf65b2da2138f4be:"refs/tags/filtered/tag_b"
a68763bdf2f45a44304067954855749e366a5533:"refs/tags/filtered/filtered/tag_a"
be41caf35896090033cfd103e06aae721a3ce541:"refs/tags/filtered/tag_a"
)
[6] :author="New Author";"new@e.mail"
$ git log --graph --decorate --pretty=oneline refs/heads/filtered
* 9fe45cb2bead844630852ab338ecd8e073f8ba50 (filtered) refs/tags/tag_a
* 2826b9a173c7a7d5c83d9ae2614de89c77205d83 (filtered) refs/tags/tag_a
|\
| * d6b88d4c1cc566b7f4d9b51353ec6f3204a93b81 refs/tags/tag_c
| * 63f8653625759f860ee31cce2d4e207974da1c37 refs/tags/tag_c
|/
* 96a731a4d64a8928e6af7abb2d425df3812b4197 (tag: filtered/tag_b) refs/tags/tag_b
* 64f712c4615dbf5e9e0a1c4cdf65b2da2138f4be refs/tags/tag_b
2 changes: 1 addition & 1 deletion tests/filter/squash_empty_initial.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
)
$ git log --graph --decorate --pretty=oneline refs/heads/filtered
* d8aa5a9937f4f0bd645dbc0b591bae5cd6b6d91b (tag: filtered/tag_a, filtered) refs/tags/tag_a
* 977cc3ee14c0d6163ba63bd96f4aeedd43916ba7 (tag: filtered/tag_a, filtered) refs/tags/tag_a
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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- sled
| |-- blobs
| |-- conf
Expand Down Expand Up @@ -162,7 +162,7 @@
]
.
|-- josh
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- 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
| `-- 21
| `-- 22
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/join_subtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Make sure all temporary namespace got removed
]
.
|-- josh
| `-- 21
| `-- 22
| `-- sled
| |-- blobs
| |-- conf
Expand Down
Loading

0 comments on commit daf9b4c

Please sign in to comment.