git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/16] skip_prefix refactoring and cleanups
@ 2014-06-18 19:41 Jeff King
  2014-06-18 19:41 ` [PATCH 01/16] parse_diff_color_slot: drop ofs parameter Jeff King
                   ` (17 more replies)
  0 siblings, 18 replies; 33+ messages in thread
From: Jeff King @ 2014-06-18 19:41 UTC (permalink / raw)
  To: git

A while ago[1] we discussed refactoring skip_prefix (or adding something
like it) to make it more natural to call. This morning I decided to take
a look at doing this, and went down a rabbit hole of cleanups. This is
part one of the result.

The short of it is that skip_prefix can now be used like this:

  if (skip_prefix(arg, "--foo=", &value)
	handle_foo(value);

or even:

  /* arg remains valid if we didn't match! */
  if (skip_prefix(arg, "--foo=", &arg))
	handle_foo(arg);
  else if (skip_prefix(arg, "--bar", &arg))
	handle_bar(arg);

though the latter form is not always useful if the conditional code
wants to see all of "arg".

  [01/16]: parse_diff_color_slot: drop ofs parameter
  [02/16]: daemon: mark some strings as const
  [03/16]: avoid using skip_prefix as a boolean

    These ones are preparatory cleanup.

  [04/16]: refactor skip_prefix to return a boolean

    The actual refactoring; it changes the existing callers[2] at the
    same time.

  [05/16]: apply: use skip_prefix instead of raw addition
  [06/16]: fast-import: fix read of uninitialized argv memory
  [07/16]: transport-helper: avoid reading past end-of-string

    These three are conversions that actually fix bugs.

  [08/16]: use skip_prefix to avoid magic numbers
  [09/16]: use skip_prefix to avoid repeating strings

    These are the straightforward conversions lumped together by the
    problem they are solving.

  [10/16]: fast-import: use skip_prefix for parsing input
  [11/16]: daemon: use skip_prefix to avoid magic numbers
  [12/16]: stat_opt: check extra strlen call
  [13/16]: fast-import: refactor parsing of spaces
  [14/16]: fetch-pack: refactor parsing in get_ack
  [15/16]: git: avoid magic number with skip_prefix

    These ones are variants of the above two that needed extra
    discussion or attention for various reasons.

  [16/16]: use skip_prefix to avoid repeated calculations

    These ones don't solve a specific problem as the patches above do,
    but I think the code ends up more readable.

My conversions are by now means exhaustive. After grepping through all
of the starts_with up to about http.c, I decided to call it a day. But
we can easily convert more as time goes on.

[1] http://thread.gmane.org/gmane.comp.version-control.git/239438/focus=239564

    I started from scratch this morning, oblivious to the fact that René
    posted something very similar to patch 4 in that thread.

[2] I test-merged with 'pu'. There is a minor textual conflict with
    jk/commit-buffer-length that should be easy to resolve. There's also
    one new caller of skip_prefix added in cc/interpret-trailers. It
    needs this fix when merged:

diff --git a/trailer.c b/trailer.c
index eaf692b..987fa29 100644
--- a/trailer.c
+++ b/trailer.c
@@ -377,8 +377,7 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)
 	enum trailer_info_type type;
 	int i;
 
-	trailer_item = skip_prefix(conf_key, "trailer.");
-	if (!trailer_item)
+	if (!skip_prefix(conf_key, "trailer.", &trailer_item))
 		return 0;
 
 	variable_name = strrchr(trailer_item, '.');

^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2014-07-01 17:35 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-18 19:41 [PATCH 0/16] skip_prefix refactoring and cleanups Jeff King
2014-06-18 19:41 ` [PATCH 01/16] parse_diff_color_slot: drop ofs parameter Jeff King
2014-06-18 19:41 ` [PATCH 02/16] daemon: mark some strings as const Jeff King
2014-06-18 19:42 ` [PATCH 03/16] avoid using skip_prefix as a boolean Jeff King
2014-06-18 19:44 ` [PATCH 04/16] refactor skip_prefix to return " Jeff King
2014-06-20  1:59   ` Eric Sunshine
2014-06-20  2:08     ` Jeff King
2014-06-20  2:30       ` Eric Sunshine
2014-06-20  2:38         ` Jeff King
2014-06-23 18:50   ` Junio C Hamano
2014-06-23 21:07     ` Jeff King
2014-06-23 21:32       ` [PATCH] builtin/clone.c: detect a clone starting at a tag correctly Junio C Hamano
2014-06-18 19:45 ` [PATCH 05/16] apply: use skip_prefix instead of raw addition Jeff King
2014-06-18 19:46 ` [PATCH 06/16] fast-import: fix read of uninitialized argv memory Jeff King
2014-06-18 19:47 ` [PATCH 07/16] transport-helper: avoid reading past end-of-string Jeff King
2014-06-18 19:47 ` [PATCH 08/16] use skip_prefix to avoid magic numbers Jeff King
2014-06-23 21:44   ` Junio C Hamano
2014-07-01 17:35     ` Jeff King
2014-06-18 19:48 ` [PATCH 09/16] use skip_prefix to avoid repeating strings Jeff King
2014-06-18 19:49 ` [PATCH 10/16] fast-import: use skip_prefix for parsing input Jeff King
2014-06-20  3:19   ` Eric Sunshine
2014-06-20  5:45     ` Jeff King
2014-06-20  8:59       ` Eric Sunshine
2014-06-18 19:49 ` [PATCH 11/16] daemon: use skip_prefix to avoid magic numbers Jeff King
2014-06-18 19:51 ` [PATCH 12/16] stat_opt: check extra strlen call Jeff King
2014-06-18 19:51 ` [PATCH 13/16] fast-import: refactor parsing of spaces Jeff King
2014-06-18 19:56 ` [PATCH 14/16] fetch-pack: refactor parsing in get_ack Jeff King
2014-06-20  5:15   ` Eric Sunshine
2014-06-18 19:56 ` [PATCH 15/16] git: avoid magic number with skip_prefix Jeff King
2014-06-18 19:57 ` [PATCH 16/16] use skip_prefix to avoid repeated calculations Jeff King
2014-06-19  5:22 ` [PATCH 0/16] skip_prefix refactoring and cleanups Tanay Abhra
2014-06-19 21:58 ` [PATCH 17/16] http-push: refactor parsing of remote object names Jeff King
2014-06-19 22:08   ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).