Code

git.git
12 years agoMerge branch 'nd/daemon-log-sock-errors'
Junio C Hamano [Fri, 14 Oct 2011 02:03:21 +0000 (19:03 -0700)]
Merge branch 'nd/daemon-log-sock-errors'

* nd/daemon-log-sock-errors:
  daemon: log errors if we could not use some sockets

12 years agoMerge branch 'cp/git-web-browse-browsers'
Junio C Hamano [Fri, 14 Oct 2011 02:03:20 +0000 (19:03 -0700)]
Merge branch 'cp/git-web-browse-browsers'

* cp/git-web-browse-browsers:
  git-web--browse: avoid the use of eval

12 years agoMerge branch 'jc/apply-blank-at-eof-fix'
Junio C Hamano [Fri, 14 Oct 2011 02:03:20 +0000 (19:03 -0700)]
Merge branch 'jc/apply-blank-at-eof-fix'

* jc/apply-blank-at-eof-fix:
  apply --whitespace=error: correctly report new blank lines at end

12 years agoMerge branch 'di/fast-import-empty-tag-note-fix'
Junio C Hamano [Fri, 14 Oct 2011 02:03:19 +0000 (19:03 -0700)]
Merge branch 'di/fast-import-empty-tag-note-fix'

* di/fast-import-empty-tag-note-fix:
  fast-import: don't allow to note on empty branch
  fast-import: don't allow to tag empty branch

12 years agoMerge branch 'nd/maint-autofix-tag-in-head'
Junio C Hamano [Fri, 14 Oct 2011 02:03:19 +0000 (19:03 -0700)]
Merge branch 'nd/maint-autofix-tag-in-head'

* nd/maint-autofix-tag-in-head:
  Accept tags in HEAD or MERGE_HEAD
  merge: remove global variable head[]
  merge: use return value of resolve_ref() to determine if HEAD is invalid
  merge: keep stash[] a local variable

Conflicts:
builtin/merge.c

12 years agoMerge branch 'bw/grep-no-index-no-exclude'
Junio C Hamano [Fri, 14 Oct 2011 02:03:18 +0000 (19:03 -0700)]
Merge branch 'bw/grep-no-index-no-exclude'

* bw/grep-no-index-no-exclude:
  grep --no-index: don't use git standard exclusions
  grep: do not use --index in the short usage output

12 years agoMerge branch 'nd/maint-sparse-errors'
Junio C Hamano [Fri, 14 Oct 2011 02:03:18 +0000 (19:03 -0700)]
Merge branch 'nd/maint-sparse-errors'

* nd/maint-sparse-errors:
  Add explanation why we do not allow to sparse checkout to empty working tree
  sparse checkout: show error messages when worktree shaping fails

12 years agot1402-check-ref-format: skip tests of refs beginning with slash on Windows
Johannes Sixt [Thu, 13 Oct 2011 08:06:20 +0000 (10:06 +0200)]
t1402-check-ref-format: skip tests of refs beginning with slash on Windows

Bash on Windows converts program arguments that look like absolute POSIX
paths to their Windows form, i.e., drive-letter-colon format. For this
reason, those tests in t1402 that check refs that begin with a slash do not
work as expected on Windows: valid_ref tests are doomed to fail, and
invalid_ref tests fail for the wrong reason (that there is a colon rather
than that they begin with a slash).

Skip these tests.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agobundle: add parse_bundle_header() helper function
Junio C Hamano [Thu, 13 Oct 2011 22:19:31 +0000 (15:19 -0700)]
bundle: add parse_bundle_header() helper function

Move most of the code from read_bundle_header() to parse_bundle_header()
that takes a file descriptor that is already opened for reading, and make
the former responsible only for opening the file and noticing errors.

As a logical consequence of this, is_bundle() helper function can be
implemented as a non-complaining variant of read_bundle_header() that
does not return an open file descriptor, and can be used to tighten
the check used to decide the use of bundle transport in transport_get()
function.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agobundle: allowing to read from an unseekable fd
Junio C Hamano [Thu, 13 Oct 2011 22:12:02 +0000 (15:12 -0700)]
bundle: allowing to read from an unseekable fd

We wished that "git bundle" to eventually learn to read from a network
socket which is not seekable. The current code opens with fopen(), reads
the file halfway and run ftell(), and reopens the same file with open()
and seeks, to skip the header.

This patch by itself does not reach that goal yet, but I think it is a
right step in that direction.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopull,rebase: handle GIT_WORK_TREE better
Jeff King [Thu, 13 Oct 2011 15:59:24 +0000 (11:59 -0400)]
pull,rebase: handle GIT_WORK_TREE better

You can't currently run git-pull or git-rebase from outside
of the work tree, even with GIT_WORK_TREE set, due to an
overeager require_work_tree function. Commit e2eb527
documents this problem and provides the infrastructure for a
fix, but left it to later commits to audit and update
individual scripts.

Changing these scripts to use require_work_tree_exists is
easy to verify. We immediately call cd_to_toplevel, anyway.
Therefore no matter which function we use, the state
afterwards is one of:

  1. We have a work tree, and we are at the top level.

  2. We don't have a work tree, and we have died.

The only catch is that we must also make sure no code that
ran before the cd_to_toplevel assumed that we were already
in the working tree.

In this case, we will only have included shell libraries and
called set_reflog_action, neither of which care about the
current working directory at all.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agosubmodule: Search for merges only at end of recursive merge
Brad King [Thu, 13 Oct 2011 12:59:05 +0000 (08:59 -0400)]
submodule: Search for merges only at end of recursive merge

The submodule merge search is not useful during virtual merges because
the results cannot be used automatically.  Furthermore any suggestions
made by the search may apply to commits different than HEAD:sub and
MERGE_HEAD:sub, thus confusing the user.  Skip searching for submodule
merges during a virtual merge such as that between B and C while merging
the heads of:

    B---BC
   / \ /
  A   X
   \ / \
    C---CB

Run the search only when the recursion level is zero (!o->call_depth).
This fixes known breakage tested in t7405-submodule-merge.

Signed-off-by: Brad King <brad.king@kitware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agosubmodule: Demonstrate known breakage during recursive merge
Brad King [Thu, 13 Oct 2011 12:59:04 +0000 (08:59 -0400)]
submodule: Demonstrate known breakage during recursive merge

Since commit 68d03e4a (Implement automatic fast-forward merge for
submodules, 2010-07-07) we try to suggest submodule commits that resolve
a conflict.  Consider a true recursive merge case

    b---bc
   / \ /
  o   X
   \ / \
    c---cb

