git
10 years agoprune-packed: fix minor memory leak
Jeff King [Sat, 13 Sep 2014 20:16:53 +0000 (16:16 -0400)] 
prune-packed: fix minor memory leak

We form all of our directories in a strbuf, but never release it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agobuiltin/log.c: mark strings for translation
Matthias Ruester [Sun, 14 Sep 2014 22:07:10 +0000 (00:07 +0200)] 
builtin/log.c: mark strings for translation

Signed-off-by: Matthias Ruester <matthias.ruester@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorerere.h: mark string for translation
Matthias Ruester [Sun, 14 Sep 2014 22:40:53 +0000 (00:40 +0200)] 
rerere.h: mark string for translation

Signed-off-by: Matthias Ruester <matthias.ruester@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agogit-svn: delay term initialization
Eric Wong [Sun, 14 Sep 2014 07:38:29 +0000 (07:38 +0000)] 
git-svn: delay term initialization

On my Debian 7 system, this fixes annoying warnings when the output
of "git svn" commands are redirected:

    Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work.
    The COLUMNS and LINES environment variables didn't work. The
    resize program didn't work.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
10 years agogit svn: find-rev allows short switches for near matches
Eric Wong [Sun, 7 Sep 2014 08:35:19 +0000 (08:35 +0000)] 
git svn: find-rev allows short switches for near matches

Allow -B and -A to act as short aliases for --before and --after
options respectively.  This reduces typing and hopefully allows
reuse of muscle memory for grep(1) users.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
10 years agogit-svn.txt: Remove mentions of repack options
Lawrence Velázquez [Fri, 5 Sep 2014 03:46:25 +0000 (23:46 -0400)] 
git-svn.txt: Remove mentions of repack options

Git no longer seems to use these flags or their associated config keys;
when they are present, git-svn outputs a message indicating that they
are being ignored.

Signed-off-by: Lawrence Velázquez <vq@larryv.me>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
10 years agogit svn: info: correctly handle absolute path args
Eric Wong [Sun, 3 Aug 2014 01:44:08 +0000 (01:44 +0000)] 
git svn: info: correctly handle absolute path args

Calling "git svn info $(pwd)" would hit:
  "Reading from filehandle failed at ..."
errors due to improper prefixing and canonicalization.

Strip the toplevel path from absolute filesystem paths to ensure
downstream canonicalization routines are only exposed to paths
tracked in git (or SVN).

v2:
  Thanks to Andrej Manduch for originally noticing the issue
  and fixing my original version of this to handle
  more corner cases such as "/path/to/top/../top" and
  "/path/to/top/../top/file" as shown in the new test cases.

v3:
  Fix pathname portability problems pointed out by Johannes Sixt
  with a hint from brian m. carlson.

Cc: Johannes Sixt <j6t@kdbg.org>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>
Signed-off-by: Andrej Manduch <amanduch@gmail.com>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
10 years agogit-svn: branch: avoid systematic prompt for cert/pass
Monard Vong [Thu, 24 Jul 2014 16:25:59 +0000 (18:25 +0200)] 
git-svn: branch: avoid systematic prompt for cert/pass

Commands such as "git svn init/fetch/dcommit" do not prompt for client
certificate/password if they are stored in SVN config file.  Make
"git svn branch" consistent with the other commands, as SVN::Client is
capable of building its own authentication baton from information in the
SVN config directory.

Signed-off-by: Monard Vong <travelingsoul86@gmail.com>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
10 years agot9300: use test_cmp_bin instead of test_cmp to compare binary files
Johannes Sixt [Fri, 12 Sep 2014 19:47:34 +0000 (21:47 +0200)] 
t9300: use test_cmp_bin instead of test_cmp to compare binary files

test_cmp is intended to produce diff output for human consumption. The
input in one instance in t9300-fast-import.sh are binary files, however.
Use test_cmp_bin to compare the files.

This was noticed because on Windows we have a special implementation of
test_cmp in pure bash code (to ignore differences due to intermittent CR
in actual output), and bash runs into an infinite loop due to the binary
nature of the input.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs: speed up is_refname_available
Jeff King [Wed, 10 Sep 2014 11:11:55 +0000 (07:11 -0400)] 
refs: speed up is_refname_available

Our filesystem ref storage does not allow D/F conflicts; so
if "refs/heads/a/b" exists, we do not allow "refs/heads/a"
to exist (and vice versa). This falls out naturally for
loose refs, where the filesystem enforces the condition. But
for packed-refs, we have to make the check ourselves.

We do so by iterating over the entire packed-refs namespace
and checking whether each name creates a conflict. If you
have a very large number of refs, this is quite inefficient,
as you end up doing a large number of comparisons with
uninteresting bits of the ref tree (e.g., we know that all
of "refs/tags" is uninteresting in the example above, yet we
check each entry in it).

Instead, let's take advantage of the fact that we have the
packed refs stored as a trie of ref_entry structs. We can
find each component of the proposed refname as we walk
through the trie, checking for D/F conflicts as we go. For a
refname of depth N (i.e., 4 in the above example), we only
have to visit N nodes. And at each visit, we can binary
search the M names at that level, for a total complexity of
O(N lg M). ("M" is different at each level, of course, but
we can take the worst-case "M" as a bound).

In a pathological case of fetching 30,000 fresh refs into a
repository with 8.5 million refs, this dropped the time to
run "git fetch" from tens of minutes to ~30s.

This may also help smaller cases in which we check against
loose refs (which we do when renaming a ref), as we may
avoid a disk access for unrelated loose directories.

Note that the tests we add appear at first glance to be
redundant with what is already in t3210. However, the early
tests are not robust; they are run with reflogs turned on,
meaning that we are not actually testing
is_refname_available at all! The operations will still fail
because the reflogs will hit D/F conflicts in the
filesystem. To get a true test, we must turn off reflogs
(but we don't want to do so for the entire script, because
the point of turning them on was to cover some other cases).

Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agot1450: make sure fsck detects a malformed tagger line
Junio C Hamano [Thu, 11 Sep 2014 21:16:36 +0000 (14:16 -0700)] 
t1450: make sure fsck detects a malformed tagger line

