Commit graph

39637 commits

Author SHA1 Message Date
Michael Haggerty ad4cd6c297 commit_ref_update(): new function, extracted from write_ref_sha1()
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:28:02 -07:00
Michael Haggerty e6fd3c6730 write_ref_to_lockfile(): new function, extracted from write_ref_sha1()
This is the first step towards separating the checking and writing of
the new reference value to committing the change.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:28:02 -07:00
Stefan Beller fc38a9bb4d t7004: rename ULIMIT test prerequisite to ULIMIT_STACK_SIZE
During creation of the patch series our discussion we could have a
more descriptive name for the prerequisite for the test so it stays
unique when other limits of ulimit are introduced.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:28:02 -07:00
Stefan Beller d415ad022d update-ref: test handling large transactions properly
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:28:02 -07:00
Junio C Hamano 4ec6591dd7 Merge branch 'mh/write-refs-sooner-2.2' into mh/write-refs-sooner-2.3
* mh/write-refs-sooner-2.2:
  ref_transaction_commit(): fix atomicity and avoid fd exhaustion
  ref_transaction_commit(): remove the local flags variable
  ref_transaction_commit(): inline call to write_ref_sha1()
  rename_ref(): inline calls to write_ref_sha1() from this function
  commit_ref_update(): new function, extracted from write_ref_sha1()
  write_ref_to_lockfile(): new function, extracted from write_ref_sha1()
  t7004: rename ULIMIT test prerequisite to ULIMIT_STACK_SIZE
  update-ref: test handling large transactions properly
2015-05-12 21:26:09 -07:00
Michael Haggerty 6c34492ab4 ref_transaction_commit(): fix atomicity and avoid fd exhaustion
The old code was roughly

    for update in updates:
        acquire locks and check old_sha
    for update in updates:
        if changing value:
            write_ref_to_lockfile()
            commit_ref_update()
    for update in updates:
        if deleting value:
            unlink()
    rewrite packed-refs file
    for update in updates:
        if reference still locked:
            unlock_ref()

This has two problems.

Non-atomic updates
==================

The atomicity of the reference transaction depends on all pre-checks
being done in the first loop, before any changes have started being
committed in the second loop. The problem is that
write_ref_to_lockfile() (previously part of write_ref_sha1()), which
is called from the second loop, contains two more checks:

* It verifies that new_sha1 is a valid object

* If the reference being updated is a branch, it verifies that
  new_sha1 points at a commit object (as opposed to a tag, tree, or
  blob).

If either of these checks fails, the "transaction" is aborted during
the second loop. But this might happen after some reference updates
have already been permanently committed. In other words, the
all-or-nothing promise of "git update-ref --stdin" could be violated.

So these checks have to be moved to the first loop.

File descriptor exhaustion
==========================

The old code locked all of the references in the first loop, leaving
all of the lockfiles open until later loops. Since we might be
updating a lot of references, this could result in file descriptor
exhaustion.

The solution
============

After this patch, the code looks like

    for update in updates:
        acquire locks and check old_sha
        if changing value:
            write_ref_to_lockfile()
        else:
            close_ref()
    for update in updates:
        if changing value:
            commit_ref_update()
    for update in updates:
        if deleting value:
            unlink()
    rewrite packed-refs file
    for update in updates:
        if reference still locked:
            unlock_ref()

This fixes both problems:

1. The pre-checks in write_ref_to_lockfile() are now done in the first
   loop, before any changes have been committed. If any of the checks
   fails, the whole transaction can now be rolled back correctly.

2. All lockfiles are closed in the first loop immediately after they
   are created (either by write_ref_to_lockfile() or by close_ref()).
   This means that there is never more than one open lockfile at a
   time, preventing file descriptor exhaustion.

To simplify the bookkeeping across loops, add a new REF_NEEDS_COMMIT
bit to update->flags, which keeps track of whether the corresponding
lockfile needs to be committed, as opposed to just unlocked. (Since
"struct ref_update" is internal to the refs module, this change is not
visible to external callers.)

