1. 19 9月, 2014 1 次提交
  2. 21 8月, 2014 1 次提交
  3. 21 6月, 2014 1 次提交
    • J
      refactor skip_prefix to return a boolean · cf4fff57
      Jeff King 提交于
      The skip_prefix() function returns a pointer to the content
      past the prefix, or NULL if the prefix was not found. While
      this is nice and simple, in practice it makes it hard to use
      for two reasons:
      
        1. When you want to conditionally skip or keep the string
           as-is, you have to introduce a temporary variable.
           For example:
      
             tmp = skip_prefix(buf, "foo");
             if (tmp)
      	       buf = tmp;
      
        2. It is verbose to check the outcome in a conditional, as
           you need extra parentheses to silence compiler
           warnings. For example:
      
             if ((cp = skip_prefix(buf, "foo"))
      	       /* do something with cp */
      
      Both of these make it harder to use for long if-chains, and
      we tend to use starts_with() instead. However, the first line
      of "do something" is often to then skip forward in buf past
      the prefix, either using a magic constant or with an extra
      strlen(3) (which is generally computed at compile time, but
      means we are repeating ourselves).
      
      This patch refactors skip_prefix() to return a simple boolean,
      and to provide the pointer value as an out-parameter. If the
      prefix is not found, the out-parameter is untouched. This
      lets you write:
      
        if (skip_prefix(arg, "foo ", &arg))
      	  do_foo(arg);
        else if (skip_prefix(arg, "bar ", &arg))
      	  do_bar(arg);
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cf4fff57
  4. 16 5月, 2014 1 次提交
    • J
      run_column_filter: use argv_array · 5eb7f7ea
      Jeff King 提交于
      We currently set up the argv array by hand in a fixed-size
      stack-local array. Using an argv array is more readable, as
      it handles buffer allocation us (not to mention makes it
      obvious we do not overflow the array).
      
      However, there's a more subtle benefit, too. We leave the
      function having run start_command (with the child_process
      in a static global), and then later run finish_command from
      another function. That means when we run finish_command,
      neither column_process.argv nor the memory it points to is
      valid any longer.
      
      Most of the time finish_command does not bother looking at
      argv, but it may if it encounters an error (e.g., waitpid
      failure or signal death). This is unusual, which is why
      nobody has noticed. But by using run-command's built-in
      argv_array, the memory ownership is handled for us
      automatically.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5eb7f7ea
  5. 01 4月, 2014 1 次提交
  6. 28 4月, 2012 4 次提交