~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/libsvn_diff/diff_memory.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
356
356
  source_tokens_t sources[2]; /* 0 == original; 1 == modified */
357
357
  apr_off_t current_token[2]; /* current token per source */
358
358
 
 
359
  int context_size;
 
360
 
359
361
  /* Cached markers, in header_encoding,
360
362
     indexed using unified_output_e */
361
363
  const char *prefix_str[3];
461
463
 
462
464
  /* Write the trailing context */
463
465
  target_token = baton->hunk_start[0] + baton->hunk_length[0]
464
 
                 + SVN_DIFF__UNIFIED_CONTEXT_SIZE;
 
466
                 + baton->context_size;
465
467
  SVN_ERR(output_unified_token_range(baton, 0 /*original*/,
466
468
                                     unified_output_context,
467
469
                                     target_token));
515
517
  apr_off_t prev_context_end;
516
518
  svn_boolean_t init_hunk = FALSE;
517
519
 
518
 
  if (original_start > SVN_DIFF__UNIFIED_CONTEXT_SIZE)
519
 
    context_prefix_length = SVN_DIFF__UNIFIED_CONTEXT_SIZE;
 
520
  if (original_start > output_baton->context_size)
 
521
    context_prefix_length = output_baton->context_size;
520
522
  else
521
523
    context_prefix_length = original_start;
522
524
 
526
528
    {
527
529
      prev_context_end = output_baton->hunk_start[0]
528
530
                         + output_baton->hunk_length[0]
529
 
                         + SVN_DIFF__UNIFIED_CONTEXT_SIZE;
 
531
                         + output_baton->context_size;
530
532
    }
531
533
  else
532
534
    {
608
610
 
609
611
 
610
612
svn_error_t *
611
 
svn_diff_mem_string_output_unified2(svn_stream_t *output_stream,
 
613
svn_diff_mem_string_output_unified3(svn_stream_t *output_stream,
612
614
                                    svn_diff_t *diff,
613
615
                                    svn_boolean_t with_diff_header,
614
616
                                    const char *hunk_delimiter,
617
619
                                    const char *header_encoding,
618
620
                                    const svn_string_t *original,
619
621
                                    const svn_string_t *modified,
620
 
                                    apr_pool_t *pool)
 
622
                                    int context_size,
 
623
                                    svn_cancel_func_t cancel_func,
 
624
                                    void *cancel_baton,
 
625
                                    apr_pool_t *scratch_pool)
621
626
{
622
627
 
623
628
  if (svn_diff_contains_diffs(diff))
626
631
 
627
632
      memset(&baton, 0, sizeof(baton));
628
633
      baton.output_stream = output_stream;
629
 
      baton.pool = svn_pool_create(pool);
 
634
      baton.pool = svn_pool_create(scratch_pool);
630
635
      baton.header_encoding = header_encoding;
631
 
      baton.hunk = svn_stringbuf_create_empty(pool);
 
636
      baton.hunk = svn_stringbuf_create_empty(scratch_pool);
632
637
      baton.hunk_delimiter = hunk_delimiter;
633
638
      baton.no_newline_string
634
639
        = (hunk_delimiter == NULL || strcmp(hunk_delimiter, "##") != 0)
635
640
          ? APR_EOL_STR SVN_DIFF__NO_NEWLINE_AT_END_OF_FILE APR_EOL_STR
636
641
          : APR_EOL_STR SVN_DIFF__NO_NEWLINE_AT_END_OF_PROPERTY APR_EOL_STR;
 
642
      baton.context_size = context_size >= 0 ? context_size
 
643
                                             : SVN_DIFF__UNIFIED_CONTEXT_SIZE;
637
644
 
638
645
      SVN_ERR(svn_utf_cstring_from_utf8_ex2
639
646
              (&(baton.prefix_str[unified_output_context]), " ",
640
 
               header_encoding, pool));
 
647
               header_encoding, scratch_pool));
641
648
      SVN_ERR(svn_utf_cstring_from_utf8_ex2
642
649
              (&(baton.prefix_str[unified_output_delete]), "-",
643
 
               header_encoding, pool));
 
650
               header_encoding, scratch_pool));