With "hash-object --literally", write a tag object that is not
supposed to pass one of the new checks added to "fsck", and make
sure that the new check catches the breakage.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoMerge branch 'js/fsck-tag-validation' into HEAD
Junio C Hamano [Fri, 12 Sep 2014 18:05:08 +0000 (11:05 -0700)] 
Merge branch 'js/fsck-tag-validation' into HEAD

* js/fsck-tag-validation:
  Make sure that index-pack --strict checks tag objects
  Add regression tests for stricter tag fsck'ing
  fsck: check tag objects' headers
  Make sure fsck_commit_buffer() does not run out of the buffer
  fsck_object(): allow passing object data separately from the object itself
  Refactor type_from_string() to allow continuing after detecting an error

10 years agoMake sure that index-pack --strict checks tag objects
Johannes Schindelin [Fri, 12 Sep 2014 08:08:16 +0000 (10:08 +0200)] 
Make sure that index-pack --strict checks tag objects

One of the most important use cases for the strict tag object checking
is when transfer.fsckobjects is set to true to catch invalid objects
early on. This new regression test essentially tests the same code path
by directly calling 'index-pack --strict' on a pack containing an
tag object without a 'tagger' line.

Technically, this test is not enough: it only exercises a code path that
*warns*, not one that *fails*. The reason is that hash-object and
pack-objects both insist on parsing the tag objects and would fail on
invalid tag objects at this time.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agofsck: return non-zero status on missing ref tips
Jeff King [Fri, 12 Sep 2014 03:38:30 +0000 (23:38 -0400)] 
fsck: return non-zero status on missing ref tips

Fsck tries hard to detect missing objects, and will complain
(and exit non-zero) about any inter-object links that are
missing. However, it will not exit non-zero for any missing
ref tips, meaning that a severely broken repository may
still pass "git fsck && echo ok".

The problem is that we use for_each_ref to iterate over the
ref tips, which hides broken tips. It does at least print an
error from the refs.c code, but fsck does not ever see the
ref and cannot note the problem in its exit code. We can solve
this by using for_each_rawref and noting the error ourselves.

In addition to adding tests for this case, we add tests for
all types of missing-object links (all of which worked, but
which we were not testing).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoconfig: avoid a funny sentinel value "a^"
Jeff King [Tue, 19 Aug 2014 06:20:00 +0000 (02:20 -0400)] 
config: avoid a funny sentinel value "a^"

Introduce CONFIG_REGEX_NONE as a more explicit sentinel value to say
"we do not want to replace any existing entry" and use it in the
implementation of "git config --add".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agopre-push.sample: Write error message to stderr
W. Trevor King [Thu, 11 Sep 2014 20:35:30 +0000 (13:35 -0700)] 
pre-push.sample: Write error message to stderr

githooks(5) suggests:

  Information about why the push is rejected may be sent to the user
  by writing to standard error.

So follow that advice in the sample.

Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agohash-object: add --literally option
Junio C Hamano [Thu, 11 Sep 2014 20:14:51 +0000 (13:14 -0700)] 
hash-object: add --literally option

This allows "hash-object --stdin" to just hash any garbage into a
"loose object" that may not pass the standard object parsing check
or fsck, so that different kind of corrupt objects we may encounter
in the field can be imitated in our test suite.  That would in turn
allow us to test features that catch these corrupt objects.

Note that "cat-file" may need to learn "--literally" option to allow
us peek into a truly broken object.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoAdd regression tests for stricter tag fsck'ing
Johannes Schindelin [Thu, 11 Sep 2014 14:26:41 +0000 (16:26 +0200)] 
Add regression tests for stricter tag fsck'ing

The intent of the new test case is to catch general breakages in
the fsck_tag() function, not so much to test it extensively, trying to
strike the proper balance between thoroughness and speed.

While it *would* have been nice to test the code path where fsck_object()
encounters an invalid tag object, this is not possible using git fsck: tag
objects are parsed already before fsck'ing (and the parser already fails
upon such objects).

Even worse: we would not even be able write out invalid tag objects
because git hash-object parses those objects, too, unless we resorted to
really ugly hacks such as using something like this in the unit tests
(essentially depending on Perl *and* Compress::Zlib):

