Skip to content

Commit e85bc71

Browse files
Make :linear filter non-recursive (#756)
The :linear filter was implemented recursively by accident, making it very slow on non trivial repos. Change-Id: non-recursive-linear
1 parent 7303556 commit e85bc71

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/filter/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,21 @@ fn apply_to_commit2(
297297

298298
let filtered_tree = match &to_op(filter) {
299299
Op::Linear => {
300-
let p: Vec<_> = commit.parents().collect();
300+
let p: Vec<_> = commit.parent_ids().collect();
301301
if p.len() == 0 {
302+
transaction.insert(filter, commit.id(), commit.id(), true);
302303
return Ok(Some(commit.id()));
303304
}
304-
let parent = some_or!(apply_to_commit2(op, &p[0], transaction)?, {
305+
let parent = some_or!(transaction.get(filter, p[0]), {
305306
return Ok(None);
306307
});
307308

308-
let parent_commit = repo.find_commit(parent)?;
309-
return Some(history::rewrite_commit(
310-
repo,
309+
return Some(history::create_filtered_commit(
311310
commit,
312-
&[&parent_commit],
313-
&commit.tree()?,
311+
vec![parent],
312+
commit.tree()?,
313+
transaction,
314+
filter,
314315
))
315316
.transpose();
316317
}

tests/filter/linear.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* add file1
3333

3434
$ josh-filter -s :linear refs/heads/master --update refs/heads/filtered
35+
[3] :linear
3536

3637
$ git log --graph --pretty=%s refs/heads/filtered
3738
* Merge branch 'branch2'
@@ -56,6 +57,7 @@
5657
* add file1
5758

5859
$ josh-filter -s :linear refs/heads/master --update refs/heads/filtered --reverse
60+
[3] :linear
5961

6062
$ git log --graph --pretty=%s refs/heads/master
6163
* mod file2

0 commit comments

Comments
 (0)