-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlog.b
88 lines (66 loc) · 1.56 KB
/
log.b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
implement Log;
include "sys.m";
sys: Sys;
include "draw.m";
include "tables.m";
Strhash: import Tables;
include "bufio.m";
bufio: Bufio;
Iobuf: import bufio;
include "utils.m";
utils: Utils;
exists, chomp, readsha1file: import utils;
include "string.m";
stringmodule: String;
splitr: import stringmodule;
include "log.m";
stderr: ref Sys->FD;
msgchan: chan of array of byte;
REPOPATH: string;
init(ch: chan of array of byte, args: list of string)
{
sys = load Sys Sys->PATH;
stringmodule = load String String->PATH;
utils = load Utils Utils->PATH;
REPOPATH = hd args;
utils->init(REPOPATH);
bufio = load Bufio Bufio->PATH;
msgchan = ch;
showlog(tl args);
}
showlog(commits: list of string)
{
if(commits == nil){
msgchan <-= nil;
return;
}
sha1 := hd commits;
commits = tl commits;
(filetype, filesize, buf) := readsha1file(sha1);
if(filetype != "commit")
return showlog(commits);
msgchan <-= sys->aprint("Commit: %s\n", sha1);
ibuf := bufio->aopen(buf);
#reading tree and throwing it away(maybe it can be used in the future).
ibuf.gets('\n');
while((s := ibuf.gets('\n')) != nil){
(t, parentsha1) := splitr(s, " ");
if(t != "parent ")
break;
parentsha1 = chomp(parentsha1);
commits = parentsha1 :: commits;
}
author := chomp(s);
committer := ibuf.gets('\n');
ibuf.gets('\n');
comments := ibuf.gets('\0');
msgchan <-= sys->aprint("%s\n", author);
msgchan <-= sys->aprint("%s\n", committer);
msgchan <-= sys->aprint("%s\n", comments);
showlog(commits);
}
usage()
{
sys->fprint(stderr, "log <commit-sha1>\n");
return;
}