644
651
      SVN_ERR(svn_utf_cstring_from_utf8_ex2
645
652
              (&(baton.prefix_str[unified_output_insert]), "+",
646
 
               header_encoding, pool));
 
653
               header_encoding, scratch_pool));
647
654
 
648
 
      fill_source_tokens(&baton.sources[0], original, pool);
649
 
      fill_source_tokens(&baton.sources[1], modified, pool);
 
655
      fill_source_tokens(&baton.sources[0], original, scratch_pool);
 
656
      fill_source_tokens(&baton.sources[1], modified, scratch_pool);
650
657
 
651
658
      if (with_diff_header)
652
659
        {
653
660
          SVN_ERR(svn_diff__unidiff_write_header(
654
661
                    output_stream, header_encoding,
655
 
                    original_header, modified_header, pool));
 
662
                    original_header, modified_header, scratch_pool));
656
663
        }
657
664
 
658
 
      SVN_ERR(svn_diff_output(diff, &baton,
659
 
                              &mem_output_unified_vtable));
 
665
      SVN_ERR(svn_diff_output2(diff, &baton,
 
666
                              &mem_output_unified_vtable,
 
667
                              cancel_func, cancel_baton));
660
668
 
661
669
      SVN_ERR(output_unified_flush_hunk(&baton, hunk_delimiter));
662
670
 
666
674
  return SVN_NO_ERROR;
667
675
}
668
676
 
669
 
svn_error_t *
670
 
svn_diff_mem_string_output_unified(svn_stream_t *output_stream,
671
 
                                   svn_diff_t *diff,
672
 
                                   const char *original_header,
673
 
                                   const char *modified_header,
674
 
                                   const char *header_encoding,
675
 
                                   const svn_string_t *original,
676
 
                                   const svn_string_t *modified,
677
 
                                   apr_pool_t *pool)
678
 
{
679
 
  SVN_ERR(svn_diff_mem_string_output_unified2(output_stream,
680
 
                                              diff,
681
 
                                              TRUE,
682
 
                                              NULL,
683
 
                                              original_header,
684
 
                                              modified_header,
685
 
                                              header_encoding,
686
 
                                              original,
687
 
                                              modified,
688
 
                                              pool));
689
 
  return SVN_NO_ERROR;
690
 
}
691
677
 
692
678
 
693
679
 
698
684
   *pointers! */
699
685
typedef struct context_saver_t {
700
686
  svn_stream_t *stream;
701
 
  const char *data[SVN_DIFF__UNIFIED_CONTEXT_SIZE];
702
 
  apr_size_t len[SVN_DIFF__UNIFIED_CONTEXT_SIZE];
 
687
  int context_size;
 
688
  const char **data; /* const char *data[context_size] */
 
689
  apr_size_t *len;   /* apr_size_t len[context_size] */
703
690
  apr_size_t next_slot;
704
691
  apr_size_t total_written;
705
692
} context_saver_t;
713
700
  context_saver_t *cs = baton;
714
701
  cs->data[cs->next_slot] = data;
715
702
  cs->len[cs->next_slot] = *len;
716
 
  cs->next_slot = (cs->next_slot + 1) % SVN_DIFF__UNIFIED_CONTEXT_SIZE;
 
703
  cs->next_slot = (cs->next_slot + 1) % cs->context_size;
717
704
  cs->total_written++;
718
705
  return SVN_NO_ERROR;
719
706
}
733
720
  const char *marker_eol;
734
721
 
735
722
  svn_diff_conflict_display_style_t conflict_style;
 
723
  int context_size;
 
724
 
 
725
  /* cancel support */
 
726
  svn_cancel_func_t cancel_func;
 
727
  void *cancel_baton;
736
728
 
737
729
  /* The rest of the fields are for
738
730
     svn_diff_conflict_display_only_conflicts only.  Note that for
753
745
                    svn_stream_t *output_stream)
754
746
{
755
747
  int i;
756
 
  for (i = 0; i < SVN_DIFF__UNIFIED_CONTEXT_SIZE; i++)
 
748
  for (i = 0; i < cs->context_size; i++)
757
749
    {
758
 
      apr_size_t slot = (i + cs->next_slot) % SVN_DIFF__UNIFIED_CONTEXT_SIZE;
 
750
      apr_size_t slot = (i + cs->next_slot) % cs->context_size;
759
751
      if (cs->data[slot])
760
752
        {
761
753
          apr_size_t len = cs->len[slot];
771
763
{
772
764
  context_saver_t *cs;
773
765
 
 
766
  assert(mob->context_size > 0); /* Or nothing to save */
 
