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

Re: [PATCH 1/2] apply: add unit tests for parse_range and rename to parse_fragment_range

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 4, 2024, 19:27 UTC
Message-ID
<xmqqsf01yllb.fsf@gitster.g>
In-Reply-To
<CAJ6X7_Uc0OdzYToJSs15+vbydraKAB8x4DPj7UsL1PKLzyY0dQ@mail.gmail.com>
Philip <philip.c.peterson@gmail.com> writes:
> On Mon, Feb 19, 2024 at 4:35 PM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> "Philip Peterson via GitGitGadget" <gitgitgadget@gmail.com> writes:
It's quite a blast from a long time ago that I no longer remember.
Show 10 quoted lines
>> Alternatively we could do something like this to make the blast
>> radius of this patch smaller.
>>
>> -static int parse_range(const char *line, int len, int offset, const char *expect,
>> +#define apply_parse_fragment_range parse_range
>> +int parse_range(const char *line, int len, int offset, const char *expect,
>>                         unsigned long *p1, unsigned long *p2)
>
> From what I understand, this still creates a new extern symbol
> called parse_range.

Sorry, I misspoke. The direction of #define is the other way around. That is, we may have to give the function a name that is overly long because it needs to be externally linkable only to support for your test, but we would want to locally rename that long name down to the name currently used by the primary callers of that function, so that the patch does not have to touch these existing calling sites. After all, this function is a small implementation detail and not a part of the official apply.c API, and the only reason why we are making it extern is because some new tests want to link with it from the side.

So, in the <apply.h> header file you'll do
	/* 
	 * exposed only for tests; do not call this as it not
	 * a part of the API
	 */
	extern int apply_parse_fragment_range(...);

and then in the original file that used to have "static int parse_range(...)", you'd add

	#define parse_range apply_parse_fragment_range
near the top, after the header files are included.
Thanks.
Previous: PhilipNext: Philip Peterson via GitGitGadget
Message 5 of 12 in “apply: add unit tests for parse_range”
  1. 0/2 apply: add unit tests for parse_rangePhilip Peterson via GitGitGadget, Feb 19, 2024
  2. 1/2 apply: add unit tests for parse_range and rename to parse_fragment_rangePhilip Peterson via GitGitGadget, Feb 19, 2024
  3. Junio C HamanoFeb 19, 2024
  4. PhilipApr 4, 2024
  5. Junio C HamanoApr 4, 2024
  6. 2/2 apply: rewrite unit tests with structured casesPhilip Peterson via GitGitGadget, Feb 19, 2024
  7. Junio C HamanoFeb 19, 2024
  8. Kristoffer HaugsbakkFeb 19, 2024
  9. apply: add unit tests for parse_rangePhilip Peterson via GitGitGadget, May 26, 2024
  10. Junio C HamanoJun 6, 2024
  11. Phillip WoodJun 7, 2024
  12. Junio C HamanoJun 7, 2024

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.