Property deletions, modifications, and additions are now differentiated
[viewsvn.git] / includes / svnlib.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program 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; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Command line interface with the SVN commands
24 *
25 * @package ViewSVN
26 */
27
28 /**
29 * Interacts with the command line subsystem to
30 * access SVN information
31 *
32 * @package ViewSVN
33 * @version $Id$
34 */
35 class SVNLib
36 {
37 /**
38 * Path to the SVN binary
39 * @var string
40 */
41 var $svnpath;
42
43 /**
44 * Common command system
45 * @var object
46 */
47 var $common;
48
49 /**
50 * Constructor: validate SVN path
51 *
52 * @param string Path to SVN binary
53 */
54 function SVNLib($svnpath)
55 {
56 global $viewsvn;
57
58 $this->svnpath = $viewsvn->shell->cmd($svnpath);
59
60 $this->common =& new SVNCommon();
61
62 $access = $viewsvn->shell->exec($this->svnpath . ' --version');
63
64 if (!$access)
65 {
66 $viewsvn->trigger->error($viewsvn->lang->string('The SVN binary could not be located'));
67 }
68
69 if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0])))
70 {
71 $viewsvn->trigger->error($viewsvn->lang->string('The SVN binary does not appear to be valid (it failed our tests)'));
72 }
73 }
74
75 /**
76 * Prepares data for output
77 *
78 * @access public
79 *
80 * @param string Standard data
81 *
82 * @return string Output-ready data
83 */
84 function format($string)
85 {
86 // convert entities
87 $string = htmlspecialchars($string);
88
89 // tabs to 5 spaces
90 $string = str_replace("\t", ' ', $string);
91
92 // spaces to nbsp
93 if (true)
94 {
95 $string = preg_replace('#( +)#e', '$this->format_spaces("\1")', $string);
96 }
97 // no word wrap
98 else
99 {
100 $string = str_replace(' ', '&nbsp;', $string);
101 }
102
103 // convert advanced diff
104 $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('<span class="diff_add_bit">', '<span class="diff_del_bit">'), $string);
105 $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '</span>', $string);
106
107 // nl2br
108 $string = nl2br($string);
109
110 return $string;
111 }
112
113 /**
114 * Counts the spaces and replaces two or more ones
115 *
116 * @access private
117 *
118 * @param string Spaced string
119 *
120 * @return string &nbsp;'d string
121 */
122 function format_spaces($thestring)
123 {
124 if (strlen($thestring) >= 2)
125 {
126 $thestring = str_replace(' ', '&nbsp;', $thestring);
127 }
128
129 return $thestring;
130 }
131
132 /**
133 * Executes the SVN binary
134 *
135 * @access private
136 *
137 * @param string Command
138 *
139 * @return array Output
140 */
141 function svn($command)
142 {
143 global $viewsvn;
144
145 $output = $viewsvn->shell->exec($this->svnpath . ' ' . $command . ' 2>&1');
146
147 // make sure that we keep escaped chars
148 //$output = str_replace(array('\t', '\n', '\r'), array('\\\t', '\\\n', '\\\r'), $output);
149 //$output = preg_replace('#\\\(.)#', '\\\\\\\\' . '\1', $output);
150 //$output = str_replace('\\', '\\\\', $output);
151
152 $temp = implode("\n", $output);
153 if (strpos($temp, '(apr' . '_err=') !== false)
154 {
155 $viewsvn->trigger->error(nl2br($temp));
156 }
157 return $output;
158 }
159
160 /**
161 * SVN Wrapper: standard command system
162 *
163 * @access private
164 *
165 * @param string SVN command
166 * @param string Repository
167 * @param string Path
168 * @param integer Revision
169 *
170 * @return array Lines of output
171 */
172 function std($command, $repos, $path, $revision)
173 {
174 global $viewsvn;
175
176 $revision = $this->rev($revision);
177 $repospath = $viewsvn->repos->fetch_path($repos, false);
178
179 return $this->svn($command . ' ' . $repospath . $path . '@' . $revision);
180 }
181
182 /**
183 * SVN Wrapper: blame
184 *
185 * @access protected
186 *
187 * @param string Repository
188 * @param string Path
189 * @param integer Revision
190 *
191 * @return array Lines of blame output
192 */
193 function blame($repos, $path, $revision)
194 {
195 return $this->std('blame', $repos, $path, $revision);
196 }
197
198 /**
199 * SVN Wrapper: cat
200 *
201 * @access protected
202 *
203 * @param string Repository
204 * @param string Path
205 * @param integer Revision
206 *
207 * @return array Lines of cat output
208 */
209 function cat($repos, $path, $revision)
210 {
211 return $this->std('cat', $repos, $path, $revision);
212 }
213
214 /**
215 * SVN Wrapper: diff
216 *
217 * @access protected
218 *
219 * @param string Repository
220 * @param string Path
221 * @param integer Lower revision
222 * @param integer Higher revision
223 *
224 * @return array Lines of diff output
225 */
226 function diff($repos, $path, $lorev, $hirev)
227 {
228 global $viewsvn;
229
230 $hirev = $this->rev($hirev);
231 $lorev = $this->rev($lorev);
232 if ($lorev == 'HEAD')
233 {
234 $lorev = 1;
235 }
236
237 if (is_integer($hirev) AND is_integer($lorev))
238 {
239 if ($lorev > $hirev)
240 {
241 $lorev = $hirev - 1;
242 }
243 if ($lorev == $hirev)
244 {
245 $lorev = 0;
246 }
247 }
248
249 $repospath = $viewsvn->repos->fetch_path($repos, false);
250
251 return $this->svn('diff -r' . $lorev . ':' . $hirev . ' ' . $repospath . $path);
252 }
253
254 /**
255 * SVN Wrapper: log
256 *
257 * @access protected
258 *
259 * @param string Repository
260 * @param string Path
261 * @param integer Lower revision
262 * @param integer Higher revision
263 *
264 * @return array Lines of log output
265 */
266 function log($repos, $path, $lorev, $hirev)
267 {
268 global $viewsvn;
269
270 $hirev = $this->rev($hirev);
271 $lorev = $this->rev($hirev);
272 if ($lorev == 'HEAD')
273 {
274 $lorev = 0;
275 }
276
277 if (is_integer($hirev) AND is_integer($lorev))
278 {
279 if ($lorev > $hirev)
280 {
281 $lorev = $hirev - 1;
282 }
283 if ($lorev == $hirev)
284 {
285 $lorev = 0;
286 }
287 }
288
289 $repospath = $viewsvn->repos->fetch_path($repos, false);
290
291 return $this->svn('log -v -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path);
292 }
293
294 /**
295 * SVN Wrapper: ls (list)
296 *
297 * @access protected
298 *
299 * @param string Repository
300 * @param string Path
301 * @param integer Revision
302 *
303 * @return array Lines of list output
304 */
305 function ls($repos, $path, $revision)
306 {
307 return $this->std('list', $repos, $path, $revision);
308 }
309
310 /**
311 * Generates a clean revision number
312 *
313 * @access public
314 *
315 * @param integer Revision number
316 *
317 * @return mixed Cleaned revision or HEAD
318 */
319 function rev($revision)
320 {
321 if (($revision = intval($revision)) < 1)
322 {
323 $revision = 'HEAD';
324 }
325 return $revision;
326 }
327 }
328
329 /**
330 * Commonly executed SVN commands that return data
331 * used in many parts of the system
332 *
333 * @package ViewSVN
334 * @version $Id$
335 */
336 class SVNCommon
337 {
338 /**
339 * Registry object
340 * @var object
341 */
342 var $registry;
343
344 /**
345 * List of revisions
346 * @var array
347 */
348 var $revisions;
349
350 /**
351 * List of logs
352 * @var array
353 */
354 var $logs;
355
356 /**
357 * Constructor: bind with registry
358 */
359 function SVNCommon()
360 {
361 global $viewsvn;
362
363 $this->registry =& $viewsvn;
364 }
365
366 /**
367 * Checks to see if the given universal path is
368 * a directory
369 *
370 * @access public
371 *
372 * @param string Universal path
373 *
374 * @return bool Directory or not
375 */
376 function isdir($path)
377 {
378 $output = $this->registry->svn->std('info', $this->registry->paths->fetch_repos($path), $this->registry->paths->fetch_path($path), $this->registry->paths->fetch_rev_num());
379
380 foreach ($output AS $line)
381 {
382 if (preg_match('#^Node Kind: (.*)#', $line, $matches))
383 {
384 if (trim(strtolower($matches[1])) == 'directory')
385 {
386 return true;
387 }
388 }
389 }
390
391 return false;
392 }
393
394 /**
395 * Get a list of revisions for a path
396 *
397 * @access public
398 *
399 * @param string Universal path
400 *
401 * @return array Key revisions
402 */
403 function fetch_revs($path)
404 {
405 if (!isset($this->revisions["$path"]))
406 {
407 $log = $this->fetch_logs($path);
408
409 $revs = array_keys($log);
410
411 $this->revisions["$path"] = array(
412 'HEAD' => $revs[0],
413 'START' => $revs[ count($revs) - 1 ],
414 'revs' => $revs
415 );
416 }
417
418 return $this->revisions["$path"];
419 }
420
421 /**
422 * Gets the revision that is marked as HEAD
423 *
424 * @access public
425 *
426 * @param string Universal path
427 *
428 * @return integer Revision
429 */
430 function fetch_head_rev($path)
431 {
432 $output = $this->registry->shell->exec($this->registry->svn->svnpath . ' info ' . $this->registry->repos->fetch_path($this->registry->paths->fetch_repos($path), false) . $this->registry->paths->fetch_path($path));
433
434 foreach ($output AS $line)
435 {
436 if (preg_match('#^Last Changed Rev: (.*)#', $line, $matches))
437 {
438 return $matches[1];
439 }
440 }
441
442 $revs = $this->fetch_revs($path);
443 return $revs['HEAD'];
444 }
445
446 /**
447 * Returns the previous revision to the one given
448 *
449 * @access public
450 *
451 * @param string Universal path
452 * @param integer Arbitrary revision
453 *
454 * @return integer Previous revision (-1 if none)
455 */
456 function fetch_prev_rev($path, $current)
457 {
458 global $viewsvn;
459
460 $revs = $this->fetch_revs($path);
461
462 if ($current == 'HEAD')
463 {
464 $current = $this->fetch_head_rev($path);
465 }
466
467 $index = array_search($current, $revs['revs']);
468 if ($current === false)
469 {
470 $message->trigger->error(sprintf($viewsvn->lang->string('Revision r%1$s is not in path %2$s'), $current, $path));
471 }
472
473 if (isset($revs['revs'][ $index + 1 ]))
474 {
475 return $revs['revs'][ $index + 1 ];
476 }
477 else
478 {
479 return -1;
480 }
481 }
482
483 /**
484 * Get a list of logs
485 *
486 * @access public
487 *
488 * @param string Universal path
489 * @param bool Override the cache system?
490 *
491 * @return array Log data
492 */
493 function fetch_logs($path)
494 {
495 if (!isset($this->logs["$path"]))
496 {
497 $log = new SVNLog($this->registry->paths->fetch_repos($path), $this->registry->paths->fetch_path($path), 0, $this->registry->paths->fetch_rev_num());
498
499 $this->logs["$path"] = $log->fetch();
500 }
501
502 return $this->logs["$path"];
503 }
504
505 /**
506 * Returns a given log entry for a path
507 * and revision
508 *
509 * @access public
510 *
511 * @param string Universal path
512 * @param integer Arbitrary revision
513 *
514 * @return array Log entry
515 */
516 function fetch_log($path, $rev)
517 {
518 $logs = $this->fetch_logs($path);
519
520 $rev = $this->registry->svn->rev($rev);
521 if ($rev == 'HEAD')
522 {
523 $rev = $this->fetch_head_rev($path);
524 }
525
526 if (isset($logs["$rev"]))
527 {
528 return $logs["$rev"];
529 }
530 else
531 {
532 $keys = array_keys($logs);
533 sort($keys);
534
535 for ($i = 0; $i < count($keys); $i++)
536 {
537 if ($rev > $keys["$i"] AND $rev < $keys[ $i + 1 ])
538 {
539 return $logs["$keys[$i]"];
540 }
541 }
542
543 return null;
544 }
545 }
546
547 /**
548 * Prints the file changed list
549 *
550 * @access public
551 *
552 * @public array List of file changes
553 * @public string The repository
554 * @public integer Current revision
555 *
556 * @return string Processed HTML
557 */
558 function construct_file_changes($changes, $repos, $revision)
559 {
560 global $viewsvn;
561
562 $files = '';
563
564 foreach ($changes AS $file)
565 {
566 switch ($file['action'])
567 {
568 case 'A':
569 $class = 'file_add';
570 $tooltip = $viewsvn->lang->string('Added');
571 break;
572 case 'D':
573 $class = 'file_delete';
574 $tooltip = $viewsvn->lang->string('Deleted');
575 break;
576 case 'M':
577 $class = 'file_modify';
578 $tooltip = $viewsvn->lang->string('Modified');
579 break;
580 case 'R':
581 $class = 'file_replace';
582 $tooltip = $viewsvn->lang->string('Replaced');
583 break;
584 }
585
586 $show['from'] = (bool)$file['from'];
587
588 if ($file['from'])
589 {
590 $class = 'file_move';
591 $tooltip = 'Moved/Copied';
592 preg_match('#(.*):([0-9]+)#', $file['from'], $matches);
593 $link['from'] = $viewsvn->paths->out('view.php' . $viewsvn->paths->fetch_rev_str(false, $matches[2]), $repos . $matches[1]);
594 }
595
596 $link['file'] = $viewsvn->paths->out('view.php' . $viewsvn->paths->fetch_rev_str(false, $revision), $repos . $file['file']);
597
598 eval('$files .= "' . $viewsvn->template->fetch('file_change') . '";');
599 }
600
601 return $files;
602 }
603 }
604
605 /**
606 * Annotation/blame system; constructs an array
607 * that is ready for output
608 *
609 * @package ViewSVN
610 * @version $Id$
611 */
612 class SVNBlame
613 {
614 /**
615 * Array of blame information
616 * @var array
617 */
618 var $blame = array();
619
620 /**
621 * Raw "svn blame" output
622 * @var array
623 */
624 var $rawoutput;
625
626 /**
627 * Constructor: create blame and store data
628 *
629 * @param string Repository
630 * @param string Path
631 * @param integer Revision
632 */
633 function SVNBlame($repos, $path, $revision)
634 {
635 global $viewsvn;
636
637 $this->rawoutput = $viewsvn->svn->blame($repos, $path, $revision);
638 $this->process();
639 }
640
641 /**
642 * Returns blame for display
643 *
644 * @access public
645 *
646 * @return array Blame data
647 */
648 function fetch()
649 {
650 return $this->blame;
651 }
652
653 /**
654 * Parses the blame data
655 *
656 * @access private
657 */
658 function process()
659 {
660 $lineno = 1;
661
662 foreach ($this->rawoutput AS $line)
663 {
664 if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches))
665 {
666 $this->blame[] = array(
667 'rev' => $matches[1],
668 'author' => $matches[2],
669 'line' => $matches[3],
670 'lineno' => $lineno++
671 );
672 }
673 // a blank line
674 else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches))
675 {
676 $this->blame[] = array(
677 'rev' => $matches[1],
678 'author' => $matches[2],
679 'line' => '',
680 'lineno' => $lineno++
681 );
682 }
683 }
684 }
685 }
686
687 /**
688 * Log management system; creates a complex list
689 * of SVN log information
690 *
691 * @package ViewSVN
692 * @version $Id$
693 */
694 class SVNLog
695 {
696 /**
697 * Array of logs
698 * @var array
699 */
700 var $logs = array();
701
702 /**
703 * Raw "svn log" output
704 * @var array
705 */
706 var $rawoutput;
707
708 /**
709 * Constructor: create log store for the given file
710 *
711 * @param string Repository
712 * @param string Path
713 * @param integer Lower revision
714 * @param integer Higher revision
715 */
716 function SVNLog($repos, $path, $lorev, $hirev)
717 {
718 global $viewsvn;
719
720 $this->rawoutput = $viewsvn->svn->log($repos, $path, $lorev, $hirev);
721 $this->process();
722 }
723
724 /**
725 * Returns logs for display
726 *
727 * @access public
728 *
729 * @return array Log data
730 */
731 function fetch()
732 {
733 return $this->logs;
734 }
735
736 /**
737 * Splits up the raw output into a usable log
738 *
739 * @access private
740 */
741 function process()
742 {
743 $lastrev = 0;
744
745 for ($i = 1; $i <= count($this->rawoutput) - 1; $i++)
746 {
747 $line = $this->rawoutput["$i"];
748
749 if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
750 {
751 if (isset($this->logs["$lastrev"]))
752 {
753 $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
754 }
755
756 $this->logs["$matches[1]"] = array(
757 'rev' => $matches[1],
758 'author' => $matches[2],
759 'date' => $matches[3],
760 'timezone' => $matches[4],
761 'lines' => $matches[6],
762 'message' => ''
763 );
764
765 $lastrev = $matches[1];
766 }
767 else if (preg_match('#^\s+([ADMR])\s(.*)#', $line, $matches))
768 {
769 if (preg_match('#(.*) \(from (.*?)\)$#', $matches[2], $amatches))
770 {
771 $matches[2] = $amatches[1];
772 }
773
774 $this->logs["$lastrev"]['files'][] = array(
775 'action' => $matches[1],
776 'file' => trim($matches[2]),
777 'from' => (isset($amatches[2]) ? $amatches[2] : '')
778 );
779 }
780 else
781 {
782 if (trim($line) != 'Changed paths:')
783 {
784 $this->logs["$lastrev"]['message'] .= $line . "\n";
785 }
786 }
787 }
788
789 if (isset($this->logs["$lastrev"]))
790 {
791 $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
792 }
793 }
794
795 /**
796 * Trims the last dash line off a message
797 *
798 * @access private
799 *
800 * @param string Message with annoying-ass line
801 *
802 * @return string Clean string
803 */
804 function strip_last_line($string)
805 {
806 return trim(preg_replace("#\n(.*?)\n$#", '', $string));
807 }
808 }
809
810 /**
811 * Diff system; constructs a diff array that
812 * is ready for output
813 *
814 * @package ViewSVN
815 */
816 class SVNDiff
817 {
818 /**
819 * Array of diff information
820 * @var array
821 */
822 var $diff = array();
823
824 /**
825 * Raw "svn diff" output
826 * @var array
827 */
828 var $rawoutput;
829
830 /**
831 * Constructor: create and store diff data
832 *
833 * @param string Repository
834 * @param string Path
835 * @param integer Lower revision
836 * @param integer Higher revision
837 */
838 function SVNDiff($repos, $path, $lorev, $hirev)
839 {
840 global $viewsvn;
841
842 $this->rawoutput = $viewsvn->svn->diff($repos, $path, $lorev, $hirev);
843 $this->process();
844 }
845
846 /**
847 * Returns diffs for display
848 *
849 * @access public
850 *
851 * @return array Diff data
852 */
853 function fetch()
854 {
855 return $this->diff;
856 }
857
858 /**
859 * Processes and prepares diff data
860 *
861 * @access private
862 */
863 function process()
864 {
865 global $viewsvn;
866
867 $chunk = 0;
868 $indexcounter = null;
869 $curprop = '';
870
871 $delstack = array();
872
873 foreach ($this->rawoutput AS $line)
874 {
875 if (preg_match('#^@@ \-([0-9]*),([0-9]*) \+([0-9]*),([0-9]*) @@$#', $line, $bits))
876 {
877 $property = false;
878 $delstack = array();
879 $this->diff["$index"][ ++$chunk ]['hunk'] = array('old' => array('line' => $bits[1], 'count' => $bits[2]), 'new' => array('line' => $bits[3], 'count' => $bits[4]));
880 $lines['old'] = $this->diff["$index"]["$chunk"]['hunk']['old']['line'] - 1;
881 $lines['new'] = $this->diff["$index"]["$chunk"]['hunk']['new']['line'] - 1;
882 continue;
883 }
884 else if (preg_match('#^Property changes on: (.*?)$#', $line, $bits))
885 {
886 $property = true;
887 $index = $bits[1];
888 $this->diff["$index"]['props'] = array();
889 continue;
890 }
891
892 if ($indexcounter <= 3 AND $indexcounter !== null)
893 {
894 $indexcounter++;
895 continue;
896 }
897 else if ($indexcounter == 3)
898 {
899 $indexcounter = null;
900 continue;
901 }
902
903 if (preg_match('#^([\+\- ])(.*)#', $line, $matches) AND !$property)
904 {
905 $act = $matches[1];
906 $content = $matches[2];
907
908 if ($act == ' ')
909 {
910 $this->diff["$index"]["$chunk"][] = array(
911 'line' => $content,
912 'act' => '',
913 'oldlineno' => ++$lines['old'],
914 'newlineno' => ++$lines['new']
915 );
916
917 $delstack = array();
918 }
919 else if ($act == '+')
920 {
921 // potential line delta
922 if (count($delstack) > 0)
923 {
924 $lastline = array_shift($delstack);
925
926 if ($delta = @$this->fetch_diff_extent($lastline['line'], $content))
927 {
928 if (strlen($lastline['line']) > ($delta['start'] - $delta['end']))
929 {
930 $end = strlen($lastline['line']) + $delta['end'];
931 $viewsvn->debug("RM delta- = " . $end);
932 $change = '{@-' . '-}' . substr($lastline['line'], $delta['start'], $end - $delta['start']) . '{/@-' . '-}';
933 $this->diff["$index"]["$chunk"]["$lastline[INDEX]"]['line'] = substr($lastline['line'], 0, $delta['start']) . $change . substr($lastline['line'], $end);
934 }
935
936 if (strlen($content) > $delta['start'] - $delta['end'])
937 {
938 $end = strlen($content) + $delta['end'];
939 $viewsvn->debug("MK delta+ = " . $end);
940 $change = '{@+' . '+}' . substr($content, $delta['start'], $end - $delta['start']) . '{/@+' . '+}';
941 $content = substr($content, 0, $delta['start']) . $change . substr($content, $end);
942 }
943 }
944 }
945
946 $this->diff["$index"]["$chunk"][] = array(
947 'line' => $content,
948 'act' => '+',
949 'oldlineno' => '',
950 'newlineno' => ++$lines['new']
951 );
952 }
953 else if ($act == '-')
954 {
955 $this->diff["$index"]["$chunk"][] = $thearray = array(
956 'line' => $content,
957 'act' => '-',
958 'oldlineno' => ++$lines['old'],
959 'newlineno' => ''
960 );
961
962 $key = count($this->diff["$index"]["$chunk"]) - 2;
963 $thearray['INDEX'] = $key;
964
965 array_push($delstack, $thearray);
966 }
967 }
968 // whitespace lines
969 else
970 {
971 if (preg_match('#^Index: (.*?)$#', $line, $matches))
972 {
973 $index = $matches[1];
974 $indexcounter = 1;
975 $chunk = 0;
976 continue;
977 }
978
979 if ($property)
980 {
981 if (preg_match('#^__*_$#', trim($line)))
982 {
983 $viewsvn->debug("skipping: $line");
984 continue;
985 }
986
987 if (preg_match('#Name: (.*?)$#', $line, $matches))
988 {
989 $curprop = $matches[1];
990 $viewsvn->debug("prop: $curprop");
991 continue;
992 }
993 else
994 {
995 if (preg_match('#^\s+?\+(.*)#', $line, $matches))
996 {
997 $mode = 'add';
998 $this->diff["$index"]['props']["$curprop"]['add'] .= $matches[1];
999 }
1000 else if (preg_match('#^\s+?\-(.*)#', $line, $matches))
1001 {
1002 $mode = 'del';
1003 $this->diff["$index"]['props']["$curprop"]['del'] .= $matches[1];
1004 }
1005 else if (!preg_match('#^\s+[\+\- ](.*)#', $line) AND trim($line) != '')
1006 {
1007 $this->diff["$index"]['props']["$curprop"]["$mode"] .= "\n" . $line;
1008 }
1009 continue;
1010 }
1011 }
1012
1013 $this->diff["$index"]["$chunk"][] = array(
1014 'line' => '',
1015 'act' => '',
1016 'oldlineno' => ++$lines['old'],
1017 'newlineno' => ++$lines['new']
1018 );
1019
1020 $delstack = array();
1021 }
1022 }
1023 }
1024
1025 /**
1026 * Returns the amount of change that occured
1027 * between two lines
1028 *
1029 * @access private
1030 *
1031 * @param string Old line
1032 * @param string New line
1033 *
1034 * @return array Difference of positions
1035 */
1036 function fetch_diff_extent($old, $new)
1037 {
1038 global $viewsvn;
1039
1040 $start = 0;
1041 $min = min(strlen($old), strlen($new));
1042
1043 $viewsvn->debug("min1 = $min");
1044
1045 while ($start < $min AND $old{"$start"} == $new{"$start"})
1046 {
1047 $start++;
1048 }
1049
1050 $end = -1;
1051 $min = $min - $start;
1052
1053 $viewsvn->debug("min2 = $min");
1054
1055 $viewsvn->debug("checking: " . $old{ strlen($old) + $end } . ' == ' . $new{ strlen($new) + $end });
1056
1057 while (-$end <= $min AND $old{ strlen($old) + $end } == $new{ strlen($new) + $end })
1058 {
1059 $end--;
1060 }
1061
1062 return array('start' => $start, 'end' => $end + 1);
1063 }
1064 }
1065
1066 /*=====================================================================*\
1067 || ###################################################################
1068 || # $HeadURL$
1069 || # $Id$
1070 || ###################################################################
1071 \*=====================================================================*/
1072 ?>