-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalyse.svn.diff.pl
More file actions
executable file
·791 lines (651 loc) · 24.2 KB
/
analyse.svn.diff.pl
File metadata and controls
executable file
·791 lines (651 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
#!/usr/bin/perl -I ./thirds -w
# author: lilong'en(lilongen@163.com)
# date: 11/14/2010
# add this file to implement:
# 1. LOC between two Revision
# 2. svn web diff individually (without ViewVC)
#
use strict;
use English;
use Data::Dumper;
use CGI;
use Assistor;
use CcvUtil;
use bytes;
no warnings 'reserved';
sub main();
sub print_loc_info();
sub write_data_to_file();
sub generate_group_items();
sub write_flat_items();
sub get_flat_item($);
sub construct_tree();
sub parse_command_line();
sub output($);
sub handle_file_finished();
sub get_file_shown_info($);
sub get_directory_suffix_info($);
sub friend_revs_dates_4UI();
sub replacePart1PMS($$);
sub replacePart2PMS($);
sub get_independent_file_diff_url($);
sub parse_unified_format();
sub persistence_module_info($$$);
sub setGV();
sub resetSumInfo();
sub resetFileInfo();
sub initGlobals();
#parameters for construct Assistor object
my $CFG = "";
my $T_SNAP = "";
my $MID = "";
parse_command_line();
my $GV = {};
my $G_SumInfo = {};
my $G_FileInfo = {};
my $G_Flags = {};
my $G_H_TEXT_FILE = undef;
my $G_H_MODULE_TEXT_FILE = undef;
my $G_H_GROUP_HTML_FILE = undef; ;
my $G_H_FLAT_HTML_FILE = undef;
my $G_H_DIFF = undef;
my $assistor = new Assistor($CFG, $T_SNAP); $assistor->getModules();
my $moduleInfo = $assistor->get_module_info_by_module_id($MID);
my $ccvUtil = new CcvUtil();
my $pms = $ccvUtil->loadFile($assistor->get_specified_operate_file("PMS"));
sub setGV() {
$GV->{revsDates} = $pms->{dfRevs} || $pms->{dfDates};
$GV->{dfOutFile} = $assistor->get_revisions_module_diff_out_file($GV->{revsDates}, $moduleInfo->{diff});
$GV->{dfOutFileUrl} = "/ccv/" . $GV->{dfOutFile};
#Error define
# 0: no error
# 1: acount id/passwd not correct
# 2: no such tag/revision
#
$GV->{Error} = 0;
$GV->{ErrorString} = "";
$GV->{ExDirLevels} = 4;
$GV->{DiffViewer} = "/ccv-cgi/svn.differ.pl?AT=DF&DF=%s&OB=%d&OE=%d";
$GV->{InitStatus} = 1;
$GV->{AllBriefReportFile} = $assistor->get_brief_report_file();
$GV->{ModuleBriefReportFile}= $assistor->get_module_brief_report_file($MID);
}
sub resetSumInfo() {
$G_SumInfo->{fileCnt} = 0;
$G_SumInfo->{lines} = 0;
$G_SumInfo->{linesAdded} = 0;
$G_SumInfo->{linesRemoved} = 0;
$G_SumInfo->{fsCntUnexistInLeft} = 0;
$G_SumInfo->{fsCntUnexistInRight}= 0;
$G_SumInfo->{flatItems} = [];
$G_SumInfo->{newFiles} = [];
$G_SumInfo->{binFiles} = [];
$G_SumInfo->{removedFiles} = [];
$G_SumInfo->{items} = {};
$G_SumInfo->{tempItems} = $G_SumInfo->{items};
$G_SumInfo->{tempPrevItems} = $G_SumInfo->{tempItems};
$G_SumInfo->{lefts} = [];
$G_SumInfo->{treeItems} = [];
}
sub resetFileInfo() {
$G_FileInfo->{file} = "";
$G_FileInfo->{r1} = "";
$G_FileInfo->{r2} = "";
$G_FileInfo->{unExistIn} = "";
$G_FileInfo->{linesAdded} = 0;
$G_FileInfo->{linesRemoved} = 0;
$G_FileInfo->{OffsetStart} = 0;
$G_FileInfo->{OffsetEnd} = 0;
$G_FileInfo->{isBinary} = 0;
}
sub initGlobals() {
setGV();
resetSumInfo();
resetFileInfo();
}
exit main();
sub main() {
initGlobals();
if (!open($G_H_DIFF, $GV->{dfOutFile})) {
output("Can not open $GV->{dfOutFile}!\n");
return 1;
}
parse_unified_format();
close($G_H_DIFF);
unshift(@{$G_SumInfo->{flatItems}}, @{$G_SumInfo->{newFiles}}); # put new added files into first
unshift(@{$G_SumInfo->{flatItems}}, @{$G_SumInfo->{removedFiles}}); # put removed files into first
push(@{$G_SumInfo->{flatItems}}, @{$G_SumInfo->{binFiles}}); # last binary file in array
print_loc_info();
write_data_to_file();
return 0;
}
sub parse_unified_format() {
my $fileBeginLineNo = -1;
my $lineNo = -1;
my $line = "";
my $flagFileFound = 0;
while (1) {
$line = <$G_H_DIFF>;
if (!defined($line)) {
if ($flagFileFound == 1) {
$G_FileInfo->{OffsetEnd} = tell($G_H_DIFF);
handle_file_finished();
}
$G_SumInfo->{tempItems} = $G_SumInfo->{items};
$G_SumInfo->{tempPrevItems} = $G_SumInfo->{tempItems};
$G_SumInfo->{lines} = $G_SumInfo->{linesAdded} + $G_SumInfo->{linesRemoved};
last;
}
if ($lineNo++ == -1) {
if ($line !~ m/^Index: (.*)$/) { # no such tag, and so on
$GV->{Error} = 2;
$GV->{ErrorString} = $line;
last;
}
}
#Index: res/strings/bulid.xml
#===================================================================
#--- res/strings/bulid.xml (revision 0)
#+++ res/strings/bulid.xml (revision 1000)
#@@ -0,0 +1,45 @@
if ($line =~ m/^Index: (.*)$/) {
$fileBeginLineNo = $lineNo;
if ($flagFileFound == 1 && $G_SumInfo->{fileCnt} > 0) {
$G_FileInfo->{OffsetEnd} = tell($G_H_DIFF) - length($line);
handle_file_finished();
}
my $fileExt = substr($1, rindex($1, "."));
if ($moduleInfo->{file_filter} eq ".*"
|| index($moduleInfo->{file_filter}, $fileExt) != -1) {
$flagFileFound = 1;
$G_FileInfo->{file} = $1;
$G_FileInfo->{OffsetStart} = tell($G_H_DIFF) - length($line);
$G_SumInfo->{fileCnt}++;
next;
} else {
$flagFileFound = 0;
next;
}
}
#print "fileBeginLineNo: $fileBeginLineNo -- lineNo: $lineNo -- $line";
if ($flagFileFound == 1 && $lineNo == ($fileBeginLineNo + 1)) {
next;
}
if ($flagFileFound == 1 && $lineNo == ($fileBeginLineNo + 2)) {
if ($line =~ m/^\-\-\-\s+.*\s+\(revision (\d+)\)$/) {
$G_FileInfo->{r1} = $1;
$G_FileInfo->{isBinary} = 0;
} else {
$G_FileInfo->{r1} = "";
$G_FileInfo->{isBinary} = 1;
}
next;
}
if ($flagFileFound == 1 && $lineNo == ($fileBeginLineNo + 3)) {
if ($line =~ m/^\+\+\+\s+.*\s+\(revision (\d+)\)$/) {
$G_FileInfo->{r2} = $1;
} else {
$G_FileInfo->{r2} = "";
}
next;
}
#@@ -0,0 +1,160 @@
#@@ -1 +1 @@
if ($flagFileFound == 1
&& $lineNo == ($fileBeginLineNo + 4)) {
if ($line =~ m/^\@\@ -(\d+),(\d+) +(\d+),(\d+) \@\@$/) {
if ($1 == 0 && $2 == 0) {
$G_FileInfo->{unExistIn} = "L";
$G_SumInfo->{fsCntUnexistInLeft} ++;
} elsif ($3 == 0 && $4 == 0) {
$G_FileInfo->{unExistIn} = "R";
$G_SumInfo->{fsCntUnexistInRight} ++;
} else {
$G_FileInfo->{unExistIn} = "";
}
}
next;
}
if ($flagFileFound == 1
&& $lineNo > ($fileBeginLineNo + 4)
&& $line =~ m/^([\-\+])/) {
if ($1 eq "+") {
$G_FileInfo->{linesAdded} ++;
} elsif ($1 eq "-") {
$G_FileInfo->{linesRemoved} ++;
}
}
} #end while
}
sub handle_file_finished() {
#clone hash reference
my %item = %{$G_FileInfo};
my $fileItem = \%item;
my @directorys = split(/[\/\\]+/, $G_FileInfo->{file});
$fileItem->{SELF} = $directorys[$#directorys];
my $dir_levels = $#directorys;
for (my $level = 0; $level < $dir_levels; $level++) {
if (!defined($G_SumInfo->{tempItems}->{$directorys[$level]})) {
$G_SumInfo->{tempItems}->{$directorys[$level]} = {};
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'} = {};
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{LEVEL} = $level;
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{HANDLED} = 0;
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{SELF} = $directorys[$level];
if ($level == 0) {
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{PARENT} = "";
} else {
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{PARENT} = $G_SumInfo->{tempPrevItems}->{$directorys[$level - 1]}->{'__CCV_INFO__'}->{PARENT} . $directorys[$level - 1] . "/";
}
}
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{'FILES'} ++ ;
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{'LINE_ADDED'} += $fileItem->{linesAdded};
$G_SumInfo->{tempItems}->{$directorys[$level]}->{'__CCV_INFO__'}->{'LINE_REMOVED'} += $fileItem->{linesRemoved};
$G_SumInfo->{tempPrevItems} = $G_SumInfo->{tempItems};
$G_SumInfo->{tempItems} = $G_SumInfo->{tempItems}->{$directorys[$level]};
}
$fileItem->{LEVEL} = $G_SumInfo->{tempPrevItems}->{$directorys[$dir_levels - 1]}->{'__CCV_INFO__'}->{LEVEL} + 1;
$fileItem->{PARENT} = $G_SumInfo->{tempPrevItems}->{$directorys[$dir_levels - 1]}->{'__CCV_INFO__'}->{PARENT} . $directorys[$dir_levels - 1] . "/";
$G_SumInfo->{tempItems}->{$directorys[$dir_levels]} = $fileItem;
$G_SumInfo->{tempItems} = $G_SumInfo->{items};
if ($fileItem->{unExistIn} eq 'L' ) {
push(@{$G_SumInfo->{newFiles}}, $fileItem);
} elsif ($fileItem->{unExistIn} eq "R") {
push(@{$G_SumInfo->{removedFiles}}, $fileItem);
} elsif ($G_FileInfo->{isBinary}) {
push(@{$G_SumInfo->{binFiles}}, $fileItem);
} else {
push(@{$G_SumInfo->{flatItems}}, $fileItem);
}
$G_SumInfo->{linesAdded} += $fileItem->{linesAdded};
$G_SumInfo->{linesRemoved} += $fileItem->{linesRemoved};
resetFileInfo();
}
sub write_data_to_file() {
if (!open($G_H_TEXT_FILE, ">>", "$GV->{AllBriefReportFile}")) {
output("Can not create/open $GV->{AllBriefReportFile}!\n");
return 1;
}
if (!open($G_H_MODULE_TEXT_FILE, ">>", "$GV->{ModuleBriefReportFile}")) {
output("Can not create/open $GV->{ModuleBriefReportFile}!\n");
return 1;
}
my $HTML_TEMPLATE = $assistor->get_report_template_file("DIFF");
my $node_flag = "#NODE#";
my $template = $assistor->read_whole_file($HTML_TEMPLATE);
my $node_pos = index($template, $node_flag);
my $part1 = substr($template, 0, $node_pos);
my $part2 = substr($template, $node_pos + length($node_flag));
my $file_part1 = $part1;
my $group_html_out_file = $assistor->get_specified_output_report_file({flag => "DIFF_GROUP", revs => $GV->{revsDates}, mid=> $MID});
my $flat_html_out_file = $assistor->get_specified_output_report_file({flag => "DIFF_FLAT", revs => $GV->{revsDates}, mid=> $MID});
if (!open($G_H_GROUP_HTML_FILE, ">", "$group_html_out_file")) {
output("Can not create/open $group_html_out_file!\n");
return 1;
}
if (!open($G_H_FLAT_HTML_FILE, ">", "$flat_html_out_file")) {
output("Can not create/open $flat_html_out_file!\n");
return 1;
}
my $moduleSvnUrl = $assistor->get_svn_module_url($moduleInfo, "", "trunk");
friend_revs_dates_4UI();
my $module_brief_txt = sprintf("Module: %s (%s - %s); Revision1: %s; Revision2: %s; Date1: %s; Date2: %s,,\n",
$MID,
$moduleInfo->{module},
$moduleSvnUrl,
$pms->{r1},
$pms->{r2},
$pms->{d1},
$pms->{d2});
$module_brief_txt .= sprintf("LOC, FOC\n%07d, %04d\n\n",
$G_SumInfo->{lines},
$G_SumInfo->{fileCnt});
my $LOC = sprintf("%d(+%d, -%d)\n",
$G_SumInfo->{lines},
$G_SumInfo->{linesAdded},
$G_SumInfo->{linesRemoved});
my $diff_group_report_url = $assistor->transReportLocalPath2WebPath($assistor->get_specified_output_report_file({flag => "DIFF_GROUP", revs => $GV->{revsDates}, mid=> $MID}));
my $diff_flat_report_url = $assistor->transReportLocalPath2WebPath($assistor->get_specified_output_report_file({flag => "DIFF_FLAT", revs => $GV->{revsDates}, mid=> $MID}));
my $module_rdiff_brief_report_url = $assistor->transReportLocalPath2WebPath($assistor->get_module_brief_report_file($MID));
my $rdiff_brief_report_url = $assistor->transReportLocalPath2WebPath($assistor->get_brief_report_file());
my $template_parametrs = {'MODULE' => $moduleInfo->{module},
'SVN_URL' => $moduleSvnUrl,
'REVISION1' => $pms->{r1},
'REVISION2' => $pms->{r2},
'DATE1' => $pms->{d1},
'DATE2' => $pms->{d2},
'FOC' => $G_SumInfo->{fileCnt},
'LOC' => $LOC,
'CURRENT_URL' => "",
'CURRENT_NAME' => "",
'OTHER_URL' => $diff_flat_report_url,
'OTHER_NAME' => "Flat",
'MODULE_PLAIN_REPORT' => $module_rdiff_brief_report_url,
'PLAIN_REPORT' => $rdiff_brief_report_url};
replacePart1PMS(\$part1, $template_parametrs);
$template_parametrs->{OTHER_URL} = $diff_group_report_url;
$template_parametrs->{OTHER_NAME} = "Tree";
replacePart1PMS(\$file_part1, $template_parametrs);
replacePart2PMS(\$part2);
if ($GV->{Error} != 0) {
$GV->{ErrorString} = "<font size='8pt' color='#ff0000'><b>" . $GV->{ErrorString} . "</b></font><br/><br/>";
}
print $G_H_GROUP_HTML_FILE $part1;
if ($GV->{Error} == 0) {# no error
generate_group_items();
construct_tree();
} else {
print $G_H_GROUP_HTML_FILE $GV->{ErrorString};
}
print $G_H_GROUP_HTML_FILE $part2;
print $G_H_FLAT_HTML_FILE $file_part1;
if ($GV->{Error} == 0) {# no error
write_flat_items();
} else {
print $G_H_FLAT_HTML_FILE $GV->{ErrorString};
}
print $G_H_FLAT_HTML_FILE $part2;
print $G_H_TEXT_FILE $module_brief_txt . "\n\n";
print $G_H_MODULE_TEXT_FILE $module_brief_txt . "\n\n";
close($G_H_TEXT_FILE);
close($G_H_MODULE_TEXT_FILE);
close($G_H_GROUP_HTML_FILE);
close($G_H_FLAT_HTML_FILE);
persistence_module_info($MID, $G_SumInfo->{fileCnt}, $G_SumInfo->{lines});
return 0;
}
sub persistence_module_info($$$) {
my $mid = shift;
my $foc = shift;
my $loc = shift;
my $data = {};
$data->{$mid} = {foc => $foc, loc => $loc};
my $G_ALL_MODULES_INFO_FILE = $assistor->get_all_modules_sum_info_data_file();
my $tmp;
if (-e $G_ALL_MODULES_INFO_FILE) {
$tmp = $ccvUtil->loadFile($G_ALL_MODULES_INFO_FILE);
$tmp->{$mid} = $data->{$mid};
} else {
$tmp = $data;
}
$ccvUtil->dumpFile($G_ALL_MODULES_INFO_FILE, $tmp);
}
sub replacePart1PMS($$){
my $content = $_[0];
my $paras = $_[1];
$$content =~ s/#BODY_CLS#/svn/;
$$content =~ s/#MODULE#/$paras->{MODULE}/;
$$content =~ s/#MODULE_URI#/$paras->{SVN_URL}/;
$$content =~ s/#REVISION1#/$paras->{REVISION1}/;
$$content =~ s/#REVISION2#/$paras->{REVISION2}/;
$$content =~ s/#DATE1#/$paras->{DATE1}/;
$$content =~ s/#DATE2#/$paras->{DATE2}/;
$$content =~ s/#FOC#/$paras->{FOC}/;
$$content =~ s/#LOC#/$paras->{LOC}/;
$$content =~ s/#OTHER_URL#/$paras->{OTHER_URL}/;
$$content =~ s/#OTHER_NAME#/$paras->{OTHER_NAME}/;
$$content =~ s/#DIFF_FILE#/$GV->{dfOutFileUrl}/;
$$content =~ s/#MODULE_PLAIN_REPORT#/$paras->{MODULE_PLAIN_REPORT}/;
$$content =~ s/#PLAIN_REPORT#/$paras->{PLAIN_REPORT}/;
}
sub replacePart2PMS($) {
my $content = $_[0];
my $GV_IN_JS =<<GV_IN_JS;
{
T_SNAP: "$T_SNAP",
MID: "$MID",
Error: "$GV->{Error}",
ShowGraphEntry: "0",
ShowSrcDetails: "0",
ReportType: "SVN_DIFF"
}
GV_IN_JS
$$content =~ s/#GV#/$GV_IN_JS/;
}
sub friend_revs_dates_4UI() {
my $HEAD = "HEAD(MAIN)";
if ($pms->{r1} eq "_CCV_NULL_" && $pms->{r2} eq "_CCV_NULL_") {
$pms->{r1} = "N/A";
$pms->{r2} = "N/A";
} else {
if (!($pms->{r1} ne "_CCV_NULL_" && $pms->{r2} ne "_CCV_NULL_")) {
$pms->{r1} = ($pms->{r1} ne "_CCV_NULL_" ? $pms->{r1} : $pms->{r2});
$pms->{r2} = $HEAD;
}
}
if ($pms->{d1} eq "_CCV_NULL_" && $pms->{d2} eq "_CCV_NULL_") {
$pms->{d1} = "N/A";
$pms->{d2} = "N/A";
} else {
if (!($pms->{d1} ne "_CCV_NULL_" && $pms->{d2} ne "_CCV_NULL_")) {
$pms->{d1} = ($pms->{d1} ne "_CCV_NULL_" ? $pms->{d1} : $pms->{d2});
$pms->{d2} = $HEAD;
}
}
}
#use stack method to replace recursive calling
sub generate_group_items() {
while (1) {
if ($GV->{InitStatus} == 1 || defined($G_SumInfo->{tempItems}->{__CCV_INFO__})) { # directory
$GV->{InitStatus} = 0;
my @curr_keys = sort {
lc($a) cmp lc($b) # compare with key
} keys %{$G_SumInfo->{tempItems}};
my $checked_length = $#curr_keys;
for (my $index = 0; $index <= $checked_length; $index++) {
if ($curr_keys[$index] ne "__CCV_INFO__" && !defined($G_SumInfo->{tempItems}->{$curr_keys[$index]}->{__CCV_INFO__})) { # file
my $kname = $curr_keys[$index];
splice(@curr_keys, $index, 1);
push(@curr_keys, $kname);
$checked_length --;
$index --;
}
}
for (my $i = $#curr_keys; $i >= 0; $i--) {
if (defined($G_SumInfo->{tempItems}->{$curr_keys[$i]}->{__CCV_INFO__})) { # directory
push(@{$G_SumInfo->{lefts}}, $G_SumInfo->{tempItems}->{$curr_keys[$i]});
next;
} else { # file
if ($curr_keys[$i] eq "__CCV_INFO__") {
next;
}
push(@{$G_SumInfo->{lefts}}, $G_SumInfo->{tempItems}->{$curr_keys[$i]});
}
}
}
if ($#{$G_SumInfo->{lefts}} < 0) {
last;
}
$G_SumInfo->{tempItems} = pop(@{$G_SumInfo->{lefts}});
push(@{$G_SumInfo->{treeItems}}, $G_SumInfo->{tempItems});
}
}
sub construct_tree() {
my $tree_string = "";
my $suffix = "";
my $item = "";
my $level = -1;
my $previous_level = -1;
my $previous_is_directory = 0;
my $is_directory = 0;
my $delta_level = 0;
my $dir_operator_style = "";
my $dir_display = "";
my $dir_suffix_info = "";
for (my $i = 0; $i <= $#{$G_SumInfo->{treeItems}}; $i++) {
$is_directory = defined($G_SumInfo->{treeItems}->[$i]->{__CCV_INFO__});
if ($is_directory) {
$dir_suffix_info = get_directory_suffix_info($G_SumInfo->{treeItems}->[$i]->{__CCV_INFO__});
}
if ($is_directory) { #directory
$level = $G_SumInfo->{treeItems}->[$i]->{__CCV_INFO__}->{LEVEL};
} else {
$level = $G_SumInfo->{treeItems}->[$i]->{LEVEL};
}
my $indent = 220 + (12 - $level) * 22;
$indent .= "px";
if ($i == 0) {
$suffix = "";
$previous_level = 0;
$previous_is_directory = 1;
my $treeOperator = "<i>[<a href='javascript: expandAll(true)' class='treeOperator'>Expand All</a> / <a href='javascript: expandAll(false)' class='treeOperator'>Collapse All</a>]</i>";
$item = "\n<li class='shown'><span class='minus' onclick='showChildren(this)'></span><span class='fwspan' style='width: $indent;'><a href='#' class='directory'>" . $G_SumInfo->{treeItems}->[$i]->{__CCV_INFO__}->{SELF} . "</a> " . $treeOperator . "</span>$dir_suffix_info \n<ul style='display: block;'>";
} else {
$delta_level = $level - $previous_level;
if (!$previous_is_directory) {
if ($is_directory) {
$delta_level ++;
}
}
if ($delta_level > 0) {
$suffix = "";
} elsif ($delta_level < 0) {
$suffix = "";
if (!$previous_is_directory && !$is_directory) {
$delta_level ++;
}
for (my $j = 0; $j <= abs($delta_level); $j ++) {
$suffix .= "\n</ul>\n</li>";
}
} else { #equal
if ($is_directory) {
$suffix = "\n</ul>\n</li>";
} else {
$suffix = "";
}
}
if ($is_directory) {
$dir_operator_style = $level >= $GV->{ExDirLevels} ? "plus" : "minus";
$dir_display = $level >= $GV->{ExDirLevels} ? "none" : "block";
$item = "\n<li><span class='$dir_operator_style' onclick='showChildren(this)'></span><a href='#' class='dirLOC'><span class='fwspan' style='width: $indent;'><span class='directory'>" . $G_SumInfo->{treeItems}->[$i]->{__CCV_INFO__}->{SELF} . "</span></span></a>" . $dir_suffix_info . "\n<ul style='display: $dir_display;'>";
} else {
my $file_shown_info = get_file_shown_info($G_SumInfo->{treeItems}->[$i]);
if ($G_SumInfo->{treeItems}->[$i]->{isBinary} == 1) {
$item = sprintf("\n<li><span class='ci'></span><span class='fwspan' title='%s' style='width: $indent;'><span class='file %s'>%s</span></span>\n</li>",
$file_shown_info->{tips},
$file_shown_info->{color},
$G_SumInfo->{treeItems}->[$i]->{SELF});
} else {
my $LOC = sprintf("<span class='fileLoc'>%s(+%s, -%s)</span>",
$file_shown_info->{total_lines},
$file_shown_info->{added_lines},
$file_shown_info->{removed_lines});
$item = sprintf("\n<li><span class='ci'></span><a target='_blank' class='loc' href='%s' title='%s'><span class='fwspan' style='width: $indent;'><span class='file %s'>%s</span></span>%s</a>\n</li>",
$file_shown_info->{diff_url},
$file_shown_info->{tips},
$file_shown_info->{color},
$G_SumInfo->{treeItems}->[$i]->{SELF},
$LOC);
}
}
$previous_level = $level;
$previous_is_directory = $is_directory;
}
$tree_string .= $suffix . $item;
if ($i % 20 == 0 || $i == $#{$G_SumInfo->{treeItems}}) {
print $G_H_GROUP_HTML_FILE $tree_string;
$tree_string = "";
}
}
}
sub write_flat_items() {
my $files_cnt = $#{$G_SumInfo->{flatItems}};
my $html_out = "";
for (my $index = 0; $index <= $files_cnt; $index++) {
$html_out .= get_flat_item($index);
if ($index % 20 == 0 || $index == $files_cnt) {
print $G_H_FLAT_HTML_FILE $html_out;
$html_out = "";
}
}
}
sub get_flat_item($) {
my $index = $_[0];
my $file_shown_info = get_file_shown_info($G_SumInfo->{flatItems}->[$index]);
my $ret = "";
if ($G_SumInfo->{flatItems}->[$index]->{isBinary} == 1) {
$ret = sprintf("<li><span class='ci'></span><span title='%s'><span class='binLocTxt %s'>#LINES#</span> <span class='%s'>%s</span></span></li>\n",
$file_shown_info->{tips},
$file_shown_info->{color},
$file_shown_info->{color},
$G_SumInfo->{flatItems}->[$index]->{file});
} else {
$ret = sprintf("<li><span class='ci'></span><a target='_blank' href='%s' title='%s'><span class='txtLocTxt'>#LINES#</span> <span class='%s'>%s</span></a></li>\n",
$file_shown_info->{diff_url},
$file_shown_info->{tips},
$file_shown_info->{color},
$G_SumInfo->{flatItems}->[$index]->{file});
}
my $str_total_lines = $file_shown_info->{total_lines};
my $str_added_lines = $file_shown_info->{added_lines};
my $str_removed_lines = $file_shown_info->{removed_lines};
$ret =~ s/#LINES#/$str_total_lines (+$str_added_lines, -$str_removed_lines)/;
return $ret;
}
sub get_file_shown_info($) {
my $item = $_[0];
my $file_tips = "";
my $clr_4filename = "fileNormal";
if ($item->{unExistIn} eq "L") {
$file_tips = "un-exist in revison1/date1";
$clr_4filename = "fileUnExistAtL";
}
if ($item->{unExistIn} eq "R") {
$file_tips = "un-exist in revison2/date2";
$clr_4filename = "fileUnExistAtR";
}
if ($item->{isBinary} == 1) {
$file_tips = "binary file, diff unavaiable!";
$clr_4filename = "fileBinary";
}
my $file_diff = "";
#if ($moduleInfo->{viewvc_entry} eq "" || $moduleInfo->{viewvc_entry} eq "NONE") { riff mode, always use ccv self diff viewer
$file_diff = get_independent_file_diff_url($item);
my $str_total_lines = sprintf("%07d", $item->{linesAdded} + $item->{linesRemoved});
my $str_added_lines = sprintf("%07d", $item->{linesAdded});
my $str_removed_lines = sprintf("%07d", $item->{linesRemoved});
return {'color' => $clr_4filename,
'tips' => $file_tips,
'diff_url' => $file_diff,
'total_lines' => $str_total_lines,
'added_lines' => $str_added_lines,
'removed_lines' => $str_removed_lines};
}
sub get_directory_suffix_info($) {
my $item = $_[0];
my $ret = sprintf("<span class='dirLoc'>%07d(+%07d, -%07d)</span><span class='dirFileCnt'> - %04d files</span>",
$item->{LINE_ADDED} + $item->{LINE_REMOVED},
$item->{LINE_ADDED},
$item->{LINE_REMOVED},
$item->{FILES});
return $ret;
}
sub output($) {
print $_[0];
}
sub print_loc_info() {
output("File: $GV->{dfOutFile}\n");
output("Changed file amount: $G_SumInfo->{fileCnt}\n");
output("Changed line amount: $G_SumInfo->{lines} (+$G_SumInfo->{linesAdded}, -$G_SumInfo->{linesRemoved})\n\n\n");
}
sub get_independent_file_diff_url($) {
my $item = $_[0];
my $url = sprintf($GV->{DiffViewer},
CGI::escape($GV->{dfOutFile}),
$item->{OffsetStart},
$item->{OffsetEnd}
);
return $url;
}
sub parse_command_line() {
my $cmd_line = join (" ", @ARGV);
if ($cmd_line =~ m/(^|\s)-t([^\s]+)/) {
$T_SNAP = $2;
}
if ($cmd_line =~ m/(^|\s)-f([^\s]+)/) {
$CFG = $2;
}
if ($cmd_line =~ m/(^|\s)-m([^\s]+)/) {
$MID = $2;
}
return 0;
}