767
 
774
768
  svn_pool_clear(mob->pool);
775
769
  cs = apr_pcalloc(mob->pool, sizeof(*cs));
776
770
  cs->stream = svn_stream_empty(mob->pool);
778
772
  svn_stream_set_write(cs->stream, context_saver_stream_write);
779
773
  mob->context_saver = cs;
780
774
  mob->output_stream = cs->stream;
 
775
  cs->context_size = mob->context_size;
 
776
  cs->data = apr_pcalloc(mob->pool, sizeof(*cs->data) * cs->context_size);
 
777
  cs->len = apr_pcalloc(mob->pool, sizeof(*cs->len) * cs->context_size);
781
778
}
782
779
 
783
780
 
784
 
/* A stream which prints SVN_DIFF__UNIFIED_CONTEXT_SIZE lines to
 
781
/* A stream which prints LINES_TO_PRINT (based on context_size) lines to
785
782
   BATON->REAL_OUTPUT_STREAM, and then changes BATON->OUTPUT_STREAM to
786
783
   a context_saver; used for *trailing* context. */
787
784
 
815
812
  svn_pool_clear(btn->pool);
816
813
 
817
814
  tcp = apr_pcalloc(btn->pool, sizeof(*tcp));
818
 
  tcp->lines_to_print = SVN_DIFF__UNIFIED_CONTEXT_SIZE;
 
815
  tcp->lines_to_print = btn->context_size;
819
816
  tcp->mob = btn;
820
817
  s = svn_stream_empty(btn->pool);
821
818
  svn_stream_set_baton(s, tcp);
913
910
  if (style == svn_diff_conflict_display_resolved_modified_latest)
914
911
    {
915
912
      if (diff)
916
 
        return svn_diff_output(diff, baton, &merge_output_vtable);
 
913
        return svn_diff_output2(diff, baton, &merge_output_vtable,
 
914
                                btn->cancel_func, btn->cancel_baton);
917
915
      else
918
916
        style = svn_diff_conflict_display_modified_latest;
919
917
    }
949
947
  return SVN_NO_ERROR;
950
948
}
951
949
 
 
950
static svn_error_t *
 
951
output_conflict_with_context_marker(merge_output_baton_t *btn,
 
952
                                    const char *label,
 
953
                                    apr_off_t start,
 
954
                                    apr_off_t length)
 
955
{
 
956
  if (length == 1)
 
957
    SVN_ERR(svn_stream_printf(btn->output_stream, btn->pool,
 
958
                              "%s (%" APR_OFF_T_FMT ")",
 
959
                              label, start + 1));
 
960
  else
 
961
    SVN_ERR(svn_stream_printf(btn->output_stream, btn->pool,
 
962
                              "%s (%" APR_OFF_T_FMT ",%" APR_OFF_T_FMT ")",
 
963
                              label, start + 1, length));
 
964
 
 
965
  SVN_ERR(output_marker_eol(btn));
 
966
 
 
967
  return SVN_NO_ERROR;
 
968
}
952
969
 
953
970
static svn_error_t *
954
971
output_conflict_with_context(void *baton,
966
983
     trailing context)?  If so, flush it. */
967
984
  if (btn->output_stream == btn->context_saver->stream)
968
985
    {
969
 
      if (btn->context_saver->total_written > SVN_DIFF__UNIFIED_CONTEXT_SIZE)
 
986
      if (btn->context_saver->total_written > btn->context_size)
970
987
        SVN_ERR(svn_stream_puts(btn->real_output_stream, "@@\n"));
971
988
      SVN_ERR(flush_context_saver(btn->context_saver, btn->real_output_stream));
972
989
    }
975
992
  btn->output_stream = btn->real_output_stream;
976
993
 
977
994
  /* Output the conflict itself. */
