MCPcopy Index your code
hub / github.com/antonmedv/gitmal / generateCommitPage

Function generateCommitPage

commit.go:108–259  ·  view source on GitHub ↗
(commit git.Commit, params Params)

Source from the content-addressed store, hash-verified

106}
107
108func generateCommitPage(commit git.Commit, params Params) error {
109 diff, err := git.CommitDiff(commit.Hash, params.RepoDir)
110 if err != nil {
111 return err
112 }
113
114 files, _, err := gitdiff.Parse(strings.NewReader(diff))
115 if err != nil {
116 return err
117 }
118
119 style := styles.Get(params.Style)
120 if style == nil {
121 return fmt.Errorf("unknown style: %s", params.Style)
122 }
123
124 formatter := html.New(
125 html.WithClasses(true),
126 html.WithCSSComments(false),
127 html.WithCustomCSS(map[chroma.TokenType]string{
128 chroma.GenericInserted: "display: block;",
129 chroma.GenericDeleted: "display: block;",
130 }),
131 )
132
133 var cssBuf bytes.Buffer
134 if err := formatter.WriteCSS(&cssBuf, style); err != nil {
135 return err
136 }
137
138 lexer := lexers.Get("diff")
139 if lexer == nil {
140 return fmt.Errorf("failed to get lexer for diff")
141 }
142
143 outPath := filepath.Join(params.OutputDir, "commit", commit.Hash+".html")
144
145 f, err := os.Create(outPath)
146 if err != nil {
147 return err
148 }
149 rootHref := filepath.ToSlash("../")
150
151 fileTree := buildFileTree(files)
152
153 // Create a stable order for files that matches the file tree traversal
154 // so that the per-file views appear in the same order as the sidebar tree.
155 fileOrder := make(map[string]int)
156 {
157 // Preorder traversal (dirs first, then files), respecting sortNode ordering
158 var idx int
159 var walk func(nodes []*templates.FileTree)
160 walk = func(nodes []*templates.FileTree) {
161 for _, n := range nodes {
162 if n.IsDir {
163 // Children are already sorted by sortNode
164 walk(n.Children)
165 continue

Callers 1

generateCommitsFunction · 0.85

Calls 10

CommitDiffFunction · 0.92
ParseFunction · 0.92
buildFileTreeFunction · 0.85
ErrorfMethod · 0.80
NewMethod · 0.80
WriteStringMethod · 0.80
IsEmptyMethod · 0.80
DirNameMethod · 0.80
StringMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected