-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitlogclasses.pas
More file actions
111 lines (97 loc) · 2.3 KB
/
gitlogclasses.pas
File metadata and controls
111 lines (97 loc) · 2.3 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
unit gitlogclasses;
interface
uses
SysUtils, Classes, gitlogparser;
type
TLogFile = class(TObject)
public
fileName : string;
action : string;
end;
{ TLogEntry }
TLogEntry = class(TObject)
Hash : string;
Author : string;
AuthorDate : TDatetime;
Commit : string;
CommitDate : TDateTime;
Message : string;
files : TList;
constructor Create;
destructor Destroy; override;
function AddFile: TLogFile;
end;
procedure ReadEntries(dst: TList; const srcFile: string);
procedure ClearList(dst: TList);
implementation
{ TLogEntry }
constructor TLogEntry.Create;
begin
inherited Create;
files := TList.Create;
end;
destructor TLogEntry.Destroy;
var
i : integer;
begin
for i:=0 to files.Count-1 do TObject(files[i]).Free;
files.Free;
inherited Destroy;
end;
function TLogEntry.AddFile: TLogFile;
begin
Result := TLogFile.Create;
files.Add(Result);
end;
procedure ReadEntries(dst: TList; const srcFile: string);
var
fs : TFileStream;
st : TStringList;
scan : TGitLogScanner;
en : TLogEntry;
i : integer;
fn : TLogFile;
begin
fs:=TFileStream.Create(srcFile, fmOpenRead or fmshareDenyNone);
st := TStringList.Create;
scan := TGitLogScanner.Create;
try
st.LoadFromFile(srcFile);
en := nil;
for i:=0 to st.Count-1 do begin
case scan.ConsumeLine(st[i]) of
gleCommitEnd: en := nil;
gleCommit: begin
en := TLogEntry.Create;
en.Hash := scan.CommitHash;
dst.Add(en);
end;
gleTitle: begin
if en.Message = '' then en.Message := Copy(scan.EntryValue, 5, length(scan.EntryValue)-4)
else en.Message := en.Message + #10 + Copy(scan.EntryValue, 5, length(scan.EntryValue)-4);
end;
gleFileName: begin
fn := en.AddFile;
fn.fileName := scan.EntryValue;
fn.action := scan.FileMod;
end;
//,gleInfo
//,gleGitAttr
end;
end;
finally
scan.Free;
st.Free;
fs.Free;
end;
end;
procedure ClearList(dst: TList);
var
i : integer;
begin
if not Assigned(dst) then Exit;
for i:=0 to dst.Count-1 do
TObject(dst[i]).free;
dst.Clear;
end;
end.