Skip to content

Commit cce49a3

Browse files
committed
Revert "Change diff renamed files (#1040)"
This reverts commit 5f466ff.
1 parent c3dbce1 commit cce49a3

22 files changed

+122
-497
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ This is was a immediate followup patch release to `0.20` see [release notes](htt
6363
- support inspecting annotation of tag ([#1076](https://github.com/extrawurst/gitui/issues/1076))
6464
- support deleting tag on remote ([#1074](https://github.com/extrawurst/gitui/issues/1074))
6565
- support git credentials helper (https) ([#800](https://github.com/extrawurst/gitui/issues/800))
66-
- Correct diff of renamed files [[@Mifom](https://github.com/Mifom)] ([#1038](https://github.com/extrawurst/gitui/issues/1038))
6766

6867
### Fixed
6968
- Keep commit message when pre-commit hook fails ([#1035](https://github.com/extrawurst/gitui/issues/1035))

asyncgit/src/diff.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ pub enum DiffType {
2929
///
3030
#[derive(Debug, Hash, Clone, PartialEq)]
3131
pub struct DiffParams {
32-
///
33-
pub src_path: String,
3432
/// path to the file to diff
35-
pub dst_path: String,
33+
pub path: String,
3634
/// what kind of diff
3735
pub diff_type: DiffType,
3836
/// diff options
@@ -163,28 +161,26 @@ impl AsyncDiff {
163161
let res = match params.diff_type {
164162
DiffType::Stage => sync::diff::get_diff(
165163
repo_path,
166-
&params.src_path,
167-
&params.dst_path,
164+
&params.path,
168165
true,
169166
Some(params.options),
170167
)?,
171168
DiffType::WorkDir => sync::diff::get_diff(
172169
repo_path,
173-
&params.src_path,
174-
&params.dst_path,
170+
&params.path,
175171
false,
176172
Some(params.options),
177173
)?,
178174
DiffType::Commit(id) => sync::diff::get_diff_commit(
179175
repo_path,
180176
id,
181-
params.dst_path.clone(),
177+
params.path.clone(),
182178
Some(params.options),
183179
)?,
184180
DiffType::Commits(ids) => sync::diff::get_diff_commits(
185181
repo_path,
186182
ids,
187-
params.dst_path.clone(),
183+
params.path.clone(),
188184
Some(params.options),
189185
)?,
190186
};

asyncgit/src/sync/commit_files.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,21 @@ pub fn get_commit_files(
2626
get_commit_diff(repo_path, &repo, id, None, None)?
2727
};
2828

29-
let res =
30-
diff.deltas()
31-
.map(|delta| {
32-
let status = StatusItemType::from(delta.status());
33-
34-
StatusItem {
35-
old_path: delta.old_file().path().map(|p| {
36-
p.to_str().unwrap_or("").to_string()
37-
}),
38-
new_path: delta
39-
.new_file()
40-
.path()
41-
.map(|p| p.to_str().unwrap_or("").to_string())
42-
.unwrap_or_default(),
43-
status,
44-
}
45-
})
46-
.collect::<Vec<_>>();
29+
let res = diff
30+
.deltas()
31+
.map(|delta| {
32+
let status = StatusItemType::from(delta.status());
33+
34+
StatusItem {
35+
path: delta
36+
.new_file()
37+
.path()
38+
.map(|p| p.to_str().unwrap_or("").to_string())
39+
.unwrap_or_default(),
40+
status,
41+
}
42+
})
43+
.collect::<Vec<_>>();
4744

4845
Ok(res)
4946
}

asyncgit/src/sync/diff.rs

Lines changed: 13 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::{
1010
};
1111
use easy_cast::Conv;
1212
use git2::{
13-
Delta, Diff, DiffDelta, DiffFindOptions, DiffFormat, DiffHunk,
14-
Patch, Repository,
13+
Delta, Diff, DiffDelta, DiffFormat, DiffHunk, Patch, Repository,
1514
};
1615
use scopetime::scope_time;
1716
use std::{cell::RefCell, fs, path::Path, rc::Rc};
@@ -150,8 +149,7 @@ impl Default for DiffOptions {
150149

151150
pub(crate) fn get_diff_raw<'a>(
152151
repo: &'a Repository,
153-
src: &str,
154-
dst: &str,
152+
p: &str,
155153
stage: bool,
156154
reverse: bool,
157155
options: Option<DiffOptions>,
@@ -164,11 +162,10 @@ pub(crate) fn get_diff_raw<'a>(
164162
opt.ignore_whitespace(options.ignore_whitespace);
165163
opt.interhunk_lines(options.interhunk_lines);
166164
}
167-
opt.pathspec(src);
168-
opt.pathspec(dst);
165+
opt.pathspec(p);
169166
opt.reverse(reverse);
170167

171-
let mut diff = if stage {
168+
let diff = if stage {
172169
// diff against head
173170
if let Ok(id) = get_head_repo(repo) {
174171
let parent = repo.find_commit(id.into())?;
@@ -192,25 +189,21 @@ pub(crate) fn get_diff_raw<'a>(
192189
repo.diff_index_to_workdir(None, Some(&mut opt))?
193190
};
194191

195-
diff.find_similar(Some(
196-
DiffFindOptions::new().renames(true).for_untracked(true),
197-
))?;
198192
Ok(diff)
199193
}
200194

201195
/// returns diff of a specific file either in `stage` or workdir
202196
pub fn get_diff(
203197
repo_path: &RepoPath,
204-
src: &str,
205-
dst: &str,
198+
p: &str,
206199
stage: bool,
207200
options: Option<DiffOptions>,
208201
) -> Result<FileDiff> {
209202
scope_time!("get_diff");
210203

211204
let repo = repo(repo_path)?;
212205
let work_dir = work_dir(&repo)?;
213-
let diff = get_diff_raw(&repo, src, dst, stage, false, options)?;
206+
let diff = get_diff_raw(&repo, p, stage, false, options)?;
214207

215208
raw_diff_to_file_diff(&diff, work_dir)
216209
}
@@ -257,8 +250,8 @@ pub fn get_diff_commits(
257250
///
258251
//TODO: refactor into helper type with the inline closures as dedicated functions
259252
#[allow(clippy::too_many_lines)]
260-
fn raw_diff_to_file_diff(
261-
diff: &Diff,
253+
fn raw_diff_to_file_diff<'a>(
254+
diff: &'a Diff,
262255
work_dir: &Path,
263256
) -> Result<FileDiff> {
264257
let res = Rc::new(RefCell::new(FileDiff::default()));
@@ -429,7 +422,7 @@ mod tests {
429422
},
430423
};
431424
use std::{
432-
fs::{self, remove_file, File},
425+
fs::{self, File},
433426
io::Write,
434427
path::Path,
435428
};
@@ -451,14 +444,8 @@ mod tests {
451444

452445
assert_eq!(get_statuses(repo_path), (1, 0));
453446

454-
let diff = get_diff(
455-
repo_path,
456-
"foo/bar.txt",
457-
"foo/bar.txt",
458-
false,
459-
None,
460-
)
461-
.unwrap();
447+
let diff =
448+
get_diff(repo_path, "foo/bar.txt", false, None).unwrap();
462449

463450
assert_eq!(diff.hunks.len(), 1);
464451
assert_eq!(&*diff.hunks[0].lines[1].content, "test");
@@ -488,7 +475,6 @@ mod tests {
488475
let diff = get_diff(
489476
repo_path,
490477
file_path.to_str().unwrap(),
491-
file_path.to_str().unwrap(),
492478
true,
493479
None,
494480
)
@@ -544,8 +530,7 @@ mod tests {
544530
let res = get_status(repo_path, StatusType::WorkingDir, None)
545531
.unwrap();
546532
assert_eq!(res.len(), 1);
547-
assert_eq!(res[0].new_path, "bar.txt");
548-
assert_eq!(res[0].old_path, Some("bar.txt".to_string()));
533+
assert_eq!(res[0].path, "bar.txt");
549534

550535
stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
551536
assert_eq!(get_statuses(repo_path), (0, 1));
@@ -561,8 +546,7 @@ mod tests {
561546
assert_eq!(get_statuses(repo_path), (1, 1));
562547

563548
let res =
564-
get_diff(repo_path, "bar.txt", "bar.txt", false, None)
565-
.unwrap();
549+
get_diff(repo_path, "bar.txt", false, None).unwrap();
566550

567551
assert_eq!(res.hunks.len(), 2)
568552
}
@@ -584,7 +568,6 @@ mod tests {
584568
let diff = get_diff(
585569
&sub_path.to_str().unwrap().into(),
586570
file_path.to_str().unwrap(),
587-
file_path.to_str().unwrap(),
588571
false,
589572
None,
590573
)
@@ -613,7 +596,6 @@ mod tests {
613596
let diff = get_diff(
614597
repo_path,
615598
file_path.to_str().unwrap(),
616-
file_path.to_str().unwrap(),
617599
false,
618600
None,
619601
)
@@ -640,7 +622,6 @@ mod tests {
640622
let diff = get_diff(
641623
repo_path,
642624
file_path.to_str().unwrap(),
643-
file_path.to_str().unwrap(),
644625
false,
645626
None,
646627
)
@@ -684,50 +665,4 @@ mod tests {
684665

685666
Ok(())
686667
}
687-
688-
#[test]
689-
fn test_rename() {
690-
let (_td, repo) = repo_init().unwrap();
691-
let root = repo.path().parent().unwrap();
692-
let repo_path: &RepoPath =
693-
&root.as_os_str().to_str().unwrap().into();
694-
695-
assert_eq!(get_statuses(repo_path), (0, 0));
696-
697-
let file_path = root.join("bar.txt");
698-
699-
{
700-
File::create(&file_path)
701-
.unwrap()
702-
.write_all(HUNK_A.as_bytes())
703-
.unwrap();
704-
}
705-
706-
let res = get_status(repo_path, StatusType::WorkingDir, None)
707-
.unwrap();
708-
assert_eq!(res.len(), 1);
709-
assert_eq!(res[0].new_path, "bar.txt");
710-
assert_eq!(res[0].old_path, Some("bar.txt".to_string()));
711-
712-
stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
713-
assert_eq!(get_statuses(repo_path), (0, 1));
714-
715-
// Move file
716-
let other_file_path = root.join("baz.txt");
717-
{
718-
File::create(&other_file_path)
719-
.unwrap()
720-
.write_all(HUNK_A.as_bytes())
721-
.unwrap();
722-
remove_file(&file_path).unwrap();
723-
}
724-
725-
assert_eq!(get_statuses(repo_path), (1, 1));
726-
727-
let res =
728-
get_diff(repo_path, "bar.txt", "baz.txt", false, None)
729-
.unwrap();
730-
731-
assert_eq!(res.hunks.len(), 0)
732-
}
733668
}

asyncgit/src/sync/hunks.rs

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@ use scopetime::scope_time;
1313
///
1414
pub fn stage_hunk(
1515
repo_path: &RepoPath,
16-
src_file_path: &str,
17-
dst_file_path: &str,
16+
file_path: &str,
1817
hunk_hash: u64,
1918
) -> Result<()> {
2019
scope_time!("stage_hunk");
2120

2221
let repo = repo(repo_path)?;
2322

24-
let diff = get_diff_raw(
25-
&repo,
26-
src_file_path,
27-
dst_file_path,
28-
false,
29-
false,
30-
None,
31-
)?;
23+
let diff = get_diff_raw(&repo, file_path, false, false, None)?;
3224

3325
let mut opt = ApplyOptions::new();
3426
opt.hunk_callback(|hunk| {
@@ -53,9 +45,7 @@ pub fn reset_hunk(
5345

5446
let repo = repo(repo_path)?;
5547

56-
let diff = get_diff_raw(
57-
&repo, file_path, file_path, false, false, None,
58-
)?;
48+
let diff = get_diff_raw(&repo, file_path, false, false, None)?;
5949

6050
let hunk_index = find_hunk_index(&diff, hunk_hash);
6151
if let Some(hunk_index) = hunk_index {
@@ -67,9 +57,7 @@ pub fn reset_hunk(
6757
res
6858
});
6959

70-
let diff = get_diff_raw(
71-
&repo, file_path, file_path, false, true, None,
72-
)?;
60+
let diff = get_diff_raw(&repo, file_path, false, true, None)?;
7361

7462
repo.apply(&diff, ApplyLocation::WorkDir, Some(&mut opt))?;
7563

@@ -108,22 +96,14 @@ fn find_hunk_index(diff: &Diff, hunk_hash: u64) -> Option<usize> {
10896
///
10997
pub fn unstage_hunk(
11098
repo_path: &RepoPath,
111-
src_file_path: &str,
112-
dst_file_path: &str,
99+
file_path: &str,
113100
hunk_hash: u64,
114101
) -> Result<bool> {
115102
scope_time!("revert_hunk");
116103

117104
let repo = repo(repo_path)?;
118105

119-
let diff = get_diff_raw(
120-
&repo,
121-
src_file_path,
122-
dst_file_path,
123-
true,
124-
false,
125-
None,
126-
)?;
106+
let diff = get_diff_raw(&repo, file_path, true, false, None)?;
127107
let diff_count_positive = diff.deltas().len();
128108

129109
let hunk_index = find_hunk_index(&diff, hunk_hash);
@@ -132,14 +112,7 @@ pub fn unstage_hunk(
132112
Ok,
133113
)?;
134114

135-
let diff = get_diff_raw(
136-
&repo,
137-
src_file_path,
138-
dst_file_path,
139-
true,
140-
true,
141-
None,
142-
)?;
115+
let diff = get_diff_raw(&repo, file_path, true, true, None)?;
143116

144117
if diff.deltas().len() != diff_count_positive {
145118
return Err(Error::Generic(format!(
@@ -201,7 +174,6 @@ mod tests {
201174
let diff = get_diff(
202175
sub_path,
203176
file_path.to_str().unwrap(),
204-
file_path.to_str().unwrap(),
205177
false,
206178
None,
207179
)?;

asyncgit/src/sync/merge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn abort_pending_state(repo_path: &RepoPath) -> Result<()> {
4242
let repo = repo(repo_path)?;
4343

4444
reset_stage(repo_path, "*")?;
45-
reset_workdir(repo_path, None, "*")?;
45+
reset_workdir(repo_path, "*")?;
4646

4747
repo.cleanup_state()?;
4848

0 commit comments

Comments
 (0)