diff options
author | Teddy Wing | 2020-08-22 21:53:56 +0200 |
---|---|---|
committer | Teddy Wing | 2020-08-22 21:53:56 +0200 |
commit | 3c6f337e26964077d1ce629fa17d16e4484b877f (patch) | |
tree | d61f1039aa25d01ff5dc354c25a0e936590e6b7b | |
parent | 5cbc3972644a321442b9640cfcc50f7ef014a6c9 (diff) | |
download | git-suggestion-3c6f337e26964077d1ce629fa17d16e4484b877f.tar.bz2 |
Suggestion.diff_command: Return the right side version blob
Don't run the `git diff` command in this function, instead return the
new blob created for the right hand side of the comparison.
This will facilitate showing the diffs of multiple suggestions at once.
Maybe. I haven't tried the command yet.
Actually, looking at the man page, it doesn't say we can include more
than one blob pair, so I might need to put all of the suggestion changes
into a single blob and compare the original commit with that.
-rw-r--r-- | github-suggestion/src/suggestion.rs | 24 | ||||
-rw-r--r-- | src/bin/git-sugdiff.rs | 10 |
2 files changed, 19 insertions, 15 deletions
diff --git a/github-suggestion/src/suggestion.rs b/github-suggestion/src/suggestion.rs index 3f124ce..21591b1 100644 --- a/github-suggestion/src/suggestion.rs +++ b/github-suggestion/src/suggestion.rs @@ -16,7 +16,6 @@ use std::io::{BufRead, BufReader, BufWriter, Write}; use std::path::Path; -use std::process::Command; use git2::{Patch, Repository}; use regex::Regex; @@ -81,6 +80,14 @@ pub struct Suggestion { } impl Suggestion { + pub fn commit(&self) -> &str { + &self.commit + } + + pub fn path(&self) -> &str { + &self.path + } + /// Get the suggestion diff for the current repository. pub fn diff(&self) -> Result<String, Error> { let repo = Repository::open(".")?; @@ -127,7 +134,7 @@ impl Suggestion { ) } - pub fn diff_command(&self) -> Result<(), Error> { + pub fn diff_command(&self) -> Result<git2::Oid, Error> { let repo = Repository::open(".")?; let commit = repo.find_commit(self.commit.parse()?)?; @@ -150,18 +157,7 @@ impl Suggestion { message: "unable to read right side of patch".to_owned(), })?; - let patched_blob = repo.blob(&new_buffer)?; - - Command::new("git") - .arg("diff") - .arg(format!("{}:{}", commit.id(), self.path)) - .arg(patched_blob.to_string()) - .spawn() - .unwrap(); - - // Maybe: Return blob - - Ok(()) + Ok(repo.blob(&new_buffer)?) } /// Extract suggestion code from a comment body. diff --git a/src/bin/git-sugdiff.rs b/src/bin/git-sugdiff.rs index c8ecf40..9c7ff1f 100644 --- a/src/bin/git-sugdiff.rs +++ b/src/bin/git-sugdiff.rs @@ -16,6 +16,7 @@ use std::env; use std::process; +use std::process::Command; use exitcode; @@ -42,7 +43,14 @@ fn main() { &config, |suggestion| { // TODO: Needs to work for multiple suggestions at once - suggestion.diff_command().unwrap(); + let blob = suggestion.diff_command().unwrap(); + + Command::new("git") + .arg("diff") + .arg(format!("{}:{}", suggestion.commit(), suggestion.path())) + .arg(blob.to_string()) + .spawn() + .unwrap(); }, ); } |