in which the two heads themselves (bc,cb) had resolved a submodule
conflict (i.e. reference different commits than their parents).  The
submodule merge search runs during the temporary merge of the two merge
bases (b,c) and prints out a suggestion that is not meaningful to the
user.  Then during the main merge the submodule merge search runs again
but dies with the message

  fatal: --ancestry-path given but there are no bottom commits

while trying to enumerate candidates.  Demonstrate this known breakage
with a new test in t7405-submodule-merge covering the case.

Signed-off-by: Brad King <brad.king@kitware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoTeach merge the '[-e|--edit]' option
Jay Soffian [Sat, 8 Oct 2011 18:39:52 +0000 (14:39 -0400)]
Teach merge the '[-e|--edit]' option

Implemented internally instead of as "git merge --no-commit && git commit"
so that "merge --edit" is otherwise consistent (hooks, etc) with "merge".

Note: the edit message does not include the status information that one
gets with "commit --status" and it is cleaned up after editing like one
gets with "commit --cleanup=default". A later patch could add the status
information if desired.

Note: previously we were not calling stripspace() after running the
prepare-commit-msg hook. Now we are, stripping comments and
leading/trailing whitespace lines if --edit is given, otherwise only
stripping leading/trailing whitespace lines if not given --edit.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoUpdate draft release notes to 1.7.8
Junio C Hamano [Wed, 12 Oct 2011 19:42:44 +0000 (12:42 -0700)]
Update draft release notes to 1.7.8

Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoMerge branch 'cb/do-not-pretend-to-hijack-long-help'
Junio C Hamano [Wed, 12 Oct 2011 19:34:30 +0000 (12:34 -0700)]
Merge branch 'cb/do-not-pretend-to-hijack-long-help'

* cb/do-not-pretend-to-hijack-long-help:
  use -h for synopsis and --help for manpage consistently

12 years agoMerge branch 'sp/smart-http-failure'
Junio C Hamano [Wed, 12 Oct 2011 19:34:27 +0000 (12:34 -0700)]
Merge branch 'sp/smart-http-failure'

* sp/smart-http-failure:
  remote-curl: Fix warning after HTTP failure

12 years agoMerge branch 'nd/document-err-packet'
Junio C Hamano [Wed, 12 Oct 2011 19:34:18 +0000 (12:34 -0700)]
Merge branch 'nd/document-err-packet'

* nd/document-err-packet:
  pack-protocol: document "ERR" line

12 years agoMerge branch 'jc/parse-options-boolean'
Junio C Hamano [Wed, 12 Oct 2011 19:34:15 +0000 (12:34 -0700)]
Merge branch 'jc/parse-options-boolean'

* jc/parse-options-boolean:
  apply: use OPT_NOOP_NOARG
  revert: use OPT_NOOP_NOARG
  parseopt: add OPT_NOOP_NOARG
  archive.c: use OPT_BOOL()
  parse-options: deprecate OPT_BOOLEAN

Conflicts:
builtin/revert.c

12 years agoMerge branch 'rs/test-ctype'
Junio C Hamano [Wed, 12 Oct 2011 19:34:11 +0000 (12:34 -0700)]
Merge branch 'rs/test-ctype'

* rs/test-ctype:
  test-ctype: add test for is_pathspec_magic
  test-ctype: macrofy

12 years agoMerge branch 'rs/name-rev-usage'
Junio C Hamano [Wed, 12 Oct 2011 19:34:08 +0000 (12:34 -0700)]
Merge branch 'rs/name-rev-usage'

* rs/name-rev-usage:
  name-rev: split usage string

12 years agoMerge branch 'cs/perl-config-path-send-email'
Junio C Hamano [Wed, 12 Oct 2011 19:34:05 +0000 (12:34 -0700)]
Merge branch 'cs/perl-config-path-send-email'

* cs/perl-config-path-send-email:
  use new Git::config_path() for aliasesfile
  Add Git::config_path()

12 years agoMerge branch 'zj/send-email-authen-sasl'
Junio C Hamano [Wed, 12 Oct 2011 19:34:03 +0000 (12:34 -0700)]
Merge branch 'zj/send-email-authen-sasl'

* zj/send-email-authen-sasl:
  send-email: auth plain/login fix

12 years agot5403: convert leading spaces to tabs
Nguyễn Thái Ngọc Duy [Wed, 12 Oct 2011 09:35:04 +0000 (20:35 +1100)]
t5403: convert leading spaces to tabs

The first and last tests use tabs. The rest uses spaces. Convert all
to tabs.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agofix "git apply --index ..." not to deref NULL
Jim Meyering [Wed, 12 Oct 2011 14:33:54 +0000 (16:33 +0200)]
fix "git apply --index ..." not to deref NULL

I noticed this when "git am CORRUPTED" unexpectedly failed with an
odd diagnostic, and even removed one of the files it was supposed
to have patched.

Reproduce with any valid old/new patch from which you have removed
the "+++ b/FILE" line.  You'll see a diagnostic like this

    fatal: unable to write file '(null)' mode 100644: Bad address

and you'll find that FILE has been removed.

The above is on glibc-based systems.  On other systems, rather than
getting "null", you may provoke a segfault as git tries to
dereference the NULL file name.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agot1300: test mixed-case variable retrieval
Jeff King [Wed, 12 Oct 2011 18:30:02 +0000 (14:30 -0400)]
t1300: test mixed-case variable retrieval

We should be able to ask for a config value both by its
canonical all-lowercase name (as git does internally), as
well as by random mixed-case (which will be canonicalized by
git-config for us).

Subsections are a tricky point, though. Since we have both

  [section "Foo"]

and

  [section.Foo]

you might want git-config to canonicalize the subsection or
not, depending on which you are expecting. But there's no
way to communicate this; git-config sees only the key, and
doesn't know which type of section name will be in the
config file.

So it must leave the subsection intact, and it is up to the
caller to provide a canonical version of the subsection if
they want to match the latter form.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agot1300: put git invocations inside test function
Jeff King [Wed, 12 Oct 2011 18:29:20 +0000 (14:29 -0400)]
t1300: put git invocations inside test function

This is a very old script, and did a lot of:

  echo whatever >expect
  git config foo bar
  test_expect_success 'cmp .git/config expect'

which meant that we didn't actually check that the call to
git-config succeeded. Fix this, and while we're at it,
modernize the style to use test_cmp.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoFix is_gitfile() for files too small or larger than PATH_MAX to be a gitfile
Johannes Schindelin [Tue, 11 Oct 2011 19:25:32 +0000 (14:25 -0500)]
Fix is_gitfile() for files too small or larger than PATH_MAX to be a gitfile

