Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Commits on Aug 11, 2015
  1. @peff @gitster

    vreportf: avoid intermediate buffer

    peff authored gitster committed
    When we call "die(fmt, args...)", we end up in vreportf with
    two pieces of information:
    
      1. The prefix "fatal: "
    
      2. The original fmt and va_list of args.
    
    We format item (2) into a temporary buffer, and then fprintf
    the prefix and the temporary buffer, along with a newline.
    This has the unfortunate side effect of truncating any error
    messages that are longer than 4096 bytes.
    
    Instead, let's use separate calls for the prefix and
    newline, letting us hand the item (2) directly to vfprintf.
    This is essentially undoing d048a96 (print
    warning/error/fatal messages in one shot, 2007-11-09), which
    tried to have the whole output end up in a single `write`
    call.
    
    But we can address this instead by explicitly requesting
    line-buffering for the output handle, and by making sure
    that the buffer is empty before we start (so that outputting
    the prefix does not cause a flush due to hitting the buffer
    limit).
    
    We may still break the output into two writes if the content
    is larger than our buffer, but there's not much we can do
    there; depending on the stdio implementation, that might
    have happened even with a single fprintf call.
    
    Signed-off-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @peff @gitster

    vreportf: report to arbitrary filehandles

    peff authored gitster committed
    The vreportf function always goes to stderr, but run-command
    wants child errors to go to the parent's original stderr. To
    solve this, commit a5487dd duplicates the stderr fd and
    installs die and error handlers to direct the output
    appropriately (which later turned into the vwritef
    function). This has two downsides, though:
    
      - we make multiple calls to write(), which contradicts the
        "write at once" logic from d048a96 (print
        warning/error/fatal messages in one shot, 2007-11-09).
    
      - the custom handlers basically duplicate the normal
        handlers.  They're only a few lines of code, but we
        should not have to repeat the magic "exit(128)", for
        example.
    
    We can solve the first by using fdopen() on the duplicated
    descriptor. We can't pass this to vreportf, but we could
    introduce a new vreportf_to to handle it.
    
    However, to fix the second problem, we instead introduce a
    new "set_error_handle" function, which lets the normal
    vreportf calls output to a handle besides stderr. Thus we
    can get rid of our custom handlers entirely, and just ask
    the regular handlers to output to our new descriptor.
    
    And as vwritef has no more callers, it can just go away.
    
    Signed-off-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Apr 19, 2013
  1. @gitster

    Merge branch 'jk/a-thread-only-dies-once'

    gitster authored
    A regression fix for the logic to detect die() handler triggering
    itself recursively.
    
    * jk/a-thread-only-dies-once:
      run-command: use thread-aware die_is_recursing routine
      usage: allow pluggable die-recursion checks
