Skip to content

Commit 419e07f

Browse files
committed
rustfmt
1 parent c346bb4 commit 419e07f

File tree

2 files changed

+1439
-881
lines changed

2 files changed

+1439
-881
lines changed

src/main.rs

Lines changed: 77 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,62 +1720,69 @@ impl GitChain {
17201720
}
17211721

17221722
// Helper function to get merge commit information for detailed reporting
1723-
fn get_merge_commit_info(&self, parent_branch: &str, branch_name: &str) -> Result<Vec<MergeCommitInfo>, Error> {
1724-
1723+
fn get_merge_commit_info(
1724+
&self,
1725+
parent_branch: &str,
1726+
branch_name: &str,
1727+
) -> Result<Vec<MergeCommitInfo>, Error> {
17251728
// Get the latest commit on the branch
17261729
let mut command = Command::new("git");
17271730
command.args(["log", "--oneline", "-1", branch_name]);
17281731
let output = match command.output() {
17291732
Ok(output) => output,
17301733
Err(_) => return Ok(vec![]), // Return empty vec on error
17311734
};
1732-
1735+
17331736
if !output.status.success() {
17341737
return Ok(vec![]);
17351738
}
1736-
1739+
17371740
let latest_commit = String::from_utf8_lossy(&output.stdout).trim().to_string();
17381741
if latest_commit.is_empty() {
17391742
return Ok(vec![]);
17401743
}
1741-
1744+
17421745
// Check if it's a merge commit by looking for parent commits
17431746
let commit_hash = latest_commit.split_whitespace().next().unwrap_or("");
17441747
if commit_hash.is_empty() {
17451748
return Ok(vec![]);
17461749
}
1747-
1750+
17481751
// Get commit information
17491752
let mut command = Command::new("git");
17501753
command.args(["show", "--stat", commit_hash]);
17511754
let output = match command.output() {
17521755
Ok(output) => output,
1753-
Err(_) => return Ok(vec![]),
1756+
Err(_) => return Ok(vec![]),
17541757
};
1755-
1758+
17561759
if !output.status.success() {
17571760
return Ok(vec![]);
17581761
}
1759-
1762+
17601763
let commit_info = String::from_utf8_lossy(&output.stdout).to_string();
1761-
1764+
17621765
// Check if it's a merge commit, which typically contains "Merge" in the commit message
1763-
if commit_info.contains(&format!("Merge branch '{}'", parent_branch)) || commit_info.contains("Merge branch") {
1766+
if commit_info.contains(&format!("Merge branch '{}'", parent_branch))
1767+
|| commit_info.contains("Merge branch")
1768+
{
17641769
// Extract commit message (first line after commit hash)
17651770
let commit_lines: Vec<&str> = commit_info.lines().collect();
1766-
let message = commit_lines.iter()
1771+
let message = commit_lines
1772+
.iter()
17671773
.position(|line| line.trim().starts_with("Merge branch"))
17681774
.map(|idx| commit_lines[idx].trim().to_string());
1769-
1775+
17701776
// Extract stats
1771-
let stats_line = commit_lines.iter()
1777+
let stats_line = commit_lines
1778+
.iter()
17721779
.find(|line| line.contains("files changed") || line.contains("file changed"));
1773-
1780+
17741781
let stats = stats_line.map(|line| {
17751782
let mut files_changed = 0;
17761783
let mut insertions = 0;
17771784
let mut deletions = 0;
1778-
1785+
17791786
if let Some(files_idx) = line.find("file changed") {
17801787
if let Some(files_num) = line[..files_idx].split_whitespace().last() {
17811788
files_changed = files_num.parse().unwrap_or(0);
@@ -1785,7 +1792,7 @@ impl GitChain {
17851792
files_changed = files_num.parse().unwrap_or(0);
17861793
}
17871794
}
1788-
1795+
17891796
if let Some(ins_idx) = line.find("insertion") {
17901797
if let Some(ins_end) = line[..ins_idx].rfind(' ') {
17911798
if let Some(ins_start) = line[..ins_end].rfind(' ') {
@@ -1794,7 +1801,7 @@ impl GitChain {
17941801
}
17951802
}
17961803
}
1797-
1804+
17981805
if let Some(del_idx) = line.find("deletion") {
17991806
if let Some(del_end) = line[..del_idx].rfind(' ') {
18001807
if let Some(del_start) = line[..del_end].rfind(' ') {
@@ -1803,17 +1810,17 @@ impl GitChain {
18031810
}
18041811
}
18051812
}
1806-
1813+
18071814
MergeStats {
18081815
files_changed,
18091816
insertions,
18101817
deletions,
18111818
}
18121819
});
1813-
1820+
18141821
return Ok(vec![MergeCommitInfo { message, stats }]);
18151822
}
1816-
1823+
18171824
// It's not a merge commit
18181825
Ok(vec![])
18191826
}
@@ -1854,72 +1861,90 @@ impl GitChain {
18541861
// For detailed reporting, show information about each branch merge
18551862
if matches!(options.report_level, ReportLevel::Detailed) && merge_operations > 0 {
18561863
println!("\n📝 Detailed Merge Information:");
1857-
1864+
18581865
// Get the chain's branches
18591866
if let Ok(chain) = Chain::get_chain(self, chain_name) {
18601867
for (index, branch) in chain.branches.iter().enumerate() {
18611868
if index == 0 && options.ignore_root {
18621869
continue; // Skip first branch if ignore_root is true
18631870
}
1864-
1871+
18651872
let prev_branch = if index == 0 {
18661873
chain.root_branch.clone()
18671874
} else {
18681875
chain.branches[index - 1].branch_name.clone()
18691876
};
1870-
1877+
18711878
// Skip printing detailed info for skipped branches and squashed merges
1872-
let is_skipped = skipped_branches.iter()
1879+
let is_skipped = skipped_branches
1880+
.iter()
18731881
.any(|(up, br)| *up == prev_branch && *br == branch.branch_name);
1874-
let is_squashed = squashed_merges.iter()
1882+
let is_squashed = squashed_merges
1883+
.iter()
18751884
.any(|(up, br)| *up == prev_branch && *br == branch.branch_name);
1876-
let is_conflict = merge_conflicts.iter()
1885+
let is_conflict = merge_conflicts
1886+
.iter()
18771887
.any(|(up, br)| *up == prev_branch && *br == branch.branch_name);
1878-
1888+
18791889
if is_skipped {
1880-
println!(" {} ➔ {}: {}",
1881-
prev_branch.bold(),
1890+
println!(
1891+
" {} ➔ {}: {}",
1892+
prev_branch.bold(),
18821893
branch.branch_name.bold(),
1883-
"Skipped".dimmed());
1894+
"Skipped".dimmed()
1895+
);
18841896
continue;
18851897
}
1886-
1898+
18871899
if is_squashed {
1888-
println!(" {} ➔ {}: {}",
1889-
prev_branch.bold(),
1900+
println!(
1901+
" {} ➔ {}: {}",
1902+
prev_branch.bold(),
18901903
branch.branch_name.bold(),
1891-
"Squashed and reset".dimmed());
1904+
"Squashed and reset".dimmed()
1905+
);
18921906
continue;
18931907
}
1894-
1908+
18951909
if is_conflict {
1896-
println!(" {} ➔ {}: {}",
1897-
prev_branch.bold(),
1910+
println!(
1911+
" {} ➔ {}: {}",
1912+
prev_branch.bold(),
18981913
branch.branch_name.bold(),
1899-
"Merge conflict".red());
1914+
"Merge conflict".red()
1915+
);
19001916
continue;
19011917
}
1902-
1918+
19031919
// Try to get commit information for successful merges
1904-
if let Ok(commits) = self.get_merge_commit_info(&prev_branch, &branch.branch_name) {
1920+
if let Ok(commits) =
1921+
self.get_merge_commit_info(&prev_branch, &branch.branch_name)
1922+
{
19051923
if commits.is_empty() {
19061924
// Branch was already up to date
1907-
println!(" {} ➔ {}: {}",
1908-
prev_branch.bold(),
1925+
println!(
1926+
" {} ➔ {}: {}",
1927+
prev_branch.bold(),
19091928
branch.branch_name.bold(),
1910-
"Already up to date".dimmed());
1929+
"Already up to date".dimmed()
1930+
);
19111931
} else {
19121932
for commit in commits {
1913-
println!(" {} ➔ {}: {}",
1914-
prev_branch.bold(),
1933+
println!(
1934+
" {} ➔ {}: {}",
1935+
prev_branch.bold(),
19151936
branch.branch_name.bold(),
1916-
commit.message.unwrap_or_else(|| "No commit message".to_string()).green());
1917-
1937+
commit
1938+
.message
1939+
.unwrap_or_else(|| "No commit message".to_string())
1940+
.green()
1941+
);
1942+
19181943
if let Some(stat) = commit.stats {
1919-
println!(" {} insertions(+), {} deletions(-) across {} files",
1920-
stat.insertions,
1921-
stat.deletions,
1922-
stat.files_changed);
1944+
println!(
1945+
" {} insertions(+), {} deletions(-) across {} files",
1946+
stat.insertions, stat.deletions, stat.files_changed
1947+
);
19231948
}
19241949
}
19251950
}

0 commit comments

Comments
 (0)