Check-in [e7b75b1a22]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Implemented many methods for Fossil. Turned several methods into class methods.
Timelines: family | ancestors | feature/rewrite-multi-async
Files: files | file ages | folders
SHA1:e7b75b1a22309c55f788cb2775df42bbb2cafdf3
User & Date: tinus 2016-02-25 20:36:58
Context
2016-02-25
20:36
Implemented many methods for Fossil. Turned several methods into class methods. Leaf check-in: e7b75b1a22 user: tinus tags: feature/rewrite-multi-async
2016-02-22
19:28
Added CreateProcess wrapper. Added first UI methods for Fossil. check-in: da9ee3161e user: tinus tags: feature/rewrite-multi-async
Changes

Changes to src/Delphi10/VCSInfo_BPL.dproj.

1
2
3
4
5
6
7
8
9
10
11
12
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
524
525
526
527
528
529
530
531









532
533
534
535
536
537
538
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>{E394A6F2-CCD7-4A8A-9E66-88F4D866E2FB}</ProjectGuid>
        <MainSource>VCSInfo_BPL.dpk</MainSource>
        <ProjectVersion>18.0</ProjectVersion>
        <FrameworkType>None</FrameworkType>
        <Base>True</Base>
        <Config Condition="'$(Config)'==''">Debug</Config>
        <Platform Condition="'$(Platform)'==''">Win32</Platform>
        <TargetedPlatforms>1</TargetedPlatforms>
        <AppType>Package</AppType>
    </PropertyGroup>
................................................................................
                </DeployFile>
                <DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\17.0\Bpl\VCSInfo_BPL.bpl" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>VCSInfo_BPL.bpl</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Name="DependencyModule">
                    <Platform Name="Win32">
                        <Operation>0</Operation>
                        <Extensions>.dll;.bpl</Extensions>
                    </Platform>
                    <Platform Name="OSX32">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectOSXResource">
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\Resources</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="AndroidClassesDexFile">
................................................................................
                </DeployClass>
                <DeployClass Name="Android_LauncherIcon36">
                    <Platform Name="Android">
                        <RemoteDir>res\drawable-ldpi</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectiOSDeviceResourceRules"/>









                <ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>




|







 







|
<
<
<
<
<
<
<
<
<







 







|
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
...
201
202
203
204
205
206
207
208









209
210
211
212
213
214
215
...
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>{E394A6F2-CCD7-4A8A-9E66-88F4D866E2FB}</ProjectGuid>
        <MainSource>VCSInfo_BPL.dpk</MainSource>
        <ProjectVersion>18.1</ProjectVersion>
        <FrameworkType>None</FrameworkType>
        <Base>True</Base>
        <Config Condition="'$(Config)'==''">Debug</Config>
        <Platform Condition="'$(Platform)'==''">Win32</Platform>
        <TargetedPlatforms>1</TargetedPlatforms>
        <AppType>Package</AppType>
    </PropertyGroup>
................................................................................
                </DeployFile>
                <DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\17.0\Bpl\VCSInfo_BPL.bpl" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>VCSInfo_BPL.bpl</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Name="ProjectiOSDeviceResourceRules"/>









                <DeployClass Name="ProjectOSXResource">
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\Resources</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="AndroidClassesDexFile">
................................................................................
                </DeployClass>
                <DeployClass Name="Android_LauncherIcon36">
                    <Platform Name="Android">
                        <RemoteDir>res\drawable-ldpi</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="DependencyModule">
                    <Platform Name="Win32">
                        <Operation>0</Operation>
                        <Extensions>.dll;.bpl</Extensions>
                    </Platform>
                    <Platform Name="OSX32">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                </DeployClass>
                <ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>

Changes to src/Delphi10/VCSInfo_XSeattle.dproj.

1
2
3
4
5
6
7
8
9
10
11
...
151
152
153
154
155
156
157
158




159
160






161
162
163





