1. 16 12月, 2016 1 次提交
  2. 15 12月, 2016 2 次提交
  3. 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
  4. 27 10月, 2016 1 次提交
    • J
      find_unique_abbrev: use 4-buffer ring · ef2ed501
      Jeff King 提交于
      Some code paths want to format multiple abbreviated sha1s in
      the same output line. Because we use a single static buffer
      for our return value, they have to either break their output
      into several calls or allocate their own arrays and use
      find_unique_abbrev_r().
      
      Intead, let's mimic sha1_to_hex() and use a ring of several
      buffers, so that the return value stays valid through
      multiple calls. This shortens some of the callers, and makes
      it harder to for them to make a silly mistake.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ef2ed501
  5. 16 9月, 2016 1 次提交
  6. 06 8月, 2016 1 次提交
  7. 27 7月, 2016 1 次提交
    • J
      prepare the builtins for a libified merge_recursive() · f241ff0d
      Johannes Schindelin 提交于
      Previously, callers of merge_trees() or merge_recursive() expected that
      code to die() with an error message. This used to be okay because we
      called those commands from scripts, and had a chance to print out a
      message in case the command failed fatally (read: with exit code 128).
      
      As scripting incurs its own set of problems (portability, speed,
      idiosyncrasies of different shells, limited data structures leading to
      inefficient code), we are converting more and more of these scripts into
      builtins, using library functions directly.
      
      We already tried to use merge_recursive() directly in the builtin
      git-am, for example. Unfortunately, we had to roll it back temporarily
      because some of the code in merge-recursive.c still deemed it okay to
      call die(), when the builtin am code really wanted to print out a useful
      advice after the merge failed fatally. In the next commits, we want to
      fix that.
      
      The code touched by this commit expected merge_trees() to die() with
      some useful message when there is an error condition, but merge_trees()
      is going to be improved by converting all die() calls to return error()
      instead (i.e. return value -1 after printing out the message as before),
      so that the caller can react more flexibly.
      
      This is a step to prepare for the version of merge_trees() that no
      longer dies,  even if we just imitate the previous behavior by calling
      exit(128): this is what callers of e.g. `git merge` have come to expect.
      
      Note that the callers of the sequencer (revert and cherry-pick) already
      fail fast even for the return value -1; The only difference is that they
      now get a chance to say "<command> failed".
      
      A caller of merge_trees() might want handle error messages themselves
      (or even suppress them). As this patch is already complex enough, we
      leave that change for a later patch.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f241ff0d
  8. 09 7月, 2016 1 次提交
  9. 29 6月, 2016 2 次提交
  10. 18 6月, 2016 2 次提交
  11. 13 4月, 2016 1 次提交
    • E
      builtin/merge.c: fix a bug with trivial merges · 40d71940
      Elijah Newren 提交于
      If read_tree_trivial() succeeds and produces a tree that is already
      in the object store, then the index is not written to disk, leaving
      it out-of-sync with both HEAD and the working tree.
      
      In order to write the index back out to disk after a merge,
      write_index_locked() needs to be called.  For most merge strategies, this
      is done from try_merge_strategy().  For fast forward updates, this is
      done from checkout_fast_forward().  When trivial merges work, the call to
      write_index_locked() is buried a little deeper:
      
        merge_trivial()
        -> write_tree_trivial()
           -> write_cache_as_tree()
              -> write_index_as_tree()
                 -> write_locked_index()
      
      However, it is only called when !cache_tree_fully_valid(), which is how
      this bug is triggered.  But that also shows why this bug doesn't affect
      any other merge strategies or cases.
      
      Add a direct call to write_index_locked() from merge_trivial() to fix
      this issue.  Since the indirect call to write_locked_index() was
      conditional on cache_tree_fully_valid(), it won't be written twice.
      Signed-off-by: NElijah Newren <newren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      40d71940
  12. 11 4月, 2016 1 次提交
  13. 24 3月, 2016 2 次提交
    • J
      merge: refuse to create too cool a merge by default · e379fdf3
      Junio C Hamano 提交于
      While it makes sense to allow merging unrelated histories of two
      projects that started independently into one, in the way "gitk" was
      merged to "git" itself aka "the coolest merge ever", such a merge is
      still an unusual event.	 Worse, if somebody creates an independent
      history by starting from a tarball of an established project and
      sends a pull request to the original project, "git merge" however
      happily creates such a merge without any sign of something unusual
      is happening.
      
      Teach "git merge" to refuse to create such a merge by default,
      unless the user passes a new "--allow-unrelated-histories" option to
      tell it that the user is aware that two unrelated projects are
      merged.
      
      Because such a "two project merge" is a rare event, a configuration
      option to always allow such a merge is not added.
      
      We could add the same option to "git pull" and have it passed
      through to underlying "git merge".  I do not have a fundamental
      opposition against such a feature, but this commit does not do so
      and instead leaves it as low-hanging fruit for others, because such
      a "two project merge" would be done after fetching the other project
      into some location in the working tree of an existing project and
      making sure how well they fit together, it is sufficient to allow a
      local merge without such an option pass-through from "git pull" to
      "git merge".  Many tests that are updated by this patch does the
      pass-through manually by turning:
      
      	git pull something
      
      into its equivalent:
      
      	git fetch something &&
      	git merge --allow-unrelated-histories FETCH_HEAD
      
      If somebody is inclined to add such an option, updated tests in this
      change need to be adjusted back to:
      
      	git pull --allow-unrelated-histories something
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e379fdf3
    • J
      merge: fix NULL pointer dereference when merging nothing into void · b84e65d4
      Junio C Hamano 提交于
      When we are on an unborn branch and merging only one foreign parent,
      we allow "git merge" to fast-forward to that foreign parent commit.
      
      This codepath incorrectly attempted to dereference the list of
      parents that the merge is going to record even when the list is
      empty.  It must refuse to operate instead when there is no parent.
      
      All other codepaths make sure the list is not empty before they
      dereference it, and are safe.
      
      Reported-by: Jose Ivan B. Vilarouca Filho
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b84e65d4
  14. 26 2月, 2016 1 次提交
    • M
      diff: activate diff.renames by default · 5404c116
      Matthieu Moy 提交于
      Rename detection is a very convenient feature, and new users shouldn't
      have to dig in the documentation to benefit from it.
      
      Potential objections to activating rename detection are that it
      sometimes fail, and it is sometimes slow. But rename detection is
      already activated by default in several cases like "git status" and "git
      merge", so activating diff.renames does not fundamentally change the
      situation. When the rename detection fails, it now fails consistently
      between "git diff" and "git status".
      
      This setting does not affect plumbing commands, hence well-written
      scripts will not be affected.
      Signed-off-by: NMatthieu Moy <Matthieu.Moy@imag.fr>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5404c116
  15. 23 2月, 2016 1 次提交
  16. 14 1月, 2016 1 次提交
  17. 20 11月, 2015 3 次提交
  18. 27 10月, 2015 1 次提交
  19. 17 10月, 2015 1 次提交
  20. 06 10月, 2015 1 次提交
    • J
      use sha1_to_hex_r() instead of strcpy · d59f765a
      Jeff King 提交于
      Before sha1_to_hex_r() existed, a simple way to get hex
      sha1 into a buffer was with:
      
        strcpy(buf, sha1_to_hex(sha1));
      
      This isn't wrong (assuming the buf is 41 characters), but it
      makes auditing the code base for bad strcpy() calls harder,
      as these become false positives.
      
      Let's convert them to sha1_to_hex_r(), and likewise for
      some calls to find_unique_abbrev(). While we're here, we'll
      double-check that all of the buffers are correctly sized,
      and use the more obvious GIT_SHA1_HEXSZ constant.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d59f765a
  21. 11 8月, 2015 1 次提交
    • J
      memoize common git-path "constant" files · f932729c
      Jeff King 提交于
      One of the most common uses of git_path() is to pass a
      constant, like git_path("MERGE_MSG"). This has two
      drawbacks:
      
        1. The return value is a static buffer, and the lifetime
           is dependent on other calls to git_path, etc.
      
        2. There's no compile-time checking of the pathname. This
           is OK for a one-off (after all, we have to spell it
           correctly at least once), but many of these constant
           strings appear throughout the code.
      
      This patch introduces a series of functions to "memoize"
      these strings, which are essentially globals for the
      lifetime of the program. We compute the value once, take
      ownership of the buffer, and return the cached value for
      subsequent calls.  cache.h provides a helper macro for
      defining these functions as one-liners, and defines a few
      common ones for global use.
      
      Using a macro is a little bit gross, but it does nicely
      document the purpose of the functions. If we need to touch
      them all later (e.g., because we learned how to change the
      git_dir variable at runtime, and need to invalidate all of
      the stored values), it will be much easier to have the
      complete list.
      
      Note that the shared-global functions have separate, manual
      declarations. We could do something clever with the macros
      (e.g., expand it to a declaration in some places, and a
      declaration _and_ a definition in path.c). But there aren't
      that many, and it's probably better to stay away from
      too-magical macros.
      
      Likewise, if we abandon the C preprocessor in favor of
      generating these with a script, we could get much fancier.
      E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
      But the small amount of saved typing is probably not worth
      the resulting confusion to readers who want to grep for the
      function's definition.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f932729c
  22. 22 5月, 2015 1 次提交
    • J
      remote.c: drop "remote" pointer from "struct branch" · 9e3751d4
      Jeff King 提交于
      When we create each branch struct, we fill in the
      "remote_name" field from the config, and then fill in the
      actual "remote" field (with a "struct remote") based on that
      name. However, it turns out that nobody really cares about
      the latter field. The only two sites that access it at all
      are:
      
        1. git-merge, which uses it to notice when the branch does
           not have a remote defined. But we can easily replace this
           with looking at remote_name instead.
      
        2. remote.c itself, when setting up the @{upstream} merge
           config. But we don't need to save the "remote" in the
           "struct branch" for that; we can just look it up for
           the duration of the operation.
      
      So there is no need to have both fields; they are redundant
      with each other (the struct remote contains the name, or you
      can look up the struct from the name). It would be nice to
      simplify this, especially as we are going to add matching
      pushremote config in a future patch (and it would be nice to
      keep them consistent).
      
      So which one do we keep and which one do we get rid of?
      
      If we had a lot of callers accessing the struct, it would be
      more efficient to keep it (since you have to do a lookup to
      go from the name to the struct, but not vice versa). But we
      don't have a lot of callers; we have exactly one, so
      efficiency doesn't matter. We can decide this based on
      simplicity and readability.
      
      And the meaning of the struct value is somewhat unclear. Is
      it always the remote matching remote_name? If remote_name is
      NULL (i.e., no per-branch config), does the struct fall back
      to the "origin" remote, or is it also NULL? These questions
      will get even more tricky with pushremotes, whose fallback
      behavior is more complicated. So let's just store the name,
      which pretty clearly represents the branch.*.remote config.
      Any lookup or fallback behavior can then be implemented in
      helper functions.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9e3751d4
  23. 30 4月, 2015 12 次提交
    • J
      merge: deprecate 'git merge <message> HEAD <commit>' syntax · d45366e8
      Junio C Hamano 提交于
      We had this in "git merge" manual for eternity:
      
          'git merge' <msg> HEAD <commit>...
      
          [This] syntax (<msg> `HEAD` <commit>...) is supported for
          historical reasons.  Do not use it from the command line or in
          new scripts.  It is the same as `git merge -m <msg> <commit>...`.
      
      With the update to "git merge" to make it understand what is
      recorded in FETCH_HEAD directly, including Octopus merge cases, we
      now can rewrite the use of this syntax in "git pull" with a simple
      "git merge FETCH_HEAD".
      
      Also there are quite a few fallouts in the test scripts, and it
      turns out that "git cvsimport" also uses this old syntax to record
      a merge.
      
      Judging from this result, I would not be surprised if dropping the
      support of the old syntax broke scripts people have written and been
      relying on for the past ten years.  But at least we can start the
      deprecation process by throwing a warning message when the syntax is
      used.
      
      With luck, we might be able to drop the support in a few years.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d45366e8
    • J
      merge: handle FETCH_HEAD internally · 74e8bc59
      Junio C Hamano 提交于
      The collect_parents() function now is responsible for
      
       1. parsing the commits given on the command line into a list of
          commits to be merged;
      
       2. filtering these parents into independent ones; and
      
       3. optionally calling fmt_merge_msg() via prepare_merge_message()
          to prepare an auto-generated merge log message, using fake
          contents that FETCH_HEAD would have had if these commits were
          fetched from the current repository with "git pull . $args..."
      
      Make "git merge FETCH_HEAD" to be the same as the traditional
      
          git merge "$(git fmt-merge-msg <.git/FETCH_HEAD)" $commits
      
      invocation of the command in "git pull", where $commits are the ones
      that appear in FETCH_HEAD that are not marked as not-for-merge, by
      making it do a bit more, specifically:
      
       - noticing "FETCH_HEAD" is the only "commit" on the command line
         and picking the commits that are not marked as not-for-merge as
         the list of commits to be merged (substitute for step #1 above);
      
       - letting the resulting list fed to step #2 above;
      
       - doing the step #3 above, using the contents of the FETCH_HEAD
         instead of fake contents crafted from the list of commits parsed
         in the step #1 above.
      
      Note that this changes the semantics.  "git merge FETCH_HEAD" has
      always behaved as if the first commit in the FETCH_HEAD file were
      directly specified on the command line, creating a two-way merge
      whose auto-generated merge log said "merge commit xyz".  With this
      change, if the previous fetch was to grab multiple branches (e.g.
      "git fetch $there topic-a topic-b"), the new world order is to
      create an octopus, behaving as if "git pull $there topic-a topic-b"
      were run.  This is a deliberate change to make that happen, and
      can be seen in the changes to t3033 tests.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      74e8bc59
    • J
    • J
    • J
      52fecab2
    • J
      merge: narrow scope of merge_names · 018b3fbc
      Junio C Hamano 提交于
      In order to pass the list of parents to fmt_merge_msg(), cmd_merge()
      uses this strbuf to create something that look like FETCH_HEAD that
      describes commits that are being merged.  This is necessary only
      when we are creating the merge commit message ourselves, but was
      done unconditionally.
      
      Move the variable and the logic to populate it to confine them in a
      block that needs them.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      018b3fbc
    • J
      merge: split reduce_parents() out of collect_parents() · 34349dbf
      Junio C Hamano 提交于
      The latter does two separate things:
      
       - Parse the list of commits on the command line, and formulate the
         list of commits to be merged (including the current HEAD);
      
       - Compute the list of parents to be recorded in the resulting merge
         commit.
      
      Split the latter into a separate helper function, so that we can
      later supply the list commits to be merged from a different source
      (namely, FETCH_HEAD).
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      34349dbf
    • J
      merge: clarify collect_parents() logic · 0b10b8a3
      Junio C Hamano 提交于
      Clarify this small function in three ways.
      
       - The function initially collects all commits to be merged into a
         commit_list "remoteheads"; the "remotes" pointer always points at
         the tail of this list (either the remoteheads variable itself, or
         the ->next slot of the element at the end of the list) to help
         elongate the list by repeated calls to commit_list_insert().
         Because the new element appended by commit_list_insert() will
         always have its ->next slot NULLed out, there is no need for us
         to assign NULL to *remotes to terminate the list at the end.
      
       - The variable "head_subsumed" always confused me every time I read
         this code.  What is happening here is that we inspect what the
         caller told us to merge (including the current HEAD) and come up
         with the list of parents to be recorded for the resulting merge
         commit, omitting commits that are ancestor of other commits.
         This filtering may remove the current HEAD from the resulting
         parent list---and we signal that fact with this variable, so that
         we can later record it as the first parent when "--no-ff" is in
         effect.
      
       - The "parents" list is created for this function by reduce_heads()
         and was not deallocated after its use, even though the loop
         control was written in such a way to allow us to do so by taking
         the "next" element in a separate variable so that it can be used
         in the next-step part of the loop control.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0b10b8a3
    • J
      merge: small leakfix and code simplification · 1016658d
      Junio C Hamano 提交于
      When parsing a merged object name like "foo~20" to formulate a merge
      summary "Merge branch foo (early part)", a temporary strbuf is used,
      but we forgot to deallocate it when we failed to find the named
      branch.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1016658d
    • J
      merge: do not check argc to determine number of remote heads · eaa4e59c
      Junio C Hamano 提交于
      To reject merging multiple commits into an unborn branch, we check
      argc, thinking that collect_parents() that reads the remaining
      command line arguments from <argc, argv> will give us the same
      number of commits as its input, i.e. argc.
      
      Because what we really care about is the number of commits, let the
      function run and then make sure it returns only one commit instead.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      eaa4e59c
    • J
      merge: clarify "pulling into void" special case · 1faac1ce
      Junio C Hamano 提交于
      Instead of having it as one of the three if/elseif/.. case arms,
      test the condition and handle this special case upfront.  This makes
      it easier to follow the flow of logic.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1faac1ce
    • J
      merge: simplify code flow · 00c7e7e7
      Junio C Hamano 提交于
      One of the first things cmd_merge() does is to see if the "--abort"
      option is given and run "reset --merge" and exit.  When the control
      reaches this point, we know "--abort" was not given.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      00c7e7e7