Index

joshstock.in / 3696e54

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
6004 Jan 2020 23:413696e54Update gitpager siteJosh Stockin1550N

Blob @ joshstock.in / gitpager / gitcontrol.js

application/javascript1966 bytesdownload raw
1const path = require("path");
2const child_process = require("child_process");
3
4function exec(commandstring) {
5 return child_process.execSync(commandstring).toString();
6}
7
8const skip_count = 20;
9
10const count_commits_command = "git --git-dir $REPOSITORY/.git rev-list --count $BRANCH";
11function count_commits(repository, branch="HEAD") {
12 call = count_commits_command.replace("$REPOSITORY", repository).replace("$BRANCH", branch);
13 return exec(call).trim();
14}
15
16const get_commit_command = "git --git-dir $REPOSITORY/.git log $BRANCH --pretty=format:'%aI ## %H ## %an ## %ae ## %s ## %b' -n 1 --";
17function get_commit(repository, branch="HEAD") {
18 call = get_commit_command.replace("$REPOSITORY", repository).replace("$BRANCH", branch);
19 properties = exec(call).split(" ## ");
20 commit = {};
21 commit.number = count_commits(repository, properties[1]);
22 commit.date = properties[0];
23 commit.hash = properties[1];
24 commit.author = properties[2];
25 commit.author_email = properties[3];
26 commit.subject = properties[4];
27 commit.body = properties[5].trim();
28 return commit;
29}
30
31const list_commits_command = `git --git-dir $REPOSITORY/.git log $BRANCH --pretty=format:'%aI ## %H ## %an ## %ae ## %s' -n ${skip_count} --skip=$SKIP --`;
32function list_commits(repository, branch="HEAD", skip=0) {
33 call = list_commits_command.replace("$REPOSITORY", repository).replace("$BRANCH", branch).replace("$SKIP", skip*skip_count);
34 commits = [];
35 lines = exec(call).split("\n");
36 if (lines == ['']) return commits;
37 for (let i = 0; i < lines.length; i++) {
38 properties = lines[i].split(" ## ");
39 commit = {};
40 commit.number = count_commits(repository, properties[1]);
41 commit.date = properties[0];
42 commit.hash = properties[1];
43 commit.author = properties[2];
44 commit.author_email = properties[3];
45 commit.subject = properties[4];
46 commits.push(commit);
47 }
48 return commits;
49}
50
51module.exports = {
52 count_commits: count_commits
53 ,get_commit: get_commit
54 ,list_commits: list_commits
55}
56