git.git
12 years agodaemon: be strict at parsing parameters --[no-]informative-errors
Nguyễn Thái Ngọc Duy [Fri, 20 Dec 2013 10:53:52 +0000 (17:53 +0700)]
daemon: be strict at parsing parameters --[no-]informative-errors

Use strcmp() instead of starts_with()/!prefixcmp() to stop accepting
--informative-errors-just-a-little

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodiff: add diff.orderfile configuration variable
Samuel Bronson [Thu, 19 Dec 2013 00:08:12 +0000 (19:08 -0500)]
diff: add diff.orderfile configuration variable

diff.orderfile acts as a default for the -O command line option.

[sb: split up aw's original patch; rework tests and docs, treat option
as pathname]

Signed-off-by: Anders Waldenborg <redacted>
Signed-off-by: Samuel Bronson <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodiff: let "git diff -O" read orderfile from any file and fail properly
Samuel Bronson [Thu, 19 Dec 2013 00:08:11 +0000 (19:08 -0500)]
diff: let "git diff -O" read orderfile from any file and fail properly

The -O flag really shouldn't silently fail to do anything when given
a path that it can't read from.

However, it should be able to read from un-mmappable files, such as:

 * pipes/fifos

 * /dev/null:  It's a character device (at least on Linux)

 * ANY empty file:

   Quoting Linux mmap(2), "SUSv3 specifies that mmap() should fail if
   length is 0.  However, in kernels before 2.6.12, mmap() succeeded in
   this case: no mapping was created and the call returned addr.  Since
   kernel 2.6.12, mmap() fails with the error EINVAL for this case."

We especially want "-O/dev/null" to work, since we will be documenting
it as the way to cancel "diff.orderfile" when we add that.

(Note: "-O/dev/null" did have the right effect, since the existing error
handling essentially worked out to "silently ignore the orderfile".  But
this was probably more coincidence than anything else.)

So, lets toss all of that logic to get the file mmapped and just use
strbuf_read_file() instead, which gives us decent error handling
practically for free.

Signed-off-by: Samuel Bronson <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agot4056: add new tests for "git diff -O"
Samuel Bronson [Thu, 19 Dec 2013 00:08:10 +0000 (19:08 -0500)]
t4056: add new tests for "git diff -O"

Adapted from $gmane/236427 by Anders Waldenborg, "diff: Add
diff.orderfile configuration variable".

Signed-off-by: Anders Waldenborg <redacted>
Signed-off-by: Samuel Bronson <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agobuiltin/prune.c: use strbuf to avoid having to worry about PATH_MAX
Jeff King [Tue, 17 Dec 2013 23:22:31 +0000 (18:22 -0500)]
builtin/prune.c: use strbuf to avoid having to worry about PATH_MAX

While at it, rename prune_tmp_object(), which used to be a helper to
remove temporary files that were created to become loose object
files, to prune_tmp_file(), as the function is also used to remove
any random cruft whose name begins with tmp_ directly in .git/object
or .git/object/pack directories these days.

Noticed-by: Michael Haggerty <redacted>
Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoget_max_fd_limit(): fall back to OPEN_MAX upon getrlimit/sysconf failure
Junio C Hamano [Wed, 18 Dec 2013 22:59:12 +0000 (14:59 -0800)]
get_max_fd_limit(): fall back to OPEN_MAX upon getrlimit/sysconf failure

On broken systems where RLIMIT_NOFILE is visible by the compliers
but underlying getrlimit() system call does not behave, we used to
simply die() when we are trying to decide how many file descriptors
to allocate for keeping packfiles open.  Instead, allow the fallback
codepath to take over when we get such a failure from getrlimit().

The same issue exists with _SC_OPEN_MAX and sysconf(); restructure
the code in a similar way to prepare for a broken sysconf() as well.

Noticed-by: Joey Hess <redacted>
Helped-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodocs: add filter-branch notes on The BFG
Roberto Tyley [Wed, 18 Dec 2013 14:25:16 +0000 (14:25 +0000)]
docs: add filter-branch notes on The BFG

The BFG is a tool specifically designed for the task of removing
unwanted data from Git repository history - a common use-case for which
git-filter-branch has been the traditional workhorse.

It's beneficial to let users know that filter-branch has an alternative
here:

* speed : The BFG is 10-50x faster
  http://rtyley.github.io/bfg-repo-cleaner/#speed
* complexity of configuration : filter-branch is a very flexible tool,
  but demands very careful usage in order to get the desired results
  http://rtyley.github.io/bfg-repo-cleaner/#examples

Obviously, filter-branch has it's advantages too - it permits very
complex rewrites, and doesn't require a JVM - but for the common
use-case of deleting unwanted data, it's helpful to users to be aware
that an alternative exists.

The BFG was released under the GPL in February 2013, and has since seen
widespread production use (The Guardian, RedHat, Google, UK Government
Digital Service), been tested against large repos (~300K commits, ~5GB
packfiles) and received significant positive feedback from users:

http://rtyley.github.io/bfg-repo-cleaner/#feedback

Signed-off-by: Roberto Tyley <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoSync with 1.8.5.2
Junio C Hamano [Tue, 17 Dec 2013 22:12:17 +0000 (14:12 -0800)]
Sync with 1.8.5.2

* maint:
  Git 1.8.5.2
  cmd_repack(): remove redundant local variable "nr_packs"

12 years agoUpdate draft release notes to 1.9
Junio C Hamano [Tue, 17 Dec 2013 22:05:50 +0000 (14:05 -0800)]
Update draft release notes to 1.9

Signed-off-by: Junio C Hamano <redacted>
12 years agoMerge branch 'kn/gitweb-extra-branch-refs'
Junio C Hamano [Tue, 17 Dec 2013 20:03:33 +0000 (12:03 -0800)]
Merge branch 'kn/gitweb-extra-branch-refs'

Allow gitweb to be configured to show refs out of refs/heads/ as if
they were branches.

* kn/gitweb-extra-branch-refs:
  gitweb: Denote non-heads, non-remotes branches
  gitweb: Add a feature for adding more branch refs
  gitweb: Return 1 on validation success instead of passed input
  gitweb: Move check-ref-format code into separate function

