summary history branches tags files
commit:77060540c7be9b83d047e252d6eeea8ce7d7b93e
author:Trevor Bentley
committer:Trevor Bentley
date:Thu Jan 19 22:51:51 2023 +0100
parents:6bdc73f807eb85051b45ca81be4211adb9b54537
fix parent links when limit_context is specified
diff --git a/src/generate.rs b/src/generate.rs
line changes: +14/-1
index 28c8664..97d4bc1
--- a/src/generate.rs
+++ b/src/generate.rs
@@ -22,7 +22,7 @@
  */
 use crate::{
     error,
-    git::{dir_listing, parse_repo, GitFile, GitRepo, GitsyMetadata},
+    git::{dir_listing, parse_repo, GitFile, GitObject, GitRepo, GitsyMetadata},
     loud, louder, loudest, normal, normal_noln,
     settings::{GitsyCli, GitsyRepoDescriptions, GitsySettings, GitsySettingsRepo},
     template::{
@@ -34,6 +34,7 @@ use chrono::{DateTime, Local};
 use git2::{Error, Repository};
 use rayon::prelude::*;
 use std::cmp;
+use std::collections::BTreeMap;
 use std::fs::File;
 use std::io::Write;
 use std::path::{Path, PathBuf};
@@ -443,14 +444,26 @@ impl GitsyGenerator {
                 .try_for_each(|(idx, page)| {
                     let mut paged_ctx = ctx.clone();
                     let pagination = Pagination::new(idx + 1, page_count, &out_path);
+                    // make sure the 'commits' map contains the same
+                    // commits as the current page.
+                    let commits: BTreeMap<String, GitObject> = page
+                        .iter()
+                        .map(|entry| match parsed_repo.commits.get(&entry.full_hash) {
+                            Some(com) => Some((entry.full_hash.clone(), com.clone())),
+                            _ => None,
+                        })
+                        .map_while(|x| x)
+                        .collect();
                     paged_ctx.insert("page", &pagination.with_relative_paths());
                     paged_ctx.insert("history", &page);
+                    paged_ctx.insert("commits", &commits);
                     let rendered = tera.render(templ_path, &paged_ctx)?;
                     let bytes = self.write_rendered(&pagination.cur_page, &rendered);
                     repo_bytes.fetch_add(bytes, Ordering::SeqCst);
                     atomic_bytes.fetch_add(bytes, Ordering::SeqCst);
                     paged_ctx.remove("page");
                     paged_ctx.remove("history");
+                    paged_ctx.remove("commits");
                     size_check_atomic!(
                         repo_desc,
                         atomic_bytes,

diff --git a/templates/default_dark/branch.html b/templates/default_dark/branch.html
line changes: +1/-1
index 6c6ee14..e949d31
--- a/templates/default_dark/branch.html
+++ b/templates/default_dark/branch.html
@@ -6,7 +6,7 @@
 <div class="branch-page">
   <table class="branch-header">
     <tr class="header"><td class="field">branch:</td><td class="value">{{branch.ref_name}}</td></tr>
-    <tr class="header"><td class="field">commit:</td><td class="value">{% if branch.full_hash in commits -%}<a href="{{repo_url | safe}}/commit/{{branch.full_hash}}.html">{{branch.full_hash}}</a>{% else -%}{{branch.full_hash}}{% endif -%}</td></tr>
+    <tr class="header"><td class="field">commit:</td><td class="value">{% if branch.full_hash in commit_ids -%}<a href="{{repo_url | safe}}/commit/{{branch.full_hash}}.html">{{branch.full_hash}}</a>{% else -%}{{branch.full_hash}}{% endif -%}</td></tr>
     <tr class="header"><td class="field">author:</td><td class="value">{{branch.author.name}} <{{branch.author.email}}></td></tr>
     <tr class="header"><td class="field">committer:</td><td class="value">{{branch.committer.name}} <{{branch.committer.email}}></td></tr>
     <tr class="header"><td class="field">date:</td><td class="value">{{ts_to_git_timestamp(ts=branch.ts_utc, tz=branch.ts_offset)}}</td></tr>

diff --git a/templates/default_dark/commit.html b/templates/default_dark/commit.html
line changes: +1/-1
index 89982ed..44eb4d3
--- a/templates/default_dark/commit.html
+++ b/templates/default_dark/commit.html
@@ -9,7 +9,7 @@
     <tr class="header"><td class="field">author:</td><td class="value">{{commit.author.name}} <{{commit.author.email}}></td></tr>
     <tr class="header"><td class="field">committer:</td><td class="value">{{commit.committer.name}} <{{commit.committer.email}}></td></tr>
     <tr class="header"><td class="field">date:</td><td class="value">{{ts_to_git_timestamp(ts=commit.ts_utc, tz=commit.ts_offset)}}</td></tr>
-    <tr class="header"><td class="field">parents:</td><td class="value">{% for parent in commit.parents -%}{% if loop.index0 > 0 -%}, {%endif-%}{% if parent in commits -%}<a href="{{parent}}.html">{{parent}}</a>{%else-%}{{parent}}{%endif-%}{%-endfor-%}</td></tr>
+    <tr class="header"><td class="field">parents:</td><td class="value">{% for parent in commit.parents -%}{% if loop.index0 > 0 -%}, {%endif-%}{% if parent in commit_ids -%}<a href="{{parent}}.html">{{parent}}</a>{%else-%}{{parent}}{%endif-%}{%-endfor-%}</td></tr>
   </table>
   <div class="commit-message">
     <pre style="margin: 0;">{{commit.message}}</pre>

diff --git a/templates/default_dark/tag.html b/templates/default_dark/tag.html
line changes: +1/-1
index 5178118..b9e1b58
--- a/templates/default_dark/tag.html
+++ b/templates/default_dark/tag.html
@@ -7,7 +7,7 @@
   <table class="tag-header">
     <tr class="header"><td class="field">tag:</td><td class="value">{{tag.ref_name}}</td></tr>
     <tr class="header"><td class="field">hash:</td><td class="value">{{tag.full_hash}}</td></tr>
-    <tr class="header"><td class="field">tagged commit:</td><td class="value">{% if tag.tagged_id -%}{% if tag.tagged_id in commits -%}<a href="{{repo_url | safe}}/commit/{{tag.tagged_id}}.html">{{tag.tagged_id}}</a>{% else -%}{{tag.tagged_id}}{% endif -%}{% endif -%}</td></tr>
+    <tr class="header"><td class="field">tagged commit:</td><td class="value">{% if tag.tagged_id -%}{% if tag.tagged_id in commit_ids -%}<a href="{{repo_url | safe}}/commit/{{tag.tagged_id}}.html">{{tag.tagged_id}}</a>{% else -%}{{tag.tagged_id}}{% endif -%}{% endif -%}</td></tr>
     <tr class="header"><td class="field">author:</td><td class="value">{{tag.author.name}} <{{tag.author.email}}></td></tr>
     <tr class="header"><td class="field">date:</td><td class="value">{{ts_to_git_timestamp(ts=tag.ts_utc, tz=tag.ts_offset)}}</td></tr>
   </table>

diff --git a/templates/default_light/branch.html b/templates/default_light/branch.html
line changes: +1/-1
index 6c6ee14..e949d31
--- a/templates/default_light/branch.html
+++ b/templates/default_light/branch.html
@@ -6,7 +6,7 @@
 <div class="branch-page">
   <table class="branch-header">
     <tr class="header"><td class="field">branch:</td><td class="value">{{branch.ref_name}}</td></tr>
-    <tr class="header"><td class="field">commit:</td><td class="value">{% if branch.full_hash in commits -%}<a href="{{repo_url | safe}}/commit/{{branch.full_hash}}.html">{{branch.full_hash}}</a>{% else -%}{{branch.full_hash}}{% endif -%}</td></tr>
+    <tr class="header"><td class="field">commit:</td><td class="value">{% if branch.full_hash in commit_ids -%}<a href="{{repo_url | safe}}/commit/{{branch.full_hash}}.html">{{branch.full_hash}}</a>{% else -%}{{branch.full_hash}}{% endif -%}</td></tr>
     <tr class="header"><td class="field">author:</td><td class="value">{{branch.author.name}} <{{branch.author.email}}></td></tr>
     <tr class="header"><td class="field">committer:</td><td class="value">{{branch.committer.name}} <{{branch.committer.email}}></td></tr>
     <tr class="header"><td class="field">date:</td><td class="value">{{ts_to_git_timestamp(ts=branch.ts_utc, tz=branch.ts_offset)}}</td></tr>

diff --git a/templates/default_light/commit.html b/templates/default_light/commit.html
line changes: +1/-1
index 89982ed..44eb4d3
--- a/templates/default_light/commit.html
+++ b/templates/default_light/commit.html
@@ -9,7 +9,7 @@
     <tr class="header"><td class="field">author:</td><td class="value">{{commit.author.name}} <{{commit.author.email}}></td></tr>
     <tr class="header"><td class="field">committer:</td><td class="value">{{commit.committer.name}} <{{commit.committer.email}}></td></tr>
     <tr class="header"><td class="field">date:</td><td class="value">{{ts_to_git_timestamp(ts=commit.ts_utc, tz=commit.ts_offset)}}</td></tr>
-    <tr class="header"><td class="field">parents:</td><td class="value">{% for parent in commit.parents -%}{% if loop.index0 > 0 -%}, {%endif-%}{% if parent in commits -%}<a href="{{parent}}.html">{{parent}}</a>{%else-%}{{parent}}{%endif-%}{%-endfor-%}</td></tr>
+    <tr class="header"><td class="field">parents:</td><td class="value">{% for parent in commit.parents -%}{% if loop.index0 > 0 -%}, {%endif-%}{% if parent in commit_ids -%}<a href="{{parent}}.html">{{parent}}</a>{%else-%}{{parent}}{%endif-%}{%-endfor-%}</td></tr>
   </table>
   <div class="commit-message">
     <pre style="margin: 0;">{{commit.message}}</pre>

diff --git a/templates/default_light/tag.html b/templates/default_light/tag.html
line changes: +1/-1
index 5178118..b9e1b58
--- a/templates/default_light/tag.html
+++ b/templates/default_light/tag.html
@@ -7,7 +7,7 @@
   <table class="tag-header">
     <tr class="header"><td class="field">tag:</td><td class="value">{{tag.ref_name}}</td></tr>
     <tr class="header"><td class="field">hash:</td><td class="value">{{tag.full_hash}}</td></tr>
-    <tr class="header"><td class="field">tagged commit:</td><td class="value">{% if tag.tagged_id -%}{% if tag.tagged_id in commits -%}<a href="{{repo_url | safe}}/commit/{{tag.tagged_id}}.html">{{tag.tagged_id}}</a>{% else -%}{{tag.tagged_id}}{% endif -%}{% endif -%}</td></tr>
+    <tr class="header"><td class="field">tagged commit:</td><td class="value">{% if tag.tagged_id -%}{% if tag.tagged_id in commit_ids -%}<a href="{{repo_url | safe}}/commit/{{tag.tagged_id}}.html">{{tag.tagged_id}}</a>{% else -%}{{tag.tagged_id}}{% endif -%}{% endif -%}</td></tr>
     <tr class="header"><td class="field">author:</td><td class="value">{{tag.author.name}} <{{tag.author.email}}></td></tr>
     <tr class="header"><td class="field">date:</td><td class="value">{{ts_to_git_timestamp(ts=tag.ts_utc, tz=tag.ts_offset)}}</td></tr>
   </table>