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