12 years agoMerge branch 'tb/clone-ssh-with-colon-for-port'
Junio C Hamano [Tue, 17 Dec 2013 20:03:31 +0000 (12:03 -0800)]
Merge branch 'tb/clone-ssh-with-colon-for-port'

Be more careful when parsing remote repository URL given in the
scp-style host:path notation.

* tb/clone-ssh-with-colon-for-port:
  git_connect(): use common return point
  connect.c: refactor url parsing
  git_connect(): refactor the port handling for ssh
  git fetch: support host:/~repo
  t5500: add test cases for diag-url
  git fetch-pack: add --diag-url
  git_connect: factor out discovery of the protocol and its parts
  git_connect: remove artificial limit of a remote command
  t5601: add tests for ssh
  t5601: remove clear_ssh, refactor setup_ssh_wrapper

12 years agoMerge branch 'nd/transport-positive-depth-only'
Junio C Hamano [Tue, 17 Dec 2013 20:03:29 +0000 (12:03 -0800)]
Merge branch 'nd/transport-positive-depth-only'

"git fetch --depth=0" was a no-op, and was silently
ignored. Diagnose it as an error.

* nd/transport-positive-depth-only:
  clone,fetch: catch non positive --depth option value

12 years agoMerge branch 'cc/starts-n-ends-with'
Junio C Hamano [Tue, 17 Dec 2013 19:47:35 +0000 (11:47 -0800)]
Merge branch 'cc/starts-n-ends-with'

Remove a few duplicate implementations of prefix/suffix comparison
functions, and rename them to starts_with and ends_with.

* cc/starts-n-ends-with:
  replace {pre,suf}fixcmp() with {starts,ends}_with()
  strbuf: introduce starts_with() and ends_with()
  builtin/remote: remove postfixcmp() and use suffixcmp() instead
  environment: normalize use of prefixcmp() by removing " != 0"

12 years agoMerge branch 'jl/commit-v-strip-marker'
Junio C Hamano [Tue, 17 Dec 2013 19:47:18 +0000 (11:47 -0800)]
Merge branch 'jl/commit-v-strip-marker'

"git commit -v" appends the patch to the log message before
editing, and then removes the patch when the editor returned
control. However, the patch was not stripped correctly when the
first modified path was a submodule.

* jl/commit-v-strip-marker:
  commit -v: strip diffs and submodule shortlogs from the commit message

12 years agoMerge branch 'tr/send-email-ssl'
Junio C Hamano [Tue, 17 Dec 2013 19:47:12 +0000 (11:47 -0800)]
Merge branch 'tr/send-email-ssl'

SSL-related options were not passed correctly to underlying socket
layer in "git send-email".

* tr/send-email-ssl:
  send-email: set SSL options through IO::Socket::SSL::set_client_defaults
  send-email: --smtp-ssl-cert-path takes an argument
  send-email: pass Debug to Net::SMTP::SSL::new

12 years agoMerge branch 'nd/gettext-vsnprintf'
Junio C Hamano [Tue, 17 Dec 2013 19:47:10 +0000 (11:47 -0800)]
Merge branch 'nd/gettext-vsnprintf'

* nd/gettext-vsnprintf:
  gettext.c: detect the vsnprintf bug at runtime

12 years agoMerge branch 'mm/mv-file-to-no-such-dir-with-slash'
Junio C Hamano [Tue, 17 Dec 2013 19:47:08 +0000 (11:47 -0800)]
Merge branch 'mm/mv-file-to-no-such-dir-with-slash'

* mm/mv-file-to-no-such-dir-with-slash:
  mv: let 'git mv file no-such-dir/' error out

12 years agoMerge branch 'nd/remove-opt-boolean'
Junio C Hamano [Tue, 17 Dec 2013 19:47:05 +0000 (11:47 -0800)]
Merge branch 'nd/remove-opt-boolean'

* nd/remove-opt-boolean:
  parse-options: remove OPT_BOOLEAN

12 years agoMerge branch 'bc/doc-merge-no-op-revert'
Junio C Hamano [Tue, 17 Dec 2013 19:47:00 +0000 (11:47 -0800)]
Merge branch 'bc/doc-merge-no-op-revert'

* bc/doc-merge-no-op-revert:
  Documentation: document pitfalls with 3-way merge

12 years agoMerge branch 'fc/trivial'
Junio C Hamano [Tue, 17 Dec 2013 19:46:32 +0000 (11:46 -0800)]
Merge branch 'fc/trivial'

* fc/trivial:
  remote: fix status with branch...rebase=preserve
  fetch: add missing documentation
  t: trivial whitespace cleanups
  abspath: trivial style fix

12 years agoMerge branch 'jk/t5000-gzip-simplify'
Junio C Hamano [Tue, 17 Dec 2013 19:46:29 +0000 (11:46 -0800)]
Merge branch 'jk/t5000-gzip-simplify'

Test fix.

* jk/t5000-gzip-simplify:
  t5000: simplify gzip prerequisite checks

12 years agoMerge branch 'kb/doc-exclude-directory-semantics'
Junio C Hamano [Tue, 17 Dec 2013 19:44:18 +0000 (11:44 -0800)]
Merge branch 'kb/doc-exclude-directory-semantics'

* kb/doc-exclude-directory-semantics:
  gitignore.txt: clarify recursive nature of excluded directories

12 years agoGit 1.8.5.2
Junio C Hamano [Tue, 17 Dec 2013 19:42:12 +0000 (11:42 -0800)]
Git 1.8.5.2

Signed-off-by: Junio C Hamano <redacted>
12 years agoMerge branch 'rs/doc-submitting-patches' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:38:23 +0000 (11:38 -0800)]
Merge branch 'rs/doc-submitting-patches' into maint

* rs/doc-submitting-patches:
  SubmittingPatches: document how to handle multiple patches

12 years agoMerge branch 'tr/doc-git-cherry' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:37:55 +0000 (11:37 -0800)]
Merge branch 'tr/doc-git-cherry' into maint

* tr/doc-git-cherry:
  Documentation: revamp git-cherry(1)

12 years agoMerge branch 'nd/glossary-content-pathspec-markup' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:36:54 +0000 (11:36 -0800)]
Merge branch 'nd/glossary-content-pathspec-markup' into maint