The logic to check whether a file is a gitfile used the heuristics that
a gitfile cannot be larger than PATH_MAX or smaller than 10 bytes (as
its contents is "gitdir: " followed by a path) and returned early.

But it returned with a wrong value. It should have said "this cannot
possibly be a gitfile" by returning 0, but it returned 1 instead.  Our
test cases do not cover this, as the bundle files produced are smaller
than PATH_MAX, except on Windows.

While at it, fix the faulty logic that the path stored in a gitfile cannot
be larger than PATH_MAX-sizeof("gitdir: ").

Problem identified by running the test suite in msysGit, offending commit
identified by Jörg Rosenkranz.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoattr.c: respect core.ignorecase when matching attribute patterns
Brandon Casey [Tue, 11 Oct 2011 15:53:31 +0000 (10:53 -0500)]
attr.c: respect core.ignorecase when matching attribute patterns

When core.ignorecase is true, the file globs configured in the
.gitattributes file should be matched case-insensitively against the paths
in the working directory.  Let's do so.

Plus, add some tests.

The last set of tests is performed only on a case-insensitive filesystem.
Those tests make sure that git handles the case where the .gitignore file
resides in a subdirectory and the user supplies a path that does not match
the case in the filesystem.  In that case^H^H^H^Hsituation, part of the
path supplied by the user is effectively interpreted case-insensitively,
and part of it is dependent on the setting of core.ignorecase.  git will
currently only match the portion of the path below the directory holding
the .gitignore file according to the setting of core.ignorecase.

This is also partly future-proofing.  Currently, git builds the attr stack
based on the path supplied by the user, so we don't have to do anything
special (like use strcmp_icase) to handle the parts of that path that don't
match the filesystem with respect to case.  If git instead built the attr
stack by scanning the repository, then the paths in the origin field would
not necessarily match the paths supplied by the user.  If someone makes a
change like that in the future, these tests will notice.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoUpdate draft release notes to 1.7.8
Junio C Hamano [Mon, 10 Oct 2011 23:14:59 +0000 (16:14 -0700)]
Update draft release notes to 1.7.8

Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoMerge branch 'dm/tree-walk'
Junio C Hamano [Mon, 10 Oct 2011 22:56:20 +0000 (15:56 -0700)]
Merge branch 'dm/tree-walk'

* dm/tree-walk:
  tree-walk: micro-optimization in tree_entry_interesting
  tree-walk: drop unused parameter from match_dir_prefix

12 years agoMerge branch 'ps/gitweb-js-with-lineno'
Junio C Hamano [Mon, 10 Oct 2011 22:56:20 +0000 (15:56 -0700)]
Merge branch 'ps/gitweb-js-with-lineno'

* ps/gitweb-js-with-lineno:
  gitweb: Fix links to lines in blobs when javascript-actions are enabled

12 years agoMerge branch 'mh/maint-notes-merge-pathbuf-fix'
Junio C Hamano [Mon, 10 Oct 2011 22:56:20 +0000 (15:56 -0700)]
Merge branch 'mh/maint-notes-merge-pathbuf-fix'

* mh/maint-notes-merge-pathbuf-fix:
  notes_merge_commit(): do not pass temporary buffer to other function

12 years agoMerge branch 'nd/sparse-doc'
Junio C Hamano [Mon, 10 Oct 2011 22:56:20 +0000 (15:56 -0700)]
Merge branch 'nd/sparse-doc'

* nd/sparse-doc:
  git-read-tree.txt: update sparse checkout examples

12 years agoMerge branch 'jp/get-ref-dir-unsorted'
Junio C Hamano [Mon, 10 Oct 2011 22:56:19 +0000 (15:56 -0700)]
Merge branch 'jp/get-ref-dir-unsorted'

* jp/get-ref-dir-unsorted:
  refs.c: free duplicate entries in the ref array instead of leaking them
  refs.c: abort ref search if ref array is empty
  refs.c: ensure struct whose member may be passed to realloc is initialized
  refs: Use binary search to lookup refs faster
  Don't sort ref_list too early

Conflicts:
refs.c

12 years agoMerge branch 'mh/check-ref-format-3'
Junio C Hamano [Mon, 10 Oct 2011 22:56:18 +0000 (15:56 -0700)]
Merge branch 'mh/check-ref-format-3'

* mh/check-ref-format-3: (23 commits)
  add_ref(): verify that the refname is formatted correctly
  resolve_ref(): expand documentation
  resolve_ref(): also treat a too-long SHA1 as invalid
  resolve_ref(): emit warnings for improperly-formatted references
  resolve_ref(): verify that the input refname has the right format
  remote: avoid passing NULL to read_ref()
  remote: use xstrdup() instead of strdup()
  resolve_ref(): do not follow incorrectly-formatted symbolic refs
  resolve_ref(): extract a function get_packed_ref()
  resolve_ref(): turn buffer into a proper string as soon as possible
  resolve_ref(): only follow a symlink that contains a valid, normalized refname
  resolve_ref(): use prefixcmp()
  resolve_ref(): explicitly fail if a symlink is not readable
  Change check_refname_format() to reject unnormalized refnames
  Inline function refname_format_print()
  Make collapse_slashes() allocate memory for its result
  Do not allow ".lock" at the end of any refname component
  Refactor check_refname_format()
  Change check_ref_format() to take a flags argument
  Change bad_ref_char() to return a boolean value
  ...

12 years agoMerge branch 'mh/iterate-refs'
Junio C Hamano [Mon, 10 Oct 2011 22:56:18 +0000 (15:56 -0700)]
Merge branch 'mh/iterate-refs'

* mh/iterate-refs:
  refs.c: make create_cached_refs() static
  Retain caches of submodule refs
  Store the submodule name in struct cached_refs
  Allocate cached_refs objects dynamically
  Change the signature of read_packed_refs()
  Access reference caches only through new function get_cached_refs()
  Extract a function clear_cached_refs()

12 years agoMerge branch 'jm/mergetool-pathspec'
Junio C Hamano [Mon, 10 Oct 2011 22:56:18 +0000 (15:56 -0700)]
Merge branch 'jm/mergetool-pathspec'

* jm/mergetool-pathspec:
  mergetool: no longer need to save standard input
  mergetool: Use args as pathspec to unmerged files

