-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshow-diff.b
79 lines (62 loc) · 1.49 KB
/
show-diff.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
implement Showdiff;
include "show-diff.m";
include "draw.m";
include "sys.m";
sys: Sys;
include "tables.m";
tables: Tables;
Strhash: import tables;
include "bufio.m";
bufio: Bufio;
Iobuf: import bufio;
include "utils.m";
utils: Utils;
include "gitindex.m";
gitindex: Gitindex;
Index, Entry: import gitindex;
include "sh.m";
index: ref Index;
stderr: ref Sys->FD;
REPOPATH: string;
diff: Command;
init(args: list of string)
{
sys = load Sys Sys->PATH;
gitindex = load Gitindex Gitindex->PATH;
utils = load Utils Utils->PATH;
tables = load Tables Tables->PATH;
REPOPATH = hd args;
utils->init(REPOPATH);
index = Index.new(REPOPATH);
index.readindex(utils->INDEXPATH);
stderr = sys->fildes(2);
showdiffs();
}
showdiffs()
{
for(l := index.entries.all(); l != nil; l = tl l){
if(filechanged(hd l))
showdiff(hd l);
else
sys->print("File %s wasn't changed\n", (hd l).name);
}
}
filechanged(entry: ref Entry): int
{
sys->print("name is: %s\n", entry.name);
(ret, dirstat) := sys->stat(REPOPATH + entry.name);
if(ret == -1){
sys->fprint(stderr, "File stat failed: %r\n");
return 0;
}
return (!utils->equalqids(entry.qid, dirstat.qid) ||
entry.dtype != dirstat.dtype ||
entry.dev != dirstat.dev ||
entry.mtime != dirstat.mtime);
}
showdiff(entry: ref Entry)
{
#loads acme-sac diff
diff = load Command "/dis/git/acdiff.dis";
diff->init(nil, list of {"diff", "-u",utils->extractfile(utils->sha2string(entry.sha1)), REPOPATH + entry.name});
}