* nd/glossary-content-pathspec-markup:
  glossary-content.txt: fix documentation of "**" patterns

12 years agoMerge branch 'jj/doc-markup-gitcli' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:36:38 +0000 (11:36 -0800)]
Merge branch 'jj/doc-markup-gitcli' into maint

* jj/doc-markup-gitcli:
  Documentation/gitcli.txt: fix double quotes

12 years agoMerge branch 'jj/doc-markup-hints-in-coding-guidelines' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:36:10 +0000 (11:36 -0800)]
Merge branch 'jj/doc-markup-hints-in-coding-guidelines' into maint

* jj/doc-markup-hints-in-coding-guidelines:
  State correct usage of literal examples in man pages in the coding standards

12 years agoMerge branch 'jj/log-doc' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:35:41 +0000 (11:35 -0800)]
Merge branch 'jj/log-doc' into maint

* jj/log-doc:
  Documentation/git-log.txt: mark-up fix and minor rephasing
  Documentation/git-log: update "--log-size" description

12 years agoMerge branch 'jj/rev-list-options-doc' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:34:41 +0000 (11:34 -0800)]
Merge branch 'jj/rev-list-options-doc' into maint

* jj/rev-list-options-doc:
  Documentation/rev-list-options.txt: fix some grammatical issues and typos
  Documentation/rev-list-options.txt: fix mark-up

12 years agoMerge branch 'tb/doc-fetch-pack-url' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:34:24 +0000 (11:34 -0800)]
Merge branch 'tb/doc-fetch-pack-url' into maint

* tb/doc-fetch-pack-url:
  git-fetch-pack uses URLs like git-fetch

12 years agoMerge branch 'mi/typofixes' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:34:01 +0000 (11:34 -0800)]
Merge branch 'mi/typofixes' into maint

* mi/typofixes:
  contrib: typofixes
  Documentation/technical/http-protocol.txt: typofixes
  typofixes: fix misspelt comments

12 years agoMerge branch 'jh/loose-object-dirs-creation-race' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:32:50 +0000 (11:32 -0800)]
Merge branch 'jh/loose-object-dirs-creation-race' into maint

Two processes creating loose objects at the same time could have
failed unnecessarily when the name of their new objects started
with the same byte value, due to a race condition.

* jh/loose-object-dirs-creation-race:
  sha1_file.c:create_tmpfile(): Fix race when creating loose object dirs

12 years agoMerge branch 'jk/two-way-merge-corner-case-fix' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:32:04 +0000 (11:32 -0800)]
Merge branch 'jk/two-way-merge-corner-case-fix' into maint

"git am --abort" sometimes complained about not being able to write
a tree with an 0{40} object in it.

* jk/two-way-merge-corner-case-fix:
  t1005: add test for "read-tree --reset -u A B"
  t1005: reindent
  unpack-trees: fix "read-tree -u --reset A B" with conflicted index

12 years agoMerge branch 'sb/sha1-loose-object-info-check-existence' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:31:18 +0000 (11:31 -0800)]
Merge branch 'sb/sha1-loose-object-info-check-existence' into maint

"git cat-file --batch-check=ok" did not check the existence of the
named object.

* sb/sha1-loose-object-info-check-existence:
  sha1_loose_object_info(): do not return success on missing object

12 years agoMerge branch 'nd/magic-pathspec' into maint
Junio C Hamano [Tue, 17 Dec 2013 19:21:34 +0000 (11:21 -0800)]
Merge branch 'nd/magic-pathspec' into maint

"git diff -- ':(icase)makefile'" was unnecessarily rejected at the
command line parser.

* nd/magic-pathspec:
  diff: restrict pathspec limitations to diff b/f case only

12 years agocmd_repack(): remove redundant local variable "nr_packs"
Michael Haggerty [Tue, 17 Dec 2013 13:43:58 +0000 (14:43 +0100)]
cmd_repack(): remove redundant local variable "nr_packs"

Its value is the same as the number of entries in the "names"
string_list, so just use "names.nr" in its place.

Signed-off-by: Michael Haggerty <redacted>
Acked-by: Stefan Beller <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoprune-packed: use strbuf to avoid having to worry about PATH_MAX
Junio C Hamano [Tue, 17 Dec 2013 18:43:30 +0000 (10:43 -0800)]
prune-packed: use strbuf to avoid having to worry about PATH_MAX

A/very/long/path/to/.git that becomes exactly PATH_MAX bytes long
after suffixed with /objects/??/??38-hex??, would have overflown
the on-stack pathname[] buffer.

Noticed-by: Michael Haggerty <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoPrevent buffer overflows when path is too long
Antoine Pelisse [Sat, 14 Dec 2013 11:31:16 +0000 (12:31 +0100)]
Prevent buffer overflows when path is too long

Some buffers created with PATH_MAX length are not checked when being
written, and can overflow if PATH_MAX is not big enough to hold the
path.

Replace those buffers by strbufs so that their size is automatically
grown if necessary. They are created as static local variables to avoid
reallocating memory on each call. Note that prefix_filename() returns
this static buffer so each callers should copy or use the string
immediately (this is currently true).

Reported-by: Wataru Noguchi <redacted>
Signed-off-by: Antoine Pelisse <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodiff: avoid some nesting
Thomas Gummerer [Mon, 16 Dec 2013 20:19:24 +0000 (21:19 +0100)]
diff: avoid some nesting

Avoid some nesting in builtin/diff.c, to make the code easier to read.
There are no functional changes.

Helped-by: Jonathan Nieder <redacted>
Signed-off-by: Thomas Gummerer <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodiff: add test for --no-index executed outside repo
Thomas Gummerer [Mon, 16 Dec 2013 20:19:23 +0000 (21:19 +0100)]
diff: add test for --no-index executed outside repo

470faf9 diff: move no-index detection to builtin/diff.c breaks the error
message for "git diff --no-index", when the command is executed outside
of a git repository and the wrong number of arguments are given. 6df5762
diff: don't read index when --no-index is given fixes the problem.

Add a test to guard against similar breakages in the future.

