Skip to content

Commit 491ac93

Browse files
authored
Merge pull request #2399 from Urgau/gh-range-diff-new-header
Improve our range-diff header with colors and better description
2 parents 6020747 + fdac82a commit 491ac93

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

src/gh_range_diff.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,8 @@ fn process_old_new(
209209
// Create the HTML buffer with a very rough approximation for the capacity
210210
let mut html: String = String::with_capacity(800 + old.files.len() * 100);
211211

212-
let a_oldbase = a_github_commit(owner, repo, oldbase);
213-
let a_oldhead = a_github_commit(owner, repo, oldhead);
214-
let a_newbase = a_github_commit(owner, repo, newbase);
215-
let a_newhead = a_github_commit(owner, repo, newhead);
212+
let a_compare_before = a_github_compare("compare-before", owner, repo, oldbase, oldhead);
213+
let a_compare_after = a_github_compare("compare-after", owner, repo, newbase, newhead);
216214

217215
// Write HTML header, style, ...
218216
writeln!(
@@ -236,10 +234,16 @@ fn process_old_new(
236234
overflow-wrap: break-word;
237235
white-space: normal;
238236
}}
239-
.commit {{
237+
.compare {{
240238
text-decoration: none;
241239
color: unset;
242240
}}
241+
.compare-before {{
242+
color: rgb(255, 93, 93);
243+
}}
244+
.compare-after {{
245+
color: rgb(55, 227, 55);
246+
}}
243247
.diff-content {{
244248
overflow-x: auto;
245249
}}
@@ -297,6 +301,12 @@ fn process_old_new(
297301
a {{
298302
color: #41a6ff;
299303
}}
304+
.compare-before {{
305+
color: rgb(255, 93, 93);
306+
}}
307+
.compare-after {{
308+
color: rgb(88, 177, 88);
309+
}}
300310
.filename-block {{
301311
background-color: #5f8fe5;
302312
}}
@@ -340,8 +350,8 @@ fn process_old_new(
340350
</style>
341351
</head>
342352
<body>
343-
<h3>range-diff of {a_oldbase}..{a_oldhead} {a_newbase}..{a_newhead} in {owner}/{repo}</h3>
344-
<span>Legend: {REMOVED_BLOCK_SIGN}&nbsp;before | {ADDED_BLOCK_SIGN}&nbsp;after</span>
353+
<h3>range-diff of {a_compare_before} {a_compare_after} in {owner}/{repo}</h3>
354+
<span>Legend: {REMOVED_BLOCK_SIGN}&nbsp;Removed from previous diff | {ADDED_BLOCK_SIGN}&nbsp;Added in new diff</span>
345355
<div class="spacer"></div>
346356
"#
347357
)?;
@@ -766,10 +776,11 @@ fn contains_diff_marker(input: &InternedInput<&str>, mut hunk: Hunk) -> bool {
766776
|| hunk.after.any(|i| contains_diff_marker(i, &input.after))
767777
}
768778

769-
// function to create a <a> to a GitHub commit
770-
fn a_github_commit(owner: &str, repo: &str, ref_: &str) -> String {
779+
// Function to create an <a> link to a GitHub compare
780+
fn a_github_compare(class: &str, owner: &str, repo: &str, base: &str, head: &str) -> String {
771781
format!(
772-
r#"<a href="https://github.com/{owner}/{repo}/commit/{ref_}" class="commit">{}</a>"#,
773-
&ref_[..=6]
782+
r#"<a href="https://github.com/{owner}/{repo}/compare/{base}..{head}" class="compare {class}">{base_6}..{head_6}</a>"#,
783+
base_6 = &base[..base.len().min(7)],
784+
head_6 = &head[..head.len().min(7)]
774785
)
775786
}

0 commit comments

Comments
 (0)