svn2revisioninc: fix my earlier sloppy code to find out the main git branch name

git-svn-id: trunk@32847 -
This commit is contained in:
juha 2011-10-12 11:44:08 +00:00
parent f4f2ae1e2e
commit b358c98210

View File

@ -421,11 +421,12 @@ end;
function TSvn2RevisionApplication.IsThisGitUpstreamBranch: boolean;
const
cBufSize = 1024;
MainBranchNames: array[0..1] of string = ('upstream', 'master');
var
p: TProcessUTF8;
Buffer: string;
s: string;
i: integer;
i, j: integer;
n: LongInt;
sl: TStringList;
begin
@ -447,24 +448,20 @@ begin
s := s + Copy(Buffer, 1, n);
until n < cBufSize;
sl.Text := s;
// now search for the active branch marker '*' symbol
// Search for the active branch marker '*' symbol.
// Guess the main branch name. Support 'master' and 'upstream'.
MainBranch := '';
for i := 0 to sl.Count-1 do
begin
s := sl[i];
// Guess the main branch name. 'master' takes precedence if both are defined.
if (MainBranch = '') then begin
if Pos('master', s) > 0 then
MainBranch := 'master'
else if Pos('upstream', s) > 0 then
MainBranch := 'upstream';
if (MainBranch <> '') and (s[1] = '*') then
begin
for i := 0 to sl.Count-1 do begin
for j := Low(MainBranchNames) to High(MainBranchNames) do begin
if Pos(MainBranchNames[j], sl[i]) > 0 then begin
MainBranch := MainBranchNames[j];
if sl[i][1] = '*' then begin
Result := True;
exit;
end;
end;
end;
end;
except
// ignore error, default result is false
end;