Skip to content
  • Jeff King's avatar
    config.c: avoid xmmap error messages · 1570856b
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The config-writing code uses xmmap to map the existing
    config file, which will die if the map fails. This has two
    downsides:
    
      1. The error message is not very helpful, as it lacks any
         context about the file we are mapping:
    
           $ mkdir foo
           $ git config --file=foo some.key value
           fatal: Out of memory? mmap failed: No such device
    
      2. We normally do not die in this code path; instead, we'd
         rather report the error and return an appropriate exit
         status (which is part of the public interface
         documented in git-config.1).
    
    This patch introduces a "gentle" form of xmmap which lets us
    produce our own error message. We do not want to use mmap
    directly, because we would like to use the other
    compatibility elements of xmmap (e.g., handling 0-length
    maps portably).
    
    The end result is:
    
        $ git.compile config --file=foo some.key value
        error: unable to mmap 'foo': No such device
        $ echo $?
        3
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    1570856b