Skip to content

Commit 8afd31a

Browse files
authored
Merge pull request #9944 from Byron/fix
cleanup but-rebase
2 parents c5967cd + dd91e02 commit 8afd31a

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/but-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ but-core.workspace = true
2727
but-hunk-assignment.workspace = true
2828
but-action.workspace = true
2929
but-rebase.workspace = true
30+
gitbutler-serde.workspace = true
3031
gitbutler-branch.workspace = true
3132
gitbutler-branch-actions.workspace = true
3233
gitbutler-command-context.workspace = true

crates/but-api/src/commands/config.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use but_core::{RepositoryExt, settings::git::ui::GitConfigSettings};
22
use gitbutler_project::ProjectId;
3+
use gitbutler_serde::bstring_opt_lossy;
4+
use gix::bstr::BString;
35
use serde::{Deserialize, Serialize};
46

57
use crate::{App, error::Error};
@@ -57,21 +59,14 @@ pub fn store_author_globally_if_unset(
5759
}
5860

5961
/// Represents the author information from the git configuration.
60-
#[derive(Debug, Clone, Serialize, Deserialize)]
62+
#[derive(Debug, Clone, Serialize)]
6163
pub struct AuthorInfo {
6264
/// The name of the author.
63-
pub name: Option<String>,
65+
#[serde(with = "bstring_opt_lossy")]
66+
pub name: Option<BString>,
6467
/// The email of the author.
65-
pub email: Option<String>,
66-
}
67-
68-
impl From<but_rebase::commit::AuthorInfo> for AuthorInfo {
69-
fn from(author: but_rebase::commit::AuthorInfo) -> Self {
70-
Self {
71-
name: author.name.map(|s| s.to_string()),
72-
email: author.email.map(|s| s.to_string()),
73-
}
74-
}
68+
#[serde(with = "bstring_opt_lossy")]
69+
pub email: Option<BString>,
7570
}
7671

7772
#[derive(Deserialize)]
@@ -80,8 +75,14 @@ pub struct GetAuthorInfoParams {
8075
pub project_id: ProjectId,
8176
}
8277

78+
/// Return the Git author information as the project repository would see it.
8379
pub fn get_author_info(_app: &App, params: GetAuthorInfoParams) -> Result<AuthorInfo, Error> {
8480
let repo = but_core::open_repo(gitbutler_project::get(params.project_id)?.path)?;
85-
let author = but_rebase::commit::get_author_info(&repo)?;
86-
Ok(author.into())
81+
let (name, email) = repo
82+
.author()
83+
.transpose()
84+
.map_err(anyhow::Error::from)?
85+
.map(|author| (Some(author.name.to_owned()), Some(author.email.to_owned())))
86+
.unwrap_or_default();
87+
Ok(AuthorInfo { name, email })
8788
}

crates/but-rebase/src/commit.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@ use std::io::Write;
99
use std::path::Path;
1010
use std::process::Stdio;
1111

12-
/// Represents the author information from the git configuration.
13-
pub struct AuthorInfo {
14-
/// The name of the author.
15-
pub name: Option<BString>,
16-
/// The email of the author.
17-
pub email: Option<BString>,
18-
}
19-
20-
/// Get the author information from the repository's git configuration.
21-
pub fn get_author_info(repo: &gix::Repository) -> anyhow::Result<AuthorInfo> {
22-
let config = repo.config_snapshot();
23-
let name = config
24-
.string(&gix::config::tree::User::NAME)
25-
.map(|s| s.into_owned());
26-
let email = config
27-
.string(&gix::config::tree::User::EMAIL)
28-
.map(|s| s.into_owned());
29-
Ok(AuthorInfo { name, email })
30-
}
31-
3212
/// What to do with the committer (actor) and the commit time when [creating a new commit](create()).
3313
#[derive(Debug, Copy, Clone)]
3414
pub enum DateMode {

0 commit comments

Comments
 (0)