svn2cl.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. currentrevision:='';
  41. if entry.haschildnodes then
  42. begin
  43. currentinfo:=entry.firstchild;
  44. while assigned(currentinfo) do
  45. begin
  46. if currentinfo.NodeName='author' then
  47. begin
  48. if currentinfo.haschildnodes and
  49. (currentinfo.firstchild is TDOMText) then
  50. currentauthor:=(currentinfo.firstchild as TDOMText).Data
  51. else
  52. error('Malformed author node');
  53. end
  54. else if currentinfo.NodeName='msg' then
  55. begin
  56. if currentinfo.haschildnodes then
  57. begin
  58. if (currentinfo.firstchild is TDOMText) then
  59. currentmsg:=(currentinfo.firstchild as TDOMText).Data
  60. else
  61. error('Malformed msg node');
  62. end
  63. else
  64. currentmsg:='<empty log message>';
  65. end
  66. else if currentinfo.NodeName='date' then
  67. begin
  68. if currentinfo.haschildnodes and
  69. (currentinfo.firstchild is TDOMText) then
  70. currentdate:=(currentinfo.firstchild as TDOMText).Data
  71. else
  72. error('Malformed date node');
  73. end
  74. else if currentinfo.NodeName='paths' then
  75. begin
  76. currentpath:=currentinfo.firstchild;
  77. paths.clear;
  78. while assigned(currentpath) do
  79. begin
  80. if currentpath.NodeName<>'path' then
  81. error('Path node expected');
  82. if currentpath.haschildnodes and
  83. (currentpath.firstchild is TDOMText) then
  84. paths.add((currentpath.firstchild as TDOMText).Data)
  85. else
  86. error('Malformed date node');
  87. currentpath:=currentpath.NextSibling;
  88. end;
  89. end
  90. else
  91. error('Unknown logentry child '+currentinfo.NodeName+' found');
  92. currentinfo:=currentinfo.nextsibling;
  93. end;
  94. currentdate:=copy(currentdate,1,16);
  95. { replaced T }
  96. currentdate[11]:=' ';
  97. writeln(currentdate,' ',currentauthor);
  98. writeln;
  99. { search for common prefix }
  100. maxequal:=65535;
  101. for i:=1 to paths.Count-1 do
  102. begin
  103. j:=1;
  104. while (paths[0][j]=paths[i][j]) and (j<=maxequal) do
  105. inc(j);
  106. dec(j);
  107. if j<maxequal then
  108. maxequal:=j;
  109. end;
  110. { generate prefix }
  111. pathtemp:=' * '+copy(paths[0],1,maxequal)+': ';
  112. for i:=0 to paths.Count-1 do
  113. begin
  114. hs:=copy(paths[i],maxequal+1,65535);
  115. if (length(pathtemp)+length(', '+hs)>80) and
  116. (pathtemp<>' ') then
  117. begin
  118. writeln(pathtemp+',');
  119. pathtemp:=' ';
  120. end;
  121. { non empty path but not first? }
  122. if (pathtemp<>' ') and (pathtemp[length(pathtemp)-1]<>':') then
  123. pathtemp:=pathtemp+', ';
  124. pathtemp:=pathtemp+hs;
  125. end;
  126. if pathtemp<>' ' then
  127. writeln(pathtemp);
  128. { truncate trailing new line }
  129. while currentmsg[length(currentmsg)] in [#13,#10] do
  130. delete(currentmsg,length(currentmsg),1);
  131. writeln;
  132. writeln(' ',currentmsg);
  133. writeln;
  134. end
  135. else
  136. error('Empty log entry found');
  137. entry:=entry.nextsibling;
  138. end;
  139. end
  140. else
  141. error('log element not found/wrong xml format');
  142. end.