1. 22 Feb, 2016 2 commits
    • Jeff King's avatar
      convert manual allocations to argv_array · 850d2fec
      Jeff King authored
      There are many manual argv allocations that predate the
      argv_array API. Switching to that API brings a few
      advantages:
      
        1. We no longer have to manually compute the correct final
           array size (so it's one less thing we can screw up).
      
        2. In many cases we had to make a separate pass to count,
           then allocate, then fill in the array. Now we can do it
           in one pass, making the code shorter and easier to
           follow.
      
        3. argv_array handles memory ownership for us, making it
           more obvious when things should be free()d and and when
           not.
      
      Most of these cases are pretty straightforward. In some, we
      switch from "run_command_v" to "run_command" which lets us
      directly use the argv_array embedded in "struct
      child_process".
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      850d2fec
    • 0xAX's avatar
      git.c: simplify stripping extension of a file in handle_builtin() · 63ca1c09
      0xAX authored
      The handle_builtin() starts from stripping of command extension if
      STRIP_EXTENSION is enabled. Actually STRIP_EXTENSION does not used
      anywhere else.
      
      This patch introduces strip_extension() helper to strip STRIP_EXTENSION
      extension from argv[0] with the strip_suffix() instead of manually
      stripping.
      Signed-off-by: 0xAX's avatarAlexander Kuleshov <kuleshovmail@gmail.com>
      Helped-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      63ca1c09
  2. 08 Sep, 2015 1 commit
  3. 03 Sep, 2015 1 commit
    • Stefan Beller's avatar
      submodule: rewrite `module_list` shell function in C · 74703a1e
      Stefan Beller authored
      Most of the submodule operations work on a set of submodules.
      Calculating and using this set is usually done via:
      
             module_list "$@" | {
                 while read mode sha1 stage sm_path
                 do
                      # the actual operation
                 done
             }
      
      Currently the function `module_list` is implemented in the
      git-submodule.sh as a shell script wrapping a perl script.
      The rewrite is in C, such that it is faster and can later be
      easily adapted when other functions are rewritten in C.
      
      git-submodule.sh, similar to the builtin commands, will navigate
      to the top-most directory of the repository and keep the
      subdirectory as a variable. As the helper is called from
      within the git-submodule.sh script, we are already navigated
      to the root level, but the path arguments are still relative
      to the subdirectory we were in when calling git-submodule.sh.
      That's why there is a `--prefix` option pointing to an alternative
      path which to anchor relative path arguments.
      Signed-off-by: Stefan Beller's avatarStefan Beller <sbeller@google.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      74703a1e
  4. 05 Aug, 2015 2 commits
    • Paul Tan's avatar
      builtin-am: remove redirection to git-am.sh · 783d7e86
      Paul Tan authored
      At the beginning of the rewrite of git-am.sh to C, in order to not break
      existing test scripts that depended on a functional git-am, a
      redirection to git-am.sh was introduced that would activate if the
      environment variable _GIT_USE_BUILTIN_AM was not defined.
      
      Now that all of git-am.sh's functionality has been re-implemented in
      builtin/am.c, remove this redirection, and retire git-am.sh into
      contrib/examples/.
      Signed-off-by: default avatarPaul Tan <pyokagan@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      783d7e86
    • Paul Tan's avatar
      builtin-am: implement skeletal builtin am · 73c2779f
      Paul Tan authored
      For the purpose of rewriting git-am.sh into a C builtin, implement a
      skeletal builtin/am.c that redirects to $GIT_EXEC_PATH/git-am if the
      environment variable _GIT_USE_BUILTIN_AM is not defined. Since in the
      Makefile git-am.sh takes precedence over builtin/am.c,
      $GIT_EXEC_PATH/git-am will contain the shell script git-am.sh, and thus
      this allows us to fall back on the functional git-am.sh when running the
      test suite for tests that depend on a working git-am implementation.
      
      Since git-am.sh cannot handle any environment modifications by
      setup_git_directory(), "am" is declared with no setup flags in git.c. On
      the other hand, to re-implement git-am.sh in builtin/am.c, we need to
      run all the git dir and work tree setup logic that git.c typically does
      for us. As such, we work around this temporarily by copying the logic in
      git.c's run_builtin(), which is roughly:
      
      	prefix = setup_git_directory();
      	trace_repo_setup(prefix);
      	setup_work_tree();
      
      This redirection should be removed when all the features of git-am.sh
      have been re-implemented in builtin/am.c.
      Helped-by: default avatarJunio C Hamano <gitster@pobox.com>
      Signed-off-by: default avatarPaul Tan <pyokagan@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      73c2779f
  5. 06 Jul, 2015 1 commit
    • Eric Sunshine's avatar
      checkout: require worktree unconditionally · 0ca560cb
      Eric Sunshine authored
      In order to allow linked worktree creation via "git checkout --to" from
      a bare repository, 3473ad0c (checkout: don't require a work tree when
      checking out into a new one, 2014-11-30) dropped git-checkout's
      unconditional NEED_WORK_TREE requirement and instead performed worktree
      setup conditionally based upon presence or absence of the --to option.
      Now that --to has been retired and git-checkout is no longer responsible
      for linked worktree creation, the NEED_WORK_TREE requirement can be
      re-instated.
      
      This effectively reverts 3473ad0c, except for the tests it added which
      now check bare repository behavior of "git worktree add" instead.
      Signed-off-by: Eric Sunshine's avatarEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      0ca560cb
  6. 29 Jun, 2015 1 commit
  7. 15 Jun, 2015 1 commit
    • Paul Tan's avatar
      pull: implement skeletal builtin pull · 1e1ea69f
      Paul Tan authored
      For the purpose of rewriting git-pull.sh into a C builtin, implement a
      skeletal builtin/pull.c that redirects to $GIT_EXEC_PATH/git-pull.sh if
      the environment variable _GIT_USE_BUILTIN_PULL is not defined. This
      allows us to fall back on the functional git-pull.sh when running the
      test suite for tests that depend on a working git-pull implementation.
      
      This redirection should be removed when all the features of git-pull.sh
      have been re-implemented in builtin/pull.c.
      Helped-by: default avatarJunio C Hamano <gitster@pobox.com>
      Signed-off-by: default avatarPaul Tan <pyokagan@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      1e1ea69f
  8. 07 Mar, 2015 1 commit
  9. 06 Mar, 2015 1 commit
  10. 14 Jan, 2015 1 commit
  11. 10 Jan, 2015 1 commit
    • 0xAX's avatar
      git.c: remove unnecessary #includes · 50fea42e
      0xAX authored
      "cache.h" and "commit.h" are already included via "builtin.h".
      
      We started to include "quote.h" at 575ba9d6 (GIT_TRACE: show which
      built-in/external commands are executed, 2006-06-25) that wanted to
      use sq_quote_print().
      
      When 6ce4e61f (Trace into a file or an open fd and refactor tracing
      code., 2006-09-02) introduced trace.c API, the calls this file makes
      to sq_quote_print() were replaced by calls to trace_argv_printf()
      that are declared in "cache.h", which this file already includes.
      We should have stopped including "quote.h" in that commit, but
      forgot to do so.
      Signed-off-by: 0xAX's avatarAlexander Kuleshov <kuleshovmail@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      50fea42e
  12. 01 Dec, 2014 1 commit
    • Dennis Kaarsemaker's avatar
      checkout: don't require a work tree when checking out into a new one · 3473ad0c
      Dennis Kaarsemaker authored
      For normal use cases, it does not make sense for 'checkout' to work on
      a bare repository, without a worktree. But "checkout --to" is an
      exception because it _creates_ a new worktree. Allow this option to
      run on bare repositories.
      
      People who check out from a bare repository should remember that
      core.logallrefupdates is off by default and it should be turned back
      on. `--to` cannot do this automatically behind the user's back because
      some user may deliberately want no reflog.
      
      For people interested in repository setup/discovery code,
      is_bare_repository_cfg (aka "core.bare") is unchanged by this patch,
      which means 'true' by default for bare repos. Fortunately when we get
      the repo through a linked checkout, is_bare_repository_cfg is never
      used. So all is still good.
      
      [nd: commit message]
      Signed-off-by: Dennis Kaarsemaker's avatarDennis Kaarsemaker <dennis@kaarsemaker.net>
      Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3473ad0c
  13. 13 Nov, 2014 1 commit
  14. 13 Oct, 2014 1 commit
  15. 18 Sep, 2014 2 commits
    • Patrick Reynolds's avatar
      unblock and unignore SIGPIPE · 7559a1be
      Patrick Reynolds authored
      Blocked and ignored signals -- but not caught signals -- are inherited
      across exec.  Some callers with sloppy signal-handling behavior can call
      git with SIGPIPE blocked or ignored, even non-deterministically.  When
      SIGPIPE is blocked or ignored, several git commands can run indefinitely,
      ignoring EPIPE returns from write() calls, even when the process that
      called them has gone away.  Our specific case involved a pipe of git
      diff-tree output to a script that reads a limited amount of diff data.
      
      In an ideal world, git would never be called with SIGPIPE blocked or
      ignored.  But in the real world, several real potential callers, including
      Perl, Apache, and Unicorn, sometimes spawn subprocesses with SIGPIPE
      ignored.  It is easier and more productive to harden git against this
      mistake than to clean it up in every potential parent process.
      Signed-off-by: default avatarPatrick Reynolds <patrick.reynolds@github.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      7559a1be
    • René Scharfe's avatar
  16. 02 Sep, 2014 1 commit
  17. 26 Aug, 2014 1 commit
  18. 14 Jul, 2014 1 commit
    • Karsten Blees's avatar
      git: add performance tracing for git's main() function to debug scripts · 578da039
      Karsten Blees authored
      Use trace_performance to measure and print execution time and command line
      arguments of the entire main() function. In constrast to the shell's 'time'
      utility, which measures total time of the parent process, this logs all
      involved git commands recursively. This is particularly useful to debug
      performance issues of scripted commands (i.e. which git commands were
      called with which parameters, and how long did they execute).
      
      Due to git's deliberate use of exit(), the implementation uses an atexit
      routine rather than just adding trace_performance_since() at the end of
      main().
      
      Usage example: > GIT_TRACE_PERFORMANCE=~/git-trace.log git stash list
      
      Creates a log file like this:
      23:57:38.638765 trace.c:405 performance: 0.000310107 s: git command: 'git' 'rev-parse' '--git-dir'
      23:57:38.644387 trace.c:405 performance: 0.000261759 s: git command: 'git' 'rev-parse' '--show-toplevel'
      23:57:38.646207 trace.c:405 performance: 0.000304468 s: git command: 'git' 'config' '--get-colorbool' 'color.interactive'
      23:57:38.648491 trace.c:405 performance: 0.000241667 s: git command: 'git' 'config' '--get-color' 'color.interactive.help' 'red bold'
      23:57:38.650465 trace.c:405 performance: 0.000243063 s: git command: 'git' 'config' '--get-color' '' 'reset'
      23:57:38.654850 trace.c:405 performance: 0.025126313 s: git command: 'git' 'stash' 'list'
      Signed-off-by: default avatarKarsten Blees <blees@dcon.de>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      578da039
  19. 23 Jun, 2014 1 commit
  20. 20 Jun, 2014 2 commits
    • Jeff King's avatar
      git: avoid magic number with skip_prefix · 6d877803
      Jeff King authored
      After handling options, any leftover arguments should be
      commands. However, we pass through "--help" and "--version",
      so that we convert them into "git help" and "git version"
      respectively.
      
      This is a straightforward use of skip_prefix to avoid a
      magic number, but while we are there, it is worth adding a
      comment to explain this otherwise confusing behavior.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      6d877803
    • Jeff King's avatar
      use skip_prefix to avoid magic numbers · ae021d87
      Jeff King authored
      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: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ae021d87
  21. 10 Jun, 2014 1 commit
  22. 22 Apr, 2014 1 commit
  23. 20 Feb, 2014 1 commit
  24. 06 Jan, 2014 2 commits
  25. 11 Dec, 2013 1 commit
  26. 05 Dec, 2013 1 commit
    • Christian Couder's avatar
      replace {pre,suf}fixcmp() with {starts,ends}_with() · 59556548
      Christian Couder authored
      Leaving only the function definitions and declarations so that any
      new topic in flight can still make use of the old functions, replace
      existing uses of the prefixcmp() and suffixcmp() with new API
      functions.
      
      The change can be recreated by mechanically applying this:
      
          $ git grep -l -e prefixcmp -e suffixcmp -- \*.c |
            grep -v strbuf\\.c |
            xargs perl -pi -e '
              s|!prefixcmp\(|starts_with\(|g;
              s|prefixcmp\(|!starts_with\(|g;
              s|!suffixcmp\(|ends_with\(|g;
              s|suffixcmp\(|!ends_with\(|g;
            '
      
      on the result of preparatory changes in this series.
      Signed-off-by: Christian Couder's avatarChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      59556548
  27. 12 Nov, 2013 3 commits
  28. 17 Sep, 2013 1 commit
    • Stefan Beller's avatar
      repack: rewrite the shell script in C · a1bbc6c0
      Stefan Beller authored
      The motivation of this patch is to get closer to a goal of being
      able to have a core subset of git functionality built in to git.
      That would mean
      
       * people on Windows could get a copy of at least the core parts
         of Git without having to install a Unix-style shell
      
       * people using git in on servers with chrooted environments
         do not need to worry about standard tools lacking for shell
         scripts.
      
      This patch is meant to be mostly a literal translation of the
      git-repack script; the intent is that later patches would start using
      more library facilities, but this patch is meant to be as close to a
      no-op as possible so it doesn't do that kind of thing.
      Signed-off-by: default avatarStefan Beller <stefanbeller@googlemail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      a1bbc6c0
  29. 09 Sep, 2013 1 commit
    • Nazri Ramliy's avatar
      git: run in a directory given with -C option · 44e1e4d6
      Nazri Ramliy authored
      This is similar in spirit to "make -C dir ..." and "tar -C dir ...".
      
      It takes more keypresses to invoke git command in a different
      directory without leaving the current directory:
      
          1. (cd ~/foo && git status)
             git --git-dir=~/foo/.git --work-dir=~/foo status
             GIT_DIR=~/foo/.git GIT_WORK_TREE=~/foo git status
          2. (cd ../..; git grep foo)
          3. for d in d1 d2 d3; do (cd $d && git svn rebase); done
      
      The methods shown above are acceptable for scripting but are too
      cumbersome for quick command line invocations.
      
      With this new option, the above can be done with fewer keystrokes:
      
          1. git -C ~/foo status
          2. git -C ../.. grep foo
          3. for d in d1 d2 d3; do git -C $d svn rebase; done
      
      A new test script is added to verify the behavior of this option with
      other path-related options like --git-dir and --work-tree.
      Signed-off-by: Nazri Ramliy's avatarNazri Ramliy <ayiehere@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      44e1e4d6
  30. 17 Jul, 2013 1 commit
    • Thomas Rast's avatar
      git: ensure 0/1/2 are open in main() · a11c3964
      Thomas Rast authored
      Not having an open FD in the 0--2 range can lead to strange results,
      for example, a subsequent open() may return 2 (stderr) and then a
      die() would clobber this file.
      
      git-daemon and git-shell already guarded against this, but apparently
      users also manage to trip over it in other git commands.  So we call
      sanitize_stdfds() during main git startup.
      
      Since these FDs are inherited, this covers all use of 'git foo ...',
      and all internal C commands when called directly.  It does not fix
      shell/perl commands called directly.
      Signed-off-by: default avatarThomas Rast <trast@inf.ethz.ch>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      a11c3964
  31. 15 Jul, 2013 2 commits
    • Duy Nguyen's avatar
      93d93537
    • Duy Nguyen's avatar
      pathspec: support :(glob) syntax · bd30c2e4
      Duy Nguyen authored
      :(glob)path differs from plain pathspec that it uses wildmatch with
      WM_PATHNAME while the other uses fnmatch without FNM_PATHNAME. The
      difference lies in how '*' (and '**') is processed.
      
      With the introduction of :(glob) and :(literal) and their global
      options --[no]glob-pathspecs, the user can:
      
       - make everything literal by default via --noglob-pathspecs
         --literal-pathspecs cannot be used for this purpose as it
         disables _all_ pathspec magic.
      
       - individually turn on globbing with :(glob)
      
       - make everything globbing by default via --glob-pathspecs
      
       - individually turn off globbing with :(literal)
      
      The implication behind this is, there is no way to gain the default
      matching behavior (i.e. fnmatch without FNM_PATHNAME). You either get
      new globbing or literal. The old fnmatch behavior is considered
      deprecated and discouraged to use.
      Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      bd30c2e4
  32. 13 Jul, 2013 1 commit
    • Eric Sunshine's avatar
      builtin: add git-check-mailmap command · 226ad348
      Eric Sunshine authored
      Introduce command check-mailmap, similar to check-attr and check-ignore,
      which allows direct testing of .mailmap configuration.
      
      As plumbing accessible to scripts and other porcelain, check-mailmap
      publishes the stable, well-tested .mailmap functionality employed by
      built-in Git commands.  Consequently, script authors need not
      re-implement .mailmap functionality manually, thus avoiding potential
      quirks and behavioral differences.
      Signed-off-by: Eric Sunshine's avatarEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      226ad348