12 years agoMerge branch 'jc/maint-diffstat-numstat-context'
Junio C Hamano [Mon, 10 Oct 2011 22:56:18 +0000 (15:56 -0700)]
Merge branch 'jc/maint-diffstat-numstat-context'

* jc/maint-diffstat-numstat-context:
  diff: teach --stat/--numstat to honor -U$num

12 years agoMerge branch 'mz/remote-rename'
Junio C Hamano [Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)]
Merge branch 'mz/remote-rename'

* mz/remote-rename:
  remote: only update remote-tracking branch if updating refspec
  remote rename: warn when refspec was not updated
  remote: "rename o foo" should not rename ref "origin/bar"
  remote: write correct fetch spec when renaming remote 'remote'

12 years agoMerge branch 'cb/common-prefix-unification'
Junio C Hamano [Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)]
Merge branch 'cb/common-prefix-unification'

* cb/common-prefix-unification:
  rename pathspec_prefix() to common_prefix() and move to dir.[ch]
  consolidate pathspec_prefix and common_prefix
  remove prefix argument from pathspec_prefix

12 years agoMerge branch 'jn/maint-http-error-message'
Junio C Hamano [Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)]
Merge branch 'jn/maint-http-error-message'

* jn/maint-http-error-message:
  http: avoid empty error messages for some curl errors
  http: remove extra newline in error message

12 years agoMerge branch 'hv/submodule-update-none'
Junio C Hamano [Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)]
Merge branch 'hv/submodule-update-none'

* hv/submodule-update-none:
  add update 'none' flag to disable update of submodule by default
  submodule: move update configuration variable further up

12 years agoMerge branch 'fg/submodule-git-file-git-dir'
Junio C Hamano [Mon, 10 Oct 2011 22:56:16 +0000 (15:56 -0700)]
Merge branch 'fg/submodule-git-file-git-dir'

* fg/submodule-git-file-git-dir:
  Move git-dir for submodules
  rev-parse: add option --resolve-git-dir <path>

Conflicts:
cache.h
git-submodule.sh

12 years agoconfig: display key_delim for config --bool --get-regexp
Matthieu Moy [Mon, 10 Oct 2011 12:54:51 +0000 (14:54 +0200)]
config: display key_delim for config --bool --get-regexp

The previous logic in show_config was to print the delimiter when the
value was set, but Boolean variables have an implicit value "true" when
they appear with no value in the config file. As a result, we got:

git_Config        --get-regexp '.*\.Boolean' #1. Ok: example.boolean
git_Config --bool --get-regexp '.*\.Boolean' #2. NO: example.booleantrue

Fix this by defering the display of the separator until after the value
to display has been computed.

Reported-by: Brian Foster <brian.foster@maxim-ic.com>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agodiff: add option to show whole functions as context
René Scharfe [Sun, 9 Oct 2011 11:36:57 +0000 (13:36 +0200)]
diff: add option to show whole functions as context

Add the option -W/--function-context to git diff.  It is similar to
the same option of git grep and expands the context of change hunks
so that the whole surrounding function is shown.  This "natural"
context can allow changes to be understood better.

Note: GNU patch doesn't like diffs generated with the new option;
it seems to expect context lines to be the same before and after
changes.  git apply doesn't complain.

This implementation has the same shortcoming as the one in grep,
namely that there is no way to explicitly find the end of a
function.  That means that a few lines of extra context are shown,
right up to the next recognized function begins.  It's already
useful in its current form, though.

The function get_func_line() in xdiff/xemit.c is extended to work
forward as well as backward to find post-context as well as
pre-context.  It returns the position of the first found matching
line.  The func_line parameter is made optional, as we don't need
it for -W.

The enhanced function is then used in xdl_emit_diff() to extend
the context as needed.  If the added context overlaps with the
next change, it is merged into the current hunk.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoxdiff: factor out get_func_line()
René Scharfe [Sun, 9 Oct 2011 11:34:49 +0000 (13:34 +0200)]
xdiff: factor out get_func_line()

Move the code to search for a function line to be shown in the hunk
header into its own function and to make returning the length-limited
result string easier, introduce struct func_line.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agorefs.c: free duplicate entries in the ref array instead of leaking them
Brandon Casey [Sat, 8 Oct 2011 03:20:22 +0000 (22:20 -0500)]
refs.c: free duplicate entries in the ref array instead of leaking them

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agorefs.c: abort ref search if ref array is empty
Brandon Casey [Sat, 8 Oct 2011 03:20:21 +0000 (22:20 -0500)]
refs.c: abort ref search if ref array is empty

The bsearch() implementation on IRIX 6.5 segfaults if it is passed NULL
for the base array argument even if number-of-elements is zero.  So, let's
work around it by detecting an empty array and aborting early.

This is a useful optimization in its own right anyway, since we avoid a
useless allocation and initialization of the ref_entry when the ref array
is empty.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agorefs.c: ensure struct whose member may be passed to realloc is initialized
Brandon Casey [Sat, 8 Oct 2011 03:20:20 +0000 (22:20 -0500)]
refs.c: ensure struct whose member may be passed to realloc is initialized

The variable "refs" is allocated on the stack but is not initialized.  It
is passed to read_packed_refs(), and its struct members may eventually be
passed to add_ref() and ALLOC_GROW().  Since the structure has not been
initialized, its members may contain random non-zero values.  So let's
initialize it.

The call sequence looks something like this:

   resolve_gitlink_packed_ref(...) {

       struct cached_refs refs;
       ...
       read_packed_refs(f, &refs);
       ...
   }

   read_packed_refs(FILE*, struct cached_refs *cached_refs) {
       ...
       add_ref(name, sha1, flag, &cached_refs->packed, &last);
       ...
   }

   add_ref(..., struct ref_array *refs, struct ref_entry **) {
       ...
       ALLOC_GROW(refs->refs, refs->nr + 1, refs->alloc);
   }

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agocompletion: unite --format and --pretty for 'log' and 'show'
SZEDER Gábor [Sat, 8 Oct 2011 01:09:34 +0000 (03:09 +0200)]
completion: unite --format and --pretty for 'log' and 'show'

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agocompletion: unite --reuse-message and --reedit-message for 'notes'
SZEDER Gábor [Sat, 8 Oct 2011 01:06:34 +0000 (03:06 +0200)]
completion: unite --reuse-message and --reedit-message for 'notes'

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoFix some "variable might be used uninitialized" warnings
Ramsay Jones [Sun, 11 Sep 2011 19:39:32 +0000 (20:39 +0100)]
Fix some "variable might be used uninitialized" warnings

