aboutsummaryrefslogtreecommitdiffstats
path: root/github-suggestion/src
diff options
context:
space:
mode:
authorTeddy Wing2020-08-23 17:41:37 +0200
committerTeddy Wing2020-08-23 17:41:37 +0200
commit588cd526fd78b3a0e0ec1dfb9fc194ca385de902 (patch)
treeec5e973c273581c94e2bd8b5a95664cb9ba37d0a /github-suggestion/src
parent3c6f337e26964077d1ce629fa17d16e4484b877f (diff)
downloadgit-suggestion-588cd526fd78b3a0e0ec1dfb9fc194ca385de902.tar.bz2
Suggestion.diff_command: Diff an index instead of a file
This will enable us to use the `git diff` command with more than one suggestion at the same time. We compare the commit of the suggestion with the new index's tree. And as I write this, I'm realising that we can't diff multiple suggestions using the same commit because each suggestion has its own commit. Need to work out a different way to do this.
Diffstat (limited to 'github-suggestion/src')
-rw-r--r--github-suggestion/src/suggestion.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/github-suggestion/src/suggestion.rs b/github-suggestion/src/suggestion.rs
index 21591b1..29fab04 100644
--- a/github-suggestion/src/suggestion.rs
+++ b/github-suggestion/src/suggestion.rs
@@ -157,7 +157,27 @@ impl Suggestion {
message: "unable to read right side of patch".to_owned(),
})?;
- Ok(repo.blob(&new_buffer)?)
+ let mut index = repo.index()?;
+ index.add_frombuffer(
+ &git2::IndexEntry {
+ ctime: git2::IndexTime::new(0, 0),
+ mtime: git2::IndexTime::new(0, 0),
+ dev: 0,
+ ino: 0,
+ mode: 0o100644,
+ uid: 0,
+ gid: 0,
+ file_size: new_buffer.len() as u32,
+ id: git2::Oid::zero(),
+ flags: 0,
+ flags_extended: 0,
+ path: self.path.as_bytes().to_vec(),
+ },
+ &new_buffer,
+ )?;
+ let tree = index.write_tree()?;
+
+ Ok(tree)
}
/// Extract suggestion code from a comment body.