xdiffi: fix typos and touch up comments
Inspired by the thoroughly stale https://github.com/git/git/pull/159, this patch fixes a couple of typos, rewraps and clarifies some comments. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Oct 8, 2019 at 11:27 UTC
03d3b1297cd2c4db5aec9a977ddf6a13dd9a64de
1 file changed
+55
-44
xdiff/xdiffi.c
+55
-44
@@ -38,9 +38,9 @@ typedef struct s_xdpsplit {
38
* Basically considers a "box" (off1, off2, lim1, lim2) and scan from both
39
* the forward diagonal starting from (off1, off2) and the backward diagonal
40
* starting from (lim1, lim2). If the K values on the same diagonal crosses
41
- * returns the furthest point of reach. We might end up having to expensive
42
- * cases using this algorithm is full, so a little bit of heuristic is needed
43
- * to cut the search and to return a suboptimal point.
41
+ * returns the furthest point of reach. We might encounter expensive edge cases
42
+ * using this algorithm, so a little bit of heuristic is needed to cut the
43
+ * search and to return a suboptimal point.
44
*/
45
static long xdl_split(unsigned long const *ha1, long off1, long lim1,
46
unsigned long const *ha2, long off2, long lim2,
@@ -63,11 +63,13 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
63
int got_snake = 0;
64
65
/*
66
- * We need to extent the diagonal "domain" by one. If the next
66
+ * We need to extend the diagonal "domain" by one. If the next
67
* values exits the box boundaries we need to change it in the
68
- * opposite direction because (max - min) must be a power of two.
68
+ * opposite direction because (max - min) must be a power of
69
+ * two.
70
+ *
71
* Also we initialize the external K value to -1 so that we can
70
- * avoid extra conditions check inside the core loop.
72
+ * avoid extra conditions in the check inside the core loop.
73
*/
74
if (fmin > dmin)
75
kvdf[--fmin - 1] = -1;
@@ -98,11 +100,13 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
100
}
101
102
/*
101
- * We need to extent the diagonal "domain" by one. If the next
103
+ * We need to extend the diagonal "domain" by one. If the next
104
* values exits the box boundaries we need to change it in the
103
- * opposite direction because (max - min) must be a power of two.
105
+ * opposite direction because (max - min) must be a power of
106
+ * two.
107
+ *
108
* Also we initialize the external K value to -1 so that we can
105
- * avoid extra conditions check inside the core loop.
109
+ * avoid extra conditions in the check inside the core loop.
110
*/
111
if (bmin > dmin)
112
kvdb[--bmin - 1] = XDL_LINE_MAX;
@@ -138,7 +142,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
142
/*
143
* If the edit cost is above the heuristic trigger and if
144
* we got a good snake, we sample current diagonals to see
141
- * if some of the, have reached an "interesting" path. Our
145
+ * if some of them have reached an "interesting" path. Our
146
* measure is a function of the distance from the diagonal
147
* corner (i1 + i2) penalized with the distance from the
148
* mid diagonal itself. If this value is above the current
@@ -196,8 +200,9 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
200
}
201
202
/*
199
- * Enough is enough. We spent too much time here and now we collect
200
- * the furthest reaching path using the (i1 + i2) measure.
203
+ * Enough is enough. We spent too much time here and now we
204
+ * collect the furthest reaching path using the (i1 + i2)
205
+ * measure.
206
*/
207
if (ec >= xenv->mxcost) {
208
long fbest, fbest1, bbest, bbest1;
@@ -244,9 +249,9 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
249
250
251
/*
247
- * Rule: "Divide et Impera". Recursively split the box in sub-boxes by calling
248
- * the box splitting function. Note that the real job (marking changed lines)
249
- * is done in the two boundary reaching checks.
252
+ * Rule: "Divide et Impera" (divide & conquer). Recursively split the box in
253
+ * sub-boxes by calling the box splitting function. Note that the real job
254
+ * (marking changed lines) is done in the two boundary reaching checks.
255
*/
256
int xdl_recs_cmp(diffdata_t *dd1, long off1, long lim1,
257
diffdata_t *dd2, long off2, long lim2,
@@ -323,7 +328,9 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
328
}
329
330
/*
326
- * Allocate and setup K vectors to be used by the differential algorithm.
331
+ * Allocate and setup K vectors to be used by the differential
332
+ * algorithm.
333
+ *
334
* One is to store the forward path and one to store the backward path.
335
*/
336
ndiags = xe->xdf1.nreff + xe->xdf2.nreff + 3;
@@ -394,8 +401,8 @@ static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags)
401
/*
402
* If a line is indented more than this, get_indent() just returns this value.
403
* This avoids having to do absurd amounts of work for data that are not
397
- * human-readable text, and also ensures that the output of get_indent fits within
398
- * an int.
404
+ * human-readable text, and also ensures that the output of get_indent fits
405
+ * within an int.
406
*/
407
#define MAX_INDENT 200
408
@@ -429,9 +436,9 @@ static int get_indent(xrecord_t *rec)
436
}
437
438
/*
432
- * If more than this number of consecutive blank rows are found, just return this
433
- * value. This avoids requiring O(N^2) work for pathological cases, and also
434
- * ensures that the output of score_split fits in an int.
439
+ * If more than this number of consecutive blank rows are found, just return
440
+ * this value. This avoids requiring O(N^2) work for pathological cases, and
441
+ * also ensures that the output of score_split fits in an int.
442
*/
443
#define MAX_BLANKS 20
444
@@ -443,8 +450,8 @@ struct split_measurement {
450
int end_of_file;
451
452
/*
446
- * How much is the line immediately following the split indented (or -1 if
447
- * the line is blank):
453
+ * How much is the line immediately following the split indented (or -1
454
+ * if the line is blank):
455
*/
456
int indent;
457
@@ -454,8 +461,8 @@ struct split_measurement {
461
int pre_blank;
462
463
/*
457
- * How much is the nearest non-blank line above the split indented (or -1
458
- * if there is no such line)?
464
+ * How much is the nearest non-blank line above the split indented (or
465
+ * -1 if there is no such line)?
466
*/
467
int pre_indent;
468
@@ -581,13 +588,13 @@ static void measure_split(const xdfile_t *xdf, long split,
588
589
/*
590
* Compute a badness score for the hypothetical split whose measurements are
584
- * stored in m. The weight factors were determined empirically using the tools and
585
- * corpus described in
591
+ * stored in m. The weight factors were determined empirically using the tools
592
+ * and corpus described in
593
*
594
* https://github.com/mhagger/diff-slider-tools
595
*
589
- * Also see that project if you want to improve the weights based on, for example,
590
- * a larger or more diverse corpus.
596
+ * Also see that project if you want to improve the weights based on, for
597
+ * example, a larger or more diverse corpus.
598
*/
599
static void score_add_split(const struct split_measurement *m, struct split_score *s)
600
{
@@ -809,13 +816,16 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
816
group_init(xdfo, &go);
817
818
while (1) {
812
- /* If the group is empty in the to-be-compacted file, skip it: */
819
+ /*
820
+ * If the group is empty in the to-be-compacted file, skip it:
821
+ */
822
if (g.end == g.start)
823
goto next;
824
825
/*
826
* Now shift the change up and then down as far as possible in
818
- * each direction. If it bumps into any other changes, merge them.
827
+ * each direction. If it bumps into any other changes, merge
828
+ * them.
829
*/
830
do {
831
groupsize = g.end - g.start;
@@ -858,17 +868,17 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
868
* If the group can be shifted, then we can possibly use this
869
* freedom to produce a more intuitive diff.
870
*
861
- * The group is currently shifted as far down as possible, so the
862
- * heuristics below only have to handle upwards shifts.
871
+ * The group is currently shifted as far down as possible, so
872
+ * the heuristics below only have to handle upwards shifts.
873
*/
874
875
if (g.end == earliest_end) {
876
/* no shifting was possible */
877
} else if (end_matching_other != -1) {
878
/*
869
- * Move the possibly merged group of changes back to line
870
- * up with the last group of changes from the other file
871
- * that it can align with.
879
+ * Move the possibly merged group of changes back to
880
+ * line up with the last group of changes from the
881
+ * other file that it can align with.
882
*/
883
while (go.end == go.start) {
884
if (group_slide_up(xdf, &g, flags))
@@ -879,14 +889,15 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
889
} else if (flags & XDF_INDENT_HEURISTIC) {
890
/*
891
* Indent heuristic: a group of pure add/delete lines
882
- * implies two splits, one between the end of the "before"
883
- * context and the start of the group, and another between
884
- * the end of the group and the beginning of the "after"
885
- * context. Some splits are aesthetically better and some
886
- * are worse. We compute a badness "score" for each split,
887
- * and add the scores for the two splits to define a
888
- * "score" for each position that the group can be shifted
889
- * to. Then we pick the shift with the lowest score.
892
+ * implies two splits, one between the end of the
893
+ * "before" context and the start of the group, and
894
+ * another between the end of the group and the
895
+ * beginning of the "after" context. Some splits are
896
+ * aesthetically better and some are worse. We compute
897
+ * a badness "score" for each split, and add the scores
898
+ * for the two splits to define a "score" for each
899
+ * position that the group can be shifted to. Then we
900
+ * pick the shift with the lowest score.
901
*/
902
long shift, best_shift = -1;
903
struct split_score best_score;