]> git.ipfire.org Git - thirdparty/git.git/commit - fast-import.c
use skip_prefix to avoid magic numbers
authorJeff King <peff@peff.net>
Wed, 18 Jun 2014 19:47:50 +0000 (15:47 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Jun 2014 17:44:45 +0000 (10:44 -0700)
commitae021d87911da4328157273df24779892cb51277
treeaede96cb37d98c5675cd3f31322d4fb50f14d6e9
parent21a2d4ada52132e6b0b67f8e28aa4bcda416f7f2
use skip_prefix to avoid magic numbers

It's a common idiom to match a prefix and then skip past it
with a magic number, like:

  if (starts_with(foo, "bar"))
  foo += 3;

This is easy to get wrong, since you have to count the
prefix string yourself, and there's no compiler check if the
string changes.  We can use skip_prefix to avoid the magic
numbers here.

Note that some of these conversions could be much shorter.
For example:

  if (starts_with(arg, "--foo=")) {
  bar = arg + 6;
  continue;
  }

could become:

  if (skip_prefix(arg, "--foo=", &bar))
  continue;

However, I have left it as:

  if (skip_prefix(arg, "--foo=", &v)) {
  bar = v;
  continue;
  }

to visually match nearby cases which need to actually
process the string. Like:

  if (skip_prefix(arg, "--foo=", &v)) {
  bar = atoi(v);
  continue;
  }

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
alias.c
connect.c
convert.c
daemon.c
diff.c
fast-import.c
fetch-pack.c
git.c
help.c
http-backend.c
http-push.c