switch 'tog diff' and 'tog blame' to Myers diff for speed Make the choice of diff algorithm configurable by diff API users. The got and gotweb programs keep using Patience diffs which are prettier than Myers. But tog should be as fast as possible since it is being used interactively. If performance of Patience diff gets improved later we can consider switching tog back over to it. ok tracey jamsek
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
diff --git a/got/got.c b/got/got.c
index d9c4a83..5f7f000 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3584,7 +3584,8 @@ diff_blobs(struct got_object_id *blob_id1, struct got_object_id *blob_id2,
while (path[0] == '/')
path++;
err = got_diff_blob(NULL, NULL, blob1, blob2, f1, f2, path, path,
- diff_context, ignore_whitespace, force_text_diff, outfile);
+ GOT_DIFF_ALGORITHM_PATIENCE, diff_context, ignore_whitespace,
+ force_text_diff, outfile);
done:
if (fd1 != -1 && close(fd1) == -1 && err == NULL)
err = got_error_from_errno("close");
@@ -3645,6 +3646,7 @@ diff_trees(struct got_object_id *tree_id1, struct got_object_id *tree_id2,
arg.diff_context = diff_context;
arg.ignore_whitespace = ignore_whitespace;
arg.force_text_diff = force_text_diff;
+ arg.diff_algo = GOT_DIFF_ALGORITHM_PATIENCE;
arg.outfile = outfile;
arg.line_offsets = NULL;
arg.nlines = 0;
@@ -4590,6 +4592,7 @@ struct print_diff_arg {
const char *id_str;
int header_shown;
int diff_staged;
+ enum got_diff_algorithm diff_algo;
int ignore_whitespace;
int force_text_diff;
FILE *f1;
@@ -4720,8 +4723,8 @@ print_diff(void *arg, unsigned char status, unsigned char staged_status,
}
err = got_diff_objects_as_blobs(NULL, NULL, a->f1, a->f2,
fd1, fd2, blob_id, staged_blob_id, label1, label2,
- a->diff_context, a->ignore_whitespace, a->force_text_diff,
- a->repo, stdout);
+ a->diff_algo, a->diff_context, a->ignore_whitespace,
+ a->force_text_diff, a->repo, stdout);
goto done;
}
@@ -4812,8 +4815,8 @@ print_diff(void *arg, unsigned char status, unsigned char staged_status,
}
err = got_diff_blob_file(blob1, a->f1, size1, label1, f2 ? f2 : a->f2,
- f2_exists, sb.st_size, path, a->diff_context, a->ignore_whitespace,
- a->force_text_diff, stdout);
+ f2_exists, sb.st_size, path, GOT_DIFF_ALGORITHM_PATIENCE,
+ a->diff_context, a->ignore_whitespace, a->force_text_diff, stdout);
done:
if (fd1 != -1 && close(fd1) == -1 && err == NULL)
err = got_error_from_errno("close");
@@ -5031,6 +5034,7 @@ cmd_diff(int argc, char *argv[])
goto done;
arg.repo = repo;
arg.worktree = worktree;
+ arg.diff_algo = GOT_DIFF_ALGORITHM_PATIENCE;
arg.diff_context = diff_context;
arg.id_str = id_str;
arg.header_shown = 0;
@@ -5175,18 +5179,21 @@ cmd_diff(int argc, char *argv[])
switch (type1 == GOT_OBJ_TYPE_ANY ? type2 : type1) {
case GOT_OBJ_TYPE_BLOB:
error = got_diff_objects_as_blobs(NULL, NULL, f1, f2,
- fd1, fd2, ids[0], ids[1], NULL, NULL, diff_context,
+ fd1, fd2, ids[0], ids[1], NULL, NULL,
+ GOT_DIFF_ALGORITHM_PATIENCE, diff_context,
ignore_whitespace, force_text_diff, repo, stdout);
break;
case GOT_OBJ_TYPE_TREE:
error = got_diff_objects_as_trees(NULL, NULL, f1, f2, fd1, fd2,
- ids[0], ids[1], &paths, "", "", diff_context,
+ ids[0], ids[1], &paths, "", "",
+ GOT_DIFF_ALGORITHM_PATIENCE, diff_context,
ignore_whitespace, force_text_diff, repo, stdout);
break;
case GOT_OBJ_TYPE_COMMIT:
printf("diff %s %s\n", labels[0], labels[1]);
error = got_diff_objects_as_commits(NULL, NULL, f1, f2,
- fd1, fd2, ids[0], ids[1], &paths, diff_context,
+ fd1, fd2, ids[0], ids[1], &paths,
+ GOT_DIFF_ALGORITHM_PATIENCE, diff_context,
ignore_whitespace, force_text_diff, repo, stdout);
break;
default:
@@ -5569,7 +5576,8 @@ cmd_blame(int argc, char *argv[])
goto done;
}
error = got_blame(link_target ? link_target : in_repo_path, commit_id,
- repo, blame_cb, &bca, check_cancelled, NULL, fd2, fd3, f1, f2);
+ repo, GOT_DIFF_ALGORITHM_PATIENCE, blame_cb, &bca,
+ check_cancelled, NULL, fd2, fd3, f1, f2);
done:
free(in_repo_path);
free(link_target);
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 80bd351..da9f041 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -2912,17 +2912,18 @@ gw_output_diff(struct gw_trans *gw_trans, struct gw_header *header)
switch (obj_type) {
case GOT_OBJ_TYPE_BLOB:
error = got_diff_objects_as_blobs(NULL, NULL, f1, f2,
- fd1, fd2, id1, id2, NULL, NULL, 3, 0, 0,
- gw_trans->repo, f);
+ fd1, fd2, id1, id2, NULL, NULL, GOT_DIFF_ALGORITHM_PATIENCE,
+ 3, 0, 0, gw_trans->repo, f);
break;
case GOT_OBJ_TYPE_TREE:
error = got_diff_objects_as_trees(NULL, NULL, f1, f2,
- fd1, fd2, id1, id2, NULL, "", "", 3, 0, 0,
- gw_trans->repo, f);
+ fd1, fd2, id1, id2, NULL, "", "",
+ GOT_DIFF_ALGORITHM_PATIENCE, 3, 0, 0, gw_trans->repo, f);
break;
case GOT_OBJ_TYPE_COMMIT:
error = got_diff_objects_as_commits(NULL, NULL, f1, f2,
- fd1, fd2, id1, id2, NULL, 3, 0, 0, gw_trans->repo, f);
+ fd1, fd2, id1, id2, NULL, GOT_DIFF_ALGORITHM_PATIENCE,
+ 3, 0, 0, gw_trans->repo, f);
break;
default:
error = got_error(GOT_ERR_OBJ_TYPE);
@@ -4194,8 +4195,9 @@ gw_output_file_blame(struct gw_trans *gw_trans, struct gw_header *header)
goto done;
}
- error = got_blame(in_repo_path, commit_id, gw_trans->repo, gw_blame_cb,
- &bca, NULL, NULL, fd2, fd3, f1, f2);
+ error = got_blame(in_repo_path, commit_id, gw_trans->repo,
+ GOT_DIFF_ALGORITHM_PATIENCE, gw_blame_cb, &bca, NULL, NULL,
+ fd2, fd3, f1, f2);
done:
free(in_repo_path);
free(commit_id);
diff --git a/include/got_blame.h b/include/got_blame.h
index 5d01c00..7a5d61c 100644
--- a/include/got_blame.h
+++ b/include/got_blame.h
@@ -35,5 +35,5 @@ typedef const struct got_error *(*got_blame_cb)(void *, int, int,
* aborted and the callback's error is returned from this function.
*/
const struct got_error *got_blame(const char *,
- struct got_object_id *, struct got_repository *,
+ struct got_object_id *, struct got_repository *, enum got_diff_algorithm,
got_blame_cb, void *, got_cancel_cb, void *, int, int, FILE *, FILE *);
diff --git a/include/got_diff.h b/include/got_diff.h
index e04cc7f..4243be1 100644
--- a/include/got_diff.h
+++ b/include/got_diff.h
@@ -14,6 +14,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+enum got_diff_algorithm {
+ GOT_DIFF_ALGORITHM_MYERS,
+ GOT_DIFF_ALGORITHM_PATIENCE,
+};
+
/*
* Compute the differences between two blobs and write unified diff text
* to the provided output file. Two open temporary files must be provided
@@ -31,7 +36,8 @@
*/
const struct got_error *got_diff_blob(off_t **, size_t *,
struct got_blob_object *, struct got_blob_object *, FILE *, FILE *,
- const char *, const char *, int, int, int, FILE *);
+ const char *, const char *, enum got_diff_algorithm, int, int, int,
+ FILE *);
/*
* Compute the differences between a blob and a file and write unified diff
@@ -43,8 +49,8 @@ const struct got_error *got_diff_blob(off_t **, size_t *,
* Whitespace differences may optionally be ignored.
*/
const struct got_error *got_diff_blob_file(struct got_blob_object *, FILE *,
- off_t, const char *, FILE *, int, size_t, const char *, int, int, int,
- FILE *);
+ off_t, const char *, FILE *, int, size_t, const char *,
+ enum got_diff_algorithm, int, int, int, FILE *);
/*
* A callback function invoked to handle the differences between two blobs
@@ -74,6 +80,7 @@ struct got_diff_blob_output_unidiff_arg {
int diff_context; /* Sets the number of context lines. */
int ignore_whitespace; /* Ignore whitespace differences. */
int force_text_diff; /* Assume text even if binary data detected. */
+ enum got_diff_algorithm diff_algo; /* Diffing algorithm to use. */
/*
* The number of lines contained in produced unidiff text output,
@@ -150,9 +157,11 @@ const struct got_error *got_diff_tree_collect_changed_paths(void *,
*/
const struct got_error *got_diff_objects_as_blobs(off_t **, size_t *,
FILE *, FILE *, int, int, struct got_object_id *, struct got_object_id *,
- const char *, const char *, int, int, int,
+ const char *, const char *, enum got_diff_algorithm, int, int, int,
struct got_repository *, FILE *);
+struct got_pathlist_head;
+
/*
* Diff two objects, assuming both objects are trees. Two const char * diff
* header labels may be provided which will be used to identify each blob in
@@ -170,8 +179,8 @@ const struct got_error *got_diff_objects_as_blobs(off_t **, size_t *,
*/
const struct got_error *got_diff_objects_as_trees(off_t **, size_t *,
FILE *, FILE *, int, int, struct got_object_id *, struct got_object_id *,
- struct got_pathlist_head *, const char *, const char *, int, int, int,
- struct got_repository *, FILE *);
+ struct got_pathlist_head *, const char *, const char *,
+ enum got_diff_algorithm, int, int, int, struct got_repository *, FILE *);
/*
* Diff two objects, assuming both objects are commits.
@@ -187,6 +196,7 @@ const struct got_error *got_diff_objects_as_trees(off_t **, size_t *,
*/
const struct got_error *got_diff_objects_as_commits(off_t **, size_t *,
FILE *, FILE *, int, int, struct got_object_id *, struct got_object_id *,
- struct got_pathlist_head *, int, int, int, struct got_repository *, FILE *);
+ struct got_pathlist_head *, enum got_diff_algorithm, int, int, int,
+ struct got_repository *, FILE *);
#define GOT_DIFF_MAX_CONTEXT 64
diff --git a/lib/blame.c b/lib/blame.c
index f08e9f1..05701b8 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -32,9 +32,10 @@
#include "got_error.h"
#include "got_object.h"
#include "got_cancel.h"
-#include "got_blame.h"
#include "got_commit_graph.h"
#include "got_opentemp.h"
+#include "got_diff.h"
+#include "got_blame.h"
#include "got_lib_inflate.h"
#include "got_lib_delta.h"
@@ -493,7 +494,8 @@ flip_files(struct got_blame *blame)
static const struct got_error *
blame_open(struct got_blame **blamep, const char *path,
struct got_object_id *start_commit_id, struct got_repository *repo,
- got_blame_cb cb, void *arg, got_cancel_cb cancel_cb, void *cancel_arg,
+ enum got_diff_algorithm diff_algo, got_blame_cb cb, void *arg,
+ got_cancel_cb cancel_cb, void *cancel_arg,
int fd1, int fd2, FILE *f1, FILE *f2)
{
const struct got_error *err = NULL;
@@ -540,8 +542,8 @@ blame_open(struct got_blame **blamep, const char *path,
blame->f2 = f2;
blame->fd = fd2;
- err = got_diff_get_config(&blame->cfg, GOT_DIFF_ALGORITHM_PATIENCE,
- blame_atomize_file, blame);
+ err = got_diff_get_config(&blame->cfg, diff_algo, blame_atomize_file,
+ blame);
if (err)
goto done;
@@ -643,9 +645,9 @@ done:
const struct got_error *
got_blame(const char *path, struct got_object_id *commit_id,
- struct got_repository *repo, got_blame_cb cb, void *arg,
- got_cancel_cb cancel_cb, void* cancel_arg, int fd1, int fd2, FILE *f1,
- FILE *f2)
+ struct got_repository *repo, enum got_diff_algorithm diff_algo,
+ got_blame_cb cb, void *arg, got_cancel_cb cancel_cb, void* cancel_arg,
+ int fd1, int fd2, FILE *f1, FILE *f2)
{
const struct got_error *err = NULL, *close_err = NULL;
struct got_blame *blame;
@@ -654,8 +656,8 @@ got_blame(const char *path, struct got_object_id *commit_id,
if (asprintf(&abspath, "%s%s", path[0] == '/' ? "" : "/", path) == -1)
return got_error_from_errno2("asprintf", path);
- err = blame_open(&blame, abspath, commit_id, repo, cb, arg,
- cancel_cb, cancel_arg, fd1, fd2, f1, f2);
+ err = blame_open(&blame, abspath, commit_id, repo, diff_algo,
+ cb, arg, cancel_cb, cancel_arg, fd1, fd2, f1, f2);
free(abspath);
if (blame)
close_err = blame_close(blame);
diff --git a/lib/diff.c b/lib/diff.c
index 500149f..7268a71 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -57,7 +57,8 @@ diff_blobs(off_t **line_offsets, size_t *nlines,
struct got_diffreg_result **resultp, struct got_blob_object *blob1,
struct got_blob_object *blob2, FILE *f1, FILE *f2,
const char *label1, const char *label2, mode_t mode1, mode_t mode2,
- int diff_context, int ignore_whitespace, int force_text_diff, FILE *outfile)
+ int diff_context, int ignore_whitespace, int force_text_diff, FILE *outfile,
+ enum got_diff_algorithm diff_algo)
{
const struct got_error *err = NULL, *free_err;
char hex1[SHA1_DIGEST_STRING_LENGTH];
@@ -160,8 +161,8 @@ diff_blobs(off_t **line_offsets, size_t *nlines,
free(modestr1);
free(modestr2);
}
- err = got_diffreg(&result, f1, f2, GOT_DIFF_ALGORITHM_PATIENCE,
- ignore_whitespace, force_text_diff);
+ err = got_diffreg(&result, f1, f2, diff_algo, ignore_whitespace,
+ force_text_diff);
if (err)
goto done;
@@ -197,26 +198,27 @@ got_diff_blob_output_unidiff(void *arg, struct got_blob_object *blob1,
return diff_blobs(&a->line_offsets, &a->nlines, NULL,
blob1, blob2, f1, f2, label1, label2, mode1, mode2, a->diff_context,
- a->ignore_whitespace, a->force_text_diff, a->outfile);
+ a->ignore_whitespace, a->force_text_diff, a->outfile, a->diff_algo);
}
const struct got_error *
got_diff_blob(off_t **line_offsets, size_t *nlines,
struct got_blob_object *blob1, struct got_blob_object *blob2,
FILE *f1, FILE *f2, const char *label1, const char *label2,
- int diff_context, int ignore_whitespace, int force_text_diff,
- FILE *outfile)
+ enum got_diff_algorithm diff_algo, int diff_context,
+ int ignore_whitespace, int force_text_diff, FILE *outfile)
{
return diff_blobs(line_offsets, nlines, NULL, blob1, blob2, f1, f2,
label1, label2, 0, 0, diff_context, ignore_whitespace,
- force_text_diff, outfile);
+ force_text_diff, outfile, diff_algo);
}
static const struct got_error *
diff_blob_file(struct got_diffreg_result **resultp,
struct got_blob_object *blob1, FILE *f1, off_t size1, const char *label1,
- FILE *f2, int f2_exists, size_t size2, const char *label2, int diff_context,
- int ignore_whitespace, int force_text_diff, FILE *outfile)
+ FILE *f2, int f2_exists, size_t size2, const char *label2,
+ enum got_diff_algorithm diff_algo, int diff_context, int ignore_whitespace,
+ int force_text_diff, FILE *outfile)
{
const struct got_error *err = NULL, *free_err;
char hex1[SHA1_DIGEST_STRING_LENGTH];
@@ -237,8 +239,8 @@ diff_blob_file(struct got_diffreg_result **resultp,
f2_exists ? label2 : "/dev/null");
}
- err = got_diffreg(&result, f1, f2, GOT_DIFF_ALGORITHM_PATIENCE,
- ignore_whitespace, force_text_diff);
+ err = got_diffreg(&result, f1, f2, diff_algo, ignore_whitespace,
+ force_text_diff);
if (err)
goto done;
@@ -266,12 +268,12 @@ done:
const struct got_error *
got_diff_blob_file(struct got_blob_object *blob1, FILE *f1, off_t size1,
const char *label1, FILE *f2, int f2_exists, size_t size2,
- const char *label2, int diff_context, int ignore_whitespace,
- int force_text_diff, FILE *outfile)
+ const char *label2, enum got_diff_algorithm diff_algo, int diff_context,
+ int ignore_whitespace, int force_text_diff, FILE *outfile)
{
return diff_blob_file(NULL, blob1, f1, size1, label1, f2, f2_exists,
- size2, label2, diff_context, ignore_whitespace, force_text_diff,
- outfile);
+ size2, label2, diff_algo, diff_context, ignore_whitespace,
+ force_text_diff, outfile );
}
static const struct got_error *
@@ -727,7 +729,8 @@ const struct got_error *
got_diff_objects_as_blobs(off_t **line_offsets, size_t *nlines,
FILE *f1, FILE *f2, int fd1, int fd2,
struct got_object_id *id1, struct got_object_id *id2,
- const char *label1, const char *label2, int diff_context,
+ const char *label1, const char *label2,
+ enum got_diff_algorithm diff_algo, int diff_context,
int ignore_whitespace, int force_text_diff,
struct got_repository *repo, FILE *outfile)
{
@@ -748,8 +751,8 @@ got_diff_objects_as_blobs(off_t **line_offsets, size_t *nlines,
goto done;
}
err = got_diff_blob(line_offsets, nlines, blob1, blob2, f1, f2,
- label1, label2, diff_context, ignore_whitespace, force_text_diff,
- outfile);
+ label1, label2, diff_algo, diff_context, ignore_whitespace,
+ force_text_diff, outfile);
done:
if (blob1)
got_object_blob_close(blob1);
@@ -918,7 +921,8 @@ diff_objects_as_trees(off_t **line_offsets, size_t *nlines,
struct got_object_id *id1, struct got_object_id *id2,
struct got_pathlist_head *paths, const char *label1, const char *label2,
int diff_context, int ignore_whitespace, int force_text_diff,
- struct got_repository *repo, FILE *outfile)
+ struct got_repository *repo, FILE *outfile,
+ enum got_diff_algorithm diff_algo)
{
const struct got_error *err;
struct got_tree_object *tree1 = NULL, *tree2 = NULL;
@@ -939,6 +943,7 @@ diff_objects_as_trees(off_t **line_offsets, size_t *nlines,
goto done;
}
+ arg.diff_algo = diff_algo;
arg.diff_context = diff_context;
arg.ignore_whitespace = ignore_whitespace;
arg.force_text_diff = force_text_diff;
@@ -975,8 +980,8 @@ got_diff_objects_as_trees(off_t **line_offsets, size_t *nlines,
FILE *f1, FILE *f2, int fd1, int fd2,
struct got_object_id *id1, struct got_object_id *id2,
struct got_pathlist_head *paths, const char *label1, const char *label2,
- int diff_context, int ignore_whitespace, int force_text_diff,
- struct got_repository *repo, FILE *outfile)
+ enum got_diff_algorithm diff_algo, int diff_context, int ignore_whitespace,
+ int force_text_diff, struct got_repository *repo, FILE *outfile)
{
const struct got_error *err;
char *idstr = NULL;
@@ -1020,7 +1025,7 @@ got_diff_objects_as_trees(off_t **line_offsets, size_t *nlines,
err = diff_objects_as_trees(line_offsets, nlines, f1, f2, fd1, fd2,
id1, id2, paths, label1, label2, diff_context, ignore_whitespace,
- force_text_diff, repo, outfile);
+ force_text_diff, repo, outfile, diff_algo);
done:
free(idstr);
return err;
@@ -1030,7 +1035,7 @@ const struct got_error *
got_diff_objects_as_commits(off_t **line_offsets, size_t *nlines,
FILE *f1, FILE *f2, int fd1, int fd2,
struct got_object_id *id1, struct got_object_id *id2,
- struct got_pathlist_head *paths,
+ struct got_pathlist_head *paths, enum got_diff_algorithm diff_algo,
int diff_context, int ignore_whitespace, int force_text_diff,
struct got_repository *repo, FILE *outfile)
{
@@ -1076,7 +1081,8 @@ got_diff_objects_as_commits(off_t **line_offsets, size_t *nlines,
err = diff_objects_as_trees(line_offsets, nlines, f1, f2, fd1, fd2,
commit1 ? got_object_commit_get_tree_id(commit1) : NULL,
got_object_commit_get_tree_id(commit2), paths, "", "",
- diff_context, ignore_whitespace, force_text_diff, repo, outfile);
+ diff_context, ignore_whitespace, force_text_diff, repo, outfile,
+ diff_algo);
done:
if (commit1)
got_object_commit_close(commit1);
@@ -1090,7 +1096,7 @@ const struct got_error *
got_diff_files(struct got_diffreg_result **resultp,
FILE *f1, int f1_exists, const char *label1, FILE *f2, int f2_exists,
const char *label2, int diff_context, int ignore_whitespace,
- int force_text_diff, FILE *outfile)
+ int force_text_diff, FILE *outfile, enum got_diff_algorithm diff_algo)
{
const struct got_error *err = NULL;
struct got_diffreg_result *diffreg_result = NULL;
@@ -1105,7 +1111,7 @@ got_diff_files(struct got_diffreg_result **resultp,
f2_exists ? label2 : "/dev/null");
}
- err = got_diffreg(&diffreg_result, f1, f2, GOT_DIFF_ALGORITHM_PATIENCE,
+ err = got_diffreg(&diffreg_result, f1, f2, diff_algo,
ignore_whitespace, force_text_diff);
if (err)
goto done;
diff --git a/lib/diff3.c b/lib/diff3.c
index f28b50b..3acd317 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -80,6 +80,7 @@
#include "got_error.h"
#include "got_opentemp.h"
#include "got_object.h"
+#include "got_diff.h"
#include "buf.h"
#include "rcsutil.h"
diff --git a/lib/diffreg.c b/lib/diffreg.c
index 186401e..30c7388 100644
--- a/lib/diffreg.c
+++ b/lib/diffreg.c
@@ -28,6 +28,7 @@
#include "got_object.h"
#include "got_opentemp.h"
#include "got_error.h"
+#include "got_diff.h"
#include "got_lib_diff.h"
diff --git a/lib/got_lib_diff.h b/lib/got_lib_diff.h
index 0157c86..3ff8d96 100644
--- a/lib/got_lib_diff.h
+++ b/lib/got_lib_diff.h
@@ -18,11 +18,6 @@
#include "diff_main.h"
#include "diff_output.h"
-enum got_diff_algorithm {
- GOT_DIFF_ALGORITHM_MYERS,
- GOT_DIFF_ALGORITHM_PATIENCE,
-};
-
enum got_diff_output_format {
GOT_DIFF_OUTPUT_UNIDIFF,
GOT_DIFF_OUTPUT_EDSCRIPT,
@@ -63,4 +58,5 @@ const struct got_error *got_merge_diff3(int *, int, FILE *, FILE *, FILE *,
const char *, const char *, const char *, enum got_diff_algorithm);
const struct got_error *got_diff_files(struct got_diffreg_result **, FILE *,
- int, const char *, FILE *, int, const char *, int, int, int, FILE *);
+ int, const char *, FILE *, int, const char *, int, int, int, FILE *,
+ enum got_diff_algorithm);
diff --git a/lib/patch.c b/lib/patch.c
index 0d8af2c..6b6915f 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -45,6 +45,7 @@
#include "got_repository.h"
#include "got_opentemp.h"
#include "got_patch.h"
+#include "got_diff.h"
#include "got_lib_delta.h"
#include "got_lib_diff.h"
diff --git a/lib/worktree.c b/lib/worktree.c
index c6a2aa5..585486a 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -4547,7 +4547,7 @@ create_patched_content(char **path_outfile, int reverse_patch,
goto done;
err = got_diff_files(&diffreg_result, f1, 1, id_str, f2, 1, path2,
- 3, 0, 1, NULL);
+ 3, 0, 1, NULL, GOT_DIFF_ALGORITHM_MYERS);
if (err)
goto done;
@@ -8362,7 +8362,7 @@ create_unstaged_content(char **path_unstaged_content,
goto done;
err = got_diff_files(&diffreg_result, f1, 1, label1, f2, 1,
- path2, 3, 0, 1, NULL);
+ path2, 3, 0, 1, NULL, GOT_DIFF_ALGORITHM_MYERS);
if (err)
goto done;
diff --git a/tog/tog.c b/tog/tog.c
index e7cd627..800384d 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -321,6 +321,7 @@ struct tog_diff_view_state {
int first_displayed_line;
int last_displayed_line;
int eof;
+ enum got_diff_algorithm diff_algo;
int diff_context;
int ignore_whitespace;
int force_text_diff;
@@ -3965,14 +3966,14 @@ create_diff(struct tog_diff_view_state *s)
case GOT_OBJ_TYPE_BLOB:
err = got_diff_objects_as_blobs(&s->line_offsets, &s->nlines,
s->f1, s->f2, s->fd1, s->fd2, s->id1, s->id2,
- s->label1, s->label2, s->diff_context,
+ s->label1, s->label2, s->diff_algo, s->diff_context,
s->ignore_whitespace, s->force_text_diff, s->repo, s->f);
break;
case GOT_OBJ_TYPE_TREE:
err = got_diff_objects_as_trees(&s->line_offsets, &s->nlines,
s->f1, s->f2, s->fd1, s->fd2, s->id1, s->id2, NULL, "", "",
- s->diff_context, s->ignore_whitespace, s->force_text_diff,
- s->repo, s->f);
+ s->diff_algo, s->diff_context, s->ignore_whitespace,
+ s->force_text_diff, s->repo, s->f);
break;
case GOT_OBJ_TYPE_COMMIT: {
const struct got_object_id_queue *parent_ids;
@@ -4007,8 +4008,8 @@ create_diff(struct tog_diff_view_state *s)
err = got_diff_objects_as_commits(&s->line_offsets, &s->nlines,
s->f1, s->f2, s->fd1, s->fd2, s->id1, s->id2, NULL,
- s->diff_context, s->ignore_whitespace, s->force_text_diff,
- s->repo, s->f);
+ s->diff_algo, s->diff_context, s->ignore_whitespace,
+ s->force_text_diff, s->repo, s->f);
break;
}
default:
@@ -4218,6 +4219,7 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
s->first_displayed_line = 1;
s->last_displayed_line = view->nlines;
+ s->diff_algo = GOT_DIFF_ALGORITHM_MYERS;
s->diff_context = diff_context;
s->ignore_whitespace = ignore_whitespace;
s->force_text_diff = force_text_diff;
@@ -4948,8 +4950,8 @@ blame_thread(void *arg)
goto done;
err = got_blame(ta->path, a->commit_id, ta->repo,
- blame_cb, ta->cb_args, ta->cancel_cb, ta->cancel_arg, fd1, fd2, f1,
- f2);
+ GOT_DIFF_ALGORITHM_MYERS, blame_cb, ta->cb_args,
+ ta->cancel_cb, ta->cancel_arg, fd1, fd2, f1, f2);
if (err && err->code == GOT_ERR_CANCELLED)
err = NULL;