This change fixes two tests in t1400.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:25:27 -07:00
Michael Haggerty 805cf6e938 ref_transaction_commit(): remove the local flags variable
Instead, work directly with update->flags. This has the advantage that
the REF_DELETING bit, set in the first loop, can be read in the second
loop instead of having to be recomputed. Plus, it was potentially
confusing having both update->flags and flags, which sometimes had
different values.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:25:27 -07:00
Michael Haggerty 4da50def5b ref_transaction_commit(): inline call to write_ref_sha1()
And remove the function write_ref_sha1(), as it is no longer used.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:25:26 -07:00
Michael Haggerty 29957fda0b rename_ref(): inline calls to write_ref_sha1() from this function
Most of what it does is unneeded from these call sites.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:25:26 -07:00
Michael Haggerty 38e50e81e3 commit_ref_update(): new function, extracted from write_ref_sha1()
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:25:26 -07:00
Michael Haggerty 1d455231a0 write_ref_to_lockfile(): new function, extracted from write_ref_sha1()
This is the first step towards separating the checking and writing of
the new reference value to committing the change.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:25:26 -07:00
Stefan Beller 71ad0505cc t7004: rename ULIMIT test prerequisite to ULIMIT_STACK_SIZE
During creation of the patch series, our discussion revealed that
we could have a more descriptive name for the prerequisite for the
test so it stays unique when other limits of ulimit are introduced.

Let's rename the existing ulimit about setting the stack size to
a more explicit ULIMIT_STACK_SIZE.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 21:24:36 -07:00
Jeff King cb64800d83 add: check return value of launch_editor
When running "add -e", if launching the editor fails, we do
not notice and continue as if the output is what the user
asked for. The likely case is that the editor did not touch
the contents at all, and we end up adding everything.

Reported-by: Russ Cox <rsc@golang.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 20:25:08 -07:00
SZEDER Gábor 12bdc880c7 completion: simplify query for config variables
To get the name of all config variables in a given section we perform a
'git config --get-regex' query for all config variables containing the
name of that section, and then filter its output through a case statement
to throw away those that though contain but don't start with the given
section.

Modify the regex to match only at the beginning, so the case statement
becomes unnecessary and we can get rid of it.  Add a test to check that a
match in the middle doesn't fool us.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 15:16:46 -07:00
SZEDER Gábor e8f9e42829 completion: add a helper function to get config variables
Currently there are a few completion functions that perform similar 'git
config' queries and filtering to get config variable names: the completion
of pretty aliases, aliases, and remote groups for 'git remote update'.

Unify those 'git config' queries in a helper function to eliminate code
duplication.

Though the helper functions to get pretty aliases and alieses are reduced
to mere one-liner wrappers around the newly added function, keep these
helpers still, because users' completion functions out there might depend
on them.  And they keep their callers a tad easier to read, too.

Add tests for the pretty alias and alias helper to show that they work
as before; not for the remote groups query, though, because that's not
extracted into a helper function and it's not worth the effort to do so
for a sole callsite.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 15:12:19 -07:00
Jean-Noel Avila 975e382d13 doc: fix unmatched code fences
This mismatch upsets the renderer on git-scm.com.

Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12 13:08:13 -07:00
Junio C Hamano c518059b26 Merge branch 'maint'
* maint:
  Git 2.3.8
2015-05-11 14:39:39 -07:00
Junio C Hamano c99fec6e35 Sync with 2.3.8
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-11 14:39:28 -07:00
Junio C Hamano 9a3d637541 Git 2.3.8
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-11 14:36:31 -07:00
Junio C Hamano 811ce1b47c Merge branch 'mm/usage-log-l-can-take-regex' into maint-2.3
Documentation fix.

* mm/usage-log-l-can-take-regex:
  log -L: improve error message on malformed argument
  Documentation: change -L:<regex> to -L:<funcname>
2015-05-11 14:34:01 -07:00
Junio C Hamano cd0120857b Merge branch 'jc/diff-no-index-d-f' into maint-2.3
The usual "git diff" when seeing a file turning into a directory
showed a patchset to remove the file and create all files in the
directory, but "git diff --no-index" simply refused to work.  Also,
when asked to compare a file and a directory, imitate POSIX "diff"
and compare the file with the file with the same name in the
directory, instead of refusing to run.

