gitweb: Use descriptive names in esc_html_hl_regions()

The $s->[0] and $s->[1] variables look a bit cryptic.  Let's rename them
to $begin and $end so that it's clear what they do.

Suggested-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb: esc_html_hl_regions(): Don't create empty <span> elements

If $end is equal to or less than $begin, esc_html_hl_regions()
generates an empty <span> element.  It normally shouldn't be visible in
the web browser, but it doesn't look good when looking at page source.
It also minimally increases generated page size for no special reason.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Acked-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb: Pass esc_html_hl_regions() options to esc_html()

With this change, esc_html_hl_regions() accepts options and passes them
down to esc_html().  This may be needed if a caller wants to pass
-nbsp=>1 to esc_html().

The idea and implementation example of this change was described in
337da8d2 (gitweb: Introduce esc_html_match_hl and esc_html_hl_regions,
2012-02-27).  While other suggestions may be more useful in some cases,
there is no need to implement them at the moment.  The
esc_html_hl_regions() interface may be changed later if it's needed.

[mk: extracted from larger patch and wrote commit message]

Signed-off-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb: Extract print_sidebyside_diff_lines()

Currently, print_sidebyside_diff_chunk() does two things: it
accumulates diff lines and prints them.  Accumulation may be used to
perform additional operations on diff lines, so it makes sense to split
these two things.  Thus, whole code that formats and prints diff lines
in the 'side-by-side' manner is moved out of print_sidebyside_diff_chunk()
to a separate subroutine and two conditions that control printing
diff liens are merged.

Thanks to that, we can easily (in later patches) replace call to that
subroutine with a call to more generic print_diff_lines() that will
control whether 'inline' or 'side-by-side' diff should be printed.

As a side effect, context lines are printed just before printing added
and removed lines, and at the end of chunk (previously, they were
printed immediately on the class change).  However, this doesn't change
gitweb output.

The outcome of this patch is that print_sidebyside_diff_chunk() is now
much shorter and easier to read.

While at it, drop the '# assume that it is change' comment.  According
to Jakub Narębski:

	What I meant here when I was writing it that they are lines that
	changed between two versions, like '!' in original (not unified)
	context format.

	We can omit this comment.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Acked-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb: Use print_diff_chunk() for both side-by-side and inline diffs

This renames print_sidebyside_diff_chunk() to print_diff_chunk() and
makes use of it for both side-by-side and inline diffs.  Now diff lines
are always accumulated before they are printed.  This opens the
possibility to preprocess diff output before it's printed, which is
needed for diff refinement highlightning (implemented in incoming
patches).

If print_diff_chunk() was left as is, the new function
print_inline_diff_lines() could reorder diff lines.  It first prints all
context lines, then all removed lines and finally all added lines.  If
the diff output consisted of mixed added and removed lines, gitweb would
reorder these lines.  This is true for combined diff output, for
example:

	 - removed line for first parent
	 + added line for first parent
	  -removed line for second parent
	 ++added line for both parents

would be rendered as:

	- removed line for first parent
	 -removed line for second parent
	+ added line for first parent
	++added line for both parents

To prevent gitweb from reordering lines, print_diff_chunk() calls
print_diff_lines() as soon as it detects that both added and removed
lines are present and there was a class change, and at the end of chunk.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb: Push formatting diff lines to print_diff_chunk()

Now lines are formatted closer to place where we actually use HTML
formatted output.

This means that we put raw lines in the @chunk accumulator, rather than
formatted lines.  Because we still need to know class (type) of line
when accumulating data to post-process and print, process_diff_line()
subroutine was retired and replaced by diff_line_class() used in
git_patchset_body() and new restructured format_diff_line() used in
print_diff_chunk().

As a side effect, we have to pass \%from and \%to down to callstack.

This is a preparation patch for diff refinement highlightning. It's not
meant to change gitweb output.

[jn: wrote commit message]

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Acked-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb: Highlight interesting parts of diff

Reading diff output is sometimes very hard, even if it's colored,
especially if lines differ only in few characters.  This is often true
when a commit fixes a typo or renames some variables or functions.

This commit teaches gitweb to highlight characters that are different
between old and new line with a light green/red background.  This should
work in the similar manner as in Trac or GitHub.

The algorithm that compares lines is based on contrib/diff-highlight.
Basically, it works by determining common prefix/suffix of corresponding
lines and highlightning only the middle part of lines.  For more
information, see contrib/diff-highlight/README.

Combined diffs are not supported but a following commit will change it.

Since we need to pass esc_html()'ed or esc_html_hl_regions()'ed lines to
format_diff_lines(), so it was taught to accept preformatted lines
passed as a reference.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Acked-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb: Refinement highlightning in combined diffs