164
165
166
167
168
169
170
...
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>{8615D8A1-1FF0-4BB0-A048-52AE5019C5DF}</ProjectGuid>
        <ProjectVersion>18.0</ProjectVersion>
        <FrameworkType>None</FrameworkType>
        <MainSource>VCSInfo_XSeattle.dpr</MainSource>
        <Base>True</Base>
        <Config Condition="'$(Config)'==''">Debug</Config>
        <Platform Condition="'$(Platform)'==''">Win32</Platform>
        <TargetedPlatforms>1</TargetedPlatforms>
        <AppType>Library</AppType>
................................................................................
                </DeployFile>
                <DeployFile LocalName="..\..\out\Win32\Debug\VCSInfo_XSeattle.dll" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>VCSInfo_XSeattle.dll</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Name="ProjectiOSDeviceResourceRules">




                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>






                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>





                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectOSXResource">
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\Resources</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
................................................................................
                </DeployClass>
                <DeployClass Name="Android_LauncherIcon36">
                    <Platform Name="Android">
                        <RemoteDir>res\drawable-ldpi</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="DependencyModule">
                    <Platform Name="Win32">
                        <Operation>0</Operation>
                        <Extensions>.dll;.bpl</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\MacOS</RemoteDir>
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSSimulator">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                </DeployClass>
                <ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>



|







 







|
>
>
>
>


>
>
>
>
>
>



>
>
>
>
>







 







|
<
<
<
<


<
<
<
<
<
<



<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
525
526
527
528
529
530
531
532




533
534






535
536
537





538
539
540
541
542
543
544
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>{8615D8A1-1FF0-4BB0-A048-52AE5019C5DF}</ProjectGuid>
        <ProjectVersion>18.1</ProjectVersion>
        <FrameworkType>None</FrameworkType>
        <MainSource>VCSInfo_XSeattle.dpr</MainSource>
        <Base>True</Base>
        <Config Condition="'$(Config)'==''">Debug</Config>
        <Platform Condition="'$(Platform)'==''">Win32</Platform>
        <TargetedPlatforms>1</TargetedPlatforms>
        <AppType>Library</AppType>
................................................................................
                </DeployFile>
                <DeployFile LocalName="..\..\out\Win32\Debug\VCSInfo_XSeattle.dll" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>VCSInfo_XSeattle.dll</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Name="DependencyModule">
                    <Platform Name="Win32">
                        <Operation>0</Operation>
                        <Extensions>.dll;.bpl</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\MacOS</RemoteDir>
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSSimulator">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectOSXResource">
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\Resources</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
................................................................................
                </DeployClass>
                <DeployClass Name="Android_LauncherIcon36">
                    <Platform Name="Android">
                        <RemoteDir>res\drawable-ldpi</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectiOSDeviceResourceRules">




                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>






                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>





                    </Platform>
                </DeployClass>
                <ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>

Changes to src/vcsinfo.Fossil.pas.

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
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
138
139
140
141
142
143
144

145
146
147
148
149
150
151
...
184
185
186
187
188
189
190
191






192
193
194




195
196
197
198













199
200
201



202
203







204




205
206

function TVCSFossil.GetExecutable: string;
begin
  Result := 'fossil.exe';
end;

function TVCSFossil.GetIncoming: integer;



begin
  {$MESSAGE WARN 'TODO: if remote-url is off, then 0; otherwise -1'}
  Result := -1;





end;


function TVCSFossil.GetOutgoing: integer;



begin
  {$MESSAGE WARN 'TODO: if remote-url is off, or autosync is on, then 0; otherwise -1'}
  Result := -1;










end;




function TVCSFossil.CountPendingFiles: integer;
var
  Lines: TStringList;
begin

  Lines := TStringList.Create;
  try
    if 0 = ExecuteCmd('fossil changes', Lines.Append) then
      Result := Lines.Count
    else
      raise EVCSException.Create(Lines.Text.Trim);
  finally
................................................................................
      raise EVCSException.Create(Lines.Text.Trim);
  finally
    Lines.Free;
  end;
end;

function TVCSFossil.GetTitle: string;
var
  Lines: TStringList;