Signed-off-by: Thomas Gummerer <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodiff.c: fix some recent whitespace style violations
Jeff King [Mon, 16 Dec 2013 20:02:21 +0000 (15:02 -0500)]
diff.c: fix some recent whitespace style violations

These were introduced by ee7fb0b.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agopack-objects doc: treat output filename as opaque
Jeff King [Mon, 16 Dec 2013 19:19:33 +0000 (11:19 -0800)]
pack-objects doc: treat output filename as opaque

After 1190a1a (pack-objects: name pack files after trailer hash,
2013-12-05), the SHA-1 used to determine the filename is calculated
differently.  Update the documentation to not guarantee anything more
than that the SHA-1 depends on the pack content somehow.

Hopefully this will discourage readers from depending on the old or
the new calculation.

Reported-by: Michael Haggerty <redacted>
Signed-off-by: Jeff King <redacted>
Signed-off-by: Jonathan Nieder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agocontrib/git-credential-gnome-keyring.c: small stylistic cleanups
John Szakmeister [Sat, 14 Dec 2013 11:21:26 +0000 (06:21 -0500)]
contrib/git-credential-gnome-keyring.c: small stylistic cleanups

Signed-off-by: John Szakmeister <redacted>
Signed-off-by: Junio C Hamano <redacted>
Reviewed-by: Felipe Contreras <redacted>
12 years agol10n: Init Vietnamese translation
Trần Ngọc Quân [Sat, 14 Dec 2013 07:43:04 +0000 (14:43 +0700)]
l10n: Init Vietnamese translation

Signed-off-by: Trần Ngọc Quân <redacted>
12 years agoUpdate draft release notes to 1.9
Junio C Hamano [Thu, 12 Dec 2013 22:24:39 +0000 (14:24 -0800)]
Update draft release notes to 1.9

Signed-off-by: Junio C Hamano <redacted>
12 years agoMerge branch 'jn/scripts-updates'
Junio C Hamano [Thu, 12 Dec 2013 22:22:59 +0000 (14:22 -0800)]
Merge branch 'jn/scripts-updates'

* jn/scripts-updates:
  remove #!interpreter line from shell libraries
  test: replace shebangs with descriptions in shell libraries
  test: make FILEMODE a lazy prereq
  contrib: remove git-p4import
  mark contributed hooks executable
  mark perl test scripts executable
  mark Windows build scripts executable

12 years agoMerge branch 'cn/thin-push-capability'
Junio C Hamano [Thu, 12 Dec 2013 22:20:32 +0000 (14:20 -0800)]
Merge branch 'cn/thin-push-capability'

Allow receive-pack to insist on receiving a fat pack from "git
push" clients.

* cn/thin-push-capability:
  send-pack: don't send a thin pack to a server which doesn't support it

12 years agoMerge branch 'jk/remove-deprecated'
Junio C Hamano [Thu, 12 Dec 2013 22:18:33 +0000 (14:18 -0800)]
Merge branch 'jk/remove-deprecated'

* jk/remove-deprecated:
  stop installing git-tar-tree link
  peek-remote: remove deprecated alias of ls-remote
  lost-found: remove deprecated command
  tar-tree: remove deprecated command
  repo-config: remove deprecated alias for "git config"

12 years agoMerge branch 'tr/commit-slab-cleanup'
Junio C Hamano [Thu, 12 Dec 2013 22:18:31 +0000 (14:18 -0800)]
Merge branch 'tr/commit-slab-cleanup'

* tr/commit-slab-cleanup:
  commit-slab: sizeof() the right type in xrealloc
  commit-slab: declare functions "static inline"
  commit-slab: document clear_$slabname()

12 years agoMerge branch 'rs/doc-submitting-patches'
Junio C Hamano [Thu, 12 Dec 2013 22:18:29 +0000 (14:18 -0800)]
Merge branch 'rs/doc-submitting-patches'

* rs/doc-submitting-patches:
  SubmittingPatches: document how to handle multiple patches

12 years agoMerge branch 'tr/doc-git-cherry'
Junio C Hamano [Thu, 12 Dec 2013 22:18:23 +0000 (14:18 -0800)]
Merge branch 'tr/doc-git-cherry'

* tr/doc-git-cherry:
  Documentation: revamp git-cherry(1)

12 years agoMerge branch 'cl/p4-use-diff-tree'
Junio C Hamano [Thu, 12 Dec 2013 22:18:20 +0000 (14:18 -0800)]
Merge branch 'cl/p4-use-diff-tree'

* cl/p4-use-diff-tree:
  git p4: Use git diff-tree instead of format-patch

12 years agoMerge branch 'tr/config-multivalue-lift-max'
Junio C Hamano [Thu, 12 Dec 2013 22:18:09 +0000 (14:18 -0800)]
Merge branch 'tr/config-multivalue-lift-max'

* tr/config-multivalue-lift-max:
  config: arbitrary number of matches for --unset and --replace-all

12 years agoMerge branch 'mh/fetch-tags-in-addition-to-normal-refs'
Junio C Hamano [Thu, 12 Dec 2013 22:14:10 +0000 (14:14 -0800)]
Merge branch 'mh/fetch-tags-in-addition-to-normal-refs'

The "--tags" option to "git fetch" used to be literally a synonym to
a "refs/tags/*:refs/tags/*" refspec, which meant that (1) as an
explicit refspec given from the command line, it silenced the lazy
"git fetch" default that is configured, and (2) also as an explicit
refspec given from the command line, it interacted with "--prune"
to remove any tag that the remote we are fetching from does not
have.

This demotes it to an option; with it, we fetch all tags in
addition to what would be fetched without the option, and it does
not interact with the decision "--prune" makes to see what
remote-tracking refs the local has are missing the remote
counterpart.

* mh/fetch-tags-in-addition-to-normal-refs: (23 commits)
  fetch: improve the error messages emitted for conflicting refspecs
  handle_duplicate(): mark error message for translation
  ref_remote_duplicates(): extract a function handle_duplicate()
  ref_remove_duplicates(): simplify loop logic
  t5536: new test of refspec conflicts when fetching
  ref_remove_duplicates(): avoid redundant bisection
  git-fetch.txt: improve description of tag auto-following
  fetch-options.txt: simplify ifdef/ifndef/endif usage
  fetch, remote: properly convey --no-prune options to subprocesses
  builtin/remote.c:update(): use struct argv_array
  builtin/remote.c: reorder function definitions
  query_refspecs(): move some constants out of the loop
  fetch --prune: prune only based on explicit refspecs
  fetch --tags: fetch tags *in addition to* other stuff
  fetch: only opportunistically update references based on command line
  get_expanded_map(): avoid memory leak
  get_expanded_map(): add docstring
  builtin/fetch.c: reorder function definitions
  get_ref_map(): rename local variables
  api-remote.txt: correct section "struct refspec"
  ...

