-
Notifications
You must be signed in to change notification settings - Fork 67
Implement :from filter #1519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Implement :from filter #1519
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -286,6 +286,8 @@ enum Op { | |||||
| Pattern(String), | ||||||
| Message(String), | ||||||
|
|
||||||
| HistoryConcat(LazyRef, Filter), | ||||||
|
|
||||||
| Compose(Vec<Filter>), | ||||||
| Chain(Filter, Filter), | ||||||
| Subtract(Filter, Filter), | ||||||
|
|
@@ -410,6 +412,13 @@ fn lazy_refs2(op: &Op) -> Vec<String> { | |||||
| av | ||||||
| } | ||||||
| Op::Rev(filters) => lazy_refs2(&Op::Join(filters.clone())), | ||||||
| Op::HistoryConcat(r, _) => { | ||||||
| let mut lr = Vec::new(); | ||||||
| if let LazyRef::Lazy(s) = r { | ||||||
| lr.push(s.to_owned()); | ||||||
| } | ||||||
| lr | ||||||
| } | ||||||
| Op::Join(filters) => { | ||||||
| let mut lr = lazy_refs2(&Op::Compose(filters.values().copied().collect())); | ||||||
| lr.extend(filters.keys().filter_map(|x| { | ||||||
|
|
@@ -470,6 +479,19 @@ fn resolve_refs2(refs: &std::collections::HashMap<String, git2::Oid>, op: &Op) - | |||||
| .collect(); | ||||||
| Op::Rev(lr) | ||||||
| } | ||||||
| Op::HistoryConcat(r, filter) => { | ||||||
| let f = resolve_refs(refs, *filter); | ||||||
| let resolved_ref = if let LazyRef::Lazy(s) = r { | ||||||
| if let Some(res) = refs.get(s) { | ||||||
| LazyRef::Resolved(*res) | ||||||
| } else { | ||||||
| r.clone() | ||||||
| } | ||||||
| } else { | ||||||
| r.clone() | ||||||
| }; | ||||||
| Op::HistoryConcat(resolved_ref, f) | ||||||
| } | ||||||
| Op::Join(filters) => { | ||||||
| let lr = filters | ||||||
| .iter() | ||||||
|
|
@@ -611,6 +633,9 @@ fn spec2(op: &Op) -> String { | |||||
| Op::Message(m) => { | ||||||
| format!(":{}", parse::quote(m)) | ||||||
| } | ||||||
| Op::HistoryConcat(r, filter) => { | ||||||
| format!(":concat({}{})", r.to_string(), spec(*filter)) | ||||||
|
||||||
| format!(":concat({}{})", r.to_string(), spec(*filter)) | |
| format!(":concat({}:{})", r.to_string(), spec(*filter)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| $ export TESTTMP=${PWD} | ||
|
|
||
| $ cd ${TESTTMP} | ||
| $ git init -q libs 1> /dev/null | ||
| $ cd libs | ||
|
|
||
| $ mkdir sub1 | ||
| $ echo contents1 > sub1/file1 | ||
| $ git add sub1 | ||
| $ git commit -m "add file1" 1> /dev/null | ||
|
|
||
| $ echo contents2 > sub1/file2 | ||
| $ git add sub1 | ||
| $ git commit -m "add file2" 1> /dev/null | ||
| $ git update-ref refs/heads/from_here HEAD | ||
|
|
||
|
|
||
| $ mkdir sub2 | ||
| $ echo contents1 > sub2/file3 | ||
| $ git add sub2 | ||
| $ git commit -m "add file3" 1> /dev/null | ||
|
|
||
| $ josh-filter ":\"x\"" | ||
|
|
||
| $ git log --graph --pretty=%s:%H HEAD | ||
| * add file3:667a912db7482f3c8023082c9b4c7b267792633a | ||
| * add file2:81b10fb4984d20142cd275b89c91c346e536876a | ||
| * add file1:bb282e9cdc1b972fffd08fd21eead43bc0c83cb8 | ||
|
|
||
| $ git log --graph --pretty=%s:%H FILTERED_HEAD | ||
| * x:9d117d96dfdba145df43ebe37d9e526acac4b17c | ||
| * x:b232aa8eefaadfb5e38b3ad7355118aa59fb651e | ||
| * x:6b4d1f87c2be08f7d0f9d40b6679aab612e259b1 | ||
|
|
||
| $ josh-filter -p ":from(81b10fb4984d20142cd275b89c91c346e536876a:\"x\")" | ||
| :"x":concat(81b10fb4984d20142cd275b89c91c346e536876a:"x") | ||
| $ josh-filter ":from(81b10fb4984d20142cd275b89c91c346e536876a:\"x\")" | ||
|
|
||
| $ git log --graph --pretty=%s FILTERED_HEAD | ||
| * x | ||
| * add file2 | ||
| * add file1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
filter_concatrule incorrectly uses\"from\"as the command keyword instead of\"concat\". This causes the parser to be unable to distinguish between:from()and:concat()operations. Change line 66 to use\"concat\".