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
|
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <bio.h>
#include "dat.h"
#include "fns.h"
Revinfo*
loadrevinfo(Revlog *changelog, int rev)
{
int c, fd;
char *line;
Revinfo *ri;
vlong off;
Biobuf *buf;
if((fd = revlogopentemp(changelog, rev)) < 0)
return nil;
off = fmetaheader(fd);
seek(fd, off, 0);
ri = malloc(sizeof(*ri));
memset(ri, 0, sizeof(*ri));
ri->logoff = off;
memmove(ri->chash, changelog->map[rev].hash, HASHSZ);
buf = Bfdopen(fd, OREAD);
line = Brdstr(buf, '\n', 1);
if(line == nil)
goto Error;
hex2hash(line, ri->mhash);
free(line);
line = Brdstr(buf, '\n', 1);
if(line == nil)
goto Error;
ri->who = line;
line = Brdstr(buf, '\n', 1);
if(line == nil)
goto Error;
ri->when = strtol(line, nil, 10);
free(line);
ri->logoff = Boffset(buf);
for(;;){
if((c = Bgetc(buf)) < 0)
goto Error;
if(c == '\n')
break;
do {
if((c = Bgetc(buf)) < 0)
goto Error;
} while(c != '\n');
}
ri->loglen = Boffset(buf) - ri->logoff - 1;
line = Brdstr(buf, '\0', 1);
if(line == nil)
goto Error;
ri->why = line;
Bterm(buf);
close(fd);
return ri;
Error:
Bterm(buf);
close(fd);
free(ri->who);
free(ri->why);
free(ri);
return nil;
}
|