svn2cl.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. {$mode objfpc}
  2. {$h+}
  3. uses
  4. classes,dom,xmlread;
  5. procedure error(const s : string);
  6. begin
  7. writeln('Error: ',s);
  8. halt(1);
  9. end;
  10. var
  11. doc : txmldocument;
  12. root : TDomNode;
  13. entry,
  14. currentpath,
  15. currentinfo : TDomNode;
  16. hs,
  17. currentmsg,
  18. currentauthor,
  19. currentdate,
  20. pathtemp,
  21. currentrevision : string;
  22. paths : tstringlist;
  23. i,j,maxequal : longint;
  24. begin
  25. paths:=tstringlist.create;
  26. paths.sorted:=true;
  27. ReadXMLFile(doc,paramstr(1));
  28. root:=doc.DocumentElement;
  29. if root.haschildnodes and
  30. (root.NodeName='log') then
  31. begin
  32. entry:=root.firstchild;
  33. while assigned(entry) do
  34. begin
  35. if entry.NodeName<>'logentry' then
  36. error('Only log entry entries supported, but '+entry.NodeName+' found.');
  37. currentmsg:='';
  38. currentauthor:='';
  39. currentdate:='';
  40. { get revision }
  41. with entry as tdomelement do
  42. currentrevision:=AttribStrings['revision'];
  43. if entry.haschildnodes then
  44. begin
  45. currentinfo:=entry.firstchild;
  46. while assigned(currentinfo) do
  47. begin
  48. if currentinfo.NodeName='author' then
  49. begin
  50. if currentinfo.haschildnodes and
  51. (currentinfo.firstchild is TDOMText) then
  52. currentauthor:=(currentinfo.firstchild as TDOMText).Data
  53. else
  54. error('Malformed author node');
  55. end
  56. else if currentinfo.NodeName='msg' then
  57. begin
  58. if currentinfo.haschildnodes then
  59. begin
  60. if (currentinfo.firstchild is TDOMText) then
  61. currentmsg:=(currentinfo.firstchild as TDOMText).Data
  62. else
  63. error('Malformed msg node');
  64. end
  65. else
  66. currentmsg:='<empty log message>';
  67. end
  68. else if currentinfo.NodeName='date' then
  69. begin
  70. if currentinfo.haschildnodes and
  71. (currentinfo.firstchild is TDOMText) then
  72. currentdate:=(currentinfo.firstchild as TDOMText).Data
  73. else
  74. error('Malformed date node');
  75. end
  76. else if currentinfo.NodeName='paths' then
  77. begin
  78. currentpath:=currentinfo.firstchild;
  79. paths.clear;
  80. while assigned(currentpath) do
  81. begin
  82. if currentpath.NodeName<>'path' then
  83. error('Path node expected');
  84. if currentpath.haschildnodes and
  85. (currentpath.firstchild is TDOMText) then
  86. paths.add((currentpath.firstchild as TDOMText).Data)
  87. else
  88. error('Malformed date node');
  89. currentpath:=currentpath.NextSibling;
  90. end;
  91. end
  92. else
  93. error('Unknown logentry child '+currentinfo.NodeName+' found');
  94. currentinfo:=currentinfo.nextsibling;
  95. end;
  96. currentdate:=copy(currentdate,1,16);
  97. { replaced T }
  98. currentdate[11]:=' ';
  99. write(currentdate,' ',currentauthor);
  100. if currentrevision<>'' then
  101. writeln(' r',currentrevision)
  102. else
  103. writeln;
  104. writeln;
  105. { search for common prefix }
  106. maxequal:=65535;
  107. for i:=1 to paths.Count-1 do
  108. begin
  109. j:=1;
  110. while (paths[0][j]=paths[i][j]) and (j<=maxequal) do
  111. inc(j);
  112. dec(j);
  113. if j<maxequal then
  114. maxequal:=j;
  115. end;
  116. { test/p1.pas test/p2.pas should use the prefix test/ instead of test/p }
  117. if maxequal<65535 then
  118. while (maxequal>0) and (paths[0][maxequal]<>'/') do
  119. dec(maxequal);
  120. { generate prefix }
  121. pathtemp:=' * '+copy(paths[0],1,maxequal)+': ';
  122. for i:=0 to paths.Count-1 do
  123. begin
  124. hs:=copy(paths[i],maxequal+1,65535);
  125. if (length(pathtemp)+length(', '+hs)>80) and
  126. (pathtemp<>' ') then
  127. begin
  128. writeln(pathtemp+',');
  129. pathtemp:=' ';
  130. end;
  131. { non empty path but not first? }
  132. if (pathtemp<>' ') and (pathtemp[length(pathtemp)-1]<>':') then
  133. pathtemp:=pathtemp+', ';
  134. pathtemp:=pathtemp+hs;
  135. end;
  136. if pathtemp<>' ' then
  137. writeln(pathtemp);
  138. { truncate trailing new line }
  139. while currentmsg[length(currentmsg)] in [#13,#10] do
  140. delete(currentmsg,length(currentmsg),1);
  141. writeln;
  142. writeln(' ',currentmsg);
  143. writeln;
  144. end
  145. else
  146. error('Empty log entry found');
  147. entry:=entry.nextsibling;
  148. end;
  149. end
  150. else
  151. error('log element not found/wrong xml format');
  152. end.