In particular, gcc complains as follows:

        CC tree-walk.o
    tree-walk.c: In function `traverse_trees':
    tree-walk.c:347: warning: 'e' might be used uninitialized in this \
        function

        CC builtin/revert.o
    builtin/revert.c: In function `verify_opt_mutually_compatible':
    builtin/revert.c:113: warning: 'opt2' might be used uninitialized in \
        this function

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoMakefile: fix permissions of mergetools/ checked out with permissive umask
Junio C Hamano [Sun, 9 Oct 2011 19:59:44 +0000 (12:59 -0700)]
Makefile: fix permissions of mergetools/ checked out with permissive umask

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoMakefile: fix permissions of mergetools/ checked out with permissive umask
Jonathan Nieder [Sun, 9 Oct 2011 09:17:07 +0000 (04:17 -0500)]
Makefile: fix permissions of mergetools/ checked out with permissive umask

Ever since mergetool--lib was split into multiple files in
v1.7.7-rc0~3^2~1 (2011-08-18), the Makefile takes care to reset umask
and use tar --no-owner when installing merge tool definitions to
$(gitexecdir)/mergetools/.  Unfortunately it does not take into
account the possibility that the permission bits of the files being
copied might already be wrong.

Rather than fixing the "tar" incantation and making it even more
complicated, let's just use the "install" utility.  This only means
losing the ability to install executables and subdirectories of
mergetools/, which wasn't used.

Noticed by installing from a copy of git checked out with umask 002.
Compare v1.6.0.3~81^2 (Fix permission bits on sources checked out with
an overtight umask, 2008-08-21).

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agofix phantom untracked files when core.ignorecase is set
Jeff King [Thu, 6 Oct 2011 16:06:09 +0000 (12:06 -0400)]
fix phantom untracked files when core.ignorecase is set

When core.ignorecase is turned on and there are stale index
entries, "git commit" can sometimes report directories as
untracked, even though they contain tracked files.

You can see an example of this with:

    # make a case-insensitive repo
    git init repo && cd repo &&
    git config core.ignorecase true &&

    # with some tracked files in a subdir
    mkdir subdir &&
    > subdir/one &&
    > subdir/two &&
    git add . &&
    git commit -m base &&

    # now make the index entries stale
    touch subdir/* &&

    # and then ask commit to update those entries and show
    # us the status template
    git commit -a

which will report "subdir/"  as untracked, even though it
clearly contains two tracked files. What is happening in the
commit program is this:

  1. We load the index, and for each entry, insert it into the index's
     name_hash. In addition, if ignorecase is turned on, we make an
     entry in the name_hash for the directory (e.g., "contrib/"), which
     uses the following code from 5102c61's hash_index_entry_directories:

        hash = hash_name(ce->name, ptr - ce->name);
        if (!lookup_hash(hash, &istate->name_hash)) {
                pos = insert_hash(hash, &istate->name_hash);
if (pos) {
ce->next = *pos;
*pos = ce;
}
        }

     Note that we only add the directory entry if there is not already an
     entry.

  2. We run add_files_to_cache, which gets updated information for each
     cache entry. It helpfully inserts this information into the cache,
     which calls replace_index_entry. This in turn calls
     remove_name_hash() on the old entry, and add_name_hash() on the new
     one. But remove_name_hash doesn't actually remove from the hash, it
     only marks it as "no longer interesting" (from cache.h):

      /*
       * We don't actually *remove* it, we can just mark it invalid so that
       * we won't find it in lookups.
       *
       * Not only would we have to search the lists (simple enough), but
       * we'd also have to rehash other hash buckets in case this makes the
       * hash bucket empty (common). So it's much better to just mark
       * it.
       */
      static inline void remove_name_hash(struct cache_entry *ce)
      {
              ce->ce_flags |= CE_UNHASHED;
      }

     This is OK in the specific-file case, since the entries in the hash
     form a linked list, and we can just skip the "not here anymore"
     entries during lookup.

     But for the directory hash entry, we will _not_ write a new entry,
     because there is already one there: the old one that is actually no
     longer interesting!

  3. While traversing the directories, we end up in the
     directory_exists_in_index_icase function to see if a directory is
     interesting. This in turn checks index_name_exists, which will
     look up the directory in the index's name_hash. We see the old,
     deleted record, and assume there is nothing interesting. The
     directory gets marked as untracked, even though there are index
     entries in it.

The problem is in the code I showed above:

        hash = hash_name(ce->name, ptr - ce->name);
        if (!lookup_hash(hash, &istate->name_hash)) {
                pos = insert_hash(hash, &istate->name_hash);
if (pos) {
ce->next = *pos;
*pos = ce;
}
        }

Having a single cache entry that represents the directory is
not enough; that entry may go away if the index is changed.
It may be tempting to say that the problem is in our removal
method; if we removed the entry entirely instead of simply
marking it as "not here anymore", then we would know we need
to insert a new entry. But that only covers this particular
case of remove-replace. In the more general case, consider
something like this:

  1. We add "foo/bar" and "foo/baz" to the index. Each gets
     their own entry in name_hash, plus we make a "foo/"
     entry that points to "foo/bar".

  2. We remove the "foo/bar" entry from the index, and from
     the name_hash.

  3. We ask if "foo/" exists, and see no entry, even though
     "foo/baz" exists.

So we need that directory entry to have the list of _all_
cache entries that indicate that the directory is tracked.
So that implies making a linked list as we do for other
entries, like:

  hash = hash_name(ce->name, ptr - ce->name);
  pos = insert_hash(hash, &istate->name_hash);
  if (pos) {
  ce->next = *pos;
  *pos = ce;
  }

But that's not right either. In fact, it shows a second bug
in the current code, which is that the "ce->next" pointer is
supposed to be linking entries for a specific filename
entry, but here we are overwriting it for the directory
entry. So the same cache entry ends up in two linked lists,
but they share the same "next" pointer.

As it turns out, this second bug can't be triggered in the
current code. The "if (pos)" conditional is totally dead
code; pos will only be non-NULL if there was an existing
hash entry, and we already checked that there wasn't one
through our call to lookup_hash.

But fixing the first bug means taking out that call to
lookup_hash, which is going to activate the buggy dead code,
and we'll end up splicing the two linked lists together.

So we need to have a separate next pointer for the list in
the directory bucket, and we need to traverse that list in
index_name_exists when we are looking up a directory.

