1. 23 2月, 2018 1 次提交
  2. 29 12月, 2017 1 次提交
    • R
      checkout: avoid using the rev_info flag leak_pending · a9a03fa0
      René Scharfe 提交于
      The leak_pending flag is so awkward to use that multiple comments had to
      be added around each occurrence.  We only use it for remembering the
      commits whose marks we have to clear after checking if the old HEAD is
      detached.  This is easy, though: We need to do that for the old commit,
      the new one -- and for all refs.
      
      Don't bother tracking exactly which commits need their flags cleared,
      just nuke all we have in-core.  This change is safe because refs can
      point at anything, so other program parts can't depend on any kept flags
      anyway.  And since all refs are loaded we have to basically deal with
      all commits anyway, so performance should not be negatively impacted.
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a9a03fa0
  3. 08 12月, 2017 1 次提交
  4. 06 12月, 2017 1 次提交
    • A
      checkout: describe_detached_head: remove ellipsis after committish · ca69d4d5
      Ann T Ropea 提交于
      We do not want an ellipsis displayed following an (abbreviated) SHA-1
      value.
      
      The days when this was necessary to indicate the truncation to
      lower-level Git commands and/or the user are bygone.
      
      However, to ease the transition, the ellipsis will still be printed if
      the user sets the environment variable GIT_PRINT_SHA1_ELLIPSIS to "yes".
      
      Correct documentation with respect to what describe_detached_head prints
      when GIT_PRINT_SHA1_ELLIPSIS is not set as indicated above.
      
      Add tests for the old and new behaviour.
      Signed-off-by: NAnn T Ropea <bedhanger@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ca69d4d5
  5. 27 11月, 2017 1 次提交
  6. 13 11月, 2017 1 次提交
  7. 06 11月, 2017 1 次提交
  8. 16 10月, 2017 3 次提交
  9. 13 10月, 2017 1 次提交
    • J
      branch: split validate_new_branchname() into two · bc1c9c0e
      Junio C Hamano 提交于
      Checking if a proposed name is appropriate for a branch is strictly
      a subset of checking if we want to allow creating or updating a
      branch with such a name.  The mysterious sounding 'attr_only'
      parameter to validate_new_branchname() is used to switch the
      function between these two roles.
      
      Instead, split the function into two, and adjust the callers.  A new
      helper validate_branchname() only checks the name and reports if the
      branch already exists.
      
      This loses one NEEDSWORK from the branch API.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bc1c9c0e
  10. 06 10月, 2017 1 次提交
    • M
      treewide: prefer lockfiles on the stack · 837e34eb
      Martin Ågren 提交于
      There is no longer any need to allocate and leak a `struct lock_file`.
      The previous patch addressed an instance where we needed a minor tweak
      alongside the trivial changes.
      
      Deal with the remaining instances where we allocate and leak a struct
      within a single function. Change them to have the `struct lock_file` on
      the stack instead.
      
      These instances were identified by running `git grep "^\s*struct
      lock_file\s*\*"`.
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      837e34eb
  11. 02 10月, 2017 1 次提交
  12. 01 10月, 2017 1 次提交
  13. 24 9月, 2017 1 次提交
    • M
      leak_pending: use `object_array_clear()`, not `free()` · b2ccdf7f
      Martin Ågren 提交于
      Setting `leak_pending = 1` tells `prepare_revision_walk()` not to
      release the `pending` array, and makes that the caller's responsibility.
      See 4a43d374 (revision: add leak_pending flag, 2011-10-01) and
      353f5657 (bisect: use leak_pending flag, 2011-10-01).
      
      Commit 1da1e07c (clean up name allocation in prepare_revision_walk,
      2014-10-15) fixed a memory leak in `prepare_revision_walk()` by
      switching from `free()` to `object_array_clear()`. However, where we use
      the `leak_pending`-mechanism, we're still only calling `free()`.
      
      Use `object_array_clear()` instead. Copy some helpful comments from
      353f5657 to the other callers that we update to clarify the memory
      responsibilities, and to highlight that the commits are not affected
      when we clear the array -- it is indeed correct to both tidy up the
      commit flags and clear the object array.
      
      Document `leak_pending` in revision.h to help future users get this
      right.
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Reviewed-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b2ccdf7f
  14. 22 9月, 2017 1 次提交
    • J
      consistently use "fallthrough" comments in switches · 1cf01a34
      Jeff King 提交于
      Gcc 7 adds -Wimplicit-fallthrough, which can warn when a
      switch case falls through to the next case. The general idea
      is that the compiler can't tell if this was intentional or
      not, so you should annotate any intentional fall-throughs as
      such, leaving it to complain about any unannotated ones.
      
      There's a GNU __attribute__ which can be used for
      annotation, but of course we'd have to #ifdef it away on
      non-gcc compilers. Gcc will also recognize
      specially-formatted comments, which matches our current
      practice. Let's extend that practice to all of the
      unannotated sites (which I did look over and verify that
      they were behaving as intended).
      
      Ideally in each case we'd actually give some reasons in the
      comment about why we're falling through, or what we're
      falling through to. And gcc does support that with
      -Wimplicit-fallthrough=2, which relaxes the comment pattern
      matching to anything that contains "fallthrough" (or a
      variety of spelling variants). However, this isn't the
      default for -Wimplicit-fallthrough, nor for -Wextra. In the
      name of simplicity, it's probably better for us to support
      the default level, which requires "fallthrough" to be the
      only thing in the comment (modulo some window dressing like
      "else" and some punctuation; see the gcc manual for the
      complete set of patterns).
      
      This patch suppresses all warnings due to
      -Wimplicit-fallthrough. We might eventually want to add that
      to the DEVELOPER Makefile knob, but we should probably wait
      until gcc 7 is more widely adopted (since earlier versions
      will complain about the unknown warning type).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1cf01a34
  15. 04 8月, 2017 2 次提交
  16. 01 7月, 2017 1 次提交
    • L
      convert: add "status=delayed" to filter process protocol · 2841e8f8
      Lars Schneider 提交于
      Some `clean` / `smudge` filters may require a significant amount of
      time to process a single blob (e.g. the Git LFS smudge filter might
      perform network requests). During this process the Git checkout
      operation is blocked and Git needs to wait until the filter is done to
      continue with the checkout.
      
      Teach the filter process protocol, introduced in edcc8581 ("convert: add
      filter.<driver>.process option", 2016-10-16), to accept the status
      "delayed" as response to a filter request. Upon this response Git
      continues with the checkout operation. After the checkout operation Git
      calls "finish_delayed_checkout" which queries the filter for remaining
      blobs. If the filter is still working on the completion, then the filter
      is expected to block. If the filter has completed all remaining blobs
      then an empty response is expected.
      
      Git has a multiple code paths that checkout a blob. Support delayed
      checkouts only in `clone` (in unpack-trees.c) and `checkout` operations
      for now. The optimization is most effective in these code paths as all
      files of the tree are processed.
      Signed-off-by: NLars Schneider <larsxschneider@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2841e8f8
  17. 16 6月, 2017 1 次提交
  18. 01 6月, 2017 1 次提交
  19. 30 5月, 2017 2 次提交
    • S
      reset/checkout/read-tree: unify config callback for submodule recursion · d7a3803f
      Stefan Beller 提交于
      The callback function is essentially duplicated 3 times. Remove all
      of them and offer a new callback function, that lives in submodule.c
      
      By putting the callback function there, we no longer need the function
      'set_config_update_recurse_submodules', nor duplicate the global variable
      in each builtin as well as submodule.c
      
      In the three builtins we have different 2 ways how to load the .gitmodules
      and config file, which are slightly different. git-checkout has to load
      the submodule config all the time due to 23b4c7bc (checkout: Use
      submodule.*.ignore settings from .git/config and .gitmodules, 2010-08-28)
      
      git-reset and git-read-tree do not respect these diff settings, so loading
      the submodule configuration is optional. Also put that into submodule.c
      for code deduplication.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d7a3803f
    • S
      submodule recursing: do not write a config variable twice · 58b75bd6
      Stefan Beller 提交于
      The command line option for '--recurse-submodules' is implemented
      using an OPTION_CALLBACK, which takes both the callback (that sets
      the file static global variable) as well as passes the same file
      static global variable to the option parsing machinery to assign it.
      This is fixed in this commit by passing NULL as the variable. The
      callback sets it instead
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      58b75bd6
  20. 12 5月, 2017 1 次提交
    • J
      usability: don't ask questions if no reply is required · 6c486862
      Jean-Noel Avila 提交于
      There has been a bug report by a corporate user that stated that
      "spelling mistake of stash followed by a yes prints character 'y'
      infinite times."
      
      This analysis was false. When the spelling of a command contains
      errors, the git program tries to help the user by providing candidates
      which are close to the unexisting command. E.g Git prints the
      following:
      
              git: 'stahs' is not a git command. See 'git --help'.
              Did you mean this?
      
              stash
      
      and then exits.
      
      The problem with this hint is that it is not formally indicated as an
      hint and the user is in fact encouraged to reply to the question,
      whereas the Git command is already finished.
      
      The user was unlucky enough that it was the command he was looking
      for, and replied "yes" on the command line, effectively launching the
      `yes` program.
      
      The initial error is that the Git programs, when launched in
      command-line mode (without interaction) must not ask questions,
      because these questions would normally require a user input as a reply
      that they won't handle indeed. That's a source of confusion on UX
      level.
      
      To improve the general usability of the Git suite, the following rule
      was applied:
      
      if the sentence
       * appears in a non-interactive session
       * is printed last before exit
       * is a question addressing the user ("you")
      
      the sentence is turned into affirmative and proposes the option.
      
      The basic rewording of the question sentences has been extended to
      other spots found in the source.
      
      Requested at https://github.com/git/git-scm.com/issues/999 by rpai1
      Signed-off-by: NJean-Noel Avila <jn.avila@free.fr>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6c486862
  21. 10 5月, 2017 1 次提交
  22. 08 5月, 2017 5 次提交
    • B
      tree: convert parse_tree_indirect to struct object_id · a9dbc179
      brian m. carlson 提交于
      Convert parse_tree_indirect to take a pointer to struct object_id.
      Update all the callers.  This transformation was achieved using the
      following semantic patch and manual updates to the declaration and
      definition.  Update builtin/checkout.c manually as well, since it uses a
      ternary expression not handled by the semantic patch.
      
      @@
      expression E1;
      @@
      - parse_tree_indirect(E1.hash)
      + parse_tree_indirect(&E1)
      
      @@
      expression E1;
      @@
      - parse_tree_indirect(E1->hash)
      + parse_tree_indirect(E1)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a9dbc179
    • B
      revision: rename add_pending_sha1 to add_pending_oid · a58a1b01
      brian m. carlson 提交于
      Rename this function and convert it to take a pointer to struct
      object_id.
      
      This is a prerequisite for converting get_reference, which is needed to
      convert parse_object.
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a58a1b01
    • B
      Convert lookup_commit* to struct object_id · bc83266a
      brian m. carlson 提交于
      Convert lookup_commit, lookup_commit_or_die,
      lookup_commit_reference, and lookup_commit_reference_gently to take
      struct object_id arguments.
      
      Introduce a temporary in parse_object buffer in order to convert this
      function.  This is required since in order to convert parse_object and
      parse_object_buffer, lookup_commit_reference_gently and
      lookup_commit_or_die would need to be converted.  Not introducing a
      temporary would therefore require that lookup_commit_or_die take a
      struct object_id *, but lookup_commit would take unsigned char *,
      leaving a confusing and hard-to-use interface.
      
      parse_object_buffer will lose this temporary in a later patch.
      
      This commit was created with manual changes to commit.c, commit.h, and
      object.c, plus the following semantic patch:
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1.hash, E2)
      + lookup_commit_reference_gently(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1->hash, E2)
      + lookup_commit_reference_gently(E1, E2)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1.hash)
      + lookup_commit_reference(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1->hash)
      + lookup_commit_reference(E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1.hash)
      + lookup_commit(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1->hash)
      + lookup_commit(E1)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1.hash, E2)
      + lookup_commit_or_die(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1->hash, E2)
      + lookup_commit_or_die(E1, E2)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bc83266a
    • J
      checkout: fix memory leak · 514e8039
      Johannes Schindelin 提交于
      This change addresses part of the NEEDSWORK comment above the code,
      therefore the comment needs to be adjusted, too.
      
      Discovered via Coverity.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      514e8039
    • R
      checkout: check return value of resolve_refdup before using hash · 79e913c2
      René Scharfe 提交于
      If resolve_refdup() fails it returns NULL and possibly leaves its hash
      output parameter untouched.  Make sure to use it only if the function
      succeeded, in order to avoid accessing uninitialized memory.
      
      Found with t/t2011-checkout-invalid-head.sh --valgrind.
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      79e913c2
  23. 31 3月, 2017 1 次提交
    • J
      avoid using fixed PATH_MAX buffers for refs · 7f897b6f
      Jeff King 提交于
      Many functions which handle refs use a PATH_MAX-sized buffer
      to do so. This is mostly reasonable as we have to write
      loose refs into the filesystem, and at least on Linux the 4K
      PATH_MAX is big enough that nobody would care. But:
      
        1. The static PATH_MAX is not always the filesystem limit.
      
        2. On other platforms, PATH_MAX may be much smaller.
      
        3. As we move to alternate ref storage, we won't be bound
           by filesystem limits.
      
      Let's convert these to heap buffers so we don't have to
      worry about truncation or size limits.
      
      We may want to eventually constrain ref lengths for sanity
      and to prevent malicious names, but we should do so
      consistently across all platforms, and in a central place
      (like the ref code).
      Signed-off-by: NJeff King <peff@peff.net>
      7f897b6f
  24. 17 3月, 2017 1 次提交
  25. 03 3月, 2017 2 次提交
    • J
      checkout: restrict @-expansions when finding branch · fd4692ff
      Jeff King 提交于
      When we parse "git checkout $NAME", we try to interpret
      $NAME as a local branch-name. If it is, then we point HEAD
      to that branch. Otherwise, we detach the HEAD at whatever
      commit $NAME points to.
      
      We do the interpretation by calling strbuf_branchname(), and
      then blindly sticking "refs/heads/" on the front. This leads
      to nonsense results when expansions like "@{upstream}" or
      "@" point to something besides a local branch. We end up
      with a local branch name like "refs/heads/origin/master" or
      "refs/heads/HEAD".
      
      Normally this has no user-visible effect because those
      branches don't exist, and so we fallback to feeding the
      result to get_sha1(), which resolves them correctly.
      
      But as the new test in t3204 shows, there are corner cases
      where the effect is observable, and we check out the wrong
      local branch rather than detaching to the correct one.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fd4692ff
    • J
      interpret_branch_name: allow callers to restrict expansions · 0e9f62da
      Jeff King 提交于
      The interpret_branch_name() function converts names like
      @{-1} and @{upstream} into branch names. The expanded ref
      names are not fully qualified, and may be outside of the
      refs/heads/ namespace (e.g., "@" expands to "HEAD", and
      "@{upstream}" is likely to be in "refs/remotes/").
      
      This is OK for callers like dwim_ref() which are primarily
      interested in resolving the resulting name, no matter where
      it is. But callers like "git branch" treat the result as a
      branch name in refs/heads/.  When we expand to a ref outside
      that namespace, the results are very confusing (e.g., "git
      branch @" tries to create refs/heads/HEAD, which is
      nonsense).
      
      Callers can't know from the returned string how the
      expansion happened (e.g., did the user really ask for a
      branch named "HEAD", or did we do a bogus expansion?). One
      fix would be to return some out-parameters describing the
      types of expansion that occurred. This has the benefit that
      the caller can generate precise error messages ("I
      understood @{upstream} to mean origin/master, but that is a
      remote tracking branch, so you cannot create it as a local
      name").
      
      However, out-parameters make the function interface somewhat
      cumbersome. Instead, let's do the opposite: let the caller
      tell us which elements to expand. That's easier to pass in,
      and none of the callers give more precise error messages
      than "@{upstream} isn't a valid branch name" anyway (which
      should be sufficient).
      
      The strbuf_branchname() function needs a similar parameter,
      as most of the callers access interpret_branch_name()
      through it.
      
      We can break the callers down into two groups:
      
        1. Callers that are happy with any kind of ref in the
           result. We pass "0" here, so they continue to work
           without restrictions. This includes merge_name(),
           the reflog handling in add_pending_object_with_path(),
           and substitute_branch_name(). This last is what powers
           dwim_ref().
      
        2. Callers that have funny corner cases (mostly in
           git-branch and git-checkout). These need to make use of
           the new parameter, but I've left them as "0" in this
           patch, and will address them individually in follow-on
           patches.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0e9f62da
  26. 01 2月, 2017 1 次提交
    • C
      refs: add option core.logAllRefUpdates = always · 341fb286
      Cornelius Weig 提交于
      When core.logallrefupdates is true, we only create a new reflog for refs
      that are under certain well-known hierarchies. The reason is that we
      know that some hierarchies (like refs/tags) are not meant to change, and
      that unknown hierarchies might not want reflogs at all (e.g., a
      hypothetical refs/foo might be meant to change often and drop old
      history immediately).
      
      However, sometimes it is useful to override this decision and simply log
      for all refs, because the safety and audit trail is more important than
      the performance implications of keeping the log around.
      
      This patch introduces a new "always" mode for the core.logallrefupdates
      option which will log updates to everything under refs/, regardless
      where in the hierarchy it is (we still will not log things like
      ORIG_HEAD and FETCH_HEAD, which are known to be transient).
      Based-on-patch-by: NJeff King <peff@peff.net>
      Signed-off-by: NCornelius Weig <cornelius.weig@tngtech.com>
      Reviewed-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      341fb286
  27. 31 1月, 2017 1 次提交
  28. 08 12月, 2016 1 次提交
    • J
      hold_locked_index(): align error handling with hold_lockfile_for_update() · b3e83cc7
      Junio C Hamano 提交于
      Callers of the hold_locked_index() function pass 0 when they want to
      prepare to write a new version of the index file without wishing to
      die or emit an error message when the request fails (e.g. somebody
      else already held the lock), and pass 1 when they want the call to
      die upon failure.
      
      This option is called LOCK_DIE_ON_ERROR by the underlying lockfile
      API, and the hold_locked_index() function translates the paramter to
      LOCK_DIE_ON_ERROR when calling the hold_lock_file_for_update().
      
      Replace these hardcoded '1' with LOCK_DIE_ON_ERROR and stop
      translating.  Callers other than the ones that are replaced with
      this change pass '0' to the function; no behaviour change is
      intended with this patch.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ---
      
      Among the callers of hold_locked_index() that passes 0:
      
       - diff.c::refresh_index_quietly() at the end of "git diff" is an
         opportunistic update; it leaks the lockfile structure but it is
         just before the program exits and nobody should care.
      
       - builtin/describe.c::cmd_describe(),
         builtin/commit.c::cmd_status(),
         sequencer.c::read_and_refresh_cache() are all opportunistic
         updates and they are OK.
      
       - builtin/update-index.c::cmd_update_index() takes a lock upfront
         but we may end up not needing to update the index (i.e. the
         entries may be fully up-to-date), in which case we do not need to
         issue an error upon failure to acquire the lock.  We do diagnose
         and die if we indeed need to update, so it is OK.
      
       - wt-status.c::require_clean_work_tree() IS BUGGY.  It asks
         silence, does not check the returned value.  Compare with
         callsites like cmd_describe() and cmd_status() to notice that it
         is wrong to call update_index_if_able() unconditionally.
      b3e83cc7
  29. 10 11月, 2016 1 次提交
    • J
      create_branch: drop unused "head" parameter · 4bd488ea
      Jeff King 提交于
      This function used to have the caller pass in the current
      value of HEAD, in order to make sure we didn't clobber HEAD.
      In 55c4a673, that logic moved to validate_new_branchname(),
      which just resolves HEAD itself. The parameter to
      create_branch is now unused.
      
      Since we have to update and re-wrap the docstring describing
      the parameters anyway, let's take this opportunity to break
      it out into a list, which makes it easier to find the
      parameters.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4bd488ea
  30. 23 9月, 2016 1 次提交
  31. 21 9月, 2016 1 次提交