Index

joshstock.in / a80dd0a

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
6605 Jan 2020 15:317d8bf7dAdd missing variable to throw-catch blockJosh Stockin111N

Blob @ joshstock.in / gitpager / gitcontrol.js

application/javascript2044 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 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 log $BRANCH --pretty=format:'%aI ## %H ## %an ## %ae ## %s ## %b' -n 1 --";
17function get_commit(repository, branch="HEAD", body=true) {
18 call = get_commit_command.replace("$REPOSITORY", repository).replace("$BRANCH", branch);
19 let properties;
20 try {
21 properties = exec(call).split(" ## ");
22 } catch (e) {
23 return null;
24 }
25 commit = {};
26 commit.number = count_commits(repository, properties[1]);
27 commit.date = properties[0];
28 commit.hash = properties[1];
29 commit.author = properties[2];
30 commit.author_email = properties[3];
31 commit.subject = properties[4];
32 if (body) commit.body = properties[5].trim();
33 return commit;
34}
35
36const list_commits_command = `git --git-dir $REPOSITORY log $BRANCH --pretty=format:'%aI ## %H ## %an ## %ae ## %s' -n ${skip_count} --skip=$SKIP --`;
37function list_commits(repository, branch="HEAD", skip=0) {
38 call = list_commits_command.replace("$REPOSITORY", repository).replace("$BRANCH", branch).replace("$SKIP", skip*skip_count);
39 output = exec(call);
40 if (output == '') return null;
41 lines = output.split("\n");
42 commits = [];
43 for (let i = 0; i < lines.length; i++) {
44 properties = lines[i].split(" ## ");
45 commit = {};
46 commit.number = count_commits(repository, properties[1]);
47 commit.date = properties[0];
48 commit.hash = properties[1];
49 commit.author = properties[2];
50 commit.author_email = properties[3];
51 commit.subject = properties[4];
52 commits.push(commit);
53 }
54 return commits;
55}
56
57module.exports = {
58 count_commits: count_commits
59 ,get_commit: get_commit
60 ,list_commits: list_commits
61}
62