1. 29 6月, 2016 1 次提交
  2. 07 5月, 2016 1 次提交
    • J
      submodule: stop sanitizing config options · 89044baa
      Jeff King 提交于
      The point of having a whitelist of command-line config
      options to pass to submodules was two-fold:
      
        1. It prevented obvious nonsense like using core.worktree
           for multiple repos.
      
        2. It could prevent surprise when the user did not mean
           for the options to leak to the submodules (e.g.,
           http.sslverify=false).
      
      For case 1, the answer is mostly "if it hurts, don't do
      that". For case 2, we can note that any such example has a
      matching inverted surprise (e.g., a user who meant
      http.sslverify=true to apply everywhere, but it didn't).
      
      So this whitelist is probably not giving us any benefit, and
      is already creating a hassle as people propose things to put
      on it. Let's just drop it entirely.
      
      Note that we still need to keep a special code path for
      "prepare the submodule environment", because we still have
      to take care to pass through $GIT_CONFIG_PARAMETERS (and
      block the rest of the repo-specific environment variables).
      
      We can do this easily from within the submodule shell
      script, which lets us drop the submodule--helper option
      entirely (and it's OK to do so because as a "--" program, it
      is entirely a private implementation detail).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      89044baa
  3. 29 4月, 2016 2 次提交
    • J
      submodule: use prepare_submodule_repo_env consistently · c12e8656
      Jeff King 提交于
      Before 14111fc4 (git: submodule honor -c credential.* from
      command line, 2016-02-29), it was sufficient for code which
      spawned a process in a submodule to just set the child
      process's "env" field to "local_repo_env" to clear the
      environment of any repo-specific variables.
      
      That commit introduced a more complicated procedure, in
      which we clear most variables but allow through sanitized
      config. For C code, we used that procedure only for cloning,
      but not for any of the programs spawned by submodule.c. As a
      result, things like "git fetch --recurse-submodules" behave
      differently than "git clone --recursive"; the former will
      not pass through the sanitized config.
      
      We can fix this by using prepare_submodule_repo_env()
      everywhere in submodule.c.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c12e8656
    • J
      submodule--helper: move config-sanitizing to submodule.c · 4638728c
      Jeff King 提交于
      These functions should be used by any code which spawns a
      submodule process, which may happen in submodule.c (e.g.,
      for spawning fetch). Let's move them there and make them
      public so that submodule--helper can continue to use them.
      
      Since they're now public, let's also provide a basic overview
      of their intended use.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4638728c
  4. 17 4月, 2016 1 次提交
    • S
      submodule: port init from shell to C · 3604242f
      Stefan Beller 提交于
      By having the `submodule init` functionality in C, we can reference it
      easier from other parts in the code in later patches. The code is split
      up to have one function to initialize one submodule and a calling function
      that takes care of the rest, such as argument handling and translating the
      arguments to the paths of the submodules.
      
      This is the first submodule subcommand that is fully converted to C
      except for the usage string, so this is actually removing a call to
      the `submodule--helper list` function, which is supposed to be used in
      this transition. Instead we'll make a direct call to `module_list_compute`.
      
      An explanation why we need to edit the prefixes in cmd_update in
      git-submodule.sh in this patch:
      
      By having no processing in the shell part, we need to convey the notion
      of wt_prefix and prefix to the C parts, which former patches punted on
      and did the processing of displaying path in the shell.
      
      `wt_prefix` used to hold the path from the repository root to the current
      directory, e.g. wt_prefix would be t/ if the user invoked the
      `git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
      
      `prefix` used to hold the relative path from the repository root to the
      operation, e.g. if you have recursive submodules, the shell script would
      modify the `prefix` in each recursive step by adding the submodule path.
      
      We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
      will setup git in the directory the user actually called git-submodule.sh
      from. The `prefix` will be passed in via the `--prefix` option.
      
      Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
      calling superproject is unfortunate with this patch as the C code doesn't
      know about a possible recursion from a superproject via `submodule update
      --init --recursive`.
      
      To fix this, we change the meaning of `wt_prefix` to point to the current
      project instead of the superproject and `prefix` to include any relative
      paths issues in the superproject. That way `prefix` will become the leading
      part for displaying paths and `wt_prefix` will be empty in recursive
      calls for now.
      
      The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
      the calling directory in the superproject by just traveling reverse of
      `prefix`.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3604242f
  5. 02 3月, 2016 3 次提交
  6. 23 2月, 2016 4 次提交
    • J
      use st_add and st_mult for allocation size computation · 50a6c8ef
      Jeff King 提交于
      If our size computation overflows size_t, we may allocate a
      much smaller buffer than we expected and overflow it. It's
      probably impossible to trigger an overflow in most of these
      sites in practice, but it is easy enough convert their
      additions and multiplications into overflow-checking
      variants. This may be fixing real bugs, and it makes
      auditing the code easier.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      50a6c8ef
    • P
      config: rename git_config_set_or_die to git_config_set · 3d180648
      Patrick Steinhardt 提交于
      Rename git_config_set_or_die functions to git_config_set, leading
      to the new default behavior of dying whenever a configuration
      error occurs.
      
      By now all callers that shall die on error have been transitioned
      to the _or_die variants, thus making this patch a simple rename
      of the functions.
      Signed-off-by: NPatrick Steinhardt <ps@pks.im>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3d180648
    • P
      config: rename git_config_set to git_config_set_gently · 30598ad0
      Patrick Steinhardt 提交于
      The desired default behavior for `git_config_set` is to die
      whenever an error occurs. Dying is the default for a lot of
      internal functions when failures occur and is in this case the
      right thing to do for most callers as otherwise we might run into
      inconsistent repositories without noticing.
      
      As some code may rely on the actual return values for
      `git_config_set` we still require the ability to invoke these
      functions without aborting. Rename the existing `git_config_set`
      functions to `git_config_set_gently` to keep them available for
      those callers.
      Signed-off-by: NPatrick Steinhardt <ps@pks.im>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      30598ad0
    • P
      submodule: die on config error when linking modules · 1a90dfe8
      Patrick Steinhardt 提交于
      When trying to connect a submodule with its corresponding
      repository in '.git/modules' we try to set the core.worktree
      setting in the submodule, which may fail due to an error
      encountered in `git_config_set_in_file`.
      
      The function is used in the git-mv command when trying to move a
      submodule to another location. We already die when renaming a
      file fails but do not pay attention to the case where updating
      the connection between submodule and its repository fails. As
      this leaves the repository in an inconsistent state, as well,
      abort the program by dying early and presenting the failure to
      the user.
      Signed-off-by: NPatrick Steinhardt <ps@pks.im>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1a90dfe8
  7. 17 12月, 2015 3 次提交
  8. 20 11月, 2015 3 次提交
  9. 28 10月, 2015 1 次提交
    • J
      add_submodule_odb: initialize alt_odb list earlier · 9a6e4f03
      Jeff King 提交于
      The add_submodule_odb function tries to add a submodule's
      object store as an "alternate". It needs the existing list
      to be initialized (from the objects/info/alternates file)
      for two reasons:
      
        1. We look for duplicates with the existing alternate
           stores, but obviously this doesn't work if we haven't
           loaded any yet.
      
        2. We link our new entry into the list by prepending it to
           alt_odb_list. But we do _not_ modify alt_odb_tail.
           This variable starts as NULL, and is a signal to the
           alt_odb code that the list has not yet been
           initialized.
      
           We then call read_info_alternates on the submodule (to
           recursively load its alternates), which will try to
           append to that tail, assuming it has been initialized.
           This causes us to segfault if it is NULL.
      
      This rarely comes up in practice, because we will have
      initialized the alt_odb any time we do an object lookup. So
      you can trigger this only when:
      
        - you try to access a submodule (e.g., a diff with
          diff.submodule=log)
      
        - the access happens before any other object has been
          accessed (e.g., because the diff is between the working
          tree and the index)
      
        - the submodule contains an alternates file (so we try to
          add an entry to the NULL alt_odb_tail)
      
      To fix this, we just need to call prepare_alt_odb at the
      start of the function (and if we have already initialized,
      it is a noop).
      
      Note that we can remove the prepare_alt_odb call from the
      end. It is guaranteed to be a noop, since we will have
      called it earlier.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9a6e4f03
  10. 06 10月, 2015 1 次提交
    • J
      avoid sprintf and strcpy with flex arrays · c7ab0ba3
      Jeff King 提交于
      When we are allocating a struct with a FLEX_ARRAY member, we
      generally compute the size of the array and then sprintf or
      strcpy into it. Normally we could improve a dynamic allocation
      like this by using xstrfmt, but it doesn't work here; we
      have to account for the size of the rest of the struct.
      
      But we can improve things a bit by storing the length that
      we use for the allocation, and then feeding it to xsnprintf
      or memcpy, which makes it more obvious that we are not
      writing more than the allocated number of bytes.
      
      It would be nice if we had some kind of helper for
      allocating generic flex arrays, but it doesn't work that
      well:
      
       - the call signature is a little bit unwieldy:
      
            d = flex_struct(sizeof(*d), offsetof(d, path), fmt, ...);
      
         You need offsetof here instead of just writing to the
         end of the base size, because we don't know how the
         struct is packed (partially this is because FLEX_ARRAY
         might not be zero, though we can account for that; but
         the size of the struct may actually be rounded up for
         alignment, and we can't know that).
      
       - some sites do clever things, like over-allocating because
         they know they will write larger things into the buffer
         later (e.g., struct packed_git here).
      
      So we're better off to just write out each allocation (or
      add type-specific helpers, though many of these are one-off
      allocations anyway).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c7ab0ba3
  11. 15 9月, 2015 1 次提交
  12. 26 8月, 2015 1 次提交
  13. 25 8月, 2015 1 次提交
    • J
      write_file(): drop "fatal" parameter · 12d6ce1d
      Junio C Hamano 提交于
      All callers except three passed 1 for the "fatal" parameter to ask
      this function to die upon error, but to a casual reader of the code,
      it was not all obvious what that 1 meant.  Instead, split the
      function into two based on a common write_file_v() that takes the
      flag, introduce write_file_gently() as a new way to attempt creating
      a file without dying on error, and make three callers to call it.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      12d6ce1d
  14. 20 8月, 2015 4 次提交
    • H
      submodule: allow erroneous values for the fetchRecurseSubmodules option · 027771fc
      Heiko Voigt 提交于
      We should not die when reading the submodule config cache since the
      user might not be able to get out of that situation when the
      configuration is part of the history.
      
      We should handle this condition later when the value is about to be
      used.
      Signed-off-by: NHeiko Voigt <hvoigt@hvoigt.net>
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      027771fc
    • H
      submodule: use new config API for worktree configurations · 851e18c3
      Heiko Voigt 提交于
      We remove the extracted functions and directly parse into and read out
      of the cache. This allows us to have one unified way of accessing
      submodule configuration values specific to single submodules. Regardless
      whether we need to access a configuration from history or from the
      worktree.
      Signed-off-by: NHeiko Voigt <hvoigt@hvoigt.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      851e18c3
    • H
      submodule: extract functions for config set and lookup · 0d9f282c
      Heiko Voigt 提交于
      This is one step towards using the new configuration API. We just
      extract these functions to make replacing the actual code easier.
      Signed-off-by: NHeiko Voigt <hvoigt@hvoigt.net>
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0d9f282c
    • H
      submodule: implement a config API for lookup of .gitmodules values · 959b5455
      Heiko Voigt 提交于
      In a superproject some commands need to interact with submodules. They
      need to query values from the .gitmodules file either from the worktree
      of from certain revisions. At the moment this is quite hard since a
      caller would need to read the .gitmodules file from the history and then
      parse the values. We want to provide an API for this so we have one
      place to get values from .gitmodules from any revision (including the
      worktree).
      
      The API is realized as a cache which allows us to lazily read
      .gitmodules configurations by commit into a runtime cache which can then
      be used to easily lookup values from it. Currently only the values for
      path or name are stored but it can be extended for any value needed.
      
      It is expected that .gitmodules files do not change often between
      commits. Thats why we lookup the .gitmodules sha1 from a commit and then
      either lookup an already parsed configuration or parse and cache an
      unknown one for each sha1. The cache is lazily build on demand for each
      requested commit.
      
      This cache can be used for all purposes which need knowledge about
      submodule configurations. Example use cases are:
      
       * Recursive submodule checkout needs to lookup a submodule name from
         its path when a submodule first appears. This needs be done before
         this configuration exists in the worktree.
      
       * The implementation of submodule support for 'git archive' needs to
         lookup the submodule name to generate the archive when given a
         revision that is not checked out.
      
       * 'git fetch' when given the --recurse-submodules=on-demand option (or
         configuration) needs to lookup submodule names by path from the
         database rather than reading from the worktree. For new submodule it
         needs to lookup the name from its path to allow cloning new
         submodules into the .git folder so they can be checked out without
         any network interaction when the user does a checkout of that
         revision.
      Signed-off-by: NHeiko Voigt <hvoigt@hvoigt.net>
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      959b5455
  15. 30 6月, 2015 1 次提交
    • J
      convert "enum date_mode" into a struct · a5481a6c
      Jeff King 提交于
      In preparation for adding date modes that may carry extra
      information beyond the mode itself, this patch converts the
      date_mode enum into a struct.
      
      Most of the conversion is fairly straightforward; we pass
      the struct as a pointer and dereference the type field where
      necessary. Locations that declare a date_mode can use a "{}"
      constructor.  However, the tricky case is where we use the
      enum labels as constants, like:
      
        show_date(t, tz, DATE_NORMAL);
      
      Ideally we could say:
      
        show_date(t, tz, &{ DATE_NORMAL });
      
      but of course C does not allow that. Likewise, we cannot
      cast the constant to a struct, because we need to pass an
      actual address. Our options are basically:
      
        1. Manually add a "struct date_mode d = { DATE_NORMAL }"
           definition to each caller, and pass "&d". This makes
           the callers uglier, because they sometimes do not even
           have their own scope (e.g., they are inside a switch
           statement).
      
        2. Provide a pre-made global "date_normal" struct that can
           be passed by address. We'd also need "date_rfc2822",
           "date_iso8601", and so forth. But at least the ugliness
           is defined in one place.
      
        3. Provide a wrapper that generates the correct struct on
           the fly. The big downside is that we end up pointing to
           a single global, which makes our wrapper non-reentrant.
           But show_date is already not reentrant, so it does not
           matter.
      
      This patch implements 3, along with a minor macro to keep
      the size of the callers sane.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a5481a6c
  16. 26 5月, 2015 2 次提交
  17. 21 5月, 2015 1 次提交
  18. 23 3月, 2015 1 次提交
    • J
      submodule: use capture_command · 1d4974c9
      Jeff King 提交于
      In is_submodule_commit_present, we call run_command followed
      by a pipe read, which is prone to deadlock. It is unlikely
      to happen in this case, as rev-list should never produce
      more than a single line of output, but it does not hurt to
      avoid an anti-pattern (and using the helper simplifies the
      setup and cleanup).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1d4974c9
  19. 02 12月, 2014 1 次提交
  20. 31 10月, 2014 1 次提交
    • J
      get_merge_bases(): always clean-up object flags · 2ce406cc
      Junio C Hamano 提交于
      The callers of get_merge_bases() can choose to leave object flags
      used during the merge-base traversal by passing cleanup=0 as a
      parameter, but in practice a very few callers can afford to do so
      (namely, "git merge-base"), as they need to compute merge base in
      preparation for other processing of their own and they need to see
      the object without contaminate flags.
      
      Change the function signature of get_merge_bases_many() and
      get_merge_bases() to drop the cleanup parameter, so that the
      majority of the callers do not have to say ", 1" at the end.
      
      Give a new get_merge_bases_many_dirty() API to support only a few
      callers that know they do not need to spend cycles cleaning up the
      object flags.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2ce406cc
  21. 21 8月, 2014 1 次提交
  22. 22 7月, 2014 1 次提交
  23. 01 7月, 2014 1 次提交
  24. 06 12月, 2013 1 次提交
    • C
      replace {pre,suf}fixcmp() with {starts,ends}_with() · 59556548
      Christian Couder 提交于
      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: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      59556548
  25. 08 11月, 2013 1 次提交
    • J
      submodule: don't access the .gitmodules cache entry after removing it · bc8d6b9b
      Jens Lehmann 提交于
      Commit 5fee9952 introduced the stage_updated_gitmodules() function to
      add submodule configuration updates to the index. It assumed that even
      after calling remove_cache_entry_at() the same cache entry would still be
      valid. This was true in the old days, as cache entries could never be
      freed, but that is not so sure in the present as there is ongoing work to
      free removed cache entries, which makes this code segfault.
      
      Fix that by calling add_file_to_cache() instead of open coding it. Also
      remove the "could not find .gitmodules in index" warning, as that won't
      happen in regular use cases (and by then just silently adding it to the
      index we do the right thing).
      
      Thanks-to: Karsten Blees <karsten.blees@gmail.com>
      Signed-off-by: NJens Lehmann <Jens.Lehmann@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bc8d6b9b
  26. 20 8月, 2013 1 次提交