1. 23 5月, 2015 1 次提交
    • J
      remote.c: untangle error logic in branch_get_upstream · 1ca41a19
      Jeff King 提交于
      The error-diagnosis logic in branch_get_upstream was copied
      straight from sha1_name.c in the previous commit. However,
      because we check all error cases and upfront and then later
      diagnose them, the logic is a bit tangled. In particular:
      
        - if branch->merge[0] is NULL, we may end up dereferencing
          it for an error message (in practice, it should never be
          NULL, so this is probably not a triggerable bug).
      
        - We may enter the code path because branch->merge[0]->dst
          is NULL, but we then start our error diagnosis by
          checking whether our local branch exists. But that is
          only relevant to diagnosing missing merge config, not a
          missing tracking ref; our diagnosis may hide the real
          problem.
      
      Instead, let's just use a sequence of "if" blocks to check
      for each error type, diagnose it, and return NULL.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1ca41a19
  2. 22 5月, 2015 7 次提交
    • J
      remote.c: report specific errors from branch_get_upstream · 3a429d0a
      Jeff King 提交于
      When the previous commit introduced the branch_get_upstream
      helper, there was one call-site that could not be converted:
      the one in sha1_name.c, which gives detailed error messages
      for each possible failure.
      
      Let's teach the helper to optionally report these specific
      errors. This lets us convert another callsite, and means we
      can use the helper in other locations that want to give the
      same error messages.
      
      The logic and error messages come straight from sha1_name.c,
      with the exception that we start each error with a lowercase
      letter, as is our usual style (note that a few tests need
      updated as a result).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3a429d0a
    • J
      remote.c: introduce branch_get_upstream helper · a9f9f8cc
      Jeff King 提交于
      All of the information needed to find the @{upstream} of a
      branch is included in the branch struct, but callers have to
      navigate a series of possible-NULL values to get there.
      Let's wrap that logic up in an easy-to-read helper.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a9f9f8cc
    • J
      remote.c: hoist read_config into remote_get_1 · 8770e6fb
      Jeff King 提交于
      Before the previous commit, we had to make sure that
      read_config() was called before entering remote_get_1,
      because we needed to pass pushremote_name by value. But now
      that we pass a function, we can let remote_get_1 handle
      loading the config itself, turning our wrappers into true
      one-liners.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8770e6fb
    • J
      remote.c: provide per-branch pushremote name · da66b274
      Jeff King 提交于
      When remote.c loads its config, it records the
      branch.*.pushremote for the current branch along with the
      global remote.pushDefault value, and then binds them into a
      single value: the default push for the current branch. We
      then pass this value (which may be NULL) to remote_get_1
      when looking up a remote for push.
      
      This has a few downsides:
      
        1. It's confusing. The early-binding of the "current
           value" led to bugs like the one fixed by 98b406f3
           (remote: handle pushremote config in any order,
           2014-02-24). And the fact that pushremotes fall back to
           ordinary remotes is not explicit at all; it happens
           because remote_get_1 cannot tell the difference between
           "we are not asking for the push remote" and "there is
           no push remote configured".
      
        2. It throws away intermediate data. After read_config()
           finishes, we have no idea what the value of
           remote.pushDefault was, because the string has been
           overwritten by the current branch's
           branch.*.pushremote.
      
        3. It doesn't record other data. We don't note the
           branch.*.pushremote value for anything but the current
           branch.
      
      Let's make this more like the fetch-remote config. We'll
      record the pushremote for each branch, and then explicitly
      compute the correct remote for the current branch at the
      time of reading.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      da66b274
    • J
      remote.c: hoist branch.*.remote lookup out of remote_get_1 · f052154d
      Jeff King 提交于
      We'll want to use this logic as a fallback when looking up
      the pushremote, so let's pull it out into its own function.
      
      We don't technically need to make this available outside of
      remote.c, but doing so will provide a consistent API with
      pushremote_for_branch, which we will add later.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f052154d
    • 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
    • J
      remote.c: refactor setup of branch->merge list · ee2499fe
      Jeff King 提交于
      When we call branch_get() to lookup or create a "struct
      branch", we make sure the "merge" field is filled in so that
      callers can access it. But the conditions under which we do
      so are a little confusing, and can lead to two funny
      situations:
      
        1. If there's no branch.*.remote config, we cannot provide
           branch->merge (because it is really just an application
           of branch.*.merge to our remote's refspecs). But
           branch->merge_nr may be non-zero, leading callers to be
           believe they can access branch->merge (e.g., in
           branch_merge_matches and elsewhere).
      
           It doesn't look like this can cause a segfault in
           practice, as most code paths dealing with merge config
           will bail early if there is no remote defined. But it's
           a bit of a dangerous construct.
      
           We can fix this by setting merge_nr to "0" explicitly
           when we realize that we have no merge config. Note that
           merge_nr also counts the "merge_name" fields (which we
           _do_ have; that's how merge_nr got incremented), so we
           will "lose" access to them, in the sense that we forget
           how many we had. But no callers actually care; we use
           merge_name only while iteratively reading the config,
           and then convert it to the final "merge" form the first
           time somebody calls branch_get().
      
        2. We set up the "merge" field every time branch_get is
           called, even if it has already been done. This leaks
           memory.
      
           It's not a big deal in practice, since most code paths
           will access only one branch, or perhaps each branch
           only one time. But if you want to be pathological, you
           can leak arbitrary memory with:
      
             yes @{upstream} | head -1000 | git rev-list --stdin
      
           We can fix this by skipping setup when branch->merge is
           already non-NULL.
      
      In addition to those two fixes, this patch pushes the "do we
      need to setup merge?" logic down into set_merge, where it is
      a bit easier to follow.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ee2499fe
  3. 04 5月, 2015 1 次提交
    • J
      remote.c: drop default_remote_name variable · e41bf352
      Jeff King 提交于
      When we read the remote config from disk, we update a
      default_remote_name variable if we see branch.*.remote
      config for the current branch. This isn't wrong, or even all
      that complicated, but it is a bit simpler (because it
      reduces our overall state) to just lazily compute the
      default when we need it.
      
      The ulterior motive here is that the push config uses a
      similar structure, and _is_ much more complicated as a
      result. That will be simplified in a future patch, and it's
      more readable if the logic for remotes and push-remotes
      matches.
      
      Note that we also used default_remote_name as a signal that
      the remote config has been loaded; after this patch, we now
      use an explicit flag.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e41bf352
  4. 27 3月, 2015 4 次提交
    • J
      Git 2.4.0-rc0 · 2dfb2e07
      Junio C Hamano 提交于
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2dfb2e07
    • J
      Merge branch 'jk/test-chain-lint' · 30db51a3
      Junio C Hamano 提交于
      People often forget to chain the commands in their test together
      with &&, leaving a failure from an earlier command in the test go
      unnoticed.  The new GIT_TEST_CHAIN_LINT mechanism allows you to
      catch such a mistake more easily.
      
      * jk/test-chain-lint: (36 commits)
        t9001: drop save_confirm helper
        t0020: use test_* helpers instead of hand-rolled messages
        t: simplify loop exit-code status variables
        t: fix some trivial cases of ignored exit codes in loops
        t7701: fix ignored exit code inside loop
        t3305: fix ignored exit code inside loop
        t0020: fix ignored exit code inside loops
        perf-lib: fix ignored exit code inside loop
        t6039: fix broken && chain
        t9158, t9161: fix broken &&-chain in git-svn tests
        t9104: fix test for following larger parents
        t4104: drop hand-rolled error reporting
        t0005: fix broken &&-chains
        t7004: fix embedded single-quotes
        t0050: appease --chain-lint
        t9001: use test_when_finished
        t4117: use modern test_* helpers
        t6034: use modern test_* helpers
        t1301: use modern test_* helpers
        t0020: use modern test_* helpers
        ...
      30db51a3
    • J
      Merge branch 'sg/completion-gitcomp-nl-for-refs' · 55a3b3c2
      Junio C Hamano 提交于
      Code clean-up.
      
      * sg/completion-gitcomp-nl-for-refs:
        completion: use __gitcomp_nl() for completing refs
      55a3b3c2
    • J
      Merge branch 'jc/report-path-error-to-dir' · 574ee8ae
      Junio C Hamano 提交于
      Code clean-up.
      
      * jc/report-path-error-to-dir:
        report_path_error(): move to dir.c
      574ee8ae
  5. 26 3月, 2015 22 次提交
    • J
      Getting ready for -rc0 · bca18110
      Junio C Hamano 提交于
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bca18110
    • J
      Merge branch 'nd/doc-git-index-version' · 6ce3cc5d
      Junio C Hamano 提交于
      Doc clean-up.
      
      * nd/doc-git-index-version:
        git.txt: list index versions in plain English
      6ce3cc5d
    • J
      Merge branch 'jk/run-command-capture' · ea1fd481
      Junio C Hamano 提交于
      The run-command interface was easy to abuse and make a pipe for us
      to read from the process, wait for the process to finish and then
      attempt to read its output, which is a pattern that lead to a
      deadlock.  Fix such uses by introducing a helper to do this
      correctly (i.e. we need to read first and then wait the process to
      finish) and also add code to prevent such abuse in the run-command
      helper.
      
      * jk/run-command-capture:
        run-command: forbid using run_command with piped output
        trailer: use capture_command
        submodule: use capture_command
        wt-status: use capture_command
        run-command: introduce capture_command helper
        wt_status: fix signedness mismatch in strbuf_read call
        wt-status: don't flush before running "submodule status"
      ea1fd481
    • J
      Merge branch 'tg/test-index-v4' · d78374e5
      Junio C Hamano 提交于
      A test fix.
      
      * tg/test-index-v4:
        t1700: make test pass with index-v4
      d78374e5
    • J
      Merge branch 'jk/prune-with-corrupt-refs' · 05e816e3
      Junio C Hamano 提交于
      "git prune" used to largely ignore broken refs when deciding which
      objects are still being used, which could spread an existing small
      damage and make it a larger one.
      
      * jk/prune-with-corrupt-refs:
        refs.c: drop curate_packed_refs
        repack: turn on "ref paranoia" when doing a destructive repack
        prune: turn on ref_paranoia flag
        refs: introduce a "ref paranoia" flag
        t5312: test object deletion code paths in a corrupted repository
      05e816e3
    • J
      Merge branch 'tg/fix-check-order-with-split-index' · a801bb8c
      Junio C Hamano 提交于
      The split-index mode introduced at v2.3.0-rc0~41 was broken in the
      codepath to protect us against a broken reimplementation of Git
      that writes an invalid index with duplicated index entries, etc.
      
      * tg/fix-check-order-with-split-index:
        read-cache: fix reading of split index
      a801bb8c
    • J
      Merge branch 'jk/fetch-pack' · 2f6ef713
      Junio C Hamano 提交于
      "git fetch" that fetches a commit using the allow-tip-sha1-in-want
      extension could have failed to fetch all the requested refs.
      
      * jk/fetch-pack:
        fetch-pack: remove dead assignment to ref->new_sha1
        fetch_refs_via_pack: free extra copy of refs
        filter_ref: make a copy of extra "sought" entries
        filter_ref: avoid overwriting ref->old_sha1 with garbage
      2f6ef713
    • J
      Merge branch 'jk/cleanup-failed-clone' · 927936d7
      Junio C Hamano 提交于
      An failure early in the "git clone" that started creating the
      working tree and repository could have resulted in some directories
      and files left without getting cleaned up.
      
      * jk/cleanup-failed-clone:
        clone: drop period from end of die_errno message
        clone: initialize atexit cleanup handler earlier
      927936d7
    • J
      Merge branch 'jc/submitting-patches-mention-send-email' · cf07d3fe
      Junio C Hamano 提交于
      Recommend format-patch and send-email for those who want to submit
      patches to this project.
      
      * jc/submitting-patches-mention-send-email:
        SubmittingPatches: encourage users to use format-patch and send-email
      cf07d3fe
    • J
      Merge branch 'dj/log-graph-with-no-walk' · dbd04eba
      Junio C Hamano 提交于
      "git log --graph --no-walk A B..." is a otcnflicting request that
      asks nonsense; no-walk tells us show discrete points in the
      history, while graph asks to draw connections between these
      discrete points. Forbid the combination.
      
      * dj/log-graph-with-no-walk:
        revision: forbid combining --graph and --no-walk
      dbd04eba
    • J
      Merge branch 'kd/rev-list-bisect-first-parent' · 257b204f
      Junio C Hamano 提交于
      "git rev-list --bisect --first-parent" does not work (yet) and can
      even cause SEGV; forbid it.  "git log --bisect --first-parent"
      would not be useful until "git bisect --first-parent" materializes,
      so it is also forbidden for now.
      
      * kd/rev-list-bisect-first-parent:
        rev-list: refuse --first-parent combined with --bisect
      257b204f
    • J
      Merge branch 'ws/grep-quiet-no-pager' · 01c057df
      Junio C Hamano 提交于
      Even though "git grep --quiet" is run merely to ask for the exit
      status, we spawned the pager regardless.  Stop doing that.
      
      * ws/grep-quiet-no-pager:
        grep: fix "--quiet" overwriting current output
      01c057df
    • J
      Merge branch 'jk/simplify-csum-file-sha1fd-check' · 09e32fa0
      Junio C Hamano 提交于
      Code simplification.
      
      * jk/simplify-csum-file-sha1fd-check:
        sha1fd_check: die when we cannot open the file
      09e32fa0
    • J
      Merge branch 'ct/prompt-untracked-fix' · 5f15cba2
      Junio C Hamano 提交于
      The prompt script (in contrib/) did not show the untracked sign
      when working in a subdirectory without any untracked files.
      
      * ct/prompt-untracked-fix:
        git prompt: use toplevel to find untracked files
      5f15cba2
    • J
      t9001: drop save_confirm helper · fc99da1f
      Jeff King 提交于
      The idea of this helper is that we want to save the current
      value of a config variable and then restore it again after
      the test completes. However, there's no point in actually
      saving the value; it should always be restored to the string
      "never" (which you can confirm by instrumenting
      save_confirm to print the value it finds).
      
      Let's just replace it with a single test_when_finished call.
      Suggested-by: NSZEDER Gábor <szeder@ira.uka.de>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fc99da1f
    • J
      t0020: use test_* helpers instead of hand-rolled messages · be86fb3f
      Jeff King 提交于
      These tests are not wrong, but it is much shorter and more
      idiomatic to say "verbose" or "test_must_fail" rather than
      printing our own messages on failure. Likewise, there is no
      need to say "happy" at the end of a test; the test suite
      takes care of that.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      be86fb3f
    • J
      t: simplify loop exit-code status variables · c6587bdd
      Jeff King 提交于
      Since shell loops may drop the exit code of failed commands
      inside the loop, some tests try to keep track of the status
      by setting a variable. This can end up cumbersome and hard
      to read; it is much simpler to just exit directly from the
      loop using "return 1" (since each case is either in a helper
      function or inside a test snippet).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c6587bdd
    • J
      t: fix some trivial cases of ignored exit codes in loops · e6821d09
      Jeff King 提交于
      These are all cases where we do a setup step of the form:
      
        for i in $foo; do
      	  set_up $i || break
        done &&
        more_setup
      
      would not notice a failure in set_up (because break always
      returns a 0 exit code). These are just setup steps that we
      do not expect to fail, but it does not hurt to be defensive.
      
      Most can be fixed by converting the "break" to a "return 1"
      (since we eval our tests inside a function for just this
      purpose). A few of the loops are inside subshells, so we can
      use just "exit 1" to break out of the subshell. And a few
      can actually be made shorter by just unrolling the loop.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e6821d09
    • J
      t7701: fix ignored exit code inside loop · 76e057db
      Jeff King 提交于
      When checking a list of file mtimes, we use a loop and break
      out early from the loop if any entry does not match.
      However, the exit code of a loop exited via break is always
      0, meaning that the test will fail to notice we had a
      mismatch. Since the loop is inside a function, we can fix
      this by doing an early "return 1".
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      76e057db
    • J
      t3305: fix ignored exit code inside loop · 6636cf7e
      Jeff King 提交于
      When we test deleting notes, we run "git notes remove" in a
      loop. However, the exit value of the loop will only reflect
      the final note we process. We should break out of the loop
      with a failing exit code as soon as we see a problem.
      
      Note that we can call "exit 1" here without explicitly
      creating a subshell, because the while loop on the
      right-hand side of a pipe executes in its own implicit
      subshell.
      
      Note also that the "break" above does not suffer the same
      problem; it is meant to exit the loop early at a certain
      number of iterations. We can bump it into the conditional of
      the loop to make this more obvious.
      Signed-off-by: NJeff King <peff@peff.net>
      Acked-by: NJohan Herland <johan@herland.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6636cf7e
    • J
      t0020: fix ignored exit code inside loops · fd777141
      Jeff King 提交于
      A loop like:
      
        for f in one two; do
      	  something $f ||
      	  break
        done
      
      will correctly break out of the loop when we see a failure
      of one item, but the resulting exit code will always be
      zero. We can fix that by putting the loop into a function or
      subshell, but in this case it is simpler still to just
      unroll the loop. We do add a helper function, which
      hopefully makes the end result even more readable (in
      addition to being shorter).
      Reported-by: NSZEDER Gábor <szeder@ira.uka.de>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fd777141
    • J
      perf-lib: fix ignored exit code inside loop · ecb590a9
      Jeff King 提交于
      When copying the test repository, we try to detect whether
      the copy succeeded. However, most of the heavy lifting is
      done inside a for loop, where our "break" will lose the exit
      code of the failing "cp". We can take advantage of the fact
      that we are in a subshell, and just "exit 1" to break out
      with a code.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ecb590a9
  6. 25 3月, 2015 2 次提交
    • J
      Merge branch 'master' of git://ozlabs.org/~paulus/gitk · 92e625d3
      Junio C Hamano 提交于
      * 'master' of git://ozlabs.org/~paulus/gitk:
        gitk: Update .po files
        gitk: l10n: Add Catalan translation
        gitk: Fix typo in Russian translation
        gitk: Remove tcl-format flag from a message that shouldn't have it
        gitk: Pass --invert-grep option down to "git log"
        gitk: Synchronize config file writes
        gitk: Report errors in saving config file
        gitk: Only write changed configuration variables
        gitk: Enable mouse horizontal scrolling in diff pane
        gitk: Default wrcomcmd to use --pretty=email
      92e625d3
    • J
      report_path_error(): move to dir.c · 777c55a6
      Junio C Hamano 提交于
      The expected call sequence is for the caller to use match_pathspec()
      repeatedly on a set of pathspecs, accumulating the "hits" in a
      separate array, and then call this function to diagnose a pathspec
      that never matched anything, as that can indicate a typo from the
      command line, e.g. "git commit Maekfile".
      
      Many builtin commands use this function from builtin/ls-files.c,
      which is not a very healthy arrangement.  ls-files might have been
      the first command to feel the need for such a helper, but the need
      is shared by everybody who uses the "match and then report" pattern.
      
      Move it to dir.c where match_pathspec() is defined.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      777c55a6
  7. 24 3月, 2015 3 次提交