fix: key review checkmarks by file snapshots instead of revision pairs
This commit is contained in:
+26
-6
@@ -127,6 +127,8 @@ pub struct Hunk {
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct ChangedFile {
|
||||
/// Immutable file-side identities, independent of unrelated revision changes.
|
||||
pub review_revisions: Option<[String; 2]>,
|
||||
pub path: PathBuf,
|
||||
pub old_path: Option<PathBuf>,
|
||||
pub status: FileStatus,
|
||||
@@ -676,6 +678,7 @@ impl DiffState {
|
||||
});
|
||||
comparison.root = root.clone();
|
||||
comparison.files.resize_with(paths.len(), || ChangedFile {
|
||||
review_revisions: None,
|
||||
path: PathBuf::new(),
|
||||
old_path: None,
|
||||
status: FileStatus::Modified,
|
||||
@@ -1801,11 +1804,20 @@ impl DiffState {
|
||||
}
|
||||
let records = &mut self.local_review.document.reviewed_files;
|
||||
records.retain(|record| {
|
||||
record.revisions != comparison.revisions || record.path != file.path
|
||||
record.revisions
|
||||
!= *file
|
||||
.review_revisions
|
||||
.as_ref()
|
||||
.unwrap_or(&comparison.revisions)
|
||||
|| record.path != file.path
|
||||
});
|
||||
if reviewed {
|
||||
records.push(crate::review::ReviewedFile {
|
||||
revisions: comparison.revisions.clone(),
|
||||
revisions: file
|
||||
.review_revisions
|
||||
.as_ref()
|
||||
.unwrap_or(&comparison.revisions)
|
||||
.clone(),
|
||||
path: file.path.clone(),
|
||||
old_path: file.old_path.clone(),
|
||||
after: self
|
||||
@@ -1832,12 +1844,16 @@ impl DiffState {
|
||||
.document
|
||||
.reviewed_files
|
||||
.iter()
|
||||
.filter(|record| record.revisions == comparison.revisions)
|
||||
.map(|record| (&record.path, record))
|
||||
.map(|record| ((&record.revisions, &record.path), record))
|
||||
.collect();
|
||||
for (index, file) in comparison.files.iter().enumerate() {
|
||||
let Some(record) = records
|
||||
.get(&file.path)
|
||||
.get(&(
|
||||
file.review_revisions
|
||||
.as_ref()
|
||||
.unwrap_or(&comparison.revisions),
|
||||
&file.path,
|
||||
))
|
||||
.filter(|record| record.old_path == file.old_path)
|
||||
else {
|
||||
continue;
|
||||
@@ -2263,7 +2279,11 @@ impl DiffState {
|
||||
.reviewed_files
|
||||
.iter()
|
||||
.position(|record| {
|
||||
record.revisions == comparison.revisions
|
||||
record.revisions
|
||||
== *file
|
||||
.review_revisions
|
||||
.as_ref()
|
||||
.unwrap_or(&comparison.revisions)
|
||||
&& record.path == file.path
|
||||
&& record.old_path == file.old_path
|
||||
})
|
||||
|
||||
@@ -2770,6 +2770,7 @@ impl Repository {
|
||||
continue;
|
||||
}
|
||||
files.push(ChangedFile {
|
||||
review_revisions: None,
|
||||
path: path.clone(),
|
||||
old_path: None,
|
||||
status: if a.is_none() {
|
||||
@@ -2827,6 +2828,10 @@ impl Repository {
|
||||
.files
|
||||
.iter()
|
||||
.map(|(path, old_path, status)| ChangedFile {
|
||||
review_revisions: Some([
|
||||
review_file_revision(prepared.left.get(old_path.as_ref().unwrap_or(path))),
|
||||
review_file_revision(prepared.right.get(path)),
|
||||
]),
|
||||
path: path.clone(),
|
||||
old_path: old_path.clone(),
|
||||
status: *status,
|
||||
@@ -2902,6 +2907,7 @@ impl Repository {
|
||||
)?;
|
||||
file.status = *status;
|
||||
file.old_path = old_path.clone();
|
||||
file.review_revisions = Some([review_file_revision(before), review_file_revision(after)]);
|
||||
Ok(file)
|
||||
}
|
||||
fn changed_file(
|
||||
@@ -2972,6 +2978,7 @@ impl Repository {
|
||||
};
|
||||
notices.dedup();
|
||||
Ok(ChangedFile {
|
||||
review_revisions: None,
|
||||
path: path.to_path_buf(),
|
||||
old_path: None,
|
||||
status,
|
||||
@@ -2990,6 +2997,14 @@ impl Repository {
|
||||
}
|
||||
}
|
||||
|
||||
fn review_file_revision(file: Option<&FileData>) -> String {
|
||||
// Git object IDs cover exact bytes (including binary data and EOF), without loading blobs.
|
||||
format!(
|
||||
"file:{}",
|
||||
serde_json::to_string(&file.map(file_identity)).unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
fn file_identity(file: &FileData) -> (&str, Option<&str>, &[u8], Option<&str>) {
|
||||
(
|
||||
&file.mode,
|
||||
|
||||
Reference in New Issue
Block a user