svn2cl.pp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. { generate prefix }
  117. pathtemp:=' * '+copy(paths[0],1,maxequal)+': ';
  118. for i:=0 to paths.Count-1 do
  119. begin
  120. hs:=copy(paths[i],maxequal+1,65535);
  121. if (length(pathtemp)+length(', '+hs)>80) and
  122. (pathtemp<>' ') then
  123. begin
  124. writeln(pathtemp+',');
  125. pathtemp:=' ';
  126. end;
  127. { non empty path but not first? }
  128. if (pathtemp<>' ') and (pathtemp[length(pathtemp)-1]<>':') then
  129. pathtemp:=pathtemp+', ';
  130. pathtemp:=pathtemp+hs;
  131. end;
  132. if pathtemp<>' ' then
  133. writeln(pathtemp);
  134. { truncate trailing new line }
  135. while currentmsg[length(currentmsg)] in [#13,#10] do
  136. delete(currentmsg,length(currentmsg),1);
  137. writeln;
  138. writeln(' ',currentmsg);
  139. writeln;
  140. end
  141. else
  142. error('Empty log entry found');
  143. entry:=entry.nextsibling;
  144. end;
  145. end
  146. else
  147. error('log element not found/wrong xml format');
  148. end.