Commits on Apr 16, 2013
  1. @peff @gitster

    usage: allow pluggable die-recursion checks

    peff authored gitster committed
    When any git code calls die or die_errno, we use a counter
    to detect recursion into the die functions from any of the
    helper functions. However, such a simple counter is not good
    enough for threaded programs, which may call die from a
    sub-thread, killing only the sub-thread (but incrementing
    the counter for everyone).
    
    Rather than try to deal with threads ourselves here, let's
    just allow callers to plug in their own recursion-detection
    function. This is similar to how we handle the die routine
    (the caller plugs in a die routine which may kill only the
    sub-thread).
    
    Signed-off-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Dec 15, 2012
  1. @peff @gitster

    make error()'s constant return value more visible

    peff authored gitster committed
    When git is compiled with "gcc -Wuninitialized -O3", some
    inlined calls provide an additional opportunity for the
    compiler to do static analysis on variable initialization.
    For example, with two functions like this:
    
      int get_foo(int *foo)
      {
    	if (something_that_might_fail() < 0)
    		return error("unable to get foo");
    	*foo = 0;
    	return 0;
      }
    
      void some_fun(void)
      {
    	  int foo;
    	  if (get_foo(&foo) < 0)
    		  return -1;
    	  printf("foo is %d\n", foo);
      }
    
    If get_foo() is not inlined, then when compiling some_fun,
    gcc sees only that a pointer to the local variable is
    passed, and must assume that it is an out parameter that
    is initialized after get_foo returns.
    
    However, when get_foo() is inlined, the compiler may look at
    all of the code together and see that some code paths in
    get_foo() do not initialize the variable. As a result, it
    prints a warning. But what the compiler can't see is that
    error() always returns -1, and therefore we know that either
    we return early from some_fun, or foo ends up initialized,
    and the code is safe.  The warning is a false positive.
    
    If we can make the compiler aware that error() will always
    return -1, it can do a better job of analysis. The simplest
    method would be to inline the error() function. However,
    this doesn't work, because gcc will not inline a variadc
    function. We can work around this by defining a macro. This
    relies on two gcc extensions:
    
      1. Variadic macros (these are present in C99, but we do
         not rely on that).
    
      2. Gcc treats the "##" paste operator specially between a
         comma and __VA_ARGS__, which lets our variadic macro
         work even if no format parameters are passed to
         error().
    
    Since we are using these extra features, we hide the macro
    behind an #ifdef. This is OK, though, because our goal was
    just to help gcc.
    
    Signed-off-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 16, 2012
  1. @drafnel @gitster

    usage.c: detect recursion in die routines and bail out immediately

    drafnel authored gitster committed
    It is theoretically possible for a die handler to get into a state of
    infinite recursion.  For example, if a die handler called another function
    which itself called die().  Let's at least detect this situation, inform the
    user, and call exit.
    
    Signed-off-by: Brandon Casey <bcasey@nvidia.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Aug 1, 2011
  1. @drizzd @gitster

    error_routine: use parent's stderr if exec fails

    drizzd authored gitster committed
    The new process's error output may be redirected elsewhere, but if
    the exec fails, output should still go to the parent's stderr. This
    has already been done for the die_routine. Do the same for
    error_routine.
    
    Signed-off-by: Clemens Buchacher <drizzd@aon.at>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Mar 22, 2011
  1. @bebarino @gitster

    Fix sparse warnings

    bebarino authored gitster committed
    Fix warnings from 'make check'.
    
     - These files don't include 'builtin.h' causing sparse to complain that
       cmd_* isn't declared:
    
       builtin/clone.c:364, builtin/fetch-pack.c:797,
       builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
       builtin/merge-index.c:69, builtin/merge-recursive.c:22
       builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
       builtin/notes.c:822, builtin/pack-redundant.c:596,
       builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
       builtin/remote.c:1512, builtin/remote-ext.c:240,
       builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
       builtin/unpack-file.c:25, builtin/var.c:75
    
     - These files have symbols which should be marked static since they're
       only file scope:
    
       submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
       submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
       unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
       url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
    
     - These files redeclare symbols to be different types:
    
       builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
       usage.c:49, usage.c:58, usage.c:63, usage.c:72
    
     - These files use a literal integer 0 when they really should use a NULL
       pointer:
    
       daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
    
    While we're in the area, clean up some unused #includes in builtin files
    (mostly exec_cmd.h).
    
    Signed-off-by: Stephen Boyd <bebarino@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Mar 7, 2010
  1. @gitster

    Make report() from usage.c public as vreportf() and use it.

    Johannes Sixt authored gitster committed
    There exist already a number of static functions named 'report', therefore,
    the function name was changed.
    
    Signed-off-by: Johannes Sixt <j6t@kdbg.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 23, 2009
  1. @bjorng @gitster

    Fix truncated usage messages

    bjorng authored gitster committed
    The usage messages for some commands (such as 'git diff-tree')
    are truncated because they don't fit in a fixed buffer of
    1024 bytes.
    
    It would be tempting to eliminate the buffer and the problem once
    and for all by doing the output in three steps, but doing so could
    (according to commit d048a96) increase the likelyhood of messing
    up the display.
    
    So we just increase the size of the buffer.
    
    Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 10, 2009
  1. @jrn @gitster

    Introduce usagef() that takes a printf-style format

    jrn authored gitster committed
    Some new callers would want to use printf-like formatting, when issuing
    their usage messages.  An option is to change usage() itself also be like
    printf(), which would make it similar to die() and warn().
    
    But usage() is typically fixed, as opposed to die() and warn() that gives
    diagnostics depending on the situation.  Indeed, the majority of strings
    given by existing callsites to usage() are fixed strings.  If we were to
    make usage() take printf-style format, they all need to be changed to have
    "%s" as their first argument.
    
    So instead, introduce usagef() so that limited number of callers can use
    it.
    
    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Oct 1, 2009
  1. @kusma @peff

    add NORETURN_PTR for function pointers

    kusma authored peff committed
    Some compilers (including at least MSVC and ARM RVDS) supports
    NORETURN on function declarations, but not on function pointers.
    
    This patch makes it possible to define NORETURN for these compilers,
    by splitting the NORETURN macro into two - one for function
    declarations and one for function pointers.
    
    Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
    Signed-off-by: Jeff King <peff@peff.net>
  2. @kusma @peff

    increase portability of NORETURN declarations

    kusma authored peff committed
    Some compilers (including at least MSVC) support NORETURN
    on function declarations, but only before the function-name.
    
    This patch makes it possible to define NORETURN to something
    meaningful for those compilers.
    
    Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
    Signed-off-by: Jeff King <peff@peff.net>
