Skip to content

Commit 2c97d41

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents d0690d6 + 1ee77f6 commit 2c97d41

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

.gitlab-ci.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ stages:
66
- build_and_test
77

88
.detect-branches:
9-
# Version 1.
9+
# Version 2.
1010
# Detects source and target branches. Checkout necessary branch for
1111
# repository when run downstream pipeline is detected.
1212
# ACI_SOURCE_BRANCH is set to source branch (merge request, pull)
@@ -47,10 +47,18 @@ stages:
4747
4848
# On downstream pipeline checkout the necessary branch
4949
- if [[ "$CI_PIPELINE_SOURCE" == 'pipeline' ]]; then
50-
if `git -C $CI_PROJECT_DIR show-ref $ACI_SOURCE_BRANCH > /dev/null`; then
51-
git -C $CI_PROJECT_DIR checkout $ACI_SOURCE_BRANCH;
52-
elif `git -C $CI_PROJECT_DIR show-ref $ACI_TARGET_BRANCH > /dev/null`; then
53-
git -C $CI_PROJECT_DIR checkout $ACI_TARGET_BRANCH;
50+
if git -C "$CI_PROJECT_DIR" show-ref --quiet -- "$ACI_SOURCE_BRANCH"; then
51+
git -C "$CI_PROJECT_DIR" checkout "$ACI_SOURCE_BRANCH";
52+
elif git -C "$CI_PROJECT_DIR" ls-remote --exit-code -- origin "$ACI_SOURCE_BRANCH"; then
53+
git -C "$CI_PROJECT_DIR" config remote.origin.fetch "+refs/heads/$ACI_SOURCE_BRANCH:refs/remotes/origin/$ACI_SOURCE_BRANCH";
54+
git -C "$CI_PROJECT_DIR" remote update;
55+
git -C "$CI_PROJECT_DIR" checkout "$ACI_SOURCE_BRANCH";
56+
elif git -C "$CI_PROJECT_DIR" show-ref --quiet -- "$ACI_TARGET_BRANCH"; then
57+
git -C "$CI_PROJECT_DIR" checkout "$ACI_TARGET_BRANCH";
58+
elif git -C "$CI_PROJECT_DIR" ls-remote --exit-code -- origin "$ACI_TARGET_BRANCH"; then
59+
git -C "$CI_PROJECT_DIR" config remote.origin.fetch "+refs/heads/$ACI_TARGET_BRANCH:refs/remotes/origin/$ACI_TARGET_BRANCH";
60+
git -C "$CI_PROJECT_DIR" remote update;
61+
git -C "$CI_PROJECT_DIR" checkout "$ACI_TARGET_BRANCH";
5462
fi
5563
fi
5664

source/ada/lsp-ada_driver.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ begin
337337
Register_Commands;
338338
end if;
339339

340+
Ada.Text_IO.Set_Output (Ada.Text_IO.Standard_Error);
341+
-- Protect stdout from pollution by accidental Put_Line calls
342+
340343
Server.Initialize (Stream'Unchecked_Access);
341344

342345
begin

source/client/lsp-raw_clients.adb

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ with Spawn.Processes; use Spawn.Processes;
2929

3030
package body LSP.Raw_Clients is
3131

32-
Parse_Exception : exception;
33-
-- Local exception raised when parsing invalid data
34-
3532
New_Line : constant String :=
3633
(Ada.Characters.Latin_1.CR, Ada.Characters.Latin_1.LF);
3734

@@ -267,8 +264,11 @@ package body LSP.Raw_Clients is
267264
use Ada.Strings.Fixed;
268265

269266
procedure Parse_Headers
270-
(Buffer : String; Content_Length : out Positive);
271-
-- Parse headers in Buffer and return Content-Length
267+
(Buffer : String;
268+
Content_Length : out Positive;
269+
Success : out Boolean);
270+
-- Parse headers in Buffer and return Content-Length.
271+
-- Return Success = False if encounter an unexpected header.
272272

273273
Client : Raw_Clients.Raw_Client'Class renames Self.Client.all;
274274

@@ -278,7 +278,8 @@ package body LSP.Raw_Clients is
278278

279279
procedure Parse_Headers
280280
(Buffer : String;
281-
Content_Length : out Positive)
281+
Content_Length : out Positive;
282+
Success : out Boolean)
282283
is
283284
function Skip (Pattern : String) return Boolean;
284285
-- Find Pattern in current position of Buffer and skip it
@@ -303,7 +304,9 @@ package body LSP.Raw_Clients is
303304
end Skip;
304305

305306
begin
306-
while Next < Buffer'Last loop
307+
Success := True;
308+
309+
while Success and Next < Buffer'Last loop
307310
if Skip ("Content-Type: ") then
308311
Next := Index (Buffer, New_Line);
309312
pragma Assert (Next /= 0);
@@ -316,7 +319,8 @@ package body LSP.Raw_Clients is
316319
Content_Length := Positive'Value (Buffer (From .. Next - 1));
317320
end;
318321
else
319-
raise Parse_Exception with "Unexpected header:" & Buffer;
322+
Next := Index (Buffer, New_Line);
323+
Success := False;
320324
end if;
321325

322326
Next := Next + New_Line'Length;
@@ -346,24 +350,21 @@ package body LSP.Raw_Clients is
346350
Start := Index (Client.Buffer, New_Line & New_Line);
347351

348352
if Start /= 0 then
349-
begin
350-
Parse_Headers
351-
(Slice (Client.Buffer, 1, Start + 1),
352-
Client.To_Read);
353-
Delete
354-
(Client.Buffer, 1, Start + 2 * New_Line'Length - 1);
355-
exception
356-
when E : Parse_Exception =>
357-
Client.On_Exception (E);
358-
-- Delete the first line
359-
Start :=
360-
Index (Client.Buffer,
361-
"" & Ada.Characters.Latin_1.LF);
362-
Delete
363-
(Client.Buffer, 1, Start);
364-
-- Reset start to 0 => we didn't find a header
365-
Start := 0;
366-
end;
353+
Parse_Headers
354+
(Slice (Client.Buffer, 1, Start + 1),
355+
Client.To_Read,
356+
Success);
357+
358+
if not Success then
359+
Client.On_Error
360+
("Unable to parse:" &
361+
Slice (Client.Buffer, 1, Start + 1));
362+
-- Notify upstream and try to recover by dropping the
363+
-- headers block.
364+
end if;
365+
366+
Delete
367+
(Client.Buffer, 1, Start + 2 * New_Line'Length - 1);
367368
end if;
368369
end if;
369370

0 commit comments

Comments
 (0)