Commits


fix a format string issue in array test ARRAYLIST_IDX deals with the head pointer. Explicitly cast to unsigned long and use %lu in the format string. Clang 10.0.1 used to complain as follows: arraylist_test.c:19:2: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] arraylist_test.c:15:24: note: expanded from macro 'dump' printf("[%d] %d\n", ARRAYLIST_IDX(p, list), *p); \ ~~ ^~~~~~~~~~~~~~~~~~~~~~


put functions required for using diff_output_unidiff_chunk() into public API They will be needed to implement 'got stage -p' and 'got revert -p', etc. Chunks stored in diff_result still need post-processing in order to be displayed as expected by diff_output_unidiff_chunk(). Exposing these functions allows API consumers to implement the same chunk merging loop as used internally by output_unidiff() and output_edscript(). (Perhaps, ideally, the public diff API would provide pre-merged chunks at some point in the future? Then this commit could probably be reverted.) Change return values from bool to int to avoid making stdbool.h a requirement for the public diff API.


expose chunk_context_empty() via diff_internal.h and use it in edscript output


use mergesort(3) instead of qsort(3) in patience diff Fixes test failures on OpenBSD due to unstable results of qsort if two or more elements are equal. Add a compat copy of OpenBSD mergesort(3) for Linux.


check for allocation failure in diff_atoms_mark_unique_in_both_by_qsort()


initialize to NULL instead of ""; allows pointer check to see if file is mapped


revert 1ea185225fc4897fdfbe0043837b43ddab3f1449 which caused an infinite loop


atoms are stored in an array, not a list; use direct indexing instead of loop


fix a segfault: d->data may point to "", this cannot be checked for NULL


print "\ No newline at end of file" message like UNIX diff(1) does Not adding new tests since this behaviour is covered by tests in Got.


in ed output mode, show changed lines as XXcYY etc. as UNIX diff(1) does


wrap a comment that had overlong lines


diff_myers: fix some uninitialized warnings


patience: fix uninitialized rc in diff_atoms_qsort_compar


add -Wuninitialized to CFLAGS on Linux build; exposes some bugs already


add test for -T option This uncovered a bug in diff_algo_none(), so let's keep it.


move patience data out of struct diff_atom Now allocating patience specific data only when patience is going to be used. This may allow using forward-Myers more often, since the state size per line is significantly smaller. Patience instead allocates an array, puts it in the current diff_data, and also place a pointer of the current diff_data in the root diff_data (since each atom points to the root diff_data).


add patience tests


test/verify_all.sh: allow combined cmdline opts


patience: use qsort to optimize finding unique lines


rename diff_atom->d to diff_atom->root, because it always is The idea was that for each diff box within the files, the atoms would have a backpointer to the current layer of diff_data (indicating the current section), but it is not actually needed to update the backpointer in each atom to the current diff_data. That is why the current code always points atom->d to the root diff_data for the entire file. Clarify by proper name. Constructs like atom->d->root->foo are redundant, just use atom->root->foo.


diff: drop -p, add -P -Q -T; diffreg(): use algo enum -p is traditionally used for "show which C function each change is in", so don't use it for choosing Patience. Instead add two options for using Patience, -P for only Patience and -Q to attempt forward-Myers first. Also add -T for a trivial diff (diff_algo_none).


test: add expect0{10,11,12,14}.diff


diff_main: don't run algo if left or right are empty


debug: fix logging first chunk