Skip to content

Commit 47dd595

Browse files
Use linear revwalk for find_original when used in history query (#895)
Because the history always returns simplified history we can make this assumption here and get a big performance benefit. Change-Id: liniar-find-original
1 parent f20359b commit 47dd595

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/bin/josh-filter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@ fn run_filter(args: Vec<String>) -> josh::JoshResult<i32> {
357357
}
358358

359359
if let Some(gql_query) = args.value_of("graphql") {
360+
let context = josh::graphql::context(transaction.try_clone()?, transaction.try_clone()?);
361+
*context.allow_refs.lock()? = true;
360362
let (res, _errors) = juniper::execute_sync(
361363
gql_query,
362364
None,
363365
&josh::graphql::repo_schema(".".to_string(), true),
364366
&std::collections::HashMap::new(),
365-
&josh::graphql::context(transaction.try_clone()?, transaction.try_clone()?),
367+
&context,
366368
)?;
367369

368370
let j = serde_json::to_string(&res)?;

src/graphql.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl Revision {
132132
self.filter,
133133
self.commit_id,
134134
filter_commit.id(),
135+
false,
135136
)?
136137
} else {
137138
self.commit_id
@@ -156,8 +157,14 @@ impl Revision {
156157
.parent_ids()
157158
.map(|id| Revision {
158159
filter: self.filter,
159-
commit_id: history::find_original(&transaction, self.filter, self.commit_id, id)
160-
.unwrap_or_else(|_| git2::Oid::zero()),
160+
commit_id: history::find_original(
161+
&transaction,
162+
self.filter,
163+
self.commit_id,
164+
id,
165+
false,
166+
)
167+
.unwrap_or_else(|_| git2::Oid::zero()),
161168
})
162169
.collect();
163170

@@ -198,7 +205,8 @@ impl Revision {
198205
{
199206
rs_tracing::trace_scoped!("walk");
200207
for i in 0..ids.len() {
201-
ids[i] = history::find_original(&transaction, self.filter, contained_in, ids[i])?;
208+
ids[i] =
209+
history::find_original(&transaction, self.filter, contained_in, ids[i], true)?;
202210
contained_in = transaction
203211
.repo()
204212
.find_commit(ids[i])?

src/history.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub fn find_original(
115115
filter: filter::Filter,
116116
contained_in: git2::Oid,
117117
filtered: git2::Oid,
118+
linear: bool,
118119
) -> JoshResult<git2::Oid> {
119120
if contained_in == git2::Oid::zero() {
120121
return Ok(git2::Oid::zero());
@@ -124,6 +125,9 @@ pub fn find_original(
124125
}
125126
let mut walk = transaction.repo().revwalk()?;
126127
walk.set_sorting(git2::Sort::TOPOLOGICAL)?;
128+
if linear {
129+
walk.simplify_first_parent()?;
130+
}
127131
walk.push(contained_in)?;
128132

129133
for original in walk {
@@ -311,7 +315,7 @@ pub fn unapply_filter(
311315
*original
312316
} else {
313317
tracing::info!("Had to go through the whole thing",);
314-
find_original(transaction, filterobj, original_target, new)?
318+
find_original(transaction, filterobj, original_target, new, false)?
315319
};
316320
return Ok(ret);
317321
}

0 commit comments

Comments
 (0)