12 years agogitweb: Denote non-heads, non-remotes branches
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:44 +0000 (12:54 +0100)]
gitweb: Denote non-heads, non-remotes branches

Given two branches residing in refs/heads/master and refs/wip/feature
the list-of-branches view will present them in following way:
master
feature (wip)

When getting a snapshot of a 'feature' branch, the tarball is going to
have name like 'project-wip-feature-<short hash>.tgz'.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agogitweb: Add a feature for adding more branch refs
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:43 +0000 (12:54 +0100)]
gitweb: Add a feature for adding more branch refs

Allow extra-branch-refs feature to tell gitweb to show refs from
additional hierarchies in addition to branches in the list-of-branches
view.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agogitweb: Return 1 on validation success instead of passed input
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:42 +0000 (12:54 +0100)]
gitweb: Return 1 on validation success instead of passed input

Users of validate_* passing "0" might get failures on correct name
because of coercion of "0" to false in code like:
die_error(500, "invalid ref") unless (check_ref_format ("0"));

Also, the validate_foo subs are renamed to is_valid_foo.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agogitweb: Move check-ref-format code into separate function
Krzesimir Nowak [Wed, 11 Dec 2013 11:54:41 +0000 (12:54 +0100)]
gitweb: Move check-ref-format code into separate function

This check will be used in more than one place later.

Signed-off-by: Krzesimir Nowak <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodiff: don't read index when --no-index is given
Thomas Gummerer [Wed, 11 Dec 2013 09:58:43 +0000 (10:58 +0100)]
diff: don't read index when --no-index is given

git diff --no-index ... currently reads the index, during setup, when
calling gitmodules_config().  This results in worse performance when the
index is not actually needed.  This patch avoids calling
gitmodules_config() when the --no-index option is given.  The times for
executing "git diff --no-index" in the WebKit repository are improved as
follows:

Test                      HEAD~3            HEAD
------------------------------------------------------------------
4001.1: diff --no-index   0.24(0.15+0.09)   0.01(0.00+0.00) -95.8%

An additional improvement of this patch is that "git diff --no-index" no
longer breaks when the index file is corrupt, which makes it possible to
use it for investigating the broken repository.

To improve the possible usage as investigation tool for broken
repositories, setup_git_directory_gently() is also not called when the
--no-index option is given.

Also add a test to guard against future breakages, and a performance
test to show the improvements.

Signed-off-by: Thomas Gummerer <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agodiff: move no-index detection to builtin/diff.c
Thomas Gummerer [Wed, 11 Dec 2013 09:58:42 +0000 (10:58 +0100)]
diff: move no-index detection to builtin/diff.c

Currently the --no-index option is parsed in diff_no_index().  Move the
detection if a no-index diff should be executed to builtin/diff.c, where
we can use it for executing diff_no_index() conditionally.  This will
also allow us to execute other operations conditionally, which will be
done in the next patch.

There are no functional changes.

Helped-by: Jonathan Nieder <redacted>
Signed-off-by: Thomas Gummerer <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoDocumentation/git-replace: describe --format option
Christian Couder [Wed, 11 Dec 2013 07:46:13 +0000 (08:46 +0100)]
Documentation/git-replace: describe --format option

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agobuiltin/replace: unset read_replace_refs
Christian Couder [Wed, 11 Dec 2013 07:46:12 +0000 (08:46 +0100)]
builtin/replace: unset read_replace_refs

When checking to see if some objects are of the same type
and when displaying the type of objects, git replace uses
the sha1_object_info() function.

Unfortunately this function by default respects replace
refs, so instead of the type of a replaced object, it
gives the type of the replacement object which might
be different.

To fix this bug, and because git replace should work at a
level before replacement takes place, let's unset the
read_replace_refs global variable at the beginning of
cmd_replace().

Suggested-by: Jeff King <redacted>
Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agot6050: add tests for listing with --format
Christian Couder [Wed, 11 Dec 2013 07:46:11 +0000 (08:46 +0100)]
t6050: add tests for listing with --format

This patch adds tests for "git replace -l --format=<fmt>".

'short', 'medium' and 'full' are the only allowed values
for <fmt>.

'short' is the same as with no --format option.
Tests for 'medium' and 'full' are the most needed.

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agobuiltin/replace: teach listing using short, medium or full formats
Christian Couder [Wed, 11 Dec 2013 07:46:10 +0000 (08:46 +0100)]
builtin/replace: teach listing using short, medium or full formats

By default when listing replace refs, only the sha1 of the
replaced objects are shown.

In many cases, it is much nicer to be able to list all the
sha1 of the replaced objects along with the sha1 of the
replacment objects.

And in other cases it might be interesting to also show the
types of the replaced and replacement objects.

This patch introduce a new --format=<fmt> option where
<fmt> can be any of the following:

'short': this is the same as when no --format
option is used, that is only the sha1 of
the replaced objects are shown
'medium': this also lists the sha1 of the
replacement objects
'full': this shows the sha1 and the type of both
the replaced and the replacement objects

Some documentation and some tests will follow.

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agosha1_file: perform object replacement in sha1_object_info_extended()
Christian Couder [Wed, 11 Dec 2013 07:46:09 +0000 (08:46 +0100)]
sha1_file: perform object replacement in sha1_object_info_extended()

sha1_object_info_extended() should perform object replacement
if it is needed.

The simplest way to do that is to make it call
lookup_replace_object_extended().

And now its "unsigned flags" parameter is used as it is passed
to lookup_replace_object_extended().

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agot6050: show that git cat-file --batch fails with replace objects
Christian Couder [Wed, 11 Dec 2013 07:46:08 +0000 (08:46 +0100)]
t6050: show that git cat-file --batch fails with replace objects

