Skip to content

Commit b3d8642

Browse files
committed
feat(git2-ox): Add getters for diff stats
1 parent c60f246 commit b3d8642

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

backend/git2-ox/src/commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'repo> Commit {
108108
#[derive(Clone, Debug)]
109109
#[allow(dead_code)]
110110
pub struct CommitWithReferences {
111-
#[serde(flatten)]
111+
#[cfg_attr(feature = "serde", serde(flatten))]
112112
commit: Commit,
113113
/// References pointing to the commit
114114
references: Vec<ReferenceMetadata>,

backend/git2-ox/src/diff.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{Result, error};
88
derive(serde::Serialize),
99
serde(rename_all = "camelCase")
1010
)]
11-
pub(crate) struct DiffStats {
11+
pub struct DiffStats {
1212
/// Number of files changed
1313
files_changed: usize,
1414
/// Number of insertions
@@ -20,6 +20,22 @@ pub(crate) struct DiffStats {
2020
}
2121

2222
impl DiffStats {
23+
pub fn files_changed(&self) -> usize {
24+
self.files_changed
25+
}
26+
27+
pub fn insertions(&self) -> usize {
28+
self.insertions
29+
}
30+
31+
pub fn deletions(&self) -> usize {
32+
self.deletions
33+
}
34+
35+
pub fn total_old_num_lines(&self) -> usize {
36+
self.total_old_num_lines
37+
}
38+
2339
fn from_stats_and_total_old_num_lines(
2440
stats: &git2::DiffStats,
2541
total_old_num_lines: usize,
@@ -36,6 +52,8 @@ impl DiffStats {
3652
type Path = String;
3753
type FileContent = String;
3854

55+
type FilesContent = hash_map::HashMap<Path, FileContent>;
56+
3957
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
4058
#[cfg_attr(
4159
feature = "serde",
@@ -48,10 +66,22 @@ pub struct Diff {
4866
/// Stats of the diff
4967
stats: DiffStats,
5068
/// Map of old source paths to the old content
51-
old_sources: hash_map::HashMap<Path, FileContent>,
69+
old_sources: FilesContent,
5270
}
5371

5472
impl Diff {
73+
pub fn patch(&self) -> &str {
74+
&self.patch
75+
}
76+
77+
pub fn stats(&self) -> &DiffStats {
78+
&self.stats
79+
}
80+
81+
pub fn old_sources(&self) -> &FilesContent {
82+
&self.old_sources
83+
}
84+
5585
pub fn try_from_repo_and_diff(repo: &git2::Repository, diff: &git2::Diff) -> Result<Self> {
5686
let mut patch_output = String::new();
5787
let mut total_num_lines: usize = 0;

backend/git2-ox/src/reference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'repo> TryFrom<&git2::Reference<'repo>> for ReferenceMetadata {
8787
#[derive(Clone, Debug)]
8888
#[allow(dead_code)]
8989
pub struct ResolvedReference {
90-
#[serde(flatten)]
90+
#[cfg_attr(feature = "serde", serde(flatten))]
9191
reference: ReferenceMetadata,
9292
target: Commit,
9393
}

frontend/src/types/api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ export interface components {
264264
};
265265
Diff: {
266266
/** @description Map of old source paths to the old content */
267-
oldSources: {
268-
[key: string]: components["schemas"]["String"];
269-
};
267+
oldSources: components["schemas"]["HashMap"];
270268
/** @description Patch between old and new */
271269
patch: string;
272270
/** @description Stats of the diff */
@@ -306,6 +304,9 @@ export interface components {
306304
FullFlowRequestResponse: {
307305
flow: components["schemas"]["FlowData"];
308306
};
307+
HashMap: {
308+
[key: string]: string;
309+
};
309310
ListBranchesResponse: {
310311
/** @description Found branches */
311312
branches: components["schemas"]["Branch"][];
@@ -354,7 +355,6 @@ export interface components {
354355
email: string;
355356
name: string;
356357
};
357-
String: string;
358358
TaggedCommit: {
359359
/** @description Commit the tag is on */
360360
commit: components["schemas"]["Commit"];

0 commit comments

Comments
 (0)