978
 
  SVN_ERR(svn_stream_printf(btn->output_stream, btn->pool,
979
 
                            (modified_length == 1
980
 
                             ? "%s (%" APR_OFF_T_FMT ")"
981
 
                             : "%s (%" APR_OFF_T_FMT ",%" APR_OFF_T_FMT ")"),
982
 
                            btn->markers[1],
983
 
                            modified_start + 1, modified_length));
984
 
  SVN_ERR(output_marker_eol(btn));
 
995
  SVN_ERR(output_conflict_with_context_marker(btn, btn->markers[1],
 
996
                                              modified_start,
 
997
                                              modified_length));
985
998
  SVN_ERR(output_merge_token_range(NULL, btn, 1/*modified*/,
986
999
                                   modified_start, modified_length));
987
1000
 
988
 
  SVN_ERR(svn_stream_printf(btn->output_stream, btn->pool,
989
 
                            (original_length == 1
990
 
                             ? "%s (%" APR_OFF_T_FMT ")"
991
 
                             : "%s (%" APR_OFF_T_FMT ",%" APR_OFF_T_FMT ")"),
992
 
                            btn->markers[0],
993
 
                            original_start + 1, original_length));
994
 
  SVN_ERR(output_marker_eol(btn));
 
1001
  SVN_ERR(output_conflict_with_context_marker(btn, btn->markers[0],
 
1002
                                              original_start,
 
1003
                                              original_length));
995
1004
  SVN_ERR(output_merge_token_range(NULL, btn, 0/*original*/,
996
1005
                                   original_start, original_length));
997
1006
 
998
1007
  SVN_ERR(output_merge_marker(btn, 2/*separator*/));
999
1008
  SVN_ERR(output_merge_token_range(NULL, btn, 2/*latest*/,
1000
1009
                                   latest_start, latest_length));
1001
 
  SVN_ERR(svn_stream_printf(btn->output_stream, btn->pool,
1002
 
                            (latest_length == 1
1003
 
                             ? "%s (%" APR_OFF_T_FMT ")"
1004
 
                             : "%s (%" APR_OFF_T_FMT ",%" APR_OFF_T_FMT ")"),
1005
 
                            btn->markers[3],
1006
 
                            latest_start + 1, latest_length));
1007
 
  SVN_ERR(output_marker_eol(btn));
 
1010
  SVN_ERR(output_conflict_with_context_marker(btn, btn->markers[3],
 
1011
                                              latest_start,
 
1012
                                              latest_length));
1008
1013
 
1009
1014
  /* Go into print-trailing-context mode instead. */
1010
1015
  make_trailing_context_printer(btn);
1049
1054
}
1050
1055
 
1051
1056
svn_error_t *
1052
 
svn_diff_mem_string_output_merge2(svn_stream_t *output_stream,
 
1057
svn_diff_mem_string_output_merge3(svn_stream_t *output_stream,
1053
1058
                                  svn_diff_t *diff,
1054
1059
                                  const svn_string_t *original,
1055
1060
                                  const svn_string_t *modified,
1059
1064
                                  const char *conflict_latest,
1060
1065
                                  const char *conflict_separator,
1061
1066
                                  svn_diff_conflict_display_style_t style,
1062
 
                                  apr_pool_t *pool)
 
1067
                                  svn_cancel_func_t cancel_func,
 
1068
                                  void *cancel_baton,
 
1069
                                  apr_pool_t *scratch_pool)