begin
  if 0 <> ExecuteCmd('fossil sqlite3 "SELECT value FROM config WHERE name=''project-name''"', Result) then
    raise EVCSException.Create(Result);
end;

function TVCSFossil.GetUIExecutable: string;
begin
................................................................................
  Result := '';
end;

function TVCSFossil.CountUntrackedFiles: Integer;
var
  Lines: TStringList;
begin

  Lines := TStringList.Create;
  try
    if 0 = ExecuteCmd('fossil extras', Lines.Append) then
      Result := Lines.Count
    else
      raise EVCSException.Create(Lines.Text);
  finally
................................................................................
begin
  if 0 <> ExecuteCmd(Format('fossil rename --soft "%s" "%s"', [OldName, NewName]), Text) then
    raise EVCSException.Create(Text);
end;

procedure TVCSFossil.ShowLocalStatusUI;
begin
  {$MESSAGE WARN 'TODO: fossil gdiff'}






end;

function TVCSFossil.SwitchToBranchUI(const BranchName: string): boolean;




begin
  // TODO: see old VCSInfoMenuWzrd: try fossil checkout first, then dialog with
  //    discard (fossil checkout --force), shelve (fossil stash), merge (fossil update), or cancel
  {$MESSAGE WARN 'TODO: see old VCSInfoMenuWzrd'}













end;

class function TVCSFossil.IsRepo(const APath: string; out ARootPath: string): boolean;



begin
  {$MESSAGE WARN 'TODO: fossil info; extract line for local-root'}







end;





end.







>
>
>

|

>
>
>
>
>
|
>


>
>
>

|

>
>
>
>
>
>
>
>
>
>
|
>
>
>





>







 







<
<







 







>







 







|
>
>
>
>
>
>



>
>
>
>

<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>



>
>
>

<
>
>
>
>
>
>
>
|
>
>
>
>


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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
148
149
150
151
152
153
154


155
156
157
158
159
160
161
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258
259
260
261
262
263
264

function TVCSFossil.GetExecutable: string;
begin
  Result := 'fossil.exe';
end;

function TVCSFossil.GetIncoming: integer;
var
  Line: string;
  iRes: Cardinal;
begin
  // if remote-url is off, then 0; otherwise -1
  Result := -1;

  Line := '';
  iRes := ExecuteCmd('fossil remote-url', Line);
  if (iRes = 0) and (Line <> 'off') then begin
    Result := 0;
  end;
end {TVCSFossil.GetIncoming};

function TVCSFossil.GetOutgoing: integer;
var
  Line: string;
  iRes: Cardinal;
begin
  // if remote-url is off and autosync is on, then 0; otherwise -1
  Result := -1;

  Line := '';
  iRes := ExecuteCmd('fossil settings autosync', Line);
  if (iRes = 0) and (Line <> '') and TryStrToInt(Line.Substring(28).Trim, Integer(iRes)) then begin
    if (iRes > 0) then begin
      // autosync is enabled; check for a remote-url
      Line := '';
      iRes := ExecuteCmd('fossil remote-url', Line);
      if (iRes = 0) and (Line <> 'off') then begin
        Result := 0;
      end;
    end;
  end;
end {TVCSFossil.GetOutgoing};

function TVCSFossil.CountPendingFiles: integer;
var
  Lines: TStringList;
begin
  Result := 0;
  Lines := TStringList.Create;
  try
    if 0 = ExecuteCmd('fossil changes', Lines.Append) then
      Result := Lines.Count
    else
      raise EVCSException.Create(Lines.Text.Trim);
  finally
................................................................................
      raise EVCSException.Create(Lines.Text.Trim);
  finally
    Lines.Free;
  end;
end;

function TVCSFossil.GetTitle: string;


begin
  if 0 <> ExecuteCmd('fossil sqlite3 "SELECT value FROM config WHERE name=''project-name''"', Result) then
    raise EVCSException.Create(Result);
end;

function TVCSFossil.GetUIExecutable: string;
begin
................................................................................
  Result := '';