* jc/diff-no-index-d-f:
  diff-no-index: align D/F handling with that of normal Git
  diff-no-index: DWIM "diff D F" into "diff D/F F"
2015-05-11 14:34:00 -07:00
Junio C Hamano 1add9aed85 Merge branch 'oh/fix-config-default-user-name-section' into maint-2.3
The default $HOME/.gitconfig file created upon "git config --global"
that edits it had incorrectly spelled user.name and user.email
entries in it.

* oh/fix-config-default-user-name-section:
  config: fix settings in default_user_config template
2015-05-11 14:33:59 -07:00
Junio C Hamano 13ec221d8c Merge branch 'jc/epochtime-wo-tz' into maint-2.3
"git commit --date=now" or anything that relies on approxidate lost
the daylight-saving-time offset.

* jc/epochtime-wo-tz:
  parse_date_basic(): let the system handle DST conversion
  parse_date_basic(): return early when given a bogus timestamp
2015-05-11 14:33:58 -07:00
Junio C Hamano 22aca1b3ac Second batch for 2.5 cycle
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-11 14:31:28 -07:00
Junio C Hamano 558e5a8c40 Merge branch 'pt/xdg-config-path'
Code clean-up for xdg configuration path support.

* pt/xdg-config-path:
  path.c: remove home_config_paths()
  git-config: replace use of home_config_paths()
  git-commit: replace use of home_config_paths()
  credential-store.c: replace home_config_paths() with xdg_config_home()
  dir.c: replace home_config_paths() with xdg_config_home()
  attr.c: replace home_config_paths() with xdg_config_home()
  path.c: implement xdg_config_home()
2015-05-11 14:24:01 -07:00
Junio C Hamano 7cb5073fca Merge branch 'ep/do-not-feed-a-pointer-to-array-size'
Catch a programmer mistake to feed a pointer not an array to
ARRAY_SIZE() macro, by using a couple of GCC extensions.

* ep/do-not-feed-a-pointer-to-array-size:
  git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array
2015-05-11 14:24:00 -07:00
Junio C Hamano 051086b947 Merge branch 'jc/hash-object'
"hash-object --literally" introduced in v2.2 was not prepared to
take a really long object type name.

* jc/hash-object:
  write_sha1_file(): do not use a separate sha1[] array
  t1007: add hash-object --literally tests
  hash-object --literally: fix buffer overrun with extra-long object type
  git-hash-object.txt: document --literally option
2015-05-11 14:23:59 -07:00
Junio C Hamano b9f5d3874f Merge branch 'sb/prefix-path-free-results'
Code clean-up (not a leak-fix).

* sb/prefix-path-free-results:
  prefix_path(): unconditionally free results in the callers
2015-05-11 14:23:58 -07:00
Junio C Hamano 5c38a1fad7 Merge branch 'sg/completion-no-redundant-all-command-list'
Code simplification.

* sg/completion-no-redundant-all-command-list:
  completion: remove redundant __git_compute_all_commands() call
2015-05-11 14:23:57 -07:00
Junio C Hamano 465868a225 Merge branch 'sg/complete-decorate-full-not-long'
The completion for "log --decorate=" parameter value was incorrect.

* sg/complete-decorate-full-not-long:
  completion: fix and update 'git log --decorate=' options
2015-05-11 14:23:56 -07:00
Junio C Hamano 02f8203740 Merge branch 'jk/filter-branch-use-of-sed-on-incomplete-line'
"filter-branch" corrupted commit log message that ends with an
incomplete line on platforms with some "sed" implementations that
munge such a line.  Work it around by avoiding to use "sed".

* jk/filter-branch-use-of-sed-on-incomplete-line:
  filter-branch: avoid passing commit message through sed
2015-05-11 14:23:54 -07:00
Junio C Hamano 9e4d2f6d45 Merge branch 'jc/daemon-no-ipv6-for-2.4.1'
"git daemon" fails to build from the source under NO_IPV6
configuration (regression in 2.4).

