Skip to content

Commit

Permalink
Update rustfmt config and refactor code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
oleander committed May 16, 2024
1 parent 28ecbe2 commit 96a58e5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 35 deletions.
8 changes: 5 additions & 3 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct_field_align_threshold = 40
fn_params_layout = "Compressed"
use_field_init_shorthand = true
overflow_delimited_expr = true
struct_lit_single_line = false
struct_lit_single_line = true
imports_granularity = "Module"
imports_layout = "Horizontal"
force_multiline_blocks = true
Expand All @@ -21,14 +21,16 @@ newline_style = "Auto"
fn_call_width = 90
hard_tabs = false
version = "Two"
max_width = 120
max_width = 140
tab_spaces = 2

attr_fn_like_width = 120
match_block_trailing_comma = false
where_single_line = false
chain_width = 60
edition = "2021"
struct_lit_width = 0
struct_variant_width = 0
single_line_if_else_max_width = 0

match_arm_blocks = false
struct_lit_width = 50
5 changes: 2 additions & 3 deletions src/bin/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ async fn main() -> Result<()> {
// git commit --amend or git commit -c
Some("HEAD") | None => repo.head().ok().and_then(|head| head.peel_to_tree().ok()),
// git rebase
Some(sha1) => {
Some(sha1) =>
repo
.find_object(Oid::from_str(sha1)?, None)
.ok()
.and_then(|obj| obj.peel_to_tree().ok())
}
.and_then(|obj| obj.peel_to_tree().ok()),
};

let patch = repo
Expand Down
8 changes: 2 additions & 6 deletions src/commit.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::io;

use async_openai::types::{
ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs
};
use async_openai::types::{ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs};
use async_openai::config::OpenAIConfig;
use async_openai::error::OpenAIError;
use async_openai::Client;
Expand Down Expand Up @@ -83,7 +81,5 @@ pub async fn generate(diff: String) -> Result<OpenAIResponse, ChatError> {
let choise = response.choices.first().context(reason)?;
let text = choise.message.content.clone();

Ok(OpenAIResponse {
response: text.unwrap()
})
Ok(OpenAIResponse { response: text.unwrap() })
}
6 changes: 1 addition & 5 deletions src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ impl CommitExt for git2::Commit<'_> {
let mut commit_info = "".to_string();
let mut opts = DiffOptions::new();
let tree = self.tree()?;
let parent_tree = self
.parent(0)
.ok()
.as_ref()
.and_then(|c| c.tree().ok());
let parent_tree = self.parent(0).ok().as_ref().and_then(|c| c.tree().ok());
let diff = repo.diff_tree_to_tree(parent_tree.as_ref(), Some(&tree), Some(&mut opts))?;

_ = diff
Expand Down
10 changes: 4 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn main() -> Result<()> {
let args = cli().get_matches();

match args.subcommand() {
Some(("hook", sub)) => {
Some(("hook", sub)) =>
match sub.subcommand() {
Some(("install", _)) => {
install::run()?;
Expand All @@ -84,16 +84,14 @@ async fn main() -> Result<()> {
uninstall::run()?;
}
_ => unreachable!()
}
}
Some(("config", args)) => {
},
Some(("config", args)) =>
match args.subcommand() {
Some(("set", args)) => {
config::run(args)?;
}
_ => unreachable!()
}
}
},
Some(("examples", args)) => {
examples::run(args).await?;
}
Expand Down
16 changes: 4 additions & 12 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ impl Default for TestRepo {
let repo = git2::Repository::init(repo_path.path()).unwrap();
std::env::set_var("GIT_DIR", repo_path.path().join(".git"));

Self {
repo,
repo_path
}
Self { repo, repo_path }
}
}

Expand All @@ -38,11 +35,7 @@ pub struct GitFile {

impl GitFile {
pub fn new(repo: git2::Repository, path: PathBuf, repo_path: PathBuf) -> Self {
Self {
repo,
path,
repo_path
}
Self { repo, path, repo_path }
}

pub fn stage(&self) -> Result<()> {
Expand Down Expand Up @@ -90,13 +83,12 @@ impl GitFile {
fn find_last_commit(&self) -> Result<git2::Commit, git2::Error> {
let head = match self.repo.head() {
Ok(head) => head,
Err(e) => {
Err(e) =>
if e.code() == git2::ErrorCode::UnbornBranch || e.code() == git2::ErrorCode::NotFound {
return Err(e);
} else {
panic!("Failed to retrieve HEAD: {}", e);
}
}
},
};

let commit = head.peel_to_commit()?;
Expand Down

0 comments on commit 96a58e5

Please sign in to comment.