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

Re: [PATCH 2/4] Refactoring: connect.c: move duplicated code to get_host_and_port

From
Johannes Sixt <j6t@kdbg.org>
Date
Feb 15, 2010, 21:11 UTC
Message-ID
<4B79B89C.1050603@kdbg.org>
In-Reply-To
<1266182863-5048-2-git-send-email-michael.lukashov@gmail.com>
Michael Lukashov schrieb:
> +static void get_host_and_port(char **host, const char **port, int set_port_none)

Minor nit: The last parameter, set_port_none, is a rather prominent sign that this function mixes policy and functionality. And indeed, this implementation:

Show 6 quoted lines
> +	if (colon) {
> +		*colon = 0;
> +		*port = colon + 1;
> +		if (set_port_none && !**port)
> +			*port = "<none>";
> +	}

proves it. The _functionality_ is to find host and port from a string. The _policy_ is to set the port to "<none>" if it would otherwise be empty. The callers take care of the _policy_, this function should only care about _functionality_. There's only one call site that wants "<none>"; don't move this detail into this function.

Other than that: nice catch.
-- Hannes
Previous: Michael LukashovNext: Michael Lukashov
Message 3 of 12 in “Refactoring: remove duplicated code from transport.c and builtin-send-pack.c”
  1. 1/4 Refactoring: remove duplicated code from transport.c and builtin-send-pack.cMichael Lukashov, Feb 14, 2010
  2. 2/4 Refactoring: connect.c: move duplicated code to get_host_and_portMichael Lukashov, Feb 14, 2010
  3. Johannes SixtFeb 15, 2010
  4. 3/4 Refactoring: move duplicated code from builtin-pack-objects.c and fast-import.c to object.cMichael Lukashov, Feb 14, 2010
  5. 4/4 Refactoring: remove duplicated code from builtin-checkout.c and merge-recursive.cMichael Lukashov, Feb 14, 2010
  6. Tay Ray ChuanFeb 15, 2010
  7. Jeff KingFeb 15, 2010
  8. Junio C HamanoFeb 15, 2010
  9. Jeff KingFeb 15, 2010
  10. Ilari LiusvaaraFeb 15, 2010
  11. Daniel BarkalowFeb 15, 2010
  12. Larry D'AnnaFeb 15, 2010

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.