end;

function TVCSFossil.CountUntrackedFiles: Integer;
var
  Lines: TStringList;
begin
  Result := 0;
  Lines := TStringList.Create;
  try
    if 0 = ExecuteCmd('fossil extras', Lines.Append) then
      Result := Lines.Count
    else
      raise EVCSException.Create(Lines.Text);
  finally
................................................................................
begin
  if 0 <> ExecuteCmd(Format('fossil rename --soft "%s" "%s"', [OldName, NewName]), Text) then
    raise EVCSException.Create(Text);
end;

procedure TVCSFossil.ShowLocalStatusUI;
begin
  if CountPendingFiles > 0 then begin
    if not CreateProcess('fossil gdiff') then
      RaiseLastOSError;
  end else begin
    if not CreateProcess('fossil ui') then
      RaiseLastOSError;
  end;
end;

function TVCSFossil.SwitchToBranchUI(const BranchName: string): boolean;
var
  Output: string;
  iRes: Cardinal;
  MsgType: TMsgDlgType;
begin



  Result := False;
  iRes := ExecuteCmd(Format('fossil checkout "%s"', [BranchName]), Output);
  if iRes <> 0 then begin
    if TaskMessageDlg(FRoot, Output, mtWarning, [mbRetry, mbCancel], 0) = mrCancel then
      Exit;
    iRes := ExecuteCmd(Format('fossil update "%s"', [BranchName]), Output);
  end;
  Result := iRes = 0;
  if Result then
    MsgType := mtInformation
  else
    MsgType := mtError;
  TaskMessageDlg(FRoot, Output, MsgType, [mbOK], 0);
end;

class function TVCSFossil.IsRepo(const APath: string; out ARootPath: string): boolean;
var
  Lines: TStrings;
  iRes: Cardinal;
begin

  Lines := TStringList.Create;
  try
    Lines.NameValueSeparator := ':';
    iRes := ExecuteCmd('fossil info', Lines.Append, False, nil, APath);
    Result := iRes = 0;
    if Result then begin
      ARootPath := Lines.Values['local-root'].Trim.Replace('/', PathDelim, [rfReplaceAll]);
    end;
  finally
    Lines.Free;
  end;
end {TVCSFossil.IsRepo};

end.

Changes to src/vcsinfo.VCSClient.pas.

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
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374


375
376
377
378
379
380
381
  public
    class function CreateForPath(const APath: string): TVCSClient;
    class function IsRepo(const APath: string; out ARootPath: string): boolean; virtual; abstract;
    class procedure RegisterVCSClass(const VCSClass: TVCSClientClass);
  strict private
    class var FRegisteredVCSes: TList<TVCSClientClass>;
  strict private
    function InternalExecute(CommandLine: string; var Output: string;
      OutputLineCallback: TTextHandler; RawOutput: Boolean; AbortPtr: PBoolean;
      const CurrentDir: string): Cardinal;
    function MuteCRTerminatedLines(const RawOutput: string): string;
  strict protected
    FRoot: string;

    function ExecuteCmd(const CommandLine: string;
                        OutputLineCallback: TTextHandler;
                        RawOutput: Boolean = False;
                        AbortPtr: PBoolean = nil;
                        const CurrentDir: string = ''): Cardinal; overload;
    function ExecuteCmd(const CommandLine: string;
                        var Output: string;
                        RawOutput: Boolean = False;
                        AbortPtr: PBoolean = nil;
                        const CurrentDir: string = ''): Cardinal; overload;

    function CreateProcess(const ACommand: string; const ACurrentDir: string = ''; const AShow: boolean = False): boolean;


    function  GetExecutable: string; virtual; abstract;
    function  GetUIExecutable: string; virtual; abstract;
    function  GetTitle: string; virtual;
    function  GetCurrentBranch: string; virtual;
  public
................................................................................
  end;
end;

const
  ABORT_EXIT_CODE = {$IFDEF MSWINDOWS} ERROR_CANCELLED {$ELSE} 1223 {$ENDIF};