hash_invalid_object () {
contents="$(printf '%s %d\0%s' "$1" ${#2} "$2")" &&
sha1=$(echo "$contents" | test-sha1) &&
suffix=${sha1#??} &&
mkdir -p .git/objects/${sha1%$suffix} &&
echo "$contents" |
perl -MCompress::Zlib -e 'undef $/; print compress(<>)' \
> .git/objects/${sha1%$suffix}/$suffix &&
echo $sha1
}

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agohash-object: pass 'write_object' as a flag
Junio C Hamano [Thu, 11 Sep 2014 19:44:05 +0000 (12:44 -0700)] 
hash-object: pass 'write_object' as a flag

Instead of forcing callers of lower level functions write
(write_object ? HASH_WRITE_OBJECT : 0), prepare the flag to be
passed down in the callchain from the command line parser.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agohash-object: reduce file-scope statics
Junio C Hamano [Thu, 11 Sep 2014 19:19:54 +0000 (12:19 -0700)] 
hash-object: reduce file-scope statics

Most of the knobs that affect helper functions called from
cmd_hash_object() were passed to them as parameters already, and the
only effect of having them as file-scope statics was to make the
reader wonder if the parameters are hiding the file-scope global
values by accident.  Adjust their initialisation and make them
function-local variables.

The only exception was no_filters hash_stdin_paths() peeked from the
file-scope global, which was converted to a parameter to the helper
function.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoUpdate draft release notes to 2.2
Junio C Hamano [Thu, 11 Sep 2014 18:19:47 +0000 (11:19 -0700)] 
Update draft release notes to 2.2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agofsck: check tag objects' headers
Johannes Schindelin [Thu, 11 Sep 2014 14:26:38 +0000 (16:26 +0200)] 
fsck: check tag objects' headers

We inspect commit objects pretty much in detail in git-fsck, but we just
glanced over the tag objects. Let's be stricter.

Since we do not want to limit 'tag' lines unduly, values that would fail
the refname check only result in warnings, not errors.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoMake sure fsck_commit_buffer() does not run out of the buffer
Johannes Schindelin [Thu, 11 Sep 2014 14:26:33 +0000 (16:26 +0200)] 
Make sure fsck_commit_buffer() does not run out of the buffer

So far, we assumed that the buffer is NUL terminated, but this is not
a safe assumption, now that we opened the fsck_object() API to pass a
buffer directly.

So let's make sure that there is at least an empty line in the buffer.
That way, our checks would fail if the empty line was encountered
prematurely, and consequently we can get away with the current string
comparisons even with non-NUL-terminated buffers are passed to
fsck_object().

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoDocumentation: use single-parameter --cacheinfo in example
Steffen Prohaska [Thu, 11 Sep 2014 15:19:51 +0000 (17:19 +0200)] 
Documentation: use single-parameter --cacheinfo in example

The single-parameter form is described as the preferred way.  Separate
arguments are only supported for backward compatibility.  Update the
example to the recommended form.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoMerge branch 'br/imap-send-simplify-tunnel-child-process'
Junio C Hamano [Thu, 11 Sep 2014 17:33:37 +0000 (10:33 -0700)] 
Merge branch 'br/imap-send-simplify-tunnel-child-process'

Code clean-up.

* br/imap-send-simplify-tunnel-child-process:
  imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()
  imap-send.c: imap_folder -> imap_server_conf.folder
  git-imap-send: simplify tunnel construction

10 years agoMerge branch 'jk/name-decoration-alloc'
Junio C Hamano [Thu, 11 Sep 2014 17:33:36 +0000 (10:33 -0700)] 
Merge branch 'jk/name-decoration-alloc'

The API to allocate the structure to keep track of commit
decoration was cumbersome to use, inviting lazy code to
overallocate memory.

* jk/name-decoration-alloc:
  log-tree: use FLEX_ARRAY in name_decoration
  log-tree: make name_decoration hash static
  log-tree: make add_name_decoration a public function

10 years agoMerge branch 'jn/unpack-trees-checkout-m-carry-deletion'
Junio C Hamano [Thu, 11 Sep 2014 17:33:35 +0000 (10:33 -0700)] 
Merge branch 'jn/unpack-trees-checkout-m-carry-deletion'

"git checkout -m" did not switch to another branch while carrying
the local changes forward when a path was deleted from the index.

* jn/unpack-trees-checkout-m-carry-deletion:
  checkout -m: attempt merge when deletion of path was staged
  unpack-trees: use 'cuddled' style for if-else cascade
  unpack-trees: simplify 'all other failures' case

10 years agoMerge branch 'rs/list-optim'
Junio C Hamano [Thu, 11 Sep 2014 17:33:35 +0000 (10:33 -0700)] 
Merge branch 'rs/list-optim'

Fix a couple of "accumulate into a sorted list" to "accumulate and
then sort the list".

* rs/list-optim:
  walker: avoid quadratic list insertion in mark_complete
  sha1_name: avoid quadratic list insertion in handle_one_ref

10 years agoMerge branch 'jk/fast-import-fixes'
Junio C Hamano [Thu, 11 Sep 2014 17:33:34 +0000 (10:33 -0700)] 
Merge branch 'jk/fast-import-fixes'

With sufficiently long refnames, fast-import could have overflown
an on-stack buffer.

* jk/fast-import-fixes:
  fast-import: fix buffer overflow in dump_tags
  fast-import: clean up pack_data pointer in end_packfile

10 years agoMerge branch 'jk/prune-top-level-refs-after-packing'
Junio C Hamano [Thu, 11 Sep 2014 17:33:33 +0000 (10:33 -0700)] 
Merge branch 'jk/prune-top-level-refs-after-packing'

After "pack-refs --prune" packed refs at the top-level, it failed
to prune them.

* jk/prune-top-level-refs-after-packing:
  pack-refs: prune top-level refs like "refs/foo"

10 years agoMerge branch 'nd/large-blobs'
Junio C Hamano [Thu, 11 Sep 2014 17:33:32 +0000 (10:33 -0700)] 
Merge branch 'nd/large-blobs'

Teach a few codepaths to punt (instead of dying) when large blobs
that would not fit in core are involved in the operation.

* nd/large-blobs:
  diff: shortcut for diff'ing two binary SHA-1 objects
  diff --stat: mark any file larger than core.bigfilethreshold binary
  diff.c: allow to pass more flags to diff_populate_filespec
  sha1_file.c: do not die failing to malloc in unpack_compressed_entry
  wrapper.c: introduce gentle xmallocz that does not die()

10 years agoMerge branch 'nd/fetch-pass-quiet-to-gc-child-process'
Junio C Hamano [Thu, 11 Sep 2014 17:33:32 +0000 (10:33 -0700)] 
Merge branch 'nd/fetch-pass-quiet-to-gc-child-process'

Progress output from "git gc --auto" was visible in "git fetch -q".

* nd/fetch-pass-quiet-to-gc-child-process:
  fetch: silence git-gc if --quiet is given
  fetch: convert argv_gc_auto to struct argv_array

10 years agoMerge branch 'dt/cache-tree-repair'
Junio C Hamano [Thu, 11 Sep 2014 17:33:32 +0000 (10:33 -0700)] 
Merge branch 'dt/cache-tree-repair'

Add a few more places in "commit" and "checkout" that make sure
that the cache-tree is fully populated in the index.

* dt/cache-tree-repair:
  cache-tree: do not try to use an invalidated subtree info to build a tree
  cache-tree: Write updated cache-tree after commit
  cache-tree: subdirectory tests
  test-dump-cache-tree: invalid trees are not errors
  cache-tree: create/update cache-tree on checkout

10 years agoMerge branch 'rs/ref-transaction-1'
Junio C Hamano [Thu, 11 Sep 2014 17:33:30 +0000 (10:33 -0700)] 
Merge branch 'rs/ref-transaction-1'

The second batch of the transactional ref update series.

* rs/ref-transaction-1: (22 commits)
  update-ref --stdin: pass transaction around explicitly
  update-ref --stdin: narrow scope of err strbuf
  refs.c: make delete_ref use a transaction
  refs.c: make prune_ref use a transaction to delete the ref
  refs.c: remove lock_ref_sha1
  refs.c: remove the update_ref_write function
  refs.c: remove the update_ref_lock function
  refs.c: make lock_ref_sha1 static
  walker.c: use ref transaction for ref updates
  fast-import.c: use a ref transaction when dumping tags
  receive-pack.c: use a reference transaction for updating the refs
  refs.c: change update_ref to use a transaction
  branch.c: use ref transaction for all ref updates
  fast-import.c: change update_branch to use ref transactions
  sequencer.c: use ref transactions for all ref updates
  commit.c: use ref transactions for updates
  replace.c: use the ref transaction functions for updates
  tag.c: use ref transactions when doing updates
  refs.c: add transaction.status and track OPEN/CLOSED
  refs.c: make ref_transaction_begin take an err argument
  ...

10 years agoMerge branch 'nd/mv-code-cleaning'
Junio C Hamano [Thu, 11 Sep 2014 17:33:30 +0000 (10:33 -0700)] 
Merge branch 'nd/mv-code-cleaning'

Code clean-up.

* nd/mv-code-cleaning:
  mv: no SP between function name and the first opening parenthese
  mv: combine two if(s)
  mv: unindent one level for directory move code
  mv: move index search code out
  mv: remove an "if" that's always true
  mv: split submodule move preparation code out
  mv: flatten error handling code block
  mv: mark strings for translations

10 years agoMerge branch 'mm/discourage-commit-a-to-finish-conflict-resolution'
Junio C Hamano [Thu, 11 Sep 2014 17:33:29 +0000 (10:33 -0700)] 
Merge branch 'mm/discourage-commit-a-to-finish-conflict-resolution'

* mm/discourage-commit-a-to-finish-conflict-resolution:
  merge, pull: stop advising 'commit -a' in case of conflict

10 years agoMerge branch 'jk/make-simplify-dependencies'
Junio C Hamano [Thu, 11 Sep 2014 17:33:29 +0000 (10:33 -0700)] 
Merge branch 'jk/make-simplify-dependencies'

Admit that keeping LIB_H up-to-date, only for those that do not use
the automatically generated dependencies, is a losing battle, and
make it conservative by making everything depend on anything.

* jk/make-simplify-dependencies:
  Makefile: drop CHECK_HEADER_DEPENDENCIES code
  Makefile: use `find` to determine static header dependencies
  i18n: treat "make pot" as an explicitly-invoked target

10 years agoMerge branch 'et/spell-poll-infinite-with-minus-one-only'
Junio C Hamano [Thu, 11 Sep 2014 17:33:28 +0000 (10:33 -0700)] 
Merge branch 'et/spell-poll-infinite-with-minus-one-only'

We used to pass -1000 to poll(2), expecting it to also mean "no
timeout", which should be spelled as -1.

* et/spell-poll-infinite-with-minus-one-only:
  upload-pack: keep poll(2)'s timeout to -1

10 years agoMerge branch 'br/http-init-fix'
Junio C Hamano [Thu, 11 Sep 2014 17:33:27 +0000 (10:33 -0700)] 
Merge branch 'br/http-init-fix'

Code clean-up.

* br/http-init-fix:
  http: style fixes for curl_multi_init error check
  http.c: die if curl_*_init fails

10 years agoMerge branch 'rs/child-process-init'
Junio C Hamano [Thu, 11 Sep 2014 17:33:27 +0000 (10:33 -0700)] 
Merge branch 'rs/child-process-init'

Code clean-up.

* rs/child-process-init:
  run-command: inline prepare_run_command_v_opt()
  run-command: call run_command_v_opt_cd_env() instead of duplicating it
  run-command: introduce child_process_init()
  run-command: introduce CHILD_PROCESS_INIT

10 years agoMerge branch 'jk/contrib-subtree-make-all'
Junio C Hamano [Thu, 11 Sep 2014 17:33:26 +0000 (10:33 -0700)] 
Merge branch 'jk/contrib-subtree-make-all'

* jk/contrib-subtree-make-all:
  subtree: make "all" default target of Makefile

10 years agoMerge branch 'ta/config-set-2'
Junio C Hamano [Thu, 11 Sep 2014 17:33:26 +0000 (10:33 -0700)] 
Merge branch 'ta/config-set-2'

Update git_config() users with callback functions for a very narrow
scope with calls to config-set API that lets us query a single
variable.

* ta/config-set-2:
  builtin/apply.c: replace `git_config()` with `git_config_get_string_const()`
  merge-recursive.c: replace `git_config()` with `git_config_get_int()`
  ll-merge.c: refactor `read_merge_config()` to use `git_config_string()`
  fast-import.c: replace `git_config()` with `git_config_get_*()` family
  branch.c: replace `git_config()` with `git_config_get_string()
  alias.c: replace `git_config()` with `git_config_get_string()`
  imap-send.c: replace `git_config()` with `git_config_get_*()` family
  pager.c: replace `git_config()` with `git_config_get_value()`
  builtin/gc.c: replace `git_config()` with `git_config_get_*()` family
  rerere.c: replace `git_config()` with `git_config_get_*()` family
  fetchpack.c: replace `git_config()` with `git_config_get_*()` family
  archive.c: replace `git_config()` with `git_config_get_bool()` family
  read-cache.c: replace `git_config()` with `git_config_get_*()` family
  http-backend.c: replace `git_config()` with `git_config_get_bool()` family
  daemon.c: replace `git_config()` with `git_config_get_bool()` family

10 years agoMerge branch 'ta/config-set-1'
Junio C Hamano [Thu, 11 Sep 2014 17:33:25 +0000 (10:33 -0700)] 
Merge branch 'ta/config-set-1'

Use the new caching config-set API in git_config() calls.

* ta/config-set-1:
  add tests for `git_config_get_string_const()`
  add a test for semantic errors in config files
  rewrite git_config() to use the config-set API
  config: add `git_die_config()` to the config-set API
  change `git_config()` return value to void
  add line number and file name info to `config_set`
  config.c: fix accuracy of line number in errors
  config.c: mark error and warnings strings for translation

10 years agofsck_object(): allow passing object data separately from the object itself
Johannes Schindelin [Wed, 10 Sep 2014 13:52:51 +0000 (15:52 +0200)] 
fsck_object(): allow passing object data separately from the object itself

When fsck'ing an incoming pack, we need to fsck objects that cannot be
read via read_sha1_file() because they are not local yet (and might even
be rejected if transfer.fsckobjects is set to 'true').

For commits, there is a hack in place: we basically cache commit
objects' buffers anyway, but the same is not true, say, for tag objects.

By refactoring fsck_object() to take the object buffer and size as
optional arguments -- optional, because we still fall back to the
previous method to look at the cached commit objects if the caller
passes NULL -- we prepare the machinery for the upcoming handling of tag
objects.

The assumption that such buffers are inherently NUL terminated is now
wrong, of course, hence we pass the size of the buffer so that we can
add a sanity check later, to prevent running past the end of the buffer.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoRefactor type_from_string() to allow continuing after detecting an error
Johannes Schindelin [Wed, 10 Sep 2014 13:52:44 +0000 (15:52 +0200)] 
Refactor type_from_string() to allow continuing after detecting an error

In the next commits, we will enhance the fsck_tag() function to check
tag objects more thoroughly. To this end, we need a function to verify
that a given string is a valid object type, but that does not die() in
the negative case.

While at it, prepare type_from_string() for counted strings, i.e. strings
with an explicitly specified length rather than a NUL termination.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs: write packed_refs file using stdio
Jeff King [Wed, 10 Sep 2014 10:03:52 +0000 (06:03 -0400)] 
refs: write packed_refs file using stdio

We write each line of a new packed-refs file individually
using a write() syscall (and sometimes 2, if the ref is
peeled). Since each line is only about 50-100 bytes long,
this creates a lot of system call overhead.

We can instead open a stdio handle around our descriptor and
use fprintf to write to it. The extra buffering is not a
problem for us, because nobody will read our new packed-refs
file until we call commit_lock_file (by which point we have
flushed everything).

On a pathological repository with 8.5 million refs, this
dropped the time to run `git pack-refs` from 20s to 6s.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agofsck: exit with non-zero status upon error from fsck_obj()
Jeff King [Fri, 29 Aug 2014 20:31:46 +0000 (16:31 -0400)] 
fsck: exit with non-zero status upon error from fsck_obj()

Upon finding a corrupt loose object, we forgot to note the error to
signal it with the exit status of the entire process.

[jc: adjusted t1450 and added another test]

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoUpdate draft release notes to 2.2
Junio C Hamano [Tue, 9 Sep 2014 20:06:26 +0000 (13:06 -0700)] 
Update draft release notes to 2.2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoMerge branch 'sp/pack-protocol-doc-on-shallow'
Junio C Hamano [Tue, 9 Sep 2014 19:54:09 +0000 (12:54 -0700)] 
Merge branch 'sp/pack-protocol-doc-on-shallow'

* sp/pack-protocol-doc-on-shallow:
  Document LF appearing in shallow command during send-pack/receive-pack

10 years agoMerge branch 'tf/imap-send-create'
Junio C Hamano [Tue, 9 Sep 2014 19:54:08 +0000 (12:54 -0700)] 
Merge branch 'tf/imap-send-create'

* tf/imap-send-create:
  imap-send: create target mailbox if it is missing
  imap-send: clarify CRAM-MD5 vs LOGIN documentation

10 years agoMerge branch 'jk/prompt-stash-could-be-packed'
Junio C Hamano [Tue, 9 Sep 2014 19:54:08 +0000 (12:54 -0700)] 
Merge branch 'jk/prompt-stash-could-be-packed'

The prompt script checked $GIT_DIR/ref/stash file to see if there
is a stash, which was a no-no.

* jk/prompt-stash-could-be-packed:
  git-prompt: do not look for refs/stash in $GIT_DIR

10 years agoMerge branch 'tb/pretty-format-cd-date-format'
Junio C Hamano [Tue, 9 Sep 2014 19:54:07 +0000 (12:54 -0700)] 
Merge branch 'tb/pretty-format-cd-date-format'

Documentation update.

* tb/pretty-format-cd-date-format:
  pretty: note that %cd respects the --date= option

10 years agoMerge branch 'rs/inline-compat-path-macros'
Junio C Hamano [Tue, 9 Sep 2014 19:54:07 +0000 (12:54 -0700)] 
Merge branch 'rs/inline-compat-path-macros'

* rs/inline-compat-path-macros:
  turn path macros into inline function

10 years agoMerge branch 'rs/clean-menu-item-defn'
Junio C Hamano [Tue, 9 Sep 2014 19:54:06 +0000 (12:54 -0700)] 
Merge branch 'rs/clean-menu-item-defn'

* rs/clean-menu-item-defn:
  clean: use f(void) instead of f() to declare a pointer to a function without arguments

10 years agoMerge branch 'jc/config-mak-document-darwin-vs-macosx'
Junio C Hamano [Tue, 9 Sep 2014 19:54:05 +0000 (12:54 -0700)] 
Merge branch 'jc/config-mak-document-darwin-vs-macosx'

* jc/config-mak-document-darwin-vs-macosx:
  config.mak.uname: add hint on uname_R for MacOS X
  config.mak.uname: set NO_APPLE_COMMON_CRYPTO on older systems

10 years agoMerge branch 'sb/mailsplit-dead-code-removal'
Junio C Hamano [Tue, 9 Sep 2014 19:54:04 +0000 (12:54 -0700)] 
Merge branch 'sb/mailsplit-dead-code-removal'

* sb/mailsplit-dead-code-removal:
  mailsplit.c: remove dead code

10 years agoMerge branch 'so/rebase-doc'
Junio C Hamano [Tue, 9 Sep 2014 19:54:03 +0000 (12:54 -0700)] 
Merge branch 'so/rebase-doc'

May need further updates to the description to explain what makes
various modes of operation to decide that the request can become a
"no-op".

* so/rebase-doc:
  Documentation/git-rebase.txt: -f forces a rebase that would otherwise be a no-op

10 years agoMerge branch 'sb/prepare-revision-walk-error-check'
Junio C Hamano [Tue, 9 Sep 2014 19:54:03 +0000 (12:54 -0700)] 
Merge branch 'sb/prepare-revision-walk-error-check'

* sb/prepare-revision-walk-error-check:
  prepare_revision_walk(): check for return value in all places

10 years agoMerge branch 'sb/blame-msg-i18n'
Junio C Hamano [Tue, 9 Sep 2014 19:54:03 +0000 (12:54 -0700)] 
Merge branch 'sb/blame-msg-i18n'

* sb/blame-msg-i18n:
  builtin/blame.c: add translation to warning about failed revision walk

10 years agoMerge branch 'nd/strbuf-utf8-replace'
Junio C Hamano [Tue, 9 Sep 2014 19:54:02 +0000 (12:54 -0700)] 
Merge branch 'nd/strbuf-utf8-replace'

* nd/strbuf-utf8-replace:
  utf8.c: fix strbuf_utf8_replace() consuming data beyond input string

10 years agoMerge branch 'sb/plug-leaks'
Junio C Hamano [Tue, 9 Sep 2014 19:54:01 +0000 (12:54 -0700)] 
Merge branch 'sb/plug-leaks'

* sb/plug-leaks:
  clone.c: don't leak memory in cmd_clone
  remote.c: don't leak the base branch name in format_tracking_info

10 years agoMerge branch 'rs/refresh-beyond-symlink'
Junio C Hamano [Tue, 9 Sep 2014 19:54:01 +0000 (12:54 -0700)] 
Merge branch 'rs/refresh-beyond-symlink'

"git add x" where x that used to be a directory has become a
symbolic link to a directory misbehaved.

* rs/refresh-beyond-symlink:
  read-cache: check for leading symlinks when refreshing index

10 years agoMerge branch 'la/init-doc'
Junio C Hamano [Tue, 9 Sep 2014 19:54:00 +0000 (12:54 -0700)] 
Merge branch 'la/init-doc'

* la/init-doc:
  Documentation: git-init: flesh out example
  Documentation: git-init: template directory: reword and cross-reference
  Documentation: git-init: reword parenthetical statements
  Documentation: git-init: --separate-git-dir: clarify
  Documentation: git-init: template directory: reword
  Documentation: git-init: list items facelift
  Documentation: git-init: typographical fixes

10 years agoMerge branch 'jk/stash-list-p'
Junio C Hamano [Tue, 9 Sep 2014 19:54:00 +0000 (12:54 -0700)] 
Merge branch 'jk/stash-list-p'

Teach "git stash list -p" to show the difference between the base
commit version and the working tree version, which is in line with
what "git show" gives.

* jk/stash-list-p:
  stash: default listing to working-tree diff

10 years agoMerge branch 'mm/log-branch-desc-plug-leak'
Junio C Hamano [Tue, 9 Sep 2014 19:53:59 +0000 (12:53 -0700)] 
Merge branch 'mm/log-branch-desc-plug-leak'

* mm/log-branch-desc-plug-leak:
  builtin/log.c: fix minor memory leak

10 years agoMerge branch 'lf/bundle-exclusion'
Junio C Hamano [Tue, 9 Sep 2014 19:53:58 +0000 (12:53 -0700)] 
Merge branch 'lf/bundle-exclusion'

"git bundle create" with date-range specification were meant to
exclude tags outside the range

* lf/bundle-exclusion:
  bundle: fix exclusion of annotated tags

10 years agoMerge branch 'jc/apply-ws-prefix'
Junio C Hamano [Tue, 9 Sep 2014 19:53:58 +0000 (12:53 -0700)] 
Merge branch 'jc/apply-ws-prefix'

Applying a patch not generated by Git in a subdirectory used to
check the whitespace breakage using the attributes for incorrect
paths. Also whitespace checks were performed even for paths
excluded via "git apply --exclude=<path>" mechanism.

* jc/apply-ws-prefix:
  apply: omit ws check for excluded paths
  apply: hoist use_patch() helper for path exclusion up
  apply: use the right attribute for paths in non-Git patches

10 years agoMerge branch 'jk/command-line-config-empty-string'
Junio C Hamano [Tue, 9 Sep 2014 19:53:56 +0000 (12:53 -0700)] 
Merge branch 'jk/command-line-config-empty-string'

"git -c section.var command" and "git -c section.var= command"
should pass the configuration differently (the former should be
a boolean true, the latter should be an empty string).

* jk/command-line-config-empty-string:
  config: teach "git -c" to recognize an empty string

10 years agoMerge branch 'bc/imap-send-doc'
Junio C Hamano [Tue, 9 Sep 2014 19:53:55 +0000 (12:53 -0700)] 
Merge branch 'bc/imap-send-doc'

* bc/imap-send-doc:
  imap-send doc: omit confusing "to use imap-send" modifier

10 years agoMerge branch 'jc/not-mingw-cygwin'
Junio C Hamano [Tue, 9 Sep 2014 19:53:54 +0000 (12:53 -0700)] 
Merge branch 'jc/not-mingw-cygwin'

We have been using NOT_{MINGW,CYGWIN} test prerequisites long
before Peff invented support for negated prerequisites e.g. !MINGW
and we still add more uses of the former.  Convert them to the
latter to avoid confusion.

* jc/not-mingw-cygwin:
  test prerequisites: enumerate with commas
  test prerequisites: eradicate NOT_FOO

10 years agostrbuf: use strbuf_addchars() for adding a char multiple times
René Scharfe [Sun, 7 Sep 2014 07:06:42 +0000 (09:06 +0200)] 
strbuf: use strbuf_addchars() for adding a char multiple times

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agostrbuf: export strbuf_addchars()
René Scharfe [Sun, 7 Sep 2014 07:03:32 +0000 (09:03 +0200)] 
strbuf: export strbuf_addchars()

Move strbuf_addchars() to strbuf.c, where it belongs, and make it
available for other callers.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agotrace: correct trace_strbuf() parameter type for !HAVE_VARIADIC_MACROS
René Scharfe [Sat, 6 Sep 2014 20:53:03 +0000 (22:53 +0200)] 
trace: correct trace_strbuf() parameter type for !HAVE_VARIADIC_MACROS

Reported-by: dev <dev@cor0.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoparse-options: detect attempt to add a duplicate short option name
Junio C Hamano [Wed, 3 Sep 2014 19:42:37 +0000 (12:42 -0700)] 
parse-options: detect attempt to add a duplicate short option name

It is easy to overlook an already assigned single-letter option name
and try to use it for a new one.  Help the developer to catch it
before such a mistake escapes the lab.

This retroactively forbids any short option name (which is defined
to be of type "int") outside the ASCII printable range.  We might
want to do one of two things:

 - tighten the type of short_name member to 'char', and further
   update optbug() to protect it against doing "'%c'" on a funny
   value, e.g. negative or above 127.

 - drop the check (even the "duplicate" check) for an option whose
   short_name is either negative or above 255, to allow clever folks
   to take advantage of the fact that such a short_name cannot be
   parsed from the command line and the member can be used to store
   some extra information.

Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agomv: no SP between function name and the first opening parenthese
Nguyễn Thái Ngọc Duy [Sun, 10 Aug 2014 02:29:36 +0000 (09:29 +0700)] 
mv: no SP between function name and the first opening parenthese

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agomv: combine two if(s)
Nguyễn Thái Ngọc Duy [Sun, 10 Aug 2014 02:29:35 +0000 (09:29 +0700)] 
mv: combine two if(s)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agomv: unindent one level for directory move code
Nguyễn Thái Ngọc Duy [Sun, 10 Aug 2014 02:29:34 +0000 (09:29 +0700)] 
mv: unindent one level for directory move code

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agomv: move index search code out
Nguyễn Thái Ngọc Duy [Sun, 10 Aug 2014 02:29:33 +0000 (09:29 +0700)] 
mv: move index search code out

"Huh?" is removed from die() message.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agomv: remove an "if" that's always true
Nguyễn Thái Ngọc Duy [Sun, 10 Aug 2014 02:29:32 +0000 (09:29 +0700)] 
mv: remove an "if" that's always true

This is inside an "else" block of "if (last - first < 1)", so we know
that "last - first >= 1" when we come here. No need to check
"last - first > 0".

While at there, save "argc + last - first" to a variable to shorten
the statements a bit.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agomv: split submodule move preparation code out
Nguyễn Thái Ngọc Duy [Sun, 10 Aug 2014 02:29:31 +0000 (09:29 +0700)] 
mv: split submodule move preparation code out

"Huh?" is removed from die() message.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agocalloc() and xcalloc() takes nmemb and then size
Arjun Sreedharan [Sat, 30 Aug 2014 06:54:23 +0000 (12:24 +0530)] 
calloc() and xcalloc() takes nmemb and then size

There are a handful more instances of this in compat/regex/ but they
are borrowed code taht we do not want to touch with a change that
really affects correctness, which this change is not.

Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agocompletion: Add --ignore-blank-lines for diff
Thomas Braun [Wed, 3 Sep 2014 15:00:41 +0000 (17:00 +0200)] 
completion: Add --ignore-blank-lines for diff

Signed-off-by: Thomas Braun <thomas.braun@virtuell-zuhause.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoreachable.c: add HEAD to reachability starting commits
Max Kirillov [Wed, 3 Sep 2014 16:14:10 +0000 (19:14 +0300)] 
reachable.c: add HEAD to reachability starting commits

HEAD is not explicitly used as a starting commit for
calculating reachability, so if it's detached and reflogs
are disabled it may be pruned.

Add tests which demonstrate it. Test 'prune: prune former HEAD after checking
out branch' also reverts changes to repository.

Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agocache-tree: do not try to use an invalidated subtree info to build a tree
Junio C Hamano [Tue, 2 Sep 2014 21:16:20 +0000 (14:16 -0700)] 
cache-tree: do not try to use an invalidated subtree info to build a tree

We punt from repairing the cache-tree during a branch switching if
it involves having to create a new tree object that does not yet
exist in the object store.  "mkdir dir && >dir/file && git add dir"
followed by "git checkout" is one example, when a tree that records
the state of such "dir/" is not in the object store.

However, after discovering that we do not have a tree object that
records the state of "dir/", the caller failed to remember the fact
that it noticed the cache-tree entry it received for "dir/" is
invalidated, it already knows it should not be populating the level
that has "dir/" as its immediate subdirectory, and it is not an
error at all for the sublevel cache-tree entry gave it a bogus
object name it shouldn't even look at.

This led the caller to detect and report a non-existent error.  The
end result was the same and we avoided stuffing a non-existent tree
to the cache-tree, but we shouldn't have issued an alarming error
message to the user.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoupdate-ref --stdin: pass transaction around explicitly
Jonathan Nieder [Tue, 2 Sep 2014 21:11:21 +0000 (14:11 -0700)] 
update-ref --stdin: pass transaction around explicitly

This makes it more obvious at a glance where the output of functions
parsing the --stdin stream goes.

No functional change intended.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoupdate-ref --stdin: narrow scope of err strbuf
Jonathan Nieder [Tue, 2 Sep 2014 21:10:52 +0000 (14:10 -0700)] 
update-ref --stdin: narrow scope of err strbuf

Making the strbuf local in each function that needs to print errors
saves the reader from having to think about action at a distance,
such as

 * errors piling up and being concatenated with no newline between
   them
 * errors unhandled in one function, to be later handled in another
 * concurrency issues, if this code starts using threads some day

No functional change intended.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs.c: make delete_ref use a transaction
Ronnie Sahlberg [Wed, 30 Apr 2014 16:22:45 +0000 (09:22 -0700)] 
refs.c: make delete_ref use a transaction

Change delete_ref to use a ref transaction for the deletion. At the same time
since we no longer have any callers of repack_without_ref we can now delete
this function.

Change delete_ref to return 0 on success and 1 on failure instead of the
previous 0 on success either 1 or -1 on failure.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs.c: make prune_ref use a transaction to delete the ref
Ronnie Sahlberg [Wed, 30 Apr 2014 16:03:36 +0000 (09:03 -0700)] 
refs.c: make prune_ref use a transaction to delete the ref

Change prune_ref to delete the ref using a ref transaction. To do this we also
need to add a new flag REF_ISPRUNING that will tell the transaction that we
do not want to delete this ref from the packed refs. This flag is private to
refs.c and not exposed to external callers.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs.c: remove lock_ref_sha1
Ronnie Sahlberg [Tue, 29 Apr 2014 22:45:52 +0000 (15:45 -0700)] 
refs.c: remove lock_ref_sha1

lock_ref_sha1 was only called from one place in refs.c and only provided
a check that the refname was sane before adding back the initial "refs/"
part of the ref path name, the initial "refs/" that this caller had already
stripped off before calling lock_ref_sha1.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs.c: remove the update_ref_write function
Ronnie Sahlberg [Tue, 29 Apr 2014 20:42:07 +0000 (13:42 -0700)] 
refs.c: remove the update_ref_write function

Since we only call update_ref_write from a single place and we only call it
with onerr==QUIET_ON_ERR we can just as well get rid of it and just call
write_ref_sha1 directly. This changes the return status for _commit from
1 to -1 on failures when writing to the ref. Eventually we will want
_commit to start returning more detailed error conditions than the current
simple success/failure.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs.c: remove the update_ref_lock function
Ronnie Sahlberg [Tue, 29 Apr 2014 19:14:47 +0000 (12:14 -0700)] 
refs.c: remove the update_ref_lock function

Since we now only call update_ref_lock with onerr==QUIET_ON_ERR we no longer
need this function and can replace it with just calling lock_any_ref_for_update
directly.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs.c: make lock_ref_sha1 static
Ronnie Sahlberg [Mon, 28 Apr 2014 22:38:47 +0000 (15:38 -0700)] 
refs.c: make lock_ref_sha1 static

No external callers reference lock_ref_sha1 any more so let's declare it
static.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agowalker.c: use ref transaction for ref updates
Ronnie Sahlberg [Thu, 17 Apr 2014 18:31:06 +0000 (11:31 -0700)] 
walker.c: use ref transaction for ref updates

Switch to using ref transactions in walker_fetch(). As part of the refactoring
to use ref transactions we also fix a potential memory leak where in the
original code if write_ref_sha1() would fail we would end up returning from
the function without free()ing the msg string.

Note that this function is only called when fetching from a remote HTTP
repository onto the local (most of the time single-user) repository which
likely means that the type of collisions that the previous locking would
protect against and cause the fetch to fail for are even more rare.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agofast-import.c: use a ref transaction when dumping tags
Ronnie Sahlberg [Mon, 28 Apr 2014 22:23:58 +0000 (15:23 -0700)] 
fast-import.c: use a ref transaction when dumping tags

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agoreceive-pack.c: use a reference transaction for updating the refs
Ronnie Sahlberg [Mon, 28 Apr 2014 21:36:15 +0000 (14:36 -0700)] 
receive-pack.c: use a reference transaction for updating the refs

Wrap all the ref updates inside a transaction.

In the new API there is no distinction between failure to lock and
failure to write a ref.  Both can be permanent (e.g., a ref
"refs/heads/topic" is blocking creation of the lock file
"refs/heads/topic/1.lock") or transient (e.g., file system full) and
there's no clear difference in how the client should respond, so
replace the two statuses "failed to lock" and "failed to write" with
a single status "failed to update ref".  In both cases a more
detailed message is sent by sideband to diagnose the problem.

Example, before:

 error: there are still refs under 'refs/heads/topic'
 remote: error: failed to lock refs/heads/topic
 To foo
  ! [remote rejected] HEAD -> topic (failed to lock)

After:

 error: there are still refs under 'refs/heads/topic'
 remote: error: Cannot lock the ref 'refs/heads/topic'.
 To foo
  ! [remote rejected] HEAD -> topic (failed to update ref)

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agorefs.c: change update_ref to use a transaction
Ronnie Sahlberg [Thu, 24 Apr 2014 23:36:55 +0000 (16:36 -0700)] 
refs.c: change update_ref to use a transaction

Change the update_ref helper function to use a ref transaction internally.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agobranch.c: use ref transaction for all ref updates
Ronnie Sahlberg [Wed, 16 Apr 2014 23:21:53 +0000 (16:21 -0700)] 
branch.c: use ref transaction for all ref updates

Change create_branch to use a ref transaction when creating the new branch.

This also fixes a race condition in the old code where two concurrent
create_branch could race since the lock_any_ref_for_update/write_ref_sha1
did not protect against the ref already existing. I.e. one thread could end up
overwriting a branch even if the forcing flag is false.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agofast-import.c: change update_branch to use ref transactions
Ronnie Sahlberg [Wed, 16 Apr 2014 23:21:13 +0000 (16:21 -0700)] 
fast-import.c: change update_branch to use ref transactions

Change update_branch() to use ref transactions for updates.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agosequencer.c: use ref transactions for all ref updates
Ronnie Sahlberg [Wed, 16 Apr 2014 22:37:45 +0000 (15:37 -0700)] 
sequencer.c: use ref transactions for all ref updates

Change to use ref transactions for all updates to refs.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 years agocommit.c: use ref transactions for updates
Ronnie Sahlberg [Wed, 16 Apr 2014 22:34:19 +0000 (15:34 -0700)] 
commit.c: use ref transactions for updates

Change commit.c to use ref transactions for all ref updates.
Make sure we pass a NULL pointer to ref_transaction_update if have_old
is false.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>