This bloats "struct cache_entry" by a few bytes. Which is
annoying, because it's only necessary when core.ignorecase
is enabled. There's not an easy way around it, short of
separating out the "next" pointers from cache_entry entirely
(i.e., having a separate "cache_entry_list" struct that gets
stored in the name_hash). In practice, it probably doesn't
matter; we have thousands of cache entries, compared to the
millions of objects (where adding 4 bytes to the struct
actually does impact performance).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agofetch: plug two leaks on error exit in store_updated_refs
Tay Ray Chuan [Fri, 7 Oct 2011 07:40:22 +0000 (15:40 +0800)]
fetch: plug two leaks on error exit in store_updated_refs

Close FETCH_HEAD and release the string url even if we have to leave the
function store_updated_refs() early.

Reported-by: Chris Wilson <cwilson@vigilantsw.com>
Helped-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agomingw: avoid using strbuf in syslog
Erik Faye-Lund [Thu, 6 Oct 2011 17:52:48 +0000 (19:52 +0200)]
mingw: avoid using strbuf in syslog

strbuf can call die, which again can call syslog from git-daemon.

Endless recursion is no fun; fix it by hand-rolling the logic. As
a side-effect malloc/realloc errors are changed into non-fatal
warnings; this is probably an improvement anyway.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Noticed-by: Johannes Sixt <j.sixt@viscovery.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopickaxe: factor out pickaxe
René Scharfe [Thu, 6 Oct 2011 16:50:28 +0000 (18:50 +0200)]
pickaxe: factor out pickaxe

Move the duplicate diff queue loop into its own function that accepts
a match function: has_changes() for -S and diff_grep() for -G.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopickaxe: give diff_grep the same signature as has_changes
René Scharfe [Thu, 6 Oct 2011 16:50:18 +0000 (18:50 +0200)]
pickaxe: give diff_grep the same signature as has_changes

Change diff_grep() to match the signature of has_changes() as a
preparation for the next patch that will use function pointers to
the two.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopickaxe: pass diff_options to contains and has_changes
René Scharfe [Thu, 6 Oct 2011 16:50:06 +0000 (18:50 +0200)]
pickaxe: pass diff_options to contains and has_changes

Remove the unused parameter needle from contains() and has_changes().

Also replace the parameter len with a pointer to the diff_options.  We
can use its member pickaxe to check if the needle is an empty string
and use the kwsmatch structure to find out the length of the match
instead.

This change is done as a preparation to unify the signatures of
has_changes() and diff_grep(), which will be used in the patch after
the next one to factor out common code.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopickaxe: factor out has_changes
René Scharfe [Thu, 6 Oct 2011 16:26:24 +0000 (18:26 +0200)]
pickaxe: factor out has_changes

Move duplicate if/else construct into its own helper function.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopickaxe: plug regex/kws leak
René Scharfe [Thu, 6 Oct 2011 16:23:11 +0000 (18:23 +0200)]
pickaxe: plug regex/kws leak

With -S... --pickaxe-all, free the regex or the kws before returning
even if we found a match.  Also get rid of the variable has_changes,
as we can simply break out of the loop.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopickaxe: plug regex leak
René Scharfe [Thu, 6 Oct 2011 16:14:55 +0000 (18:14 +0200)]
pickaxe: plug regex leak

With -G... --pickaxe-all, free the regex before returning even if we
found a match.  Also get rid of the variable has_changes, as we can
simply break out of the loop.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agopickaxe: plug diff filespec leak with empty needle
René Scharfe [Thu, 6 Oct 2011 16:03:35 +0000 (18:03 +0200)]
pickaxe: plug diff filespec leak with empty needle

Check first for the unlikely case of an empty needle string and only
then populate the filespec, lest we leak it.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoMerge branch 'js/maint-no-cherry-pick-head-after-punted' into js/no-cherry-pick-head...
Junio C Hamano [Fri, 7 Oct 2011 00:02:11 +0000 (17:02 -0700)]
Merge branch 'js/maint-no-cherry-pick-head-after-punted' into js/no-cherry-pick-head-after-punted

* js/maint-no-cherry-pick-head-after-punted:
  cherry-pick: do not give irrelevant advice when cherry-pick punted
  revert.c: defer writing CHERRY_PICK_HEAD till it is safe to do so

Conflicts:
builtin/revert.c

12 years agocherry-pick: do not give irrelevant advice when cherry-pick punted
Jay Soffian [Thu, 6 Oct 2011 17:58:01 +0000 (13:58 -0400)]
cherry-pick: do not give irrelevant advice when cherry-pick punted

If a cherry-pick did not even start because the working tree had local
changes that would overlap with the operation, we shouldn't be advising
the users to resolve conflicts nor to conclude it with "git commit".

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agorevert.c: defer writing CHERRY_PICK_HEAD till it is safe to do so
Jay Soffian [Thu, 6 Oct 2011 17:48:35 +0000 (13:48 -0400)]
revert.c: defer writing CHERRY_PICK_HEAD till it is safe to do so

do_pick_commit() writes out CHERRY_PICK_HEAD before invoking merge (either
via do_recursive_merge() or try_merge_command()) on the assumption that if
the merge fails it is due to conflict. However, if the tree is dirty, the
merge may not even start, aborting before do_pick_commit() can remove
CHERRY_PICK_HEAD.

Instead, defer writing CHERRY_PICK_HEAD till after merge has returned.
At this point we know the merge has either succeeded or failed due
to conflict. In either case, we want CHERRY_PICK_HEAD to be written
so that it may be picked up by the subsequent invocation of commit.

Note that do_recursive_merge() aborts if the merge cannot start, while
try_merge_command() returns a non-zero value other than 1.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agogit-gui: deal with unknown files when pressing the "Stage Changed" button
Heiko Voigt [Fri, 27 May 2011 15:40:24 +0000 (17:40 +0200)]
git-gui: deal with unknown files when pressing the "Stage Changed" button

As a shortcut the "Stage Changed" button can be used to stage all current
changes in the worktree which are not set to ignore. Previously unknown
files would be ignored. The user might want to say: "Just save everything
in my worktree". To support this workflow we now ask whether the user also
wants to stage the unknown files if there are some present.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
12 years agocompletion: push --set-upstream
Teemu Matilainen [Thu, 6 Oct 2011 18:40:31 +0000 (21:40 +0300)]
completion: push --set-upstream

Signed-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agocompletion: commit --fixup and --squash
Teemu Matilainen [Thu, 6 Oct 2011 18:40:30 +0000 (21:40 +0300)]
completion: commit --fixup and --squash