1063
1070
{
1064
1071
  merge_output_baton_t btn;
1065
1072
  const char *eol;
1069
1076
     ? &merge_only_conflicts_output_vtable : &merge_output_vtable;
1070
1077
 
1071
1078
  memset(&btn, 0, sizeof(btn));
 
1079
  btn.context_size = SVN_DIFF__UNIFIED_CONTEXT_SIZE;
1072
1080
 
1073
1081
  if (conflicts_only)
1074
1082
    {
1075
 
      btn.pool = svn_pool_create(pool);
 
1083
      btn.pool = svn_pool_create(scratch_pool);
1076
1084
      make_context_saver(&btn);
1077
1085
      btn.real_output_stream = output_stream;
1078
1086
    }
1079
1087
  else
1080
1088
    btn.output_stream = output_stream;
1081
1089
 
1082
 
  fill_source_tokens(&(btn.sources[0]), original, pool);
1083
 
  fill_source_tokens(&(btn.sources[1]), modified, pool);
1084
 
  fill_source_tokens(&(btn.sources[2]), latest, pool);
 
1090
  fill_source_tokens(&(btn.sources[0]), original, scratch_pool);
 
1091
  fill_source_tokens(&(btn.sources[1]), modified, scratch_pool);
 
1092
  fill_source_tokens(&(btn.sources[2]), latest, scratch_pool);
1085
1093
 
1086
1094
  btn.conflict_style = style;
1087
1095
 
1095
1103
    eol = APR_EOL_STR;  /* use the platform default */
1096
1104
 
1097
1105
  btn.marker_eol = eol;
 
1106
  btn.cancel_func = cancel_func;
 
1107
  btn.cancel_baton = cancel_baton;
1098
1108
 
1099
1109
  SVN_ERR(svn_utf_cstring_from_utf8(&btn.markers[1],
1100
1110
                                    conflict_modified
1101
1111
                                    ? conflict_modified
1102
1112
                                    : "<<<<<<< (modified)",
1103
 
                                    pool));
 
1113
                                    scratch_pool));
1104
1114
  SVN_ERR(svn_utf_cstring_from_utf8(&btn.markers[0],
1105
1115
                                    conflict_original
1106
1116
                                    ? conflict_original
1107
1117
                                    : "||||||| (original)",
1108
 
                                    pool));
 
1118
                                    scratch_pool));
1109
1119
  SVN_ERR(svn_utf_cstring_from_utf8(&btn.markers[2],
1110
1120
                                    conflict_separator
1111
1121
                                    ? conflict_separator
1112
1122
                                    : "=======",
1113
 
                                    pool));
 
1123
                                    scratch_pool));
1114
1124
  SVN_ERR(svn_utf_cstring_from_utf8(&btn.markers[3],
1115
1125
                                    conflict_latest
1116
1126
                                    ? conflict_latest
1117
1127
                                    : ">>>>>>> (latest)",
1118
 
                                    pool));
 
1128
                                    scratch_pool));
1119
1129
 
1120
 
  SVN_ERR(svn_diff_output(diff, &btn, vtable));
 
1130
  SVN_ERR(svn_diff_output2(diff, &btn, vtable, cancel_func, cancel_baton));
1121
1131
  if (conflicts_only)
1122
1132
    svn_pool_destroy(btn.pool);
1123
1133
 
1124
1134
  return SVN_NO_ERROR;
1125
1135
}
1126
 
 
1127
 
svn_error_t *
1128
 
svn_diff_mem_string_output_merge(svn_stream_t *output_stream,
1129
 
                                 svn_diff_t *diff,
1130
 
                                 const svn_string_t *original,
1131
 
                                 const svn_string_t *modified,
1132
 
                                 const svn_string_t *latest,
1133
 
                                 const char *conflict_original,
1134
 
                                 const char *conflict_modified,
1135
 
                                 const char *conflict_latest,
1136
 
                                 const char *conflict_separator,
1137
 
                                 svn_boolean_t display_original_in_conflict,
1138
 
                                 svn_boolean_t display_resolved_conflicts,
1139
 
                                 apr_pool_t *pool)
1140
 
{
1141
 
  svn_diff_conflict_display_style_t style =
1142
 
    svn_diff_conflict_display_modified_latest;
1143
 
 
1144
 
  if (display_resolved_conflicts)
1145
 
    style = svn_diff_conflict_display_resolved_modified_latest;
1146
 
 
1147
 
  if (display_original_in_conflict)
1148
 
    style = svn_diff_conflict_display_modified_original_latest;
1149
 
 
1150
 
  return svn_diff_mem_string_output_merge2(output_stream,
1151
 
                                           diff,
1152
 
                                           original,
1153
 
                                           modified,
1154
 
                                           latest,
1155
 
                                           conflict_original,
1156
 
                                           conflict_modified,
1157
 
                                           conflict_latest,
1158
 
                                           conflict_separator,
1159
 
                                           style,
1160
 
                                           pool);
1161
 
}