When --batch is passed to git cat-file, the sha1_object_info_extended()
function is used to get information about the objects passed to
git cat-file.

Unfortunately sha1_object_info_extended() doesn't take care of
object replacement properly, so it will often fail with a
message like this:

$ echo a3fb2e1845a1aaf129b7975048973414dc172173 | git cat-file --batch
a3fb2e1845a1aaf129b7975048973414dc172173 commit 231
fatal: object a3fb2e1845a1aaf129b7975048973414dc172173 change size!?

The goal of this patch is to show this breakage.

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agosha1_object_info_extended(): add an "unsigned flags" parameter
Christian Couder [Wed, 11 Dec 2013 07:46:07 +0000 (08:46 +0100)]
sha1_object_info_extended(): add an "unsigned flags" parameter

This parameter is not used yet, but it will be used to tell
sha1_object_info_extended() if it should perform object
replacement or not.

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agosha1_file.c: add lookup_replace_object_extended() to pass flags
Christian Couder [Wed, 11 Dec 2013 07:46:06 +0000 (08:46 +0100)]
sha1_file.c: add lookup_replace_object_extended() to pass flags

Currently, there is only one caller to lookup_replace_object()
that can benefit from passing it some flags, but we expect
that there could be more.

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoreplace_object: don't check read_replace_refs twice
Christian Couder [Wed, 11 Dec 2013 07:46:05 +0000 (08:46 +0100)]
replace_object: don't check read_replace_refs twice

Since e1111cef (inline lookup_replace_object() calls,
May 15 2011) the read_replace_refs global variable is
checked twice, once in lookup_replace_object() and
once again in do_lookup_replace_object().

As do_lookup_replace_object() is called only from
lookup_replace_object(), we can remove the check in
do_lookup_replace_object().

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agorename READ_SHA1_FILE_REPLACE flag to LOOKUP_REPLACE_OBJECT
Christian Couder [Wed, 11 Dec 2013 07:46:04 +0000 (08:46 +0100)]
rename READ_SHA1_FILE_REPLACE flag to LOOKUP_REPLACE_OBJECT

The READ_SHA1_FILE_REPLACE flag is more related to using the
lookup_replace_object() function rather than the
read_sha1_file() function.

We also need such a flag to be used with sha1_object_info()
instead of read_sha1_file().

The name LOOKUP_REPLACE_OBJECT is therefore better for this
flag.

Signed-off-by: Christian Couder <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agocat-file: handle --batch format with missing type/size
Jeff King [Wed, 11 Dec 2013 23:15:50 +0000 (07:15 +0800)]
cat-file: handle --batch format with missing type/size

Commit 98e2092 taught cat-file to stream blobs with --batch,
which requires that we look up the object type before
loading it into memory.  As a result, we now print the
object header from information in sha1_object_info, and the
actual contents from the read_sha1_file. We double-check
that the information we printed in the header matches the
content we are about to show.

Later, commit 93d2a60 allowed custom header lines for
--batch, and commit 5b08640 made type lookups optional. As a
result, specifying a header line without the type or size
means that we will not look up those items at all.

This causes our double-checking to erroneously die with an
error; we think the type or size has changed, when in fact
it was simply left at "0".

For the size, we can fix this by only doing the consistency
double-check when we have retrieved the size via
sha1_object_info. In the case that we have not retrieved the
value, that means we also did not print it, so there is
nothing for us to check that we are consistent with.

We could do the same for the type. However, besides our
consistency check, we also care about the type in deciding
whether to stream or not. So instead of handling the case
where we do not know the type, this patch instead makes sure
that we always trigger a type lookup when we are printing,
so that even a format without the type will stream as we
would in the normal case.

Reviewed-by: Jonathan Nieder <redacted>
Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agocat-file: pass expand_data to print_object_or_die
Jeff King [Wed, 11 Dec 2013 23:01:42 +0000 (07:01 +0800)]
cat-file: pass expand_data to print_object_or_die

We currently individually pass the sha1, type, and size
fields calculated by sha1_object_info. However, if we pass
the whole struct, the called function can make more
intelligent decisions about which fields were actually
filled by sha1_object_info.

This patch takes that first refactoring step, passing the
whole struct, so further patches can make those decisions
with less noise in their diffs. There should be no
functional change to this patch (aside from a minor typo fix
in the error message).

As a side effect, we can rename the local variables in the
function to "type" and "size", since the names are no longer
taken.

Reviewed-by: Jonathan Nieder <redacted>
Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agogit-clone.txt: remove shallow clone limitations
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:55 +0000 (20:02 +0700)]
git-clone.txt: remove shallow clone limitations

Now that git supports data transfer from or to a shallow clone, these
limitations are not true anymore.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoprune: clean .git/shallow after pruning objects
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:54 +0000 (20:02 +0700)]
prune: clean .git/shallow after pruning objects

This patch teaches "prune" to remove shallow roots that are no longer
reachable from any refs (e.g. when the relevant refs are removed).

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoclone: use git protocol for cloning shallow repo locally
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:53 +0000 (20:02 +0700)]
clone: use git protocol for cloning shallow repo locally

clone_local() does not handle $SRC/shallow. It could be made so, but
it's simpler to use fetch-pack/upload-pack instead.

This used to be caught by the check in upload-pack, which is triggered
by transport_get_remote_refs(), even in local clone case. The check is
now gone and check_everything_connected() should catch the result
incomplete repo. But check_everything_connected() will soon be skipped
in local clone case, opening a door to corrupt repo. This patch should
close that door.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agosend-pack: support pushing from a shallow clone via http
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:52 +0000 (20:02 +0700)]
send-pack: support pushing from a shallow clone via http

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoreceive-pack: support pushing to a shallow clone via http
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:51 +0000 (20:02 +0700)]
receive-pack: support pushing to a shallow clone via http

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agosmart-http: support shallow fetch/clone
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:50 +0000 (20:02 +0700)]
smart-http: support shallow fetch/clone

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoremote-curl: pass ref SHA-1 to fetch-pack as well
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:49 +0000 (20:02 +0700)]
remote-curl: pass ref SHA-1 to fetch-pack as well

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agosend-pack: support pushing to a shallow clone
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:48 +0000 (20:02 +0700)]
send-pack: support pushing to a shallow clone

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoreceive-pack: allow pushes that update .git/shallow
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:47 +0000 (20:02 +0700)]
receive-pack: allow pushes that update .git/shallow