* jc/daemon-no-ipv6-for-2.4.1:
  daemon: unbreak NO_IPV6 build regression
2015-05-11 14:23:53 -07:00
Junio C Hamano a0c0c2e5c2 Merge branch 'jn/clean-use-error-not-fprintf-on-stderr'
Some error messages in "git config" were emitted without calling
the usual error() facility.

* jn/clean-use-error-not-fprintf-on-stderr:
  config: use error() instead of fprintf(stderr, ...)
2015-05-11 14:23:53 -07:00
Junio C Hamano 5fa9e4c4f1 Merge branch 'tb/blame-resurrect-convert-to-git'
Some time ago, "git blame" (incorrectly) lost the convert_to_git()
call when synthesizing a fake "tip" commit that represents the
state in the working tree, which broke folks who record the history
with LF line ending to make their project portabile across
platforms while terminating lines in their working tree files with
CRLF for their platform.

* tb/blame-resurrect-convert-to-git:
  blame: CRLF in the working tree and LF in the repo
2015-05-11 14:23:52 -07:00
Junio C Hamano 1efadd79d6 Merge branch 'va/fix-git-p4-tests'
* va/fix-git-p4-tests:
  git-p4: t9814: prevent --chain-lint failure
2015-05-11 14:23:51 -07:00
Junio C Hamano ee2309dfe2 Merge branch 'ld/p4-case-fold'
* ld/p4-case-fold:
  git-p4: add failing tests for case-folding p4d
2015-05-11 14:23:50 -07:00
Junio C Hamano 352618287e Merge branch 'jk/rebase-quiet-noop'
"git rebase --quiet" was not quite quiet when there is nothing to
do.

* jk/rebase-quiet-noop:
  rebase: silence "git checkout" for noop rebase
2015-05-11 14:23:49 -07:00
Junio C Hamano 0495983679 Merge branch 'va/p4-client-path'
git p4 attempts to better handle branches in Perforce.

* va/p4-client-path:
  git-p4: improve client path detection when branches are used
  t9801: check git-p4's branch detection with client spec enabled
2015-05-11 14:23:48 -07:00
Junio C Hamano 331fe94fed Merge branch 'mm/add-p-split-error'
When "add--interactive" splits a hunk into two overlapping hunks
and then let the user choose only one, it sometimes feeds an
incorrect patch text to "git apply".  Add tests to demonstrate
this.