function TVCSClient.MuteCRTerminatedLines(const RawOutput: string): string;
const
  Delta = 1024;
var
  BufPos, OutPos, LfPos, EndPos: Integer;
  C: Char;
begin
  SetLength(Result, Length(RawOutput));
................................................................................
      Inc(OutPos);
      EndPos := OutPos;
    end;
  end;
  SetLength(Result, OutPos - 1);
end;

function TVCSClient.InternalExecute(CommandLine: string; var Output: string; OutputLineCallback: TTextHandler;
  RawOutput: Boolean; AbortPtr: PBoolean; const CurrentDir: string): Cardinal;

const
  BufferSize = 255;
type
  TBuffer = array [0..BufferSize] of AnsiChar;

................................................................................
  StartupInfo.hStdError := PipeWrite;
  UniqueString(CommandLine); // CommandLine must be in a writable memory block
  ProcessInfo.dwProcessId := 0;
  try
    if CurrentDir <> '' then
      PCurrentDir := PChar(CurrentDir)
    else
      PCurrentDir := PChar(FRoot);
    if Winapi.Windows.CreateProcess(nil, PChar(CommandLine), nil, nil, True, NORMAL_PRIORITY_CLASS,
      nil, PCurrentDir, StartupInfo, ProcessInfo) then
    begin
      CloseHandle(PipeWrite);
      PipeWrite := 0;
      if AbortPtr <> nil then
        {$IFDEF FPC}
................................................................................
    else
      if RawOutput then
        Output := Output + Line
      else
        Output := Output + MuteCRTerminatedLines(Line);
end;

function TVCSClient.ExecuteCmd(const CommandLine: string;
                                var Output: string;
                                RawOutput: Boolean = False;
                                AbortPtr: PBoolean = nil;
                                const CurrentDir: string = ''): Cardinal;
begin
  Result := InternalExecute(CommandLine, Output, nil, RawOutput, AbortPtr, CurrentDir);
end;

function TVCSClient.ExecuteCmd(const CommandLine: string;
                                OutputLineCallback: TTextHandler;
                                RawOutput: Boolean = False;
                                AbortPtr: PBoolean = nil;
                                const CurrentDir: string = ''): Cardinal;
var
  Dummy: string;
begin
  Dummy := '';
  Result := InternalExecute(CommandLine, Dummy, OutputLineCallback, RawOutput, AbortPtr, CurrentDir);
end;

{$ENDREGION}

function TVCSClient.CreateProcess(const ACommand: string; const ACurrentDir: string = ''; const AShow: boolean = False): boolean;
var
  SUI: TStartupInfo;
  Command: string;
  ProcInfo: TProcessInformation;
