Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 62744a0

Browse files
Remove revspec workaround
1 parent 2922c49 commit 62744a0

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

‎asyncgit/src/error.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ pub enum GixError {
5454
#[from] gix::reference::find::existing::Error,
5555
),
5656

57+
///
58+
#[error("gix::reference::head_tree::Error error: {0}")]
59+
ReferenceHeadTree(#[from] gix::reference::head_tree::Error),
60+
5761
///
5862
#[error("gix::reference::head_tree_id::Error error: {0}")]
5963
ReferenceHeadTreeId(#[from] gix::reference::head_tree_id::Error),
@@ -296,6 +300,12 @@ impl From<gix::reference::find::existing::Error> for Error {
296300
}
297301
}
298302

303+
impl From<gix::reference::head_tree::Error> for Error {
304+
fn from(error: gix::reference::head_tree::Error) -> Self {
305+
Self::Gix(GixError::from(error))
306+
}
307+
}
308+
299309
impl From<gix::reference::head_tree_id::Error> for Error {
300310
fn from(error: gix::reference::head_tree_id::Error) -> Self {
301311
Self::Gix(GixError::from(error))

‎asyncgit/src/sync/diff.rs‎

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -319,26 +319,6 @@ impl ConsumeHunk for FileDiff {
319319
}
320320
}
321321

322-
fn resolve_revspec(
323-
gix_repo: &gix::Repository,
324-
revspec: &str,
325-
) -> (ObjectId, Option<std::path::PathBuf>) {
326-
gix_repo.rev_parse(revspec).map_or_else(
327-
|_| {
328-
(
329-
ObjectId::null(gix::hash::Kind::Sha1),
330-
gix_repo.workdir().map(ToOwned::to_owned),
331-
)
332-
},
333-
|resolved_revspec| {
334-
resolved_revspec.single().map_or_else(
335-
|| (ObjectId::null(gix::hash::Kind::Sha1), None),
336-
|id| (id.into(), None),
337-
)
338-
},
339-
)
340-
}
341-
342322
/// returns diff of a specific file either in `stage` or workdir
343323
pub fn get_diff(
344324
repo_path: &RepoPath,
@@ -356,18 +336,42 @@ pub fn get_diff(
356336
);
357337

358338
// TODO:
359-
// Make sure that the revspec logic is correct, i. e. uses the correct syntax for all the
360-
// relevant cases.
361-
let (old_revspec, new_revspec) = if stage {
362-
(format!("HEAD:{p}"), format!(":{p}"))
339+
// The lower tree is `stage == true`, the upper tree is `stage == false`.
340+
let (old_blob_id, old_root) = if stage {
341+
(
342+
gix_repo
343+
.head_tree()?
344+
.lookup_entry_by_path(p)
345+
.expect("TODO")
346+
.expect("TODO")
347+
.object_id(),
348+
None,
349+
)
363350
} else {
364-
(format!(":{p}"), p.to_string())
351+
(
352+
gix_repo
353+
.index()?
354+
.entry_by_path(p.into())
355+
.expect("TODO")
356+
.id,
357+
None,
358+
)
359+
};
360+
let (new_blob_id, new_root) = if stage {
361+
(
362+
gix_repo
363+
.index()?
364+
.entry_by_path(p.into())
365+
.expect("TODO")
366+
.id,
367+
None,
368+
)
369+
} else {
370+
(
371+
ObjectId::null(gix::hash::Kind::Sha1),
372+
gix_repo.workdir().map(ToOwned::to_owned),
373+
)
365374
};
366-
367-
let (old_blob_id, old_root) =
368-
resolve_revspec(&gix_repo, &old_revspec);
369-
let (new_blob_id, new_root) =
370-
resolve_revspec(&gix_repo, &new_revspec);
371375

372376
let worktree_roots = gix::diff::blob::pipeline::WorktreeRoots {
373377
old_root,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /