+static unsigned long line_all_diff(struct sline *sline, unsigned long all_mask)
+{
+ /*
+ * Look at the line and see from which parents we have some difference.
+ */
+ unsigned long different = (sline->flag ^ all_mask) & all_mask;
+ if (sline->lost_head) {
+ /* Lost head list records the lines removed from
+ * the parents, and parent_map records from which
+ * parent the line was removed.
+ */
+ struct lline *ll;
+ for (ll = sline->lost_head; ll; ll = ll->next) {
+ different |= ll->parent_map;
+ }
+ }
+ return different;
+}
+
+static unsigned long adjust_hunk_tail(struct sline *sline,
+ unsigned long all_mask,
+ unsigned long hunk_begin,
+ unsigned long i)
+{
+ /* i points at the first uninteresting line.
+ * If the last line of the hunk was interesting
+ * only because it has some deletion, then
+ * it is not all that interesting for the
+ * purpose of giving trailing context lines.
+ */
+ if ((hunk_begin + 1 <= i) &&
+ ((sline[i-1].flag & all_mask) == all_mask))
+ i--;
+ return i;
+}
+
+static unsigned long next_interesting(struct sline *sline,
+ unsigned long mark,
+ unsigned long i,
+ unsigned long cnt,
+ int uninteresting)
+{
+ while (i < cnt)
+ if (uninteresting ?
+ !(sline[i].flag & mark) :
+ (sline[i].flag & mark))
+ return i;
+ else
+ i++;
+ return cnt;
+}
+
+static int give_context(struct sline *sline, unsigned long cnt, int num_parent)