The highlightning of combined diffs is currently disabled.  This is
because output from a combined diff is much harder to highlight because
it is not obvious which removed and added lines should be compared.

Current code requires that the number of added lines is equal to the
number of removed lines and only skips first +/- character, treating
second +/- as a line content, Thus, it is not possible to simply use
existing algorithm unchanged for combined diffs.

Let's start with a simple case: only highlight changes that come from
one parent, i.e. when every removed line has a corresponding added line
for the same parent.  This way the highlightning cannot get wrong. For
example, following diffs would be highlighted:

	- removed line for first parent
	+ added line for first parent
	  context line
	 -removed line for second parent
	 +added line for second parent

or

	- removed line for first parent
	 -removed line for second parent
	+ added line for first parent
	 +added line for second parent

but following output will not:

	- removed line for first parent
	 -removed line for second parent
	 +added line for second parent
	++added line for both parents

In other words, we require that pattern of '-'-es in pre-image matches
pattern of '+'-es in post-image.

Further changes may introduce more intelligent approach that better
handles combined diffs.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Acked-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'sl/test-wc-l-line-count' into pu

By Stefano Lattarini
* sl/test-wc-l-line-count:
  tests: modernise style: more uses of test_line_count
Merge branch 'hv/submodule-recurse-push' into pu

By Heiko Voigt
* hv/submodule-recurse-push:
  push: teach --recurse-submodules the on-demand option
  Refactor submodule push check to use string list instead of integer
  Teach revision walking machinery to walk multiple times sequencially

Conflicts:
	transport.h
Merge branch 'mk/gitweb-diff-hl' into pu

Rerolled.

By Michał Kiedrowicz (7) and Jakub Narębski (1)
* mk/gitweb-diff-hl:
  gitweb: Refinement highlightning in combined diffs
  gitweb: Highlight interesting parts of diff
  gitweb: Push formatting diff lines to print_diff_chunk()
  gitweb: Use print_diff_chunk() for both side-by-side and inline diffs
  gitweb: Extract print_sidebyside_diff_lines()
  gitweb: Pass esc_html_hl_regions() options to esc_html()
  gitweb: esc_html_hl_regions(): Don't create empty <span> elements
  gitweb: Use descriptive names in esc_html_hl_regions()
Merge branch 'pw/fast-import-dataref-parsing' into pu

By Pete Wyckoff
* pw/fast-import-dataref-parsing:
  fast-import: tighten parsing of datarefs
Merge branch 'tr/xdiff-fast-hash' into pu

By Thomas Rast
* tr/xdiff-fast-hash:
  xdiff: load full words in the inner loop of xdl_hash_record
Merge branch 'cb/http-multi-curl-auth' into pu

Fixes http authentication breakage when we keep multiple HTTP requests in
flight using curl-multi.

Peff may want to sign this off, but otherwise looked sensible.

By Clemens Buchacher (1) and Jeff King (1)
* cb/http-multi-curl-auth:
  fix http auth with multiple curl handles
  http auth fails with multiple curl handles
Merge branch 'mh/ref-api' into pu

By Michael Haggerty
* mh/ref-api:
  do_for_each_ref(): only iterate over the subtree that was requested
  refs: store references hierarchically
  sort_ref_dir(): simplify logic
  refs.c: rename ref_array -> ref_dir
  struct ref_entry: nest the value part in a union
  check_refname_component(): return 0 for zero-length components
  free_ref_entry(): new function
  names_conflict(): simplify implementation
  repack_without_ref(): reimplement using do_for_each_ref_in_array()
  do_for_each_ref_in_arrays(): new function
  do_for_each_ref_in_array(): new function
  refs: manage current_ref within do_one_ref()
  refs.c: reorder definitions more logically
Merge branch 'rs/commit-list-sort-in-batch' into pu

By René Scharfe
* rs/commit-list-sort-in-batch:
  revision: insert unsorted, then sort in prepare_revision_walk()
  commit: use mergesort() in commit_list_sort_by_date()
  add mergesort() for linked lists
Merge branch 'lt/octopus-simplify' into pu

By Linus Torvalds
* lt/octopus-simplify:
  Make 'git merge' simplify parents ealier
Merge branch 'jc/maint-blame-minimal' into pu

* jc/maint-blame-minimal:
  blame: accept --need-minimal
Merge branch 'ld/git-p4-tags-and-labels' into pu

By Luke Diamand
* ld/git-p4-tags-and-labels:
  git p4: import/export of labels to/from p4
  git p4: Fixing script editor checks
Merge branch 'jk/repack-no-explode-objects-from-old-pack' into pu

By Jeff King
* jk/repack-no-explode-objects-from-old-pack:
  gc: do not explode objects which will be immediately pruned