I have a slight suspicion that this may be $gmane/87202 coming back
and biting us (I seem to have said "let's run with this and see
what happens" back then).

* mm/add-p-split-error:
  stash -p: demonstrate failure of split with mixed y/n
  t3904-stash-patch: factor PERL prereq at the top of the file
  t3904-stash-patch: fix test description
  add -p: demonstrate failure when running 'edit' after a split
  t3701-add-interactive: simplify code
2015-05-11 14:23:47 -07:00
Junio C Hamano 7e98292653 Merge branch 'tb/t0027-crlf'
More line-ending tests.

* tb/t0027-crlf:
  t0027: Add repoMIX and LF_nul
  t0027: support NATIVE_CRLF platforms
  t0027: cleanup: rename functions; avoid non-leading TABs
2015-05-11 14:23:47 -07:00
Junio C Hamano 120c585b22 Merge branch 'ls/p4-changes-block-size'
"git p4" learned "--changes-block-size <n>" to read the changes in
chunks from Perforce, instead of making one call to "p4 changes"
that may trigger "too many rows scanned" error from Perforce.

* ls/p4-changes-block-size:
  git-p4: use -m when running p4 changes
2015-05-11 14:23:46 -07:00
Junio C Hamano 789e98df82 Merge branch 'jc/plug-fmt-merge-msg-leak'
* jc/plug-fmt-merge-msg-leak:
  fmt-merge-msg: plug small leak of commit buffer
2015-05-11 14:23:46 -07:00
Junio C Hamano eb10a85098 Merge branch 'nd/slim-index-pack-memory-usage'
Memory usage of "git index-pack" has been trimmed by tens of
per-cent.

* nd/slim-index-pack-memory-usage:
  index-pack: kill union delta_base to save memory
  index-pack: reduce object_entry size to save memory
2015-05-11 14:23:44 -07:00
Junio C Hamano 84e55dcb34 Merge branch 'jk/still-interesting'
"git rev-list --objects $old --not --all" to see if everything that
is reachable from $old is already connected to the existing refs
was very inefficient.

* jk/still-interesting:
  limit_list: avoid quadratic behavior from still_interesting
2015-05-11 14:23:43 -07:00
Junio C Hamano 6cc983d0ad Merge branch 'jk/reading-packed-refs'
An earlier rewrite to use strbuf_getwholeline() instead of fgets(3)
to read packed-refs file revealed that the former is unacceptably
inefficient.

* jk/reading-packed-refs:
  t1430: add another refs-escape test
  read_packed_refs: avoid double-checking sane refs
  strbuf_getwholeline: use getdelim if it is available
  strbuf_getwholeline: avoid calling strbuf_grow
  strbuf_addch: avoid calling strbuf_grow
  config: use getc_unlocked when reading from file
  strbuf_getwholeline: use getc_unlocked
  git-compat-util: add fallbacks for unlocked stdio
  strbuf_getwholeline: use getc macro
2015-05-11 14:23:42 -07:00
Junio C Hamano 66ff763ebb Merge branch 'lm/squelch-bg-progress'
Many long-running operations show progress eye-candy, even when
they are later backgrounded.  Hide the eye-candy when the process
is sent to the background instead.

* lm/squelch-bg-progress:
  compat/mingw: stubs for getpgid() and tcgetpgrp()
  progress: no progress in background
2015-05-11 14:23:42 -07:00
Junio C Hamano cedeffeee0 Merge branch 'jk/sha1-file-reduce-useless-warnings'
* jk/sha1-file-reduce-useless-warnings:
  sha1_file: squelch "packfile cannot be accessed" warnings
2015-05-11 14:23:41 -07:00
Junio C Hamano 68a2e6a2c8 Merge branch 'nd/multiple-work-trees'
A replacement for contrib/workdir/git-new-workdir that does not
rely on symbolic links and make sharing of objects and refs safer
by making the borrowee and borrowers aware of each other.

* nd/multiple-work-trees: (41 commits)
  prune --worktrees: fix expire vs worktree existence condition
  t1501: fix test with split index
  t2026: fix broken &&-chain
  t2026 needs procondition SANITY
  git-checkout.txt: a note about multiple checkout support for submodules
  checkout: add --ignore-other-wortrees
  checkout: pass whole struct to parse_branchname_arg instead of individual flags
  git-common-dir: make "modules/" per-working-directory directory
  checkout: do not fail if target is an empty directory
  t2025: add a test to make sure grafts is working from a linked checkout
  checkout: don't require a work tree when checking out into a new one
  git_path(): keep "info/sparse-checkout" per work-tree
  count-objects: report unused files in $GIT_DIR/worktrees/...
  gc: support prune --worktrees
  gc: factor out gc.pruneexpire parsing code
  gc: style change -- no SP before closing parenthesis
  checkout: clean up half-prepared directories in --to mode
  checkout: reject if the branch is already checked out elsewhere
  prune: strategies for linked checkouts
  checkout: support checking out into a new working directory
  ...
2015-05-11 14:23:39 -07:00
Junio C Hamano 17c7f4d8e4 Merge branch 'pt/credential-xdg'
Tweak the sample "store" backend of the credential helper to honor
XDG configuration file locations when specified.

* pt/credential-xdg:
  t0302: "unreadable" test needs POSIXPERM
  t0302: test credential-store support for XDG_CONFIG_HOME
  git-credential-store: support XDG_CONFIG_HOME
  git-credential-store: support multiple credential files
2015-05-11 14:23:38 -07:00
Michael Haggerty c628edfddb reflog_expire(): integrate lock_ref_sha1_basic() errors into ours
Now that lock_ref_sha1_basic() gives us back its error messages via a
strbuf, incorporate its error message into our error message rather
than emitting two separate error messages.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
2015-05-11 11:50:20 -07:00