1 | unit VCS;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, LazFileUtils, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TLogItem }
|
---|
11 |
|
---|
12 | TLogItem = class
|
---|
13 | Author: string;
|
---|
14 | Actions: string;
|
---|
15 | Time: TDateTime;
|
---|
16 | Revision: string;
|
---|
17 | Messages: TStringList;
|
---|
18 | ChangedFiles: TStringList;
|
---|
19 | constructor Create;
|
---|
20 | destructor Destroy; override;
|
---|
21 | end;
|
---|
22 |
|
---|
23 | TLogItems = class(TObjectList<TLogItem>)
|
---|
24 | end;
|
---|
25 |
|
---|
26 | TFileStatusState = (fssNonVersioned, fssAdded, fssRemoved, fssModified, fssNotModified);
|
---|
27 |
|
---|
28 | { TFileStatus }
|
---|
29 |
|
---|
30 | TFileStatus = class
|
---|
31 | FileName: string;
|
---|
32 | Version: string;
|
---|
33 | Author: string;
|
---|
34 | Time: TDateTime;
|
---|
35 | State: TFileStatusState;
|
---|
36 | procedure Assign(Source: TFileStatus);
|
---|
37 | end;
|
---|
38 |
|
---|
39 | { TFileStatuses }
|
---|
40 |
|
---|
41 | TFileStatuses = class(TObjectList<TFileStatus>)
|
---|
42 | function SearchByName(Name: string): TFileStatus;
|
---|
43 | end;
|
---|
44 |
|
---|
45 | { TWorkingCopy }
|
---|
46 |
|
---|
47 | TWorkingCopy = class
|
---|
48 | private
|
---|
49 | FPath: string;
|
---|
50 | FRepositoryURL: string;
|
---|
51 | procedure SetPath(AValue: string);
|
---|
52 | procedure SetRepositoryURL(AValue: string);
|
---|
53 | protected
|
---|
54 | EnvVars: TStringList;
|
---|
55 | procedure ExecuteProcess(Command: string; Parameters: array of string); virtual;
|
---|
56 | function GetNext(var Text: string; Separator: string): string;
|
---|
57 | public
|
---|
58 | UserName: string;
|
---|
59 | Password: string;
|
---|
60 | Email: string;
|
---|
61 | SilentExecution: Boolean;
|
---|
62 | ExecutionOutput: TStringList;
|
---|
63 | procedure Checkout; virtual;
|
---|
64 | procedure Update; virtual;
|
---|
65 | procedure CleanUp; virtual;
|
---|
66 | procedure Commit(Message: string); virtual;
|
---|
67 | procedure Move(Source, Dest: string); virtual;
|
---|
68 | procedure Merge; virtual;
|
---|
69 | procedure Refresh; virtual;
|
---|
70 | procedure Add(FileName: string); virtual;
|
---|
71 | procedure Remove(FileName: string); virtual;
|
---|
72 | procedure GetLog(FileName: string; Log: TLogItems); virtual;
|
---|
73 | procedure GetStatus(FileName: string; Status: TFileStatuses); virtual;
|
---|
74 | constructor Create;
|
---|
75 | destructor Destroy; override;
|
---|
76 | property RepositoryURL: string read FRepositoryURL write SetRepositoryURL;
|
---|
77 | property Path: string read FPath write SetPath;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | { TRepository }
|
---|
81 |
|
---|
82 | TRepository = class
|
---|
83 | protected
|
---|
84 | procedure ExecuteProcess(Command: string; Parameters: array of string); virtual;
|
---|
85 | public
|
---|
86 | ExecutionOutput: TStringList;
|
---|
87 | Path: string;
|
---|
88 | SilentExecution: Boolean;
|
---|
89 | procedure Init; virtual;
|
---|
90 | constructor Create;
|
---|
91 | destructor Destroy; override;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | function URLFromDirectory(DirName: string; Relative: Boolean): string;
|
---|
95 |
|
---|
96 | const
|
---|
97 | FileStatusStateText: array[TFileStatusState] of string = ('Not versioned',
|
---|
98 | 'Added', 'Removed', 'Modified', 'Normal');
|
---|
99 |
|
---|
100 |
|
---|
101 | implementation
|
---|
102 |
|
---|
103 | uses
|
---|
104 | FormConsole;
|
---|
105 |
|
---|
106 | function URLFromDirectory(DirName: string; Relative: Boolean): string;
|
---|
107 | begin
|
---|
108 | Result := DirName;
|
---|
109 | if Relative then Result := GetCurrentDir + DirectorySeparator + Result;
|
---|
110 | Result := 'file:///' + StringReplace(Result, DirectorySeparator, '/', [rfReplaceAll]);
|
---|
111 | end;
|
---|
112 |
|
---|
113 | { TFileStatus }
|
---|
114 |
|
---|
115 | procedure TFileStatus.Assign(Source: TFileStatus);
|
---|
116 | begin
|
---|
117 | FileName := Source.FileName;
|
---|
118 | Version := Source.Version;
|
---|
119 | Time := Source.Time;
|
---|
120 | Author := Source.Author;
|
---|
121 | State := Source.State;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | { TFileStatuses }
|
---|
125 |
|
---|
126 | function TFileStatuses.SearchByName(Name: string): TFileStatus;
|
---|
127 | var
|
---|
128 | I: Integer;
|
---|
129 | begin
|
---|
130 | I := 0;
|
---|
131 | while (I < Count) and (TFileStatus(Items[I]).FileName <> Name) do Inc(I);
|
---|
132 | if I < Count then Result := TFileStatus(Items[I])
|
---|
133 | else Result := nil;
|
---|
134 | end;
|
---|
135 |
|
---|
136 | { TRepository }
|
---|
137 |
|
---|
138 | procedure TRepository.ExecuteProcess(Command: string;
|
---|
139 | Parameters: array of string);
|
---|
140 | var
|
---|
141 | FormConsole: TFormConsole;
|
---|
142 | begin
|
---|
143 | FormConsole := TFormConsole.Create(nil);
|
---|
144 | try
|
---|
145 | FormConsole.Executable := Command;
|
---|
146 | FormConsole.Parameters.Clear;
|
---|
147 | FormConsole.Parameters.AddStrings(Parameters);
|
---|
148 | if DirectoryExists(Path) then FormConsole.WorkingDir := Path
|
---|
149 | else FormConsole.WorkingDir := '';
|
---|
150 | if SilentExecution then FormConsole.Perform
|
---|
151 | else FormConsole.ShowModal;
|
---|
152 | ExecutionOutput.Assign(FormConsole.Log);
|
---|
153 | finally
|
---|
154 | FormConsole.Free;
|
---|
155 | end;
|
---|
156 | end;
|
---|
157 |
|
---|
158 | procedure TRepository.Init;
|
---|
159 | begin
|
---|
160 | end;
|
---|
161 |
|
---|
162 | constructor TRepository.Create;
|
---|
163 | begin
|
---|
164 | ExecutionOutput := TStringList.Create;
|
---|
165 | Path := '';
|
---|
166 | end;
|
---|
167 |
|
---|
168 | destructor TRepository.Destroy;
|
---|
169 | begin
|
---|
170 | FreeAndNil(ExecutionOutput);
|
---|
171 | inherited;
|
---|
172 | end;
|
---|
173 |
|
---|
174 | { TLogItem }
|
---|
175 |
|
---|
176 | constructor TLogItem.Create;
|
---|
177 | begin
|
---|
178 | Messages := TStringList.Create;
|
---|
179 | ChangedFiles := TStringList.Create;
|
---|
180 | end;
|
---|
181 |
|
---|
182 | destructor TLogItem.Destroy;
|
---|
183 | begin
|
---|
184 | FreeAndNil(Messages);
|
---|
185 | FreeAndNil(ChangedFiles);
|
---|
186 | inherited;
|
---|
187 | end;
|
---|
188 |
|
---|
189 | { TWorkingCopy }
|
---|
190 |
|
---|
191 | procedure TWorkingCopy.SetPath(AValue: string);
|
---|
192 | begin
|
---|
193 | if FPath = AValue then Exit;
|
---|
194 | FPath := AValue;
|
---|
195 | Refresh;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | procedure TWorkingCopy.SetRepositoryURL(AValue: string);
|
---|
199 | begin
|
---|
200 | if FRepositoryURL = AValue then Exit;
|
---|
201 | FRepositoryURL := AValue;
|
---|
202 | end;
|
---|
203 |
|
---|
204 | procedure TWorkingCopy.ExecuteProcess(Command: string; Parameters: array of string);
|
---|
205 | var
|
---|
206 | FormConsole: TFormConsole;
|
---|
207 | begin
|
---|
208 | FormConsole := TFormConsole.Create(nil);
|
---|
209 | try
|
---|
210 | FormConsole.Executable := Command;
|
---|
211 | FormConsole.EnvironmentVariables.Assign(EnvVars);
|
---|
212 | FormConsole.Parameters.Clear;
|
---|
213 | FormConsole.Parameters.AddStrings(Parameters);
|
---|
214 | if DirectoryExists(Path) then FormConsole.WorkingDir := Path
|
---|
215 | else FormConsole.WorkingDir := '';
|
---|
216 | if SilentExecution then FormConsole.Perform
|
---|
217 | else FormConsole.ShowModal;
|
---|
218 | ExecutionOutput.Assign(FormConsole.Log);
|
---|
219 | finally
|
---|
220 | FormConsole.Free;
|
---|
221 | end;
|
---|
222 | end;
|
---|
223 |
|
---|
224 | function TWorkingCopy.GetNext(var Text: string; Separator: string): string;
|
---|
225 | begin
|
---|
226 | if Pos(Separator, Text) > 0 then begin
|
---|
227 | Result := Copy(Text, 1, Pos(Separator, Text) - 1);
|
---|
228 | Delete(Text, 1, Pos(Separator, Text) + Length(Separator));
|
---|
229 | end else begin
|
---|
230 | Result := Text;
|
---|
231 | Text := '';
|
---|
232 | end;
|
---|
233 | end;
|
---|
234 |
|
---|
235 | procedure TWorkingCopy.Checkout;
|
---|
236 | begin
|
---|
237 | end;
|
---|
238 |
|
---|
239 | procedure TWorkingCopy.Update;
|
---|
240 | begin
|
---|
241 | end;
|
---|
242 |
|
---|
243 | procedure TWorkingCopy.CleanUp;
|
---|
244 | begin
|
---|
245 | end;
|
---|
246 |
|
---|
247 | procedure TWorkingCopy.Commit(Message: string);
|
---|
248 | begin
|
---|
249 | end;
|
---|
250 |
|
---|
251 | procedure TWorkingCopy.Move(Source, Dest: string);
|
---|
252 | begin
|
---|
253 | end;
|
---|
254 |
|
---|
255 | procedure TWorkingCopy.Merge;
|
---|
256 | begin
|
---|
257 | end;
|
---|
258 |
|
---|
259 | procedure TWorkingCopy.Refresh;
|
---|
260 | begin
|
---|
261 | end;
|
---|
262 |
|
---|
263 | procedure TWorkingCopy.Add(FileName: string);
|
---|
264 | begin
|
---|
265 | end;
|
---|
266 |
|
---|
267 | procedure TWorkingCopy.Remove(FileName: string);
|
---|
268 | begin
|
---|
269 | end;
|
---|
270 |
|
---|
271 | procedure TWorkingCopy.GetLog(FileName: string; Log: TLogItems);
|
---|
272 | begin
|
---|
273 | Log.Clear;
|
---|
274 | end;
|
---|
275 |
|
---|
276 | procedure TWorkingCopy.GetStatus(FileName: string; Status: TFileStatuses);
|
---|
277 | begin
|
---|
278 | Status.Clear;
|
---|
279 | end;
|
---|
280 |
|
---|
281 | constructor TWorkingCopy.Create;
|
---|
282 | begin
|
---|
283 | ExecutionOutput := TStringList.Create;
|
---|
284 | EnvVars := TStringList.Create;
|
---|
285 | FPath := '';
|
---|
286 | FRepositoryURL := '';
|
---|
287 | end;
|
---|
288 |
|
---|
289 | destructor TWorkingCopy.Destroy;
|
---|
290 | begin
|
---|
291 | FreeAndNil(EnvVars);
|
---|
292 | FreeAndNil(ExecutionOutput);
|
---|
293 | inherited;
|
---|
294 | end;
|
---|
295 |
|
---|
296 | end.
|
---|
297 |
|
---|