Commits on Jun 27, 2009
  1. @gitster

    die_errno(): double % in strerror() output just in case

    gitster authored
    [tr: handle border case where % is placed at end of buffer]
    
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
    Signed-off-by: Thomas Rast <trast@student.ethz.ch>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @trast @gitster

    Introduce die_errno() that appends strerror(errno) to die()

    trast authored gitster committed
    There are many calls to die() that do, or should, report
    strerror(errno) to indicate how the syscall they guard failed.
    Introduce a small helper function for this case.
    
    Note:
    
    - POSIX says vsnprintf can modify errno in some unlikely cases, so we
      have to use errno early.
    
    - We take some care to pass the original format to die_routine(), in
      case someone wants to call die_errno() with custom format
      characters.
    
    Signed-off-by: Thomas Rast <trast@student.ethz.ch>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Mar 24, 2009
  1. @spearce @gitster

    Increase the size of the die/warning buffer to avoid truncation

    spearce authored gitster committed
    Long messages like those from lockfile.c when a lock can't be
    obtained truncate with only 256 bytes in the message buffer.
    Bump it to 1024 to give more space for these longer cases.
    
    Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 29, 2008
  1. @spearce

    usage.c: remove unused functions

    Nanako Shiraishi authored spearce committed
    This removes three functions that are not used anywhere.
    
    Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
    Acked-by: Lars Hjemli <hjemli@gmail.com>
    Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Commits on Nov 10, 2007
  1. @gitster

    print warning/error/fatal messages in one shot

    Nicolas Pitre authored gitster committed
    Not doing so is likely to create a messed up display when sent over the
    sideband protocol.
    
    Signed-off-by: Nicolas Pitre <nico@cam.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Mar 31, 2007
  1. @tytso

    Rename warn() to warning() to fix symbol conflicts on BSD and Mac OS

    tytso authored Junio C Hamano committed
    This fixes a problem reported by Randal Schwartz:
    
    >I finally tracked down all the (albeit inconsequential) errors I was getting
    >on both OpenBSD and OSX.  It's the warn() function in usage.c.  There's
    >warn(3) in BSD-style distros.  It'd take a "great rename" to change it, but if
    >someone with better C skills than I have could do that, my linker and I would
    >appreciate it.
    
    It was annoying to me, too, when I was doing some mergetool testing on
    Mac OS X, so here's a fix.
    
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
    Cc: "Randal L. Schwartz" <merlyn@stonehenge.com>
    Signed-off-by: Junio C Hamano <junkio@cox.net>
Commits on Dec 22, 2006
  1. @spearce

    Introduce a global level warn() function.

    spearce authored Junio C Hamano committed
    Like the existing error() function the new warn() function can be
    used to describe a situation that probably should not be occuring,
    but which the user (and Git) can continue to work around without
    running into too many problems.
    
    An example situation is a bad commit SHA1 found in a reflog.
    Attempting to read this record out of the reflog isn't really an
    error as we have skipped over it in the past.
    
    Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
    Signed-off-by: Junio C Hamano <junkio@cox.net>
Commits on Jun 24, 2006
  1. usage: minimum type fix.

    Junio C Hamano authored
    Signed-off-by: Junio C Hamano <junkio@cox.net>
  2. Customizable error handlers

    Petr Baudis authored Junio C Hamano committed
    This patch makes the usage(), die() and error() handlers customizable.
    Nothing in the git code itself uses that but many other libgit users
    (like Git.pm) will.
    
    This is implemented using the mutator functions primarily because you
    cannot directly modifying global variables of libgit from a program that
    dlopen()ed it, apparently. But having functions for that is a better API
    anyway.
    
    Signed-off-by: Petr Baudis <pasky@suse.cz>
    Signed-off-by: Junio C Hamano <junkio@cox.net>
Commits on Dec 5, 2005
  1. Clean up compatibility definitions.

    Junio C Hamano authored
    This attempts to clean up the way various compatibility
    functions are defined and used.
    
     - A new header file, git-compat-util.h, is introduced.  This
       looks at various NO_XXX and does necessary function name
       replacements, equivalent of -Dstrcasestr=gitstrcasestr in the
       Makefile.
    
     - Those function name replacements are removed from the Makefile.
    
     - Common features such as usage(), die(), xmalloc() are moved
       from cache.h to git-compat-util.h; cache.h includes
       git-compat-util.h itself.
    
    Signed-off-by: Junio C Hamano <junkio@cox.net>
Commits on Oct 2, 2005
  1. [PATCH] Better error reporting for "git status"

    Linus Torvalds authored Junio C Hamano committed
    Instead of "git status" ignoring (and hiding) potential errors from the
    "git-update-index" call, make it exit if it fails, and show the error.
    
    In order to do this, use the "-q" flag (to ignore not-up-to-date files)
    and add a new "--unmerged" flag that allows unmerged entries in the index
    without any errors.
    
    This also avoids marking the index "changed" if an entry isn't actually
    modified, and makes sure that we exit with an understandable error message
    if the index is corrupt or unreadable. "read_cache()" no longer returns an
    error for the caller to check.
    
    Finally, make die() and usage() exit with recognizable error codes, if we
    ever want to check the failure reason in scripts.
    
    Signed-off-by: Linus Torvalds <torvalds@osdl.org>
    Signed-off-by: Junio C Hamano <junkio@cox.net>
Commits on May 22, 2005
  1. Include file cleanups..

    Linus Torvalds authored
    Add <limits.h> to the include files handled by "cache.h", and remove
    extraneous #include directives from various .c files. The rule is that
    "cache.h" gets all the basic stuff, so that we'll have as few system
    dependencies as possible.
Commits on Apr 18, 2005
  1. Split up read-cache.c into more logical clumps.

    Linus Torvalds authored
    Do the usage and error reporting in "usage.c", and the sha1 file
    accesses in "sha1_file.c".
    
    Small, nice, easily separated parts. Good.
Something went wrong with that request. Please try again.