begin
  try
    SUI := Default(TStartupInfo);
    SUI.cb := SizeOf(SUI);


    if not AShow then begin
      SUI.dwFlags := STARTF_USESHOWWINDOW;
      SUI.wShowWindow := SW_MINIMIZE;
    end;
    Command := ACommand;
    UniqueString(Command);
    Result := Winapi.Windows.CreateProcess(nil, PChar(Command), nil, nil, False,







|


|



|




|





|







 







|







 







|







 







|







 







|








|













|








>
>







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
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
  public
    class function CreateForPath(const APath: string): TVCSClient;
    class function IsRepo(const APath: string; out ARootPath: string): boolean; virtual; abstract;
    class procedure RegisterVCSClass(const VCSClass: TVCSClientClass);
  strict private
    class var FRegisteredVCSes: TList<TVCSClientClass>;
  strict private
    class function InternalExecute(CommandLine: string; var Output: string;
      OutputLineCallback: TTextHandler; RawOutput: Boolean; AbortPtr: PBoolean;
      const CurrentDir: string): Cardinal;
    class function MuteCRTerminatedLines(const RawOutput: string): string;
  strict protected
    FRoot: string;

    class function ExecuteCmd(const CommandLine: string;
                        OutputLineCallback: TTextHandler;
                        RawOutput: Boolean = False;
                        AbortPtr: PBoolean = nil;
                        const CurrentDir: string = ''): Cardinal; overload;
    class function ExecuteCmd(const CommandLine: string;
                        var Output: string;
                        RawOutput: Boolean = False;
                        AbortPtr: PBoolean = nil;
                        const CurrentDir: string = ''): Cardinal; overload;

    function CreateProcess(const ACommand: string; ACurrentDir: string = ''; const AShow: boolean = False): boolean;


    function  GetExecutable: string; virtual; abstract;
    function  GetUIExecutable: string; virtual; abstract;
    function  GetTitle: string; virtual;
    function  GetCurrentBranch: string; virtual;
  public
................................................................................
  end;
end;

const
  ABORT_EXIT_CODE = {$IFDEF MSWINDOWS} ERROR_CANCELLED {$ELSE} 1223 {$ENDIF};


class function TVCSClient.MuteCRTerminatedLines(const RawOutput: string): string;
const
  Delta = 1024;
var
  BufPos, OutPos, LfPos, EndPos: Integer;
  C: Char;
begin
  SetLength(Result, Length(RawOutput));
................................................................................
      Inc(OutPos);
      EndPos := OutPos;
    end;
  end;
  SetLength(Result, OutPos - 1);
end;

class function TVCSClient.InternalExecute(CommandLine: string; var Output: string; OutputLineCallback: TTextHandler;
  RawOutput: Boolean; AbortPtr: PBoolean; const CurrentDir: string): Cardinal;

const
  BufferSize = 255;
type
  TBuffer = array [0..BufferSize] of AnsiChar;

................................................................................
  StartupInfo.hStdError := PipeWrite;
  UniqueString(CommandLine); // CommandLine must be in a writable memory block
  ProcessInfo.dwProcessId := 0;
  try
    if CurrentDir <> '' then
      PCurrentDir := PChar(CurrentDir)
    else
      PCurrentDir := nil;
    if Winapi.Windows.CreateProcess(nil, PChar(CommandLine), nil, nil, True, NORMAL_PRIORITY_CLASS,
      nil, PCurrentDir, StartupInfo, ProcessInfo) then
    begin
      CloseHandle(PipeWrite);
      PipeWrite := 0;
      if AbortPtr <> nil then
        {$IFDEF FPC}
................................................................................
    else
      if RawOutput then
        Output := Output + Line
      else
        Output := Output + MuteCRTerminatedLines(Line);
end;

class function TVCSClient.ExecuteCmd(const CommandLine: string;
                                var Output: string;
                                RawOutput: Boolean = False;
                                AbortPtr: PBoolean = nil;
                                const CurrentDir: string = ''): Cardinal;
begin
  Result := InternalExecute(CommandLine, Output, nil, RawOutput, AbortPtr, CurrentDir);
end;

class function TVCSClient.ExecuteCmd(const CommandLine: string;
                                OutputLineCallback: TTextHandler;
                                RawOutput: Boolean = False;
                                AbortPtr: PBoolean = nil;
                                const CurrentDir: string = ''): Cardinal;
var
  Dummy: string;
begin
  Dummy := '';
  Result := InternalExecute(CommandLine, Dummy, OutputLineCallback, RawOutput, AbortPtr, CurrentDir);
end;

{$ENDREGION}

function TVCSClient.CreateProcess(const ACommand: string; ACurrentDir: string = ''; const AShow: boolean = False): boolean;
var
  SUI: TStartupInfo;
  Command: string;
  ProcInfo: TProcessInformation;
begin
  try
    SUI := Default(TStartupInfo);
    SUI.cb := SizeOf(SUI);
    if ACurrentDir = '' then
      ACurrentDir := FRoot;
    if not AShow then begin
      SUI.dwFlags := STARTF_USESHOWWINDOW;
      SUI.wShowWindow := SW_MINIMIZE;
    end;
    Command := ACommand;
    UniqueString(Command);
    Result := Winapi.Windows.CreateProcess(nil, PChar(Command), nil, nil, False,