Commit Diff


commit - 760fe30eb1f6351170157beaae12a0ca0c2698a9
commit + 61a7b57805472a03ad39d7bf4ef6d705eb0ccac2
blob - 0716796d2d5147368425b3edd6cc0e00d8ddc9ea
blob + 570d5c58f2fda7b886d942ae92961bfddb6c1664
--- include/diff/diff_main.h
+++ include/diff/diff_main.h
@@ -37,17 +37,20 @@ struct range {
 	int end;
 };
 
-static inline bool range_empty(const struct range *r)
+static inline bool
+range_empty(const struct range *r)
 {
 	return r->start == r->end;
 }
 
-static inline bool ranges_touch(const struct range *a, const struct range *b)
+static inline bool
+ranges_touch(const struct range *a, const struct range *b)
 {
 	return (a->end >= b->start) && (a->start <= b->end);
 }
 
-static inline void ranges_merge(struct range *a, const struct range *b)
+static inline void
+ranges_merge(struct range *a, const struct range *b)
 {
 	*a = (struct range){
 		.start = MIN(a->start, b->start),
@@ -55,7 +58,8 @@ static inline void ranges_merge(struct range *a, const
 	};
 }
 
-static inline int range_len(const struct range *r)
+static inline int
+range_len(const struct range *r)
 {
 	if (!r)
 		return 0;
@@ -90,7 +94,8 @@ struct diff_atom {
 	} patience;
 };
 
-static inline bool diff_atom_same(const struct diff_atom *left, const struct diff_atom *right)
+static inline bool
+diff_atom_same(const struct diff_atom *left, const struct diff_atom *right)
 {
 	return left->hash == right->hash
 		&& left->len == right->len
blob - d3a560ca65443972ce10f241d3345d036bf04e7f
blob + 4e13a9434d0d167686e127df728bf257d02d1f0c
--- lib/debug.h
+++ lib/debug.h
@@ -26,7 +26,8 @@
 #define debug_dump_atom dump_atom
 #define debug_dump_atoms dump_atoms
 
-static inline void dump_atom(const struct diff_data *left, const struct diff_data *right, const struct diff_atom *atom)
+static inline void
+dump_atom(const struct diff_data *left, const struct diff_data *right, const struct diff_atom *atom)
 {
 	if (!atom) {
 		print("NULL atom\n");
@@ -52,7 +53,8 @@ static inline void dump_atom(const struct diff_data *l
 	print("'\n");
 }
 
-static inline void dump_atoms(const struct diff_data *d, struct diff_atom *atom, unsigned int count)
+static inline void
+dump_atoms(const struct diff_data *d, struct diff_atom *atom, unsigned int count)
 {
 	if (count > 42) {
 		dump_atoms(d, atom, 20);
@@ -67,7 +69,8 @@ static inline void dump_atoms(const struct diff_data *
 	}
 }
 
-static inline void dump(struct diff_data *d)
+static inline void
+dump(struct diff_data *d)
 {
 	dump_atoms(d, d->atoms.head, d->atoms.len);
 }
@@ -75,8 +78,9 @@ static inline void dump(struct diff_data *d)
 /* kd is a quadratic space myers matrix from the original Myers algorithm.
  * kd_forward and kd_backward are linear slices of a myers matrix from the Myers Divide algorithm.
  */
-static inline void dump_myers_graph(const struct diff_data *l, const struct diff_data *r,
-				    int *kd, int *kd_forward, int kd_forward_d, int *kd_backward, int kd_backward_d)
+static inline void
+dump_myers_graph(const struct diff_data *l, const struct diff_data *r,
+		 int *kd, int *kd_forward, int kd_forward_d, int *kd_backward, int kd_backward_d)
 {
 	#define COLOR_YELLOW "\033[1;33m"
 	#define COLOR_GREEN "\033[1;32m"
@@ -179,8 +183,9 @@ static inline void dump_myers_graph(const struct diff_
 	}
 }
 
-static inline void debug_dump_myers_graph(const struct diff_data *l, const struct diff_data *r,
-				    int *kd, int *kd_forward, int kd_forward_d, int *kd_backward, int kd_backward_d)
+static inline void
+debug_dump_myers_graph(const struct diff_data *l, const struct diff_data *r,
+		       int *kd, int *kd_forward, int kd_forward_d, int *kd_backward, int kd_backward_d)
 {
 	if (l->atoms.len > 99 || r->atoms.len > 99)
 		return;
blob - 0b88a3cedf38d100921a49d211e059e7ebdc11d5
blob + fbeb6164469b907b7e572d24ec0f8c6310a47eeb
--- lib/diff_atomize_text.c
+++ lib/diff_atomize_text.c
@@ -17,7 +17,8 @@
 
 #include <diff/diff_main.h>
 
-static int diff_data_atomize_text_lines(struct diff_data *d)
+static int
+diff_data_atomize_text_lines(struct diff_data *d)
 {
 	const uint8_t *pos = d->data;
 	const uint8_t *end = pos + d->len;
@@ -64,7 +65,8 @@ static int diff_data_atomize_text_lines(struct diff_da
 	return DIFF_RC_OK;
 }
 
-enum diff_rc diff_atomize_text_by_line(void *func_data, struct diff_data *left, struct diff_data *right)
+enum diff_rc
+diff_atomize_text_by_line(void *func_data, struct diff_data *left, struct diff_data *right)
 {
 	enum diff_rc rc;
 	rc = diff_data_atomize_text_lines(left);
blob - 46c7fc63654f51755c1bde729244e679a0fa7c6c
blob + 8858013c493332f472d8fb36c12f51e62f1c19d4
--- lib/diff_main.c
+++ lib/diff_main.c
@@ -33,9 +33,10 @@
 /* Even if a left or right side is empty, diff output may need to know the position in that file.
  * So left_start or right_start must never be NULL -- pass left_count or right_count as zero to indicate staying at that
  * position without consuming any lines. */
-struct diff_chunk *diff_state_add_chunk(struct diff_state *state, bool solved,
-					struct diff_atom *left_start, unsigned int left_count,
-					struct diff_atom *right_start, unsigned int right_count)
+struct diff_chunk *
+diff_state_add_chunk(struct diff_state *state, bool solved,
+		     struct diff_atom *left_start, unsigned int left_count,
+		     struct diff_atom *right_start, unsigned int right_count)
 {
 	struct diff_chunk *chunk;
 	diff_chunk_arraylist_t *result;
@@ -64,7 +65,8 @@ struct diff_chunk *diff_state_add_chunk(struct diff_st
 	return chunk;
 }
 
-void diff_data_init_root(struct diff_data *d, const uint8_t *data, size_t len)
+void
+diff_data_init_root(struct diff_data *d, const uint8_t *data, size_t len)
 {
 	*d = (struct diff_data){
 		.data = data,
@@ -73,8 +75,9 @@ void diff_data_init_root(struct diff_data *d, const ui
 	};
 }
 
-void diff_data_init_subsection(struct diff_data *d, struct diff_data *parent,
-			       struct diff_atom *from_atom, unsigned int atoms_count)
+void
+diff_data_init_subsection(struct diff_data *d, struct diff_data *parent,
+			  struct diff_atom *from_atom, unsigned int atoms_count)
 {
 	struct diff_atom *last_atom = from_atom + atoms_count - 1;
 	*d = (struct diff_data){
@@ -89,7 +92,8 @@ void diff_data_init_subsection(struct diff_data *d, st
 	debug_dump(d);
 }
 
-void diff_data_free(struct diff_data *diff_data)
+void
+diff_data_free(struct diff_data *diff_data)
 {
 	if (!diff_data)
 		return;
@@ -97,7 +101,8 @@ void diff_data_free(struct diff_data *diff_data)
 		ARRAYLIST_FREE(diff_data->atoms);
 }
 
-enum diff_rc diff_algo_none(const struct diff_algo_config *algo_config, struct diff_state *state)
+enum diff_rc
+diff_algo_none(const struct diff_algo_config *algo_config, struct diff_state *state)
 {
 	debug("\n** %s\n", __func__);
 	debug("left:\n");
@@ -138,7 +143,8 @@ enum diff_rc diff_algo_none(const struct diff_algo_con
 	return DIFF_RC_OK;
 }
 
-enum diff_rc diff_run_algo(const struct diff_algo_config *algo_config, struct diff_state *state)
+enum diff_rc
+diff_run_algo(const struct diff_algo_config *algo_config, struct diff_state *state)
 {
 	enum diff_rc rc;
 	ARRAYLIST_FREE(state->temp_result);
@@ -202,9 +208,10 @@ return_rc:
 	return rc;
 }
 
-struct diff_result *diff_main(const struct diff_config *config,
-			      const uint8_t *left_data, size_t left_len,
-			      const uint8_t *right_data, size_t right_len)
+struct diff_result *
+diff_main(const struct diff_config *config,
+	  const uint8_t *left_data, size_t left_len,
+	  const uint8_t *right_data, size_t right_len)
 {
 	struct diff_result *result = malloc(sizeof(struct diff_result));
 	if (!result)
@@ -235,7 +242,8 @@ struct diff_result *diff_main(const struct diff_config
 	return result;
 }
 
-void diff_result_free(struct diff_result *result)
+void
+diff_result_free(struct diff_result *result)
 {
 	if (!result)
 		return;
blob - 7a7f5de552270024ae0e6d69c930aa56b5e0a24e
blob + c14e542b7962f990a43c57c58bb31670d56d76f9
--- lib/diff_myers.c
+++ lib/diff_myers.c
@@ -185,9 +185,10 @@ struct diff_box {
  *    For d == 0, kd_forward[0] is initialized, i.e. the first invocation should be for d == 0.
  * meeting_snake: resulting meeting point, if any.
  */
-static bool diff_divide_myers_forward(struct diff_data *left, struct diff_data *right,
-				      int *kd_forward, int *kd_backward, int d,
-				      struct diff_box *meeting_snake)
+static bool
+diff_divide_myers_forward(struct diff_data *left, struct diff_data *right,
+			  int *kd_forward, int *kd_backward, int d,
+			  struct diff_box *meeting_snake)
 {
 	int delta = (int)right->atoms.len - (int)left->atoms.len;
 	int k;
@@ -428,9 +429,10 @@ static bool diff_divide_myers_forward(struct diff_data
  *    The first invocation will be for d == 1.
  * meeting_snake: resulting meeting point, if any.
  */
-static bool diff_divide_myers_backward(struct diff_data *left, struct diff_data *right,
-				       int *kd_forward, int *kd_backward, int d,
-				       struct diff_box *meeting_snake)
+static bool
+diff_divide_myers_backward(struct diff_data *left, struct diff_data *right,
+			   int *kd_forward, int *kd_backward, int d,
+			   struct diff_box *meeting_snake)
 {
 	int delta = (int)right->atoms.len - (int)left->atoms.len;
 	int c;
@@ -645,7 +647,8 @@ static bool diff_divide_myers_backward(struct diff_dat
 
 /* Myers "Divide et Impera": tracing forwards from the start and backwards from the end to find a midpoint that divides
  * the problem into smaller chunks. Requires only linear amounts of memory. */
-enum diff_rc diff_algo_myers_divide(const struct diff_algo_config *algo_config, struct diff_state *state)
+enum diff_rc
+diff_algo_myers_divide(const struct diff_algo_config *algo_config, struct diff_state *state)
 {
 	enum diff_rc rc = DIFF_RC_ENOMEM;
 	struct diff_data *left = &state->left;
@@ -783,7 +786,8 @@ return_rc:
 
 /* Myers Diff tracing from the start all the way through to the end, requiring quadratic amounts of memory. This can
  * fail if the required space surpasses algo_config->permitted_state_size. */
-enum diff_rc diff_algo_myers(const struct diff_algo_config *algo_config, struct diff_state *state)
+enum diff_rc
+diff_algo_myers(const struct diff_algo_config *algo_config, struct diff_state *state)
 {
 	/* do a diff_divide_myers_forward() without a _backward(), so that it walks forward across the entire
 	 * files to reach the end. Keep each run's state, and do a final backtrace. */
blob - c7fe3adc5f0ce38b80665f0f7703d3d608ba0047
blob + cdc0e9bd029917c5bf84ef03f748cd13965f386c
--- lib/diff_output.c
+++ lib/diff_output.c
@@ -17,7 +17,8 @@
 
 #include <diff/diff_output.h>
 
-void diff_output_lines(FILE *dest, const char *prefix, struct diff_atom *start_atom, unsigned int count)
+void
+diff_output_lines(FILE *dest, const char *prefix, struct diff_atom *start_atom, unsigned int count)
 {
 	struct diff_atom *atom;
 	foreach_diff_atom(atom, start_atom, count) {
blob - 55564fe485f024584b4094a4d203cd057b93ea1b
blob + 4195b51f8a5f76a61aff4d614ce64a923c8ecc71
--- lib/diff_output_plain.c
+++ lib/diff_output_plain.c
@@ -17,8 +17,9 @@
 
 #include <diff/diff_output.h>
 
-enum diff_rc diff_output_plain(FILE *dest, const struct diff_input_info *info,
-			       const struct diff_result *result)
+enum diff_rc
+diff_output_plain(FILE *dest, const struct diff_input_info *info,
+		  const struct diff_result *result)
 {
 	if (!result)
 		return DIFF_RC_EINVAL;
blob - 40cc34ebd59e457c7dd39671b0abd49f24937a19
blob + 8e537ca9fd7a8c27f7af66f3592eaac6043a3b2e
--- lib/diff_output_unidiff.c
+++ lib/diff_output_unidiff.c
@@ -27,7 +27,8 @@ enum chunk_type {
 	CHUNK_WEIRD,
 };
 
-static inline enum chunk_type chunk_type(const struct diff_chunk *chunk)
+static inline enum chunk_type
+chunk_type(const struct diff_chunk *chunk)
 {
 	if (!chunk->left_count && !chunk->right_count)
 		return CHUNK_EMPTY;
@@ -47,13 +48,15 @@ struct chunk_context {
 	struct range left, right;
 };
 
-static bool chunk_context_empty(const struct chunk_context *cc)
+static bool
+chunk_context_empty(const struct chunk_context *cc)
 {
 	return range_empty(&cc->chunk);
 }
 
-static void chunk_context_get(struct chunk_context *cc, const struct diff_result *r, int chunk_idx,
-		       int context_lines)
+static void
+chunk_context_get(struct chunk_context *cc, const struct diff_result *r, int chunk_idx,
+		  int context_lines)
 {
 	const struct diff_chunk *c = &r->chunks.head[chunk_idx];
 	int left_start = diff_atom_root_idx(&r->left, c->left_start);
@@ -75,22 +78,25 @@ static void chunk_context_get(struct chunk_context *cc
 	};
 }
 
-static bool chunk_contexts_touch(const struct chunk_context *cc, const struct chunk_context *other)
+static bool
+chunk_contexts_touch(const struct chunk_context *cc, const struct chunk_context *other)
 {
 	return ranges_touch(&cc->chunk, &other->chunk)
 		|| ranges_touch(&cc->left, &other->left)
 		|| ranges_touch(&cc->right, &other->right);
 }
 
-static void chunk_contexts_merge(struct chunk_context *cc, const struct chunk_context *other)
+static void
+chunk_contexts_merge(struct chunk_context *cc, const struct chunk_context *other)
 {
 	ranges_merge(&cc->chunk, &other->chunk);
 	ranges_merge(&cc->left, &other->left);
 	ranges_merge(&cc->right, &other->right);
 }
 
-static void diff_output_unidiff_chunk(FILE *dest, bool *header_printed, const struct diff_input_info *info,
-				      const struct diff_result *result, const struct chunk_context *cc)
+static void
+diff_output_unidiff_chunk(FILE *dest, bool *header_printed, const struct diff_input_info *info,
+			  const struct diff_result *result, const struct chunk_context *cc)
 {
 	if (range_empty(&cc->left) && range_empty(&cc->right))
 		return;
@@ -136,8 +142,9 @@ static void diff_output_unidiff_chunk(FILE *dest, bool
 				  cc->left.end - chunk_end_line);
 }
 
-enum diff_rc diff_output_unidiff(FILE *dest, const struct diff_input_info *info,
-				 const struct diff_result *result, unsigned int context_lines)
+enum diff_rc
+diff_output_unidiff(FILE *dest, const struct diff_input_info *info,
+		    const struct diff_result *result, unsigned int context_lines)
 {
 	if (!result)
 		return DIFF_RC_EINVAL;
blob - 17fcf075be5314b830bd4d85873c98c68516487f
blob + 9688701396a6430dba17305759f33a0b93832d9a
--- lib/diff_patience.c
+++ lib/diff_patience.c
@@ -22,7 +22,8 @@
 #include "debug.h"
 
 /* Set unique_here = true for all atoms that exist exactly once in this list. */
-static void diff_atoms_mark_unique(struct diff_data *d, unsigned int *unique_count)
+static void
+diff_atoms_mark_unique(struct diff_data *d, unsigned int *unique_count)
 {
 	struct diff_atom *i;
 	unsigned int count = 0;
@@ -55,8 +56,9 @@ static void diff_atoms_mark_unique(struct diff_data *d
 }
 
 /* Mark those lines as atom->patience.unique_in_both = true that appear exactly once in each side. */
-static void diff_atoms_mark_unique_in_both(struct diff_data *left, struct diff_data *right,
-					   unsigned int *unique_in_both_count)
+static void
+diff_atoms_mark_unique_in_both(struct diff_data *left, struct diff_data *right,
+			       unsigned int *unique_in_both_count)
 {
 	/* Derive the final unique_in_both count without needing an explicit iteration. So this is just some
 	 * optimiziation to save one iteration in the end. */
@@ -118,8 +120,9 @@ static void diff_atoms_mark_unique_in_both(struct diff
 		*unique_in_both_count = unique_in_both;
 }
 
-static void diff_atoms_swallow_identical_neighbors(struct diff_data *left, struct diff_data *right,
-						   unsigned int *unique_in_both_count)
+static void
+diff_atoms_swallow_identical_neighbors(struct diff_data *left, struct diff_data *right,
+				       unsigned int *unique_in_both_count)
 {
 	debug("trivially combine identical lines arount unique_in_both lines\n");
 
@@ -189,7 +192,8 @@ static void diff_atoms_swallow_identical_neighbors(str
  * order (with other stuff allowed to interleave). Use patience sort for that, as in the Patience Diff algorithm.
  * See https://bramcohen.livejournal.com/73318.html and, for a much more detailed explanation,
  * https://blog.jcoglan.com/2017/09/19/the-patience-diff-algorithm/ */
-enum diff_rc diff_algo_patience(const struct diff_algo_config *algo_config, struct diff_state *state)
+enum diff_rc
+diff_algo_patience(const struct diff_algo_config *algo_config, struct diff_state *state)
 {
 	enum diff_rc rc = DIFF_RC_ENOMEM;