Signed-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agocompletion: unite --reuse-message and --reedit-message handling
Teemu Matilainen [Thu, 6 Oct 2011 18:40:29 +0000 (21:40 +0300)]
completion: unite --reuse-message and --reedit-message handling

Signed-off-by: Teemu Matilainen <teemu.matilainen@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoattr: read core.attributesfile from git_default_core_config
Junio C Hamano [Thu, 6 Oct 2011 18:22:24 +0000 (13:22 -0500)]
attr: read core.attributesfile from git_default_core_config

This code calls git_config from a helper function to parse the config entry
it is interested in.  Calling git_config in this way may cause a problem if
the helper function can be called after a previous call to git_config by
another function since the second call to git_config may reset some
variable to the value in the config file which was previously overridden.

The above is not a problem in this case since the function passed to
git_config only parses one config entry and the variable it sets is not
assigned outside of the parsing function.  But a programmer who desires
all of the standard config options to be parsed may be tempted to modify
git_attr_config() so that it falls back to git_default_config() and then it
_would_ be vulnerable to the above described behavior.

So, move the call to git_config up into the top-level cmd_* function and
move the responsibility for parsing core.attributesfile into the main
config file parser.

Which is only the logical thing to do ;-)

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agobuiltin/mv.c: plug miniscule memory leak
Brandon Casey [Thu, 6 Oct 2011 18:22:23 +0000 (13:22 -0500)]
builtin/mv.c: plug miniscule memory leak

The "it" string would not be free'ed if base_name was non-NULL.
Let's free it.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agocleanup: use internal memory allocation wrapper functions everywhere
Brandon Casey [Thu, 6 Oct 2011 18:22:22 +0000 (13:22 -0500)]
cleanup: use internal memory allocation wrapper functions everywhere

The "x"-prefixed versions of strdup, malloc, etc. will check whether the
allocation was successful and terminate the process otherwise.

A few uses of malloc were left alone since they already implemented a
graceful path of failure or were in a quasi external library like xdiff.

Additionally, the call to malloc in compat/win32/syslog.c was not modified
since the syslog() implemented there is a die handler and a call to the
x-wrappers within a die handler could result in recursion should memory
allocation fail.  This will have to be addressed separately.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoattr.c: avoid inappropriate access to strbuf "buf" member
Brandon Casey [Thu, 6 Oct 2011 18:22:21 +0000 (13:22 -0500)]
attr.c: avoid inappropriate access to strbuf "buf" member

This code sequence performs a strcpy into the buf member of a strbuf
struct.  The strcpy may move the position of the terminating nul of the
string and effectively change the length of string so that it does not
match the len member of the strbuf struct.

Currently, this sequence works since the strbuf was given a hint when it
was initialized to allocate enough space to accomodate the string that will
be strcpy'ed, but this is an implementation detail of strbufs, not a
guarantee.

So, lets rework this sequence so that the strbuf is only manipulated by
strbuf functions, and direct modification of its "buf" member is not
necessary.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agomerge-one-file: fix "expr: non-numeric argument"
Jay Soffian [Thu, 6 Oct 2011 18:25:55 +0000 (14:25 -0400)]
merge-one-file: fix "expr: non-numeric argument"

When invoking expr to compare two numbers, don't quote the
variables which are the output of 'wc -c'. On OS X, this output
includes spaces, which expr balks at:

  $ sz0=`wc -c </etc/passwd`
  $ sz1=`wc -c </etc/passwd`
  $ echo "'$sz0'"
  '    3667'

  $ expr "$sz0" \< "$sz1" \* 2
  expr: non-numeric argument

  $ expr $sz0 \< $sz1 \* 2
  1

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoident: do not retrieve default ident when unnecessary
Jonathan Nieder [Thu, 6 Oct 2011 17:17:19 +0000 (12:17 -0500)]
ident: do not retrieve default ident when unnecessary

Avoid a getpwuid() call (which contacts the network if the password
database is not local), read of /etc/mailname, gethostname() call, and
reverse DNS lookup if the user has already chosen a name and email
through configuration, the environment, or the command line.

This should slightly speed up commands like "git commit".  More
importantly, it improves error reporting when computation of the
default ident string does not go smoothly.  For example, after
detecting a problem (e.g., "warning: cannot open /etc/mailname:
Permission denied") in retrieving the default committer identity:

touch /etc/mailname; # as root
chmod -r /etc/mailname; # as root
git commit -m 'test commit'

you can squelch the warning while waiting for your sysadmin to fix the
permissions problem.

echo '[user] email = me@example.com' >>~/.gitconfig

Inspired-by: Johannes Sixt <j6t@kdgb.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoadd_ref(): verify that the refname is formatted correctly
Michael Haggerty [Thu, 15 Sep 2011 21:10:43 +0000 (23:10 +0200)]
add_ref(): verify that the refname is formatted correctly

In add_ref(), verify that the refname is formatted correctly before
adding it to the ref_list.  Here we have to allow refname components
that start with ".", since (for example) the remote protocol uses
synthetic reference name ".have".  So add a new REFNAME_DOT_COMPONENT
flag that can be passed to check_refname_format() to allow leading
dots.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): expand documentation
Michael Haggerty [Thu, 15 Sep 2011 21:10:42 +0000 (23:10 +0200)]
resolve_ref(): expand documentation

Record information about resolve_ref(), hard-won via reverse
engineering, in a comment for future spelunkers.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): also treat a too-long SHA1 as invalid
Michael Haggerty [Thu, 15 Sep 2011 21:10:41 +0000 (23:10 +0200)]
resolve_ref(): also treat a too-long SHA1 as invalid

If the SHA1 in a reference file is not terminated by a space or
end-of-file, consider it malformed and emit a warning.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): emit warnings for improperly-formatted references
Michael Haggerty [Thu, 15 Sep 2011 21:10:40 +0000 (23:10 +0200)]
resolve_ref(): emit warnings for improperly-formatted references

While resolving references, if a reference is found that is in an
unrecognized format, emit a warning (and then fail, as before).
Wouldn't *you* want to know?

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): verify that the input refname has the right format
Michael Haggerty [Thu, 15 Sep 2011 21:10:39 +0000 (23:10 +0200)]
resolve_ref(): verify that the input refname has the right format

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoremote: avoid passing NULL to read_ref()
Michael Haggerty [Thu, 15 Sep 2011 21:10:38 +0000 (23:10 +0200)]
remote: avoid passing NULL to read_ref()

