1 ------------------------------------------------------------------------------
4 -- Copyright (C) 2007 --
5 -- Pascal Obry - Olivier Ramonat --
7 -- This library is free software; you can redistribute it and/or modify --
8 -- it under the terms of the GNU General Public License as published by --
9 -- the Free Software Foundation; either version 2 of the License, or (at --
10 -- your option) any later version. --
12 -- This library is distributed in the hope that it will be useful, but --
13 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
15 -- General Public License for more details. --
17 -- You should have received a copy of the GNU General Public License --
18 -- along with this library; if not, write to the Free Software Foundation, --
19 -- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --
20 ------------------------------------------------------------------------------
31 package body Morzhol
.VC
.RCS
is
38 Diff_Rev_Opt
: constant String := "-r";
39 Ci_Author_Opt
: constant String := "-w";
41 Ci_Command
: aliased constant String := "ci";
42 Ci_Opt
: aliased String := "-u";
44 Co_Command
: aliased constant String := "co";
45 Co_Opt
: aliased String := "-l";
47 Log_Command
: aliased constant String := "rlog";
48 Log_Total_Rev_Opt
: aliased String := "-h";
50 Diff_Command
: aliased constant String := "rcsdiff";
57 Initial_Revision
: in Boolean) return Boolean;
58 -- Commit or Add if Initial_Revision is True
67 Author
: in String := "") return Boolean
69 Local_RCS_Dir
: constant String :=
70 Directories
.Containing_Directory
(Filename
)
71 & OS
.Directory_Separator
& "RCS";
73 if not Directories
.Exists
(Local_RCS_Dir
) then
74 Directories
.Create_Directory
(Local_RCS_Dir
);
80 Message
=> "File : " & Filename
,
82 Initial_Revision
=> True);
93 Author
: in String := "") return Boolean is
100 Initial_Revision
=> False);
109 Filename
: in String;
112 Initial_Revision
: in Boolean) return Boolean
114 pragma Unreferenced
(Engine
);
116 use type Expect
.Expect_Match
;
118 Pd
: Expect
.Process_Descriptor
;
119 Result
: Expect
.Expect_Match
;
121 RCS_File
: aliased String := Filename
;
122 RCS_Message
: OS_Lib
.String_Access
;
123 RCS_Author
: OS_Lib
.String_Access
;
126 if Initial_Revision
then
127 RCS_Message
:= new String'("-t-" & Message);
129 RCS_Message := new String'("-m" & Message
);
133 RCS_Author
:= new String'(Ci_Author_Opt & Author);
136 Expect.Non_Blocking_Spawn
138 Command => Ci_Command,
140 OS_Lib.Argument_List'
144 4 => RCS_File
'Unchecked_Access),
147 OS_Lib
.Free
(RCS_Author
);
148 OS_Lib
.Free
(RCS_Message
);
150 Expect
.Expect
(Pd
, Result
, "done");
156 when Expect
.Invalid_Process | Expect
.Process_Died
=>
157 OS_Lib
.Free
(RCS_Author
);
158 OS_Lib
.Free
(RCS_Message
);
168 Filename
: in String;
169 From_Version
: in String;
170 To_Version
: in String)
173 pragma Unreferenced
(Engine
);
175 RCS_File
: aliased String := Filename
;
176 Rev1
: aliased String := Diff_Rev_Opt
& From_Version
;
177 Rev2
: aliased String := Diff_Rev_Opt
& To_Version
;
179 Status
: aliased Integer;
180 Result
: Unbounded_String
;
182 Result
:= +Expect
.Get_Command_Output
183 (Command
=> Diff_Command
,
185 OS_Lib
.Argument_List
'(1 => Rev1'Unchecked_Access,
186 2 => Rev2'Unchecked_Access,
187 3 => RCS_File'Unchecked_Access),
189 Status => Status'Access,
194 when Expect.Invalid_Process | Expect.Process_Died =>
204 Filename : in String;
205 Limit : in Natural := 0) return Log
207 pragma Unreferenced (Engine, Limit);
208 use type Expect.Expect_Match;
210 function Get_Revision_Number return Natural;
211 -- Return the number of revision for that file
212 -- or 0 if an error has occured
214 RCS_File : aliased String := Filename;
216 -------------------------
217 -- Get_Revision_Number --
218 -------------------------
220 function Get_Revision_Number return Natural is
222 Pd : Expect.Process_Descriptor;
223 Matched : Regpat.Match_Array (Regpat.Match_Count range 0 .. 1);
224 Result : Expect.Expect_Match;
226 Expect.Non_Blocking_Spawn
228 Command => Log_Command,
229 Args => OS_Lib.Argument_List'
230 (1 => Log_Total_Rev_Opt
'Access,
231 2 => RCS_File
'Unchecked_Access),
237 Regexp
=> "total revisions: (.*)",
242 (Expect
.Expect_Out
(Pd
)
243 (Matched
(1).First
.. Matched
(1).Last
));
247 end Get_Revision_Number
;
249 Revision_Number
: constant Natural := Get_Revision_Number
;
251 Pd
: Expect
.Process_Descriptor
;
252 File_Log
: Log
(1 .. Revision_Number
);
253 Current
: Positive := 1;
256 if Revision_Number
= 0 then
260 Expect
.Non_Blocking_Spawn
262 Command
=> Log_Command
,
263 Args
=> OS_Lib
.Argument_List
'(1 => RCS_File'Unchecked_Access),
266 while Current <= Revision_Number loop
268 Matched : Regpat.Match_Array (Regpat.Match_Count range 0 .. 4);
269 Result : Expect.Expect_Match;
275 Regexp => "\nrevision ([1-9\.]+)\ndate: (.*?);"
276 & ".*author: (.*?);.*\n(.*)",
280 +Expect.Expect_Out (Pd)
281 (Matched (1).First .. Matched (1).Last);
283 +Expect.Expect_Out (Pd)
284 (Matched (2).First .. Matched (2).Last);
286 +Expect.Expect_Out (Pd)
287 (Matched (3).First .. Matched (3).Last);
289 +Expect.Expect_Out (Pd)
290 (Matched (4).First .. Matched (4).Last);
292 File_Log (Current) := CL;
293 Current := Current + 1;
300 when Expect.Invalid_Process | Expect.Process_Died =>
309 (Engine : in RCS; Filename : in String) return Boolean
311 pragma Unreferenced (Engine);
312 use type Expect.Expect_Match;
314 Local_RCS_Dir : constant String :=
315 Directories.Containing_Directory (Filename)
316 & OS.Directory_Separator & "RCS";
318 RCS_File : aliased String := Filename;
319 Pd : Expect.Process_Descriptor;
320 Result : Expect.Expect_Match;
321 Matched : Regpat.Match_Array (Regpat.Match_Count range 0 .. 1);
324 if not Directories.Exists (Local_RCS_Dir) then
325 Directories.Create_Directory (Local_RCS_Dir);
328 Expect.Non_Blocking_Spawn
330 Command => Co_Command,
331 Args => OS_Lib.Argument_List'(1 => Co_Opt
'Access,
332 2 => RCS_File
'Unchecked_Access),
335 Expect
.Expect
(Pd
, Result
, "locked.*\n.*done.*", Matched
);
344 when Expect
.Invalid_Process | Expect
.Process_Died
=>
352 function Remove
(Engine
: in RCS
; Filename
: in String) return Boolean is
353 pragma Unreferenced
(Engine
);
355 -- Nothing special to do here as RCS support only files
357 if Directories
.Exists
(Filename
) then
358 Directories
.Delete_File
(Filename
);