The basic 8 steps to update .git/shallow does not fully apply here
because the user may choose to accept just a few refs (while fetch
always accepts all refs). The steps are modified a bit.

1-6. same as before. After calling assign_shallow_commits_to_refs at
   step 6, each shallow commit has a bitmap that marks all refs that
   require it.

7. mark all "ours" shallow commits that are reachable from any
   refs. We will need to do the original step 7 on them later.

8. go over all shallow commit bitmaps, mark refs that require new
   shallow commits.

9. setup a strict temporary shallow file to plug all the holes, even
   if it may cut some of our history short. This file is used by all
   hooks. The hooks could use --shallow-file=$GIT_DIR/shallow to
   overcome this and reach everything in current repo.

10. go over the new refs one by one. For each ref, do the reachability
   test if it needs a shallow commit on the list from step 7. Remove
   it if it's reachable from our refs. Gather all required shallow
   commits, run check_everything_connected() with the new ref, then
   install them to .git/shallow.

This mode is disabled by default and can be turned on with
receive.shallowupdate

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoconnected.c: add new variant that runs with --shallow-file
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:46 +0000 (20:02 +0700)]
connected.c: add new variant that runs with --shallow-file

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoadd GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:45 +0000 (20:02 +0700)]
add GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses

This may be needed when a hook is run after a new shallow pack is
received, but .git/shallow is not settled yet. A temporary shallow
file to plug all loose ends should be used instead. GIT_SHALLOW_FILE
is overriden by --shallow-file.

--shallow-file does not work in this case because the hook may spawn
many git subprocesses and the launch commands do not have
--shallow-file as it's a recent addition.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoreceive/send-pack: support pushing from a shallow clone
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:44 +0000 (20:02 +0700)]
receive/send-pack: support pushing from a shallow clone

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoreceive-pack: reorder some code in unpack()
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:43 +0000 (20:02 +0700)]
receive-pack: reorder some code in unpack()

This is the preparation for adding --shallow-file to both
unpack-objects and index-pack. To sum up:

 - struct argv_array used instead of const char **

 - status/code, ip/child, unpacker/keeper are moved out to function
   top level

 - successful flow now ends at the end of the function

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agofetch: add --update-shallow to accept refs that update .git/shallow
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:42 +0000 (20:02 +0700)]
fetch: add --update-shallow to accept refs that update .git/shallow

The same steps are done as in when --update-shallow is not given. The
only difference is we now add all shallow commits in "ours" and
"theirs" to .git/shallow (aka "step 8").

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoupload-pack: make sure deepening preserves shallow roots
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:41 +0000 (20:02 +0700)]
upload-pack: make sure deepening preserves shallow roots

When "fetch --depth=N" where N exceeds the longest chain of history in
the source repo, usually we just send an "unshallow" line to the
client so full history is obtained.

When the source repo is shallow we need to make sure to "unshallow"
the current shallow point _and_ "shallow" again when the commit
reaches its shallow bottom in the source repo.

This should fix both cases: large <N> and --unshallow.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agofetch: support fetching from a shallow repository
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:40 +0000 (20:02 +0700)]
fetch: support fetching from a shallow repository

This patch just put together pieces from the 8 steps patch. We stop at
step 7 and reject refs that require new shallow commits.

Note that, by rejecting refs that require new shallow commits, we
leave dangling objects in the repo, which become "object islands" by
the next "git fetch" of the same source.

If the first fetch our "ours" set is zero and we do practically
nothing at step 7, "ours" is full at the next fetch and we may need to
walk through commits for reachability test. Room for improvement.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoclone: support remote shallow repository
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:39 +0000 (20:02 +0700)]
clone: support remote shallow repository

Cloning from a shallow repository does not follow the "8 steps for new
.git/shallow" because if it does we need to get through step 6 for all
refs. That means commit walking down to the bottom.

Instead the rule to create .git/shallow is simpler and, more
importantly, cheap: if a shallow commit is found in the pack, it's
probably used (i.e. reachable from some refs), so we add it. Others
are dropped.

One may notice this method seems flawed by the word "probably". A
shallow commit may not be reachable from any refs at all if it's
attached to an object island (a group of objects that are not
reachable by any refs).

If that object island is not complete, a new fetch request may send
more objects to connect it to some ref. At that time, because we
incorrectly installed the shallow commit in this island, the user will
not see anything after that commit (fsck is still ok). This is not
desired.

Given that object islands are rare (C Git never sends such islands for
security reasons) and do not really harm the repository integrity, a
tradeoff is made to surprise the user occasionally but work faster
everyday.

A new option --strict could be added later that follows exactly the 8
steps. "git prune" can also learn to remove dangling objects _and_ the
shallow commits that are attached to them from .git/shallow.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agofetch-pack.h: one statement per bitfield declaration
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:38 +0000 (20:02 +0700)]
fetch-pack.h: one statement per bitfield declaration

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agofetch-pack.c: move shallow update code out of fetch_pack()
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:37 +0000 (20:02 +0700)]
fetch-pack.c: move shallow update code out of fetch_pack()

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoshallow.c: steps 6 and 7 to select new commits for .git/shallow
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:36 +0000 (20:02 +0700)]
shallow.c: steps 6 and 7 to select new commits for .git/shallow

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoshallow.c: the 8 steps to select new commits for .git/shallow
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:35 +0000 (20:02 +0700)]
shallow.c: the 8 steps to select new commits for .git/shallow

Suppose a fetch or push is requested between two shallow repositories
(with no history deepening or shortening). A pack that contains
necessary objects is transferred over together with .git/shallow of
the sender. The receiver has to determine whether it needs to update
.git/shallow if new refs needs new shallow comits.

The rule here is avoid updating .git/shallow by default. But we don't
want to waste the received pack. If the pack contains two refs, one
needs new shallow commits installed in .git/shallow and one does not,
we keep the latter and reject/warn about the former.