read_ref() can (and in test t5800, actually *does*) return NULL.
Don't pass the NULL along to read_ref().  Coincidentally, this mistake
didn't make resolve_ref() blow up, but upcoming changes to
resolve_ref() will make it less forgiving.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoremote: use xstrdup() instead of strdup()
Michael Haggerty [Thu, 15 Sep 2011 21:10:37 +0000 (23:10 +0200)]
remote: use xstrdup() instead of strdup()

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): do not follow incorrectly-formatted symbolic refs
Michael Haggerty [Thu, 15 Sep 2011 21:10:36 +0000 (23:10 +0200)]
resolve_ref(): do not follow incorrectly-formatted symbolic refs

Emit a warning and fail if a symbolic reference refers to an
incorrectly-formatted refname.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): extract a function get_packed_ref()
Michael Haggerty [Thu, 15 Sep 2011 21:10:35 +0000 (23:10 +0200)]
resolve_ref(): extract a function get_packed_ref()

Making it a function and giving it a name makes the code clearer.  I
also have a strong suspicion that the function will find other uses in
the future.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): turn buffer into a proper string as soon as possible
Michael Haggerty [Thu, 15 Sep 2011 21:10:34 +0000 (23:10 +0200)]
resolve_ref(): turn buffer into a proper string as soon as possible

Immediately strip off trailing spaces and null-terminate the string
holding the contents of the reference file; this allows the use of
string functions and avoids the need to keep separate track of the
string's length.  (get_sha1_hex() fails automatically if the string is
too short.)

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): only follow a symlink that contains a valid, normalized refname
Michael Haggerty [Thu, 15 Sep 2011 21:10:33 +0000 (23:10 +0200)]
resolve_ref(): only follow a symlink that contains a valid, normalized refname

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): use prefixcmp()
Michael Haggerty [Thu, 15 Sep 2011 21:10:32 +0000 (23:10 +0200)]
resolve_ref(): use prefixcmp()

Terminate the link content string one step earlier, allowing
prefixcmp() to be used instead of the less clear memcmp().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoresolve_ref(): explicitly fail if a symlink is not readable
Michael Haggerty [Thu, 15 Sep 2011 21:10:31 +0000 (23:10 +0200)]
resolve_ref(): explicitly fail if a symlink is not readable

Previously the failure came later, after a few steps in which the
length was treated like the actual length of a string.  Even though
the old code gave the same answers, it was somewhat misleading.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoChange check_refname_format() to reject unnormalized refnames
Michael Haggerty [Thu, 15 Sep 2011 21:10:30 +0000 (23:10 +0200)]
Change check_refname_format() to reject unnormalized refnames

Since much of the infrastructure does not work correctly with
unnormalized refnames, change check_refname_format() to reject them.

Similarly, change "git check-ref-format" to reject unnormalized
refnames by default.  But add an option --normalize, which causes "git
check-ref-format" to normalize the refname before checking its format,
and print the normalized refname.  This is exactly the behavior of the
old --print option, which is retained but deprecated.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoInline function refname_format_print()
Michael Haggerty [Thu, 15 Sep 2011 21:10:29 +0000 (23:10 +0200)]
Inline function refname_format_print()

Soon we will make printing independent of collapsing.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoMake collapse_slashes() allocate memory for its result
Michael Haggerty [Thu, 15 Sep 2011 21:10:28 +0000 (23:10 +0200)]
Make collapse_slashes() allocate memory for its result

This will make upcoming changes a tiny bit easier.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoDo not allow ".lock" at the end of any refname component
Michael Haggerty [Thu, 15 Sep 2011 21:10:27 +0000 (23:10 +0200)]
Do not allow ".lock" at the end of any refname component

Allowing any refname component to end with ".lock" is looking for
trouble; for example,

    $ git br foo.lock/bar
    $ git br foo
    fatal: Unable to create '[...]/.git/refs/heads/foo.lock': File exists.

Therefore, do not allow any refname component to end with ".lock".

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoRefactor check_refname_format()
Michael Haggerty [Thu, 15 Sep 2011 21:10:26 +0000 (23:10 +0200)]
Refactor check_refname_format()

Among other things, extract a function check_refname_component().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoChange check_ref_format() to take a flags argument
Michael Haggerty [Thu, 15 Sep 2011 21:10:25 +0000 (23:10 +0200)]
Change check_ref_format() to take a flags argument

Change check_ref_format() to take a flags argument that indicates what
is acceptable in the reference name (analogous to "git
check-ref-format"'s "--allow-onelevel" and "--refspec-pattern").  This
is more convenient for callers and also fixes a failure in the test
suite (and likely elsewhere in the code) by enabling "onelevel" and
"refspec-pattern" to be allowed independently of each other.

Also rename check_ref_format() to check_refname_format() to make it
obvious that it deals with refnames rather than references themselves.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agoChange bad_ref_char() to return a boolean value
Michael Haggerty [Thu, 15 Sep 2011 21:10:24 +0000 (23:10 +0200)]
Change bad_ref_char() to return a boolean value

Previously most bad characters were indicated by returning 1, but "*"
was special-cased to return 2 instead of 1.  One caller examined the
return value to see whether the special case occurred.

But it is easier (to document and understand) for bad_ref_char()
simply to return a boolean value, treating "*" like any other bad
character.  Special-case the handling of "*" (which only occurs in
very specific circumstances) at the caller.  The resulting calling
code thereby also becomes more transparent.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agogit check-ref-format: add options --allow-onelevel and --refspec-pattern
Michael Haggerty [Thu, 15 Sep 2011 21:10:23 +0000 (23:10 +0200)]
git check-ref-format: add options --allow-onelevel and --refspec-pattern

Also add tests of the new options.  (Actually, one big reason to add
the new options is to make it easy to test check_ref_format(), though
the options should also be useful to other scripts.)

Interpret the result of check_ref_format() based on which types of
refnames are allowed.  However, because check_ref_format() can only
return a single value, one test case is still broken.  Specifically,
the case "git check-ref-format --onelevel '*'" incorrectly succeeds
because check_ref_format() returns CHECK_REF_FORMAT_ONELEVEL for this
refname even though the refname is also CHECK_REF_FORMAT_WILDCARD.
The type of check that leads to this failure is used elsewhere in
"real" code and could lead to bugs; it will be fixed over the next few
commits.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 years agot1402: add some more tests
Michael Haggerty [Thu, 15 Sep 2011 21:10:22 +0000 (23:10 +0200)]
t1402: add some more tests

The new tests reflect the status quo.  Soon the rule for "*.lock" in
refname components will be tightened up.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>