source: trunk/Units/UVCS.pas

Last change on this file was 19, checked in by chronos, 7 years ago
  • Fixed: Build under Lazarus 1.8.0.
  • Modified: Updated Common package.
File size: 6.1 KB
Line 
1unit UVCS;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, LazFileUtils, Contnrs;
9
10type
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
97function URLFromDirectory(DirName: string; Relative: Boolean): string;
98
99const
100 FileStatusStateText: array[TFileStatusState] of string = ('Not versioned',
101 'Added', 'Removed', 'Modified', 'Normal');
102
103implementation
104
105uses
106 UFormConsole;
107
108function URLFromDirectory(DirName: string; Relative: Boolean): string;
109begin
110 Result := DirName;
111 if Relative then Result := GetCurrentDirUTF8 + DirectorySeparator + Result;
112 Result := 'file:///' + StringReplace(Result, DirectorySeparator, '/', [rfReplaceAll]);
113end;
114
115{ TFileStatus }
116
117procedure TFileStatus.Assign(Source: TFileStatus);
118begin
119 FileName := Source.FileName;
120 Version := Source.Version;
121 Time := Source.Time;
122 Author := Source.Author;
123 State := Source.State;
124end;
125
126{ TFileStatusList }
127
128function TFileStatusList.SearchByName(Name: string): TFileStatus;
129var
130 I: Integer;
131begin
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;
136end;
137
138{ TRepository }
139
140procedure TRepository.ExecuteProcess(Command: string;
141 Parameters: array of string);
142begin
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);
150end;
151
152procedure TRepository.Init;
153begin
154
155end;
156
157constructor TRepository.Create;
158begin
159 ExecutionOutput := TStringList.Create;
160 Path := '';
161end;
162
163destructor TRepository.Destroy;
164begin
165 FreeAndNil(ExecutionOutput);
166 inherited Destroy;
167end;
168
169{ TLogItem }
170
171constructor TLogItem.Create;
172begin
173 Messages := TStringList.Create;
174 ChangedFiles := TStringList.Create;
175end;
176
177destructor TLogItem.Destroy;
178begin
179 Messages.Free;
180 ChangedFiles.Free;
181 inherited Destroy;
182end;
183
184{ TWorkingCopy }
185
186procedure TWorkingCopy.SetPath(AValue: string);
187begin
188 if FPath = AValue then Exit;
189 FPath := AValue;
190 Refresh;
191end;
192
193procedure TWorkingCopy.SetRepositoryURL(AValue: string);
194begin
195 if FRepositoryURL=AValue then Exit;
196 FRepositoryURL:=AValue;
197end;
198
199procedure TWorkingCopy.ExecuteProcess(Command: string; Parameters: array of string);
200begin
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);
210end;
211
212function TWorkingCopy.GetNext(var Text: string; Separator: string): string;
213begin
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;
221end;
222
223procedure TWorkingCopy.Checkout;
224begin
225
226end;
227
228procedure TWorkingCopy.Update;
229begin
230
231end;
232
233procedure TWorkingCopy.CleanUp;
234begin
235
236end;
237
238procedure TWorkingCopy.Commit(Message: TStrings);
239begin
240
241end;
242
243procedure TWorkingCopy.Move(Source, Dest: string);
244begin
245
246end;
247
248procedure TWorkingCopy.Merge;
249begin
250
251end;
252
253procedure TWorkingCopy.Refresh;
254begin
255
256end;
257
258procedure TWorkingCopy.Add(FileName: string);
259begin
260
261end;
262
263procedure TWorkingCopy.Remove(FileName: string);
264begin
265
266end;
267
268procedure TWorkingCopy.GetLog(FileName: string; Log: TLogList);
269begin
270 Log.Clear;
271end;
272
273procedure TWorkingCopy.GetStatus(FileName: string; Status: TFileStatusList);
274begin
275 Status.Clear;
276end;
277
278constructor TWorkingCopy.Create;
279begin
280 ExecutionOutput := TStringList.Create;
281 EnvVars := TStringList.Create;
282 FPath := '';
283 FRepositoryURL := '';
284end;
285
286destructor TWorkingCopy.Destroy;
287begin
288 FreeAndNil(EnvVars);
289 FreeAndNil(ExecutionOutput);
290 inherited Destroy;
291end;
292
293end.
294
Note: See TracBrowser for help on using the repository browser.