Even if .git/shallow update is allowed, we only add shallow commits
strictly necessary for the former ref (remember the sender can send
more shallow commits than necessary) and pay attention not to
accidentally cut the receiver history short (no history shortening is
asked for)

So the steps to figure out what ref need what new shallow commits are:

1. Split the sender shallow commit list into "ours" and "theirs" list
   by has_sha1_file. Those that exist in current repo in "ours", the
   remaining in "theirs".

2. Check the receiver .git/shallow, remove from "ours" the ones that
   also exist in .git/shallow.

3. Fetch the new pack. Either install or unpack it.

4. Do has_sha1_file on "theirs" list again. Drop the ones that fail
   has_sha1_file. Obviously the new pack does not need them.

5. If the pack is kept, remove from "ours" the ones that do not exist
   in the new pack.

6. Walk the new refs to answer the question "what shallow commits,
   both ours and theirs, are required in .git/shallow in order to add
   this ref?". Shallow commits not associated to any refs are removed
   from their respective list.

7. (*) Check reachability (from the current refs) of all remaining
   commits in "ours". Those reachable are removed. We do not want to
   cut any part of our (reachable) history. We only check up
   commits. True reachability test is done by
   check_everything_connected() at the end as usual.

8. Combine the final "ours" and "theirs" and add them all to
   .git/shallow. Install new refs. The case where some hook rejects
   some refs on a push is explained in more detail in the push
   patches.

Of these steps, #6 and #7 are expensive. Both require walking through
some commits, or in the worst case all commits. And we rather avoid
them in at least common case, where the transferred pack does not
contain any shallow commits that the sender advertises. Let's look at
each scenario:

1) the sender has longer history than the receiver

   All shallow commits from the sender will be put into "theirs" list
   at step 1 because none of them exists in current repo. In the
   common case, "theirs" becomes empty at step 4 and exit early.

2) the sender has shorter history than the receiver

   All shallow commits from the sender are likely in "ours" list at
   step 1. In the common case, if the new pack is kept, we could empty
   "ours" and exit early at step 5.

   If the pack is not kept, we hit the expensive step 6 then exit
   after "ours" is emptied. There'll be only a handful of objects to
   walk in fast-forward case. If it's forced update, we may need to
   walk to the bottom.

3) the sender has same .git/shallow as the receiver

   This is similar to case 2 except that "ours" should be emptied at
   step 2 and exit early.

A fetch after "clone --depth=X" is case 1. A fetch after "clone" (from
a shallow repo) is case 3. Luckily they're cheap for the common case.

A push from "clone --depth=X" falls into case 2, which is expensive.
Some more work may be done at the sender/client side to avoid more
work on the server side: if the transferred pack does not contain any
shallow commits, send-pack should not send any shallow commits to the
receive-pack, effectively turning it into a normal push and avoid all
steps.

This patch implements all steps except #3, already handled by
fetch-pack and receive-pack, #6 and #7, which has their own patch due
to their size.

(*) in previous versions step 7 was put before step 3. I reorder it so
    that the common case that keeps the pack does not need to walk
    commits at all. In future if we implement faster commit
    reachability check (maybe with the help of pack bitmaps or commit
    cache), step 7 could become cheap and be moved up before 6 again.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoshallow.c: extend setup_*_shallow() to accept extra shallow commits
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:34 +0000 (20:02 +0700)]
shallow.c: extend setup_*_shallow() to accept extra shallow commits

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoconnect.c: teach get_remote_heads to parse "shallow" lines
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:33 +0000 (20:02 +0700)]
connect.c: teach get_remote_heads to parse "shallow" lines

No callers pass a non-empty pointer as shallow_points at this
stage. As a result, all clients still refuse to talk to shallow
repository on the other end.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agomake the sender advertise shallow commits to the receiver
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:32 +0000 (20:02 +0700)]
make the sender advertise shallow commits to the receiver

If either receive-pack or upload-pack is called on a shallow
repository, shallow commits (*) will be sent after the ref
advertisement (but before the packet flush), so that the receiver has
the full "shape" of the sender's commit graph. This will be needed for
the receiver to update its .git/shallow if necessary.

This breaks the protocol for all clients trying to push to a shallow
repo, or fetch from one. Which is basically the same end result as
today's "is_repository_shallow() && die()" in receive-pack and
upload-pack. New clients will be made aware of shallow upstream and
can make use of this information.

The sender must send all shallow commits that are sent in the
following pack. It may send more shallow commits than necessary.

upload-pack for example may choose to advertise no shallow commits if
it knows in advance that the pack it's going to send contains no
shallow commits. But upload-pack is the server, so we choose the
cheaper way, send full .git/shallow and let the client deal with it.

Smart HTTP is not affected by this patch. Shallow support on
smart-http comes later separately.

(*) A shallow commit is a commit that terminates the revision
    walker. It is usually put in .git/shallow in order to keep the
    revision walker from going out of bound because there is no
    guarantee that objects behind this commit is available.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoclone: prevent --reference to a shallow repository
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:31 +0000 (20:02 +0700)]
clone: prevent --reference to a shallow repository

If we borrow objects from another repository, we should also pay
attention to their $GIT_DIR/shallow (and even info/grafts). But
current alternates code does not.

Reject alternate repos that are shallow because we do not do it
right. In future the alternate code may be updated to check
$GIT_DIR/shallow properly so that this restriction could be lifted.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agosend-pack: forbid pushing from a shallow repository
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:30 +0000 (20:02 +0700)]
send-pack: forbid pushing from a shallow repository

send-pack can send a pack with loose ends to the server.  receive-pack
before 6d4bb38 (fetch: verify we have everything we need before
updating our ref - 2011-09-01) does not detect this and keeps the pack
anyway, which corrupts the repository, at least from fsck point of
view.

send-pack will learn to safely push from a shallow repository later.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
12 years agoremote.h: replace struct extra_have_objects with struct sha1_array
Nguyễn Thái Ngọc Duy [Thu, 5 Dec 2013 13:02:29 +0000 (20:02 +0700)]
remote.h: replace struct extra_have_objects with struct sha1_array

The latter can do everything the former can and is used in many more
places.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
Signed-off-by: Junio C Hamano <redacted>
git clone https://git.99rst.org/PROJECT