2
0

svn2cl.pp 4.7 KB

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