1. 23 2月, 2016 1 次提交
  2. 14 1月, 2016 1 次提交
  3. 20 11月, 2015 3 次提交
  4. 27 10月, 2015 1 次提交
  5. 17 10月, 2015 1 次提交
  6. 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
  7. 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
  8. 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
  9. 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
  10. 16 4月, 2015 1 次提交
    • J
      Revert "merge: pass verbosity flag down to merge-recursive" · 3d6bc9a7
      Junio C Hamano 提交于
      This reverts commit 2bf15a33, whose
      intention was good, but the verbosity levels used in merge-recursive
      turns out to be rather uneven.  For example, a merge of two branches
      with conflicting submodule updates used to report CONFLICT: output
      with --quiet but no longer (which *is* desired), while the final
      "Automatic merge failed; fix conflicts and then commit" message is
      still shown even with --quiet (which *is* inconsistent).
      
      Originally reported by Bryan Turner; it is too early to declare what
      the concensus is, but it seems that we would need to level the
      verbosity levels used in merge strategy backends before we can go
      forward.  In the meantime, we'd revert to the old behaviour until
      that happens.
      
      cf. $gmane/267245
      3d6bc9a7
  11. 03 4月, 2015 1 次提交
    • J
      merge: pass verbosity flag down to merge-recursive · 2bf15a33
      Jeff King 提交于
      This makes "git merge --quiet" really quiet when we call
      into merge-recursive.
      
      Note that we can't just pass our flag down as-is; the two
      parts of the code use different scales. We center at "0" as
      normal for git-merge (with "--quiet" giving a negative
      value), but merge-recursive uses "2" as its center.  This
      patch passes a negative value to merge-recursive rather than
      "1", though, as otherwise the user would have to use "-qqq"
      to squelch all messages (but the downside is that the user
      cannot distinguish between levels 0-2 if without resorting
      to the GIT_MERGE_VERBOSITY variable).
      
      We may want to review and renormalize the message severities
      in merge-recursive, but that does not have to happen now.
      This is at least in improvement in the sense that we are
      respecting "--quiet" at all.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2bf15a33
  12. 15 1月, 2015 1 次提交
  13. 30 12月, 2014 1 次提交
  14. 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
  15. 25 10月, 2014 2 次提交
  16. 16 10月, 2014 1 次提交
  17. 02 10月, 2014 3 次提交
  18. 19 9月, 2014 1 次提交
  19. 03 9月, 2014 1 次提交
  20. 21 8月, 2014 1 次提交
  21. 11 7月, 2014 1 次提交
  22. 24 6月, 2014 1 次提交
  23. 14 6月, 2014 1 次提交
  24. 13 6月, 2014 1 次提交
    • J
      commit_tree: take a pointer/len pair rather than a const strbuf · 3ffefb54
      Jeff King 提交于
      While strbufs are pretty common throughout our code, it is
      more flexible for functions to take a pointer/len pair than
      a strbuf. It's easy to turn a strbuf into such a pair (by
      dereferencing its members), but less easy to go the other
      way (you can strbuf_attach, but that has implications about
      memory ownership).
      
      This patch teaches commit_tree (and its associated callers
      and sub-functions) to take such a pair for the commit
      message rather than a strbuf.  This makes passing the buffer
      around slightly more verbose, but means we can get rid of
      some dangerous strbuf_attach calls in the next patch.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3ffefb54