git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 05/38] refs: create a base class "ref_store" for files_ref_store

From
René Scharfe <l.s.r@web.de>
Date
Jun 9, 2016, 21:54 UTC
Message-ID
<5759E5A8.9060000@web.de>
In-Reply-To
<xmqqfusprmeq.fsf@gitster.mtv.corp.google.com>
Am 07.06.2016 um 18:31 schrieb Junio C Hamano:
Show 7 quoted lines
> This is a tangent, but your series that ends at 4aa2c475 (grep: -W:
> don't extend context to trailing empty lines, 2016-05-28) does not
> seem to have much effect when viewing the change to refs.c this
> patch makes (it modifies a function in an early part, and then adds
> bunch of new functions at the end) with "git show -W".
> 
> Thanks.
Good catch, thanks!
-- >8 --
Subject: [PATCH] xdiff: fix merging of appended hunk with -W

When -W is given we search the lines between the end of the current context and the next change for a function line. If there is none then we merge those two hunks as they must be part of the same function.

If the next change is an appended chunk we abort the search early in get_func_line(), however, because its line number is out of range. Fix that by searching from the end of the pre-image in that case instead.

Reported-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 t/t4051-diff-function-context.sh | 24 +++++++++++++++++++++++-
 xdiff/xemit.c                    |  3 ++-
 2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/t/t4051-diff-function-context.sh b/t/t4051-diff-function-context.sh
index b6bb04a..b79b877 100755
--- a/t/t4051-diff-function-context.sh
+++ b/t/t4051-diff-function-context.sh
@@ -64,7 +64,13 @@ test_expect_success 'setup' '
 
 	grep -v "Begin of second part" <file.c >file.c.new &&
 	mv file.c.new file.c &&
-	commit_and_tag long_common_tail file.c
+	commit_and_tag long_common_tail file.c &&
+
+	git checkout initial &&
+	grep -v "delete me from hello" <file.c >file.c.new &&
+	mv file.c.new file.c &&
+	cat "$dir/appended1.c" >>file.c &&
+	commit_and_tag changed_hello_appended file.c
 '
 
 check_diff changed_hello 'changed function'
@@ -157,4 +163,20 @@ test_expect_success ' context does not include preceding empty lines' '
 	test "$(first_context_line <long_common_tail.diff.diff)" != " "
 '
 
+check_diff changed_hello_appended 'changed function plus appended function'
+
+test_expect_success ' context includes begin' '
+	grep "^ .*Begin of hello" changed_hello_appended.diff &&
+	grep "^[+].*Begin of first part" changed_hello_appended.diff
+'
+
+test_expect_success ' context includes end' '
+	grep "^ .*End of hello" changed_hello_appended.diff &&
+	grep "^[+].*End of first part" changed_hello_appended.diff
+'
+
+test_expect_success ' context does not include other functions' '
+	test $(grep -c "^[ +-].*Begin" changed_hello_appended.diff) -le 2
+'
+
 test_done
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index bfa53d3..49aa16f 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -246,7 +246,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
 			 * its new end.
 			 */
 			if (xche->next) {
-				long l = xche->next->i1;
+				long l = XDL_MIN(xche->next->i1,
+						 xe->xdf1.nrec - 1);
 				if (l <= e1 ||
 				    get_func_line(xe, xecfg, NULL, l, e1) < 0) {
 					xche = xche->next;
-- 
2.8.3
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 67 in “Virtualization of the refs API”
  1. 00/38 Virtualization of the refs APIMichael Haggerty, Jun 3, 2016
  2. 01/38 resolve_gitlink_ref(): eliminate temporary variableMichael Haggerty, Jun 3, 2016
  3. 02/38 rename_ref_available(): add docstringMichael Haggerty, Jun 3, 2016
  4. Junio C HamanoJun 7, 2016
  5. Michael HaggertyJun 9, 2016
  6. Junio C HamanoJun 9, 2016
  7. 03/38 refs: rename struct ref_cache to files_ref_storeMichael Haggerty, Jun 3, 2016
  8. 04/38 refs: add a backend method structureMichael Haggerty, Jun 3, 2016
  9. 05/38 refs: create a base class "ref_store" for files_ref_storeMichael Haggerty, Jun 3, 2016
  10. Junio C HamanoJun 7, 2016
  11. René ScharfeJun 9, 2016
  12. Junio C HamanoJun 7, 2016
  13. Michael HaggertyJun 9, 2016
  14. Junio C HamanoJun 9, 2016
  15. Michael HaggertyJun 10, 2016
  16. Junio C HamanoJun 10, 2016
  17. Eric SunshineJun 10, 2016
  18. Michael HaggertyJun 10, 2016
  19. 06/38 add_packed_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  20. 07/38 get_packed_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  21. 08/38 resolve_missing_loose_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  22. 09/38 {lock,commit,rollback}_packed_refs(): add files_ref_store argumentsMichael Haggerty, Jun 3, 2016
  23. 10/38 refs: add a transaction_commit() methodMichael Haggerty, Jun 3, 2016
  24. 11/38 refs: reorder definitionsMichael Haggerty, Jun 3, 2016
  25. 12/38 resolve_packed_ref(): rename function from resolve_missing_loose_ref()Michael Haggerty, Jun 3, 2016
  26. 13/38 resolve_gitlink_packed_ref(): remove functionMichael Haggerty, Jun 3, 2016
  27. 14/38 read_raw_ref(): take a (struct ref_store *) argumentMichael Haggerty, Jun 3, 2016
  28. 15/38 resolve_ref_recursively(): new functionMichael Haggerty, Jun 3, 2016
  29. 16/38 resolve_gitlink_ref(): implement using resolve_ref_recursively()Michael Haggerty, Jun 3, 2016
  30. Junio C HamanoJun 7, 2016
  31. Eric SunshineJun 14, 2016
  32. Michael HaggertyJun 16, 2016
  33. 17/38 resolve_gitlink_ref(): avoid memory allocation in many casesMichael Haggerty, Jun 3, 2016
  34. Junio C HamanoJun 7, 2016
  35. Michael HaggertyJun 9, 2016
  36. 18/38 resolve_gitlink_ref(): rename path parameter to submoduleMichael Haggerty, Jun 3, 2016
  37. 19/38 refs: make read_raw_ref() virtualMichael Haggerty, Jun 3, 2016
  38. 20/38 refs: make verify_refname_available() virtualMichael Haggerty, Jun 3, 2016
  39. 21/38 refs: make pack_refs() virtualMichael Haggerty, Jun 3, 2016
  40. Junio C HamanoJun 7, 2016
  41. Michael HaggertyJun 9, 2016
  42. 22/38 refs: make create_symref() virtualMichael Haggerty, Jun 3, 2016
  43. 23/38 refs: make peel_ref() virtualMichael Haggerty, Jun 3, 2016
  44. Junio C HamanoJun 7, 2016
  45. Michael HaggertyJun 9, 2016
  46. 24/38 repack_without_refs(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  47. 25/38 lock_raw_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  48. 26/38 commit_ref_update(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  49. 27/38 lock_ref_for_update(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  50. 28/38 lock_ref_sha1_basic(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  51. 29/38 split_symref_update(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  52. 30/38 files_ref_iterator_begin(): take a ref_store argumentMichael Haggerty, Jun 3, 2016
  53. 31/38 refs: add method iterator_beginMichael Haggerty, Jun 3, 2016
  54. 32/38 refs: add methods for reflogMichael Haggerty, Jun 3, 2016
  55. 33/38 refs: add method for initial ref transaction commitMichael Haggerty, Jun 3, 2016
  56. 34/38 refs: add method for delete_refsMichael Haggerty, Jun 3, 2016
  57. Junio C HamanoJun 7, 2016
  58. Michael HaggertyJun 9, 2016
  59. 35/38 refs: add methods to init refs dbMichael Haggerty, Jun 3, 2016
  60. 36/38 refs: add method to rename refsMichael Haggerty, Jun 3, 2016
  61. 37/38 refs: make lock genericMichael Haggerty, Jun 3, 2016
  62. Junio C HamanoJun 7, 2016
  63. Michael HaggertyJun 9, 2016
  64. Michael HaggertyJun 9, 2016
  65. 38/38 refs: implement iteration over only per-worktree refsMichael Haggerty, Jun 3, 2016
  66. Duy NguyenJul 10, 2016
  67. Michael HaggertyJul 13, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.