1. 22 9月, 2016 1 次提交
    • J
      regex: add regexec_buf() that can work on a non NUL-terminated string · 2f895225
      Johannes Schindelin 提交于
      We just introduced a test that demonstrates that our sloppy use of
      regexec() on a mmap()ed area can result in incorrect results or even
      hard crashes.
      
      So what we need to fix this is a function that calls regexec() on a
      length-delimited, rather than a NUL-terminated, string.
      
      Happily, there is an extension to regexec() introduced by the NetBSD
      project and present in all major regex implementation including
      Linux', MacOSX' and the one Git includes in compat/regex/: by using
      the (non-POSIX) REG_STARTEND flag, it is possible to tell the
      regexec() function that it should only look at the offsets between
      pmatch[0].rm_so and pmatch[0].rm_eo.
      
      That is exactly what we need.
      
      Since support for REG_STARTEND is so widespread by now, let's just
      introduce a helper function that always uses it, and tell people
      on a platform whose regex library does not support it to use the
      one from our compat/regex/ directory.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2f895225
  2. 16 9月, 2016 1 次提交
    • R
      add coccicheck make target · 63f0a758
      René Scharfe 提交于
      Provide a simple way to run Coccinelle against all source files, in the
      form of a Makefile target.  Running "make coccicheck" applies each
      .cocci file in contrib/coccinelle/ on all source files.  It generates
      a .patch file for each .cocci file, containing the actual changes for
      effecting the transformations described by the semantic patches.
      
      Non-empty .patch files are reported.  They can be applied to the work
      tree using "patch -p0", but should be checked to e.g. make sure they
      don't screw up formatting or create circular references.
      
      Coccinelle's diagnostic output (stderr) is piped into .log files.
      
      Linux has a much more elaborate make target of the same name; let's
      start nice and easy.
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      63f0a758
  3. 08 9月, 2016 1 次提交
    • R
      compat: move strdup(3) replacement to its own file · ca2baa3f
      René Scharfe 提交于
      Move our implementation of strdup(3) out of compat/nedmalloc/ and
      allow it to be used independently from USE_NED_ALLOCATOR.  The
      original nedmalloc doesn't come with strdup() and doesn't need it.
      Only _users_ of nedmalloc need it, which was added when we imported
      it to our compat/ hierarchy.
      
      This reduces the difference of our copy of nedmalloc from the
      original, making it easier to update, and allows for easier testing
      and reusing of our version of strdup().
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ca2baa3f
  4. 12 8月, 2016 1 次提交
  5. 05 8月, 2016 1 次提交
  6. 30 7月, 2016 1 次提交
    • J
      add generic most-recently-used list · 002f206f
      Jeff King 提交于
      There are a few places in Git that would benefit from a fast
      most-recently-used cache (e.g., the list of packs, which we
      search linearly but would like to order based on locality).
      This patch introduces a generic list that can be used to
      store arbitrary pointers in most-recently-used order.
      
      The implementation is just a doubly-linked list, where
      "marking" an item as used moves it to the front of the list.
      Insertion and marking are O(1), and iteration is O(n).
      
      There's no lookup support provided; if you need fast
      lookups, you are better off with a different data structure
      in the first place.
      
      There is also no deletion support. This would not be hard to
      do, but it's not necessary for handling pack structs, which
      are created and never removed.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      002f206f
  7. 08 7月, 2016 1 次提交
    • R
      Makefile: add NEEDS_LIBRT to optionally link with librt · d19e3a5b
      Ronald Wampler 提交于
      We unconditionally link with librt, when HAVE_CLOCK_GETTIME is defined.
      But clock_gettime() has been available in most libc implementations for
      some time now (e.g., for glibc since version 2.17) and no longer
      requires linking with librt. Furthermore, commit a6c3c638 (configure.ac:
      check for clock_gettime() and CLOCK_MONOTONIC) will automatically
      determined which library (libc or librt) is required for linking when
      checking for clock_gettime().
      
      The assumption to unconditionally link with librt was OK, since either
      almost every Unix-like system provides a version of librt for backwards
      compatibility or other systems, namely Windows or OS X, never provided
      clock_gettime(). However, in the latest release of OS X (macOS Sierra),
      this function has been added to OS X libc version. As a result, when
      running the configuration script, HAVE_CLOCK_GETTIME is set and since
      librt is not present, it causes a linker error.
      
      This patches requires those not building via the configuration scripts
      to define NEEDS_LIBRT in addition to HAVE_CLOCK_GETTIME, if needed.
      Signed-off-by: NRonald Wampler <rdwampler@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d19e3a5b
  8. 07 7月, 2016 2 次提交
  9. 02 7月, 2016 1 次提交
    • J
      add an extra level of indirection to main() · 3f2e2297
      Jeff King 提交于
      There are certain startup tasks that we expect every git
      process to do. In some cases this is just to improve the
      quality of the program (e.g., setting up gettext()). In
      others it is a requirement for using certain functions in
      libgit.a (e.g., system_path() expects that you have called
      git_extract_argv0_path()).
      
      Most commands are builtins and are covered by the git.c
      version of main(). However, there are still a few external
      commands that use their own main(). Each of these has to
      remember to include the correct startup sequence, and we are
      not always consistent.
      
      Rather than just fix the inconsistencies, let's make this
      harder to get wrong by providing a common main() that can
      run this standard startup.
      
      We basically have two options to do this:
      
       - the compat/mingw.h file already does something like this by
         adding a #define that replaces the definition of main with a
         wrapper that calls mingw_startup().
      
         The upside is that the code in each program doesn't need
         to be changed at all; it's rewritten on the fly by the
         preprocessor.
      
         The downside is that it may make debugging of the startup
         sequence a bit more confusing, as the preprocessor is
         quietly inserting new code.
      
       - the builtin functions are all of the form cmd_foo(),
         and git.c's main() calls them.
      
         This is much more explicit, which may make things more
         obvious to somebody reading the code. It's also more
         flexible (because of course we have to figure out _which_
         cmd_foo() to call).
      
         The downside is that each of the builtins must define
         cmd_foo(), instead of just main().
      
      This patch chooses the latter option, preferring the more
      explicit approach, even though it is more invasive. We
      introduce a new file common-main.c, with the "real" main. It
      expects to call cmd_main() from whatever other objects it is
      linked against.
      
      We link common-main.o against anything that links against
      libgit.a, since we know that such programs will need to do
      this setup. Note that common-main.o can't actually go inside
      libgit.a, as the linker would not pick up its main()
      function automatically (it has no callers).
      
      The rest of the patch is just adjusting all of the various
      external programs (mostly in t/helper) to use cmd_main().
      I've provided a global declaration for cmd_main(), which
      means that all of the programs also need to match its
      signature. In particular, many functions need to switch to
      "const char **" instead of "char **" for argv. This effect
      ripples out to a few other variables and functions, as well.
      
      This makes the patch even more invasive, but the end result
      is much better. We should be treating argv strings as const
      anyway, and now all programs conform to the same signature
      (which also matches the way builtins are defined).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3f2e2297
  10. 21 6月, 2016 2 次提交
    • M
      dir_iterator: new API for iterating over a directory tree · 0fe5043d
      Michael Haggerty 提交于
      The iterator interface is modeled on that for references, though no
      vtable is necessary because there is (so far?) only one type of
      dir_iterator.
      
      There are obviously a lot of features that could easily be added to this
      class:
      
      * Skip/include directory paths in the iteration
      * Shallow/deep iteration
      * Letting the caller decide which subdirectories to recurse into (e.g.,
        via a dir_iterator_advance_into() function)
      * Option to iterate in sorted order
      * Option to iterate over directory paths before vs. after their contents
      
      But these are not needed for the current patch series, so I refrain.
      Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0fe5043d
    • M
      refs: introduce an iterator interface · 3bc581b9
      Michael Haggerty 提交于
      Currently, the API for iterating over references is via a family of
      for_each_ref()-type functions that invoke a callback function for each
      selected reference. All of these eventually call do_for_each_ref(),
      which knows how to do one thing: iterate in parallel through two
      ref_caches, one for loose and one for packed refs, giving loose
      references precedence over packed refs. This is rather complicated code,
      and is quite specialized to the files backend. It also requires callers
      to encapsulate their work into a callback function, which often means
      that they have to define and use a "cb_data" struct to manage their
      context.
      
      The current design is already bursting at the seams, and will become
      even more awkward in the upcoming world of multiple reference storage
      backends:
      
      * Per-worktree vs. shared references are currently handled via a kludge
        in git_path() rather than iterating over each part of the reference
        namespace separately and merging the results. This kludge will cease
        to work when we have multiple reference storage backends.
      
      * The current scheme is inflexible. What if we sometimes want to bypass
        the ref_cache, or use it only for packed or only for loose refs? What
        if we want to store symbolic refs in one type of storage backend and
        non-symbolic ones in another?
      
      In the future, each reference backend will need to define its own way of
      iterating over references. The crux of the problem with the current
      design is that it is impossible to compose for_each_ref()-style
      iterations, because the flow of control is owned by the for_each_ref()
      function. There is nothing that a caller can do but iterate through all
      references in a single burst, so there is no way for it to interleave
      references from multiple backends and present the result to the rest of
      the world as a single compound backend.
      
      This commit introduces a new iteration primitive for references: a
      ref_iterator. A ref_iterator is a polymorphic object that a reference
      storage backend can be asked to instantiate. There are three functions
      that can be applied to a ref_iterator:
      
      * ref_iterator_advance(): move to the next reference in the iteration
      * ref_iterator_abort(): end the iteration before it is exhausted
      * ref_iterator_peel(): peel the reference currently being looked at
      
      Iterating using a ref_iterator leaves the flow of control in the hands
      of the caller, which means that ref_iterators from multiple
      sources (e.g., loose and packed refs) can be composed and presented to
      the world as a single compound ref_iterator.
      
      It also means that the backend code for implementing reference iteration
      will sometimes be more complicated. For example, the
      cache_ref_iterator (which iterates over a ref_cache) can't use the C
      stack to recurse; instead, it must manage its own stack internally as
      explicit data structures. There is also a lot of boilerplate connected
      with object-oriented programming in C.
      
      Eventually, end-user callers will be able to be written in a more
      natural way—managing their own flow of control rather than having to
      work via callbacks. Since there will only be a few reference backends
      but there are many consumers of this API, this is a good tradeoff.
      
      More importantly, we gain composability, and especially the possibility
      of writing interchangeable parts that can work with any ref_iterator.
      
      For example, merge_ref_iterator implements a generic way of merging the
      contents of any two ref_iterators. It is used to merge loose + packed
      refs as part of the implementation of the files_ref_iterator. But it
      will also be possible to use it to merge other pairs of reference
      sources (e.g., per-worktree vs. shared refs).
      
      Another example is prefix_ref_iterator, which can be used to trim a
      prefix off the front of reference names before presenting them to the
      caller (e.g., "refs/heads/master" -> "master").
      
      In this patch, we introduce the iterator abstraction and many utilities,
      and implement a reference iterator for the files ref storage backend.
      (I've written several other obvious utilities, for example a generic way
      to filter references being iterated over. These will probably be useful
      in the future. But they are not needed for this patch series, so I am
      not including them at this time.)
      
      In a moment we will rewrite do_for_each_ref() to work via reference
      iterators (allowing some special-purpose code to be discarded), and do
      something similar for reflogs. In future patch series, we will expose
      the ref_iterator abstraction in the public refs API so that callers can
      use it directly.
      
      Implementation note: I tried abstracting this a layer further to allow
      generic iterators (over arbitrary types of objects) and generic
      utilities like a generic merge_iterator. But the implementation in C was
      very cumbersome, involving (in my opinion) too much boilerplate and too
      much unsafe casting, some of which would have had to be done on the
      caller side. However, I did put a few iterator-related constants in a
      top-level header file, iterator.h, as they will be useful in a moment to
      implement iteration over directory trees and possibly other types of
      iterators in the future.
      Signed-off-by: NRamsay Jones <ramsay@ramsayjones.plus.com>
      Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3bc581b9
  11. 18 6月, 2016 2 次提交
  12. 01 6月, 2016 2 次提交
    • M
      Makefile: add $(DEVELOPER_CFLAGS) variable · 51dd3e81
      Matthieu Moy 提交于
      This does not change the behavior, but allows the user to tweak
      DEVELOPER_CFLAGS on the command-line or in a config.mak* file if
      needed.
      
      This also makes the code somewhat cleaner as it follows the pattern
      
      <initialisation of variables>
      <include statements>
      <actual build logic>
      
      by specifying which flags to activate in the first part, and actually
      activating them in the last one.
      Signed-off-by: NMatthieu Moy <Matthieu.Moy@imag.fr>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      51dd3e81
    • M
      Makefile: move 'ifdef DEVELOPER' after config.mak* inclusion · d615628c
      Matthieu Moy 提交于
      The DEVELOPER knob was introduced in 658df95a (add DEVELOPER makefile
      knob to check for acknowledged warnings, 2016-02-25), and works well
      when used as "make DEVELOPER=1", and when the configure script was not
      used.
      
      However, the advice given in CodingGuidelines to add DEVELOPER=1 to
      config.mak does not: config.mak is included after testing for
      DEVELOPER in the Makefile, and at least GNU Make's manual specifies
      "Conditional directives are parsed immediately", hence the config.mak
      declaration is not visible at the time the conditional is evaluated.
      
      Also, when using the configure script to generate a
      config.mak.autogen, the later file contained a "CFLAGS = <flags>"
      initialization, which overrode the "CFLAGS += -W..." triggered by
      DEVELOPER.
      
      This patch fixes both issues.
      Signed-off-by: NMatthieu Moy <Matthieu.Moy@imag.fr>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d615628c
  13. 11 5月, 2016 1 次提交
    • J
      ci: validate "linkgit:" in documentation · ab81411c
      Junio C Hamano 提交于
      It is easy to add incorrect "linkgit:<page>[<section>]" references
      to our documentation suite.  Catch these common classes of errors:
      
       * Referring to Documentation/<page>.txt that does not exist.
      
       * Referring to a <page> outside the Git suite.  In general, <page>
         must begin with "git".
      
       * Listing the manual <section> incorrectly.  The first line of the
         Documentation/<page>.txt must end with "(<section>)".
      
      with a new script "ci/lint-gitlink", and drive it from "make check-docs".
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ab81411c
  14. 28 4月, 2016 1 次提交
  15. 20 4月, 2016 1 次提交
  16. 16 4月, 2016 2 次提交
  17. 09 4月, 2016 1 次提交
  18. 07 4月, 2016 1 次提交
    • J
      Makefile: stop pretending to support rpmbuild · ab214331
      Junio C Hamano 提交于
      Nobody in the active development community seems to watch breakages
      in the rpmbuild target.  As most major RPM based distros use their
      own specfile when packaging us, they aren't looking after us as
      their pristine upstream tree, either.  At this point, it is turning
      to be a disservice to the users to pretend that our tree natively
      supports "make rpmbuild" target when we do not properly maintain it.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ab214331
  19. 05 4月, 2016 1 次提交
    • J
      Makefile: fix misdirected redirections · d55de70a
      Junio C Hamano 提交于
      In general "echo 2>&1 $msg" to redirect a possible error message
      that comes from 'echo' itself into the same standard output stream
      $msg is getting written to does not make any sense; it is not like
      we are expecting to see any errors out of 'echo' in these statements,
      and even if it were the case, there is no reason to prevent the
      error messages from being sent to the standard error stream.
      
      These are clearly meant to send the argument given to echo to the
      standard error stream as error messages.  Correctly redirect by
      saying "send what is written to the standard output to the standard
      error", i.e. "1>&2" aka ">&2".
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d55de70a
  20. 11 3月, 2016 1 次提交
    • J
      sane_grep: pass "-a" if grep accepts it · 71b40103
      Junio C Hamano 提交于
      Newer versions of GNU grep is reported to be pickier when we feed a
      non-ASCII input and break some Porcelain scripts.  As we know we do
      not feed random binary file to our own sane_grep wrapper, allow us
      to always pass "-a" by setting SANE_TEXT_GREP=-a Makefile variable
      to work it around.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      71b40103
  21. 26 2月, 2016 1 次提交
  22. 28 1月, 2016 1 次提交
    • J
      mingw: fix t5601-clone.sh · 3064d5a3
      Johannes Schindelin 提交于
      Since baaf2337 (connect: improve check for plink to reduce false
      positives, 2015-04-26), t5601 writes out a `plink.exe` for testing that
      is actually a shell script. So the assumption that the `.exe` extension
      implies that the file is *not* a shell script is now wrong.
      
      Since there was no love for the idea of allowing `.exe` files to be
      shell scripts on Windows, let's go the other way round: *make*
      `plink.exe` a real `.exe`.
      
      This fixes t5601-clone.sh in Git for Windows' SDK.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3064d5a3
  23. 17 12月, 2015 1 次提交
  24. 20 11月, 2015 1 次提交
    • M
      refs: split filesystem-based refs code into a new file · 7bd9bcf3
      Michael Haggerty 提交于
      As another step in the move to pluggable reference backends, move the
      code that is specific to the filesystem-based reference backend (i.e.,
      the current system of storing references as loose and packed files) into
      a separate file, refs/files-backend.c.
      
      Aside from a tiny bit of file header boilerplate, this commit only moves
      a subset of the code verbatim from refs.c to the new file, as can easily
      be verified using patience diff:
      
          git diff --patience $commit^:refs.c $commit:refs.c
          git diff --patience $commit^:refs.c $commit:refs/files-backend.c
      Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJeff King <peff@peff.net>
      7bd9bcf3
  25. 06 11月, 2015 1 次提交
  26. 22 10月, 2015 3 次提交
  27. 06 10月, 2015 1 次提交
  28. 03 10月, 2015 1 次提交
  29. 11 9月, 2015 3 次提交
  30. 04 9月, 2015 1 次提交
    • S
      submodule: rewrite `module_list` shell function in C · 74703a1e
      Stefan Beller 提交于
      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: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      74703a1e
  31. 26 8月, 2015 1 次提交
    • E
      generate-cmdlist: re-implement as shell script · 82aec45b
      Eric Sunshine 提交于
      527ec398 (generate-cmdlist: parse common group commands, 2015-05-21)
      replaced generate-cmdlist.sh with a more functional Perl version,
      generate-cmdlist.perl. The Perl version gleans named tags from a new
      "common groups" section in command-list.txt and recognizes those
      tags in "command list" section entries in place of the old 'common'
      tag. This allows git-help to, not only recognize, but also group
      common commands.
      
      Although the tests require Perl, 527ec398 creates an unconditional
      dependence upon Perl in the build system itself, which can not be
      overridden with NO_PERL. Such a dependency may be undesirable; for
      instance, the 'git-lite' package in the FreeBSD ports tree is
      intended as a minimal Git installation (which may, for example, be
      useful on servers needing only local clone and update capability),
      which, historically, has not depended upon Perl[1].
      
      Therefore, revive generate-cmdlist.sh and extend it to recognize
      "common groups" and its named tags. Retire generate-cmdlist.perl.
      
      [1]: http://thread.gmane.org/gmane.comp.version-control.git/275905/focus=276132Signed-off-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      82aec45b