My pretty neat website
git clone git://soophie.de/soso
blob: f37fe7ce24134e3d55bf7673a9a106c2d6292e2b (3062 bytes)[raw]
1
% #include "src/duc_macro.h" %2
% #include "src/module/git_repo.h" %3
% #include "src/module/git_repo_commit.h" %4
% #include <math.h> %6
% DUC_TEMPLDEF(7
duc_git_repo_commit,8
git_repo_t *repo;9
git_repo_commit_t *commit;10
char *parent_commit_oid;11
char *diff;12
) %14
<div class="commit--meta">15
<h3 class="commit--summary">% STRING(ctx->commit->summary) %</h3>16
% if (ctx->commit->body) { %17
<pre class="commit--body">% STRING(ctx->commit->body) %</pre>18
% } %19
<hr/>20
<span class="commit--info">commit: <a href="/git/% STRING(ctx->repo->meta.name) %/commit?oid=% STRING(ctx->commit->oid) %">% STRING(ctx->commit->oid) %</a></span><br/>21
% if (ctx->parent_commit_oid) { %22
<span class="commit--info">parent: <a href="/git/% STRING(ctx->repo->meta.name) %/commit?oid=% STRING(ctx->parent_commit_oid) %">% STRING(ctx->parent_commit_oid) %</a></span><br/>23
% } %24
<span class="commit--info">author: % STRING(ctx->commit->author_name) % <<a href="mailto:% STRING(ctx->commit->author_email) %">% STRING(ctx->commit->author_email) %</a>></span><br/>25
<span class="commit--info">time: % FORMAT_TIME(&ctx->commit->time, "%%Y-%%m-%%d %%H:%%M") %</span></br>26
</div>27
<div class="commit--diff">28
% if (ctx->diff) { %29
<pre class="diff--meta">%31
size_t len = strlen(ctx->diff);32
size_t i = 0;33
size_t ln = 0;34
size_t sol = 0;35
while (i < len) {36
char c = ctx->diff[i];37
if (c == '\n') {38
ln++;39
}40
i++;41
}42
size_t pad = floor(log10(ln + 1)) + 1;43
i = 0;44
ln = 0;45
sol = 0;46
size_t df = 0;47
bool is_meta = false;48
while (i < len) {49
char c = ctx->diff[i];50
if (c == '\n') {51
size_t ln_len = i - sol;52
char line[ln_len + 1];53
memcpy(line, ctx->diff + sol, ln_len);54
line[ln_len] = '\0';55
sol = i + 1;56
bool is_diff = strncmp(line, "diff --git", 10) == 0;57
bool is_hunk = strncmp(line, "@@ ", 3) == 0;58
if (is_diff) {59
is_meta = true;60
}61
if (is_diff && ln != 0) {62
df++;63
%</pre>%64
%<pre class="diff--meta">%65
}66
if (is_hunk && is_meta) {67
is_meta = false;68
ln = 0;69
%</pre>%70
%<pre class="diff--code">%71
}72
if (is_meta) {73
%<p>%STRING(line)%</p>%74
}75
else {76
%<p id="% NUMBER(df) %-% NUMBER(ln + 1) %" class="% if (is_hunk) { %is-hunk% } % % if (strncmp(line, "+", 1) == 0 && strncmp(line, "+++", 3) != 0) { %is-add% } % % if (strncmp(line, "-", 1) == 0 && strncmp(line, "---", 3) != 0) { %is-rem% } %"><span class="ln"><a href="#% NUMBER(df) %-% NUMBER(ln + 1) %">% PRINTF("%%*ld", pad, ln + 1) %</a></span><span class="line"><code>% STRING(line) %</code></span></p>%77
}78
ln++;79
}80
i++;81
}82
%</pre>83
% } %84
</div>86
% DUC_ENDTEMPL %