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

Re: [PATCH 3/5] use SWAP macro

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2017, 22:22 UTC
Message-ID
<xmqqr33ktch9.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<187c2b39-40cf-7e07-b489-d40cdf5f9145@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 5 quoted lines
>  		if (tree2->flags & UNINTERESTING) {
> -			struct object *tmp = tree2;
> -			tree2 = tree1;
> -			tree1 = tmp;
> +			SWAP(tree2, tree1);
A human would have written this SWAP(tree1, tree2).

Not that I think such a manual fix-up should be made in _this_ patch, which may end up mixing mechanical conversion (which we may want to keep reproducible) and hand tweaks. But this swapped swap reads somewhat silly.

Show 12 quoted lines
> diff --git a/diff-no-index.c b/diff-no-index.c
> index f420786039..1ae09894d7 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -186,9 +186,8 @@ static int queue_diff(struct diff_options *o,
>  
>  		if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
>  			unsigned tmp;
> -			const char *tmp_c;
>  			tmp = mode1; mode1 = mode2; mode2 = tmp;
> -			tmp_c = name1; name1 = name2; name2 = tmp_c;
> +			SWAP(name1, name2);
Curious that mode swapping is left for a later iteration.
Show 15 quoted lines
> diff --git a/diff.c b/diff.c
> index f08cd8e033..9de1ba264f 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -5118,13 +5118,11 @@ void diff_change(struct diff_options *options,
>  
>  	if (DIFF_OPT_TST(options, REVERSE_DIFF)) {
>  		unsigned tmp;
> -		const unsigned char *tmp_c;
> -		tmp = old_mode; old_mode = new_mode; new_mode = tmp;
> -		tmp_c = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_c;
> +		SWAP(old_mode, new_mode);
> +		SWAP(old_sha1, new_sha1);
>  		tmp = old_sha1_valid; old_sha1_valid = new_sha1_valid;
>  			new_sha1_valid = tmp;
So is this one.
Show 6 quoted lines
> diff --git a/merge-recursive.c b/merge-recursive.c
> ...
> -			tmp = ren2;
> -			ren2 = ren1;
> -			ren1 = tmp;
> +			SWAP(ren2, ren1);
A human would have written this SWAP(ren1, ren2).
Previous: René ScharfeNext: René Scharfe
Message 41 of 50 in “introduce SWAP macro”
  1. 0/5 introduce SWAP macroRené Scharfe, Jan 28, 2017
  2. 1/5 add SWAP macroRené Scharfe, Jan 28, 2017
  3. Johannes SchindelinJan 30, 2017
  4. René ScharfeJan 30, 2017
  5. Johannes SchindelinJan 30, 2017
  6. René ScharfeJan 30, 2017
  7. Johannes SchindelinJan 31, 2017
  8. René ScharfeJan 31, 2017
  9. Ramsay JonesFeb 1, 2017
  10. Johannes SchindelinFeb 1, 2017
  11. Johannes SchindelinJan 30, 2017
  12. René ScharfeJan 30, 2017
  13. Johannes SixtJan 30, 2017
  14. Johannes SchindelinJan 30, 2017
  15. René ScharfeJan 30, 2017
  16. Brandon WilliamsJan 30, 2017
  17. René ScharfeJan 31, 2017
  18. Jeff KingJan 31, 2017
  19. Junio C HamanoJan 31, 2017
  20. Jeff KingJan 31, 2017
  21. Johannes SchindelinFeb 1, 2017
  22. Jeff KingFeb 1, 2017
  23. René ScharfeFeb 1, 2017
  24. Junio C HamanoFeb 1, 2017
  25. René ScharfeFeb 7, 2017
  26. Junio C HamanoFeb 7, 2017
  27. Johannes SchindelinFeb 8, 2017
  28. Johannes SchindelinJan 31, 2017
  29. Jeff KingApr 24, 2017
  30. Jeff KingApr 24, 2017
  31. Duy NguyenApr 24, 2017
  32. René ScharfeApr 28, 2017
  33. Jeff KingApr 28, 2017
  34. René ScharfeApr 29, 2017
  35. Jeff KingApr 30, 2017
  36. René ScharfeMay 2, 2017
  37. 2/5 apply: use SWAP macroRené Scharfe, Jan 28, 2017
  38. 3/5 use SWAP macroRené Scharfe, Jan 28, 2017
  39. Johannes SchindelinJan 30, 2017
  40. René ScharfeJan 30, 2017
  41. Junio C HamanoJan 30, 2017
  42. René ScharfeJan 31, 2017
  43. 4/5 diff: use SWAP macroRené Scharfe, Jan 28, 2017
  44. Johannes SchindelinJan 30, 2017
  45. René ScharfeJan 30, 2017
  46. Junio C HamanoJan 30, 2017
  47. 5/5 graph: use SWAP macroRené Scharfe, Jan 28, 2017
  48. Johannes SchindelinJan 30, 2017
  49. René ScharfeJan 30, 2017
  50. Junio C HamanoJan 30, 2017

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.