git
9 years agocheckout: check_linked_checkout: simplify symref parsing
Eric Sunshine [Fri, 17 Jul 2015 23:00:02 +0000 (19:00 -0400)] 
checkout: check_linked_checkout: simplify symref parsing

check_linked_checkout() only understands symref-style HEAD (i.e. "ref:
refs/heads/master"), however, HEAD may also be a an actual symbolic link
(on platforms which support it), thus it will need to check that style
HEAD, as well (via readlink()). As a preparatory step, simplify parsing
of symref-style HEAD so the actual branch check can be re-used easily
for symbolic links (in an upcoming patch).

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: check_linked_checkout: improve "already checked out" aesthetic
Eric Sunshine [Fri, 17 Jul 2015 23:00:01 +0000 (19:00 -0400)] 
checkout: check_linked_checkout: improve "already checked out" aesthetic

When check_linked_checkout() discovers that the branch is already
checked out elsewhere, it emits the diagnostic:

    'blorp' is already checked out at '/some/path/.git'

which is misleading since "checked out at" implies the working tree, but
".git" is the location of the repository administrative files. Fix by
dropping ".git" from the message.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: generalize die_if_checked_out() branch name argument
Eric Sunshine [Fri, 17 Jul 2015 23:00:00 +0000 (19:00 -0400)] 
checkout: generalize die_if_checked_out() branch name argument

The plan is to publish die_if_checked_out() so that callers other than
git-checkout can take advantage of it, however, those callers won't have
access to git-checkout's "struct branch_info". Therefore, change it to
accept the full name of the branch as a simple string instead.

While here, also give the argument a more meaningful name ("branch"
instead of "new").

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: die_if_checked_out: simplify strbuf management
Eric Sunshine [Fri, 17 Jul 2015 22:59:59 +0000 (18:59 -0400)] 
checkout: die_if_checked_out: simplify strbuf management

There is no reason to keep the strbuf active long after its last use.
By releasing it as early as possible, resource management is simplified
and there is less worry about future changes resulting in a leak.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: improve die_if_checked_out() robustness
Eric Sunshine [Fri, 17 Jul 2015 22:59:58 +0000 (18:59 -0400)] 
checkout: improve die_if_checked_out() robustness

die_if_checked_out() is intended to check if the branch about to be
checked out is already checked out either in the main worktree or in a
linked worktree. However, if .git/worktrees directory does not exist,
then it never bothers checking the main worktree, even though the
specified branch might indeed be checked out there, which is fragile
behavior.

This hasn't been a problem in practice since the current implementation
of "git worktree add" (and, earlier, "git checkout --to") always creates
.git/worktrees before die_if_checked_out() is called by the child "git
checkout" invocation which populates the new worktree.

However, git-worktree will eventually want to call die_if_checked_out()
itself rather than only doing so indirectly as a side-effect of invoking
git-checkout, and reliance upon order of operations (creating
.git/worktrees before checking if a branch is already checked out) is
fragile. As a general function, callers should not be expected to abide
by this undocumented and unwarranted restriction. Therefore, make
die_if_checked_out() more robust by checking the main worktree whether
.git/worktrees exists or not.

While here, also move a comment explaining why die_if_checked_out()'s
helper parses HEAD manually. Such information resides more naturally
with the helper itself rather than at its first point of call.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: name check_linked_checkouts() more meaningfully
Eric Sunshine [Fri, 17 Jul 2015 22:59:57 +0000 (18:59 -0400)] 
checkout: name check_linked_checkouts() more meaningfully

check_linked_checkouts() doesn't just "check" linked checkouts for
"something"; specifically, it aborts the operation if the branch about
to be checked out is already checked out elsewhere. Therefore, rename it
to die_if_checked_out() to give a better indication of its function.
The more meaningful name will be particularly important when this
function is later published for use by other callers.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: avoid resolving HEAD unnecessarily
Eric Sunshine [Fri, 17 Jul 2015 22:59:56 +0000 (18:59 -0400)] 
checkout: avoid resolving HEAD unnecessarily

When --ignore-other-worktree is specified, we unconditionally skip the
check to see if the requested branch is already checked out in a linked
worktree. Since we know that we will be skipping that check, there is no
need to resolve HEAD in order to detect other conditions under which we
may skip the check.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoconfig: rename "gc.pruneWorktreesExpire" to "gc.worktreePruneExpire"
Eric Sunshine [Mon, 20 Jul 2015 05:29:22 +0000 (01:29 -0400)] 
config: rename "gc.pruneWorktreesExpire" to "gc.worktreePruneExpire"

As of df0b6cf (worktree: new place for "git prune --worktrees",
2015-06-29), linked worktree pruning functionality moved from
"git prune --worktrees" to "git worktree prune". Rename the
associated configuration variable accordingly.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: wordsmith worktree-related manpages
Michael Haggerty [Mon, 20 Jul 2015 05:29:21 +0000 (01:29 -0400)] 
Documentation/git-worktree: wordsmith worktree-related manpages

[es: reword .git/worktrees and .git/worktrees/<id>/locked descriptions]

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/config: fix stale "git prune --worktree" reference
Michael Haggerty [Mon, 20 Jul 2015 05:29:20 +0000 (01:29 -0400)] 
Documentation/config: fix stale "git prune --worktree" reference

This should have been changed to "git worktree prune" by df0b6cf
(worktree: new place for "git prune --worktrees", 2015-06-29)

[es: reword commit message]

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: fix incorrect reference to file "locked"
Michael Haggerty [Mon, 20 Jul 2015 05:29:19 +0000 (01:29 -0400)] 
Documentation/git-worktree: fix incorrect reference to file "locked"

The administrative file to suppress pruning is named "locked", not "lock".

[es: don't touch unrelated "git worktree lock" command; reword commit
message]

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: consistently use term "linked working tree"
Michael Haggerty [Mon, 20 Jul 2015 05:29:18 +0000 (01:29 -0400)] 
Documentation/git-worktree: consistently use term "linked working tree"

Sometimes linked working trees were called "linked working
directories" or "linked worktrees". Always refer to them as "linked
working trees" for consistency.

[es: fix additional occurrences]

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git: fix stale "MULTIPLE CHECKOUT MODE" reference
Eric Sunshine [Fri, 17 Jul 2015 00:17:02 +0000 (20:17 -0400)] 
Documentation/git: fix stale "MULTIPLE CHECKOUT MODE" reference

This should have been changed by 93a3649 (Documentation: move linked
worktree description from checkout to worktree, 2015-07-06).

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: caution that this is still experimental
Junio C Hamano [Thu, 16 Jul 2015 22:59:48 +0000 (15:59 -0700)] 
worktree: caution that this is still experimental

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: fix stale "git checkout --to" references
Eric Sunshine [Thu, 16 Jul 2015 22:09:43 +0000 (18:09 -0400)] 
Documentation/git-worktree: fix stale "git checkout --to" references

These should have been changed to "git worktree add" by fc56361
(worktree: introduce "add" command, 2015-07-06.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoRevert "checkout: retire --ignore-other-worktrees in favor of --force"
Junio C Hamano [Sun, 12 Jul 2015 16:38:21 +0000 (09:38 -0700)] 
Revert "checkout: retire --ignore-other-worktrees in favor of --force"

This reverts commit 0d1a1517835a10818f2d40d8780a268dbb5e20ce.

When trying to switch to a different branch, that happens to be
checked out in another working tree, the user shouldn't have to
give up the other safety measures (like protecting the local changes
that overlap the difference between the branches) while defeating
the "no two checkouts of the same branch" safety.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: retire --ignore-other-worktrees in favor of --force
Eric Sunshine [Mon, 6 Jul 2015 17:31:00 +0000 (13:31 -0400)] 
checkout: retire --ignore-other-worktrees in favor of --force

As a safeguard, checking out a branch already checked out by a different
worktree is disallowed. This behavior can be overridden with
--ignore-other-worktrees, however, this option is neither obvious nor
particularly discoverable. As a common safeguard override, --force is
more likely to come to mind. Therefore, overload it to also suppress the
check for a branch already checked out elsewhere.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: add: auto-vivify new branch when <branch> is omitted
Eric Sunshine [Mon, 6 Jul 2015 17:30:59 +0000 (13:30 -0400)] 
worktree: add: auto-vivify new branch when <branch> is omitted

As a convenience, when <branch> is omitted from "git worktree <path>
<branch>" and neither -b nor -B is used, automatically create a new
branch named after <path>, as if "-b $(basename <path>)" was specified.
Thus, "git worktree add ../hotfix" creates a new branch named "hotfix"
and associates it with new worktree "../hotfix".

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: add: make -b/-B default to HEAD when <branch> is omitted
Eric Sunshine [Mon, 6 Jul 2015 17:30:58 +0000 (13:30 -0400)] 
worktree: add: make -b/-B default to HEAD when <branch> is omitted

As a convenience, like "git branch" and "git checkout -b", make
"git worktree add -b <newbranch> <path> <branch>" default to HEAD when
<branch> is omitted.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: extract basename computation to new function
Eric Sunshine [Mon, 6 Jul 2015 17:30:57 +0000 (13:30 -0400)] 
worktree: extract basename computation to new function

A subsequent patch will also need to compute the basename of the new
worktree, so factor out this logic into a new function.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: require worktree unconditionally
Eric Sunshine [Mon, 6 Jul 2015 17:30:56 +0000 (13:30 -0400)] 
checkout: require worktree unconditionally

In order to allow linked worktree creation via "git checkout --to" from
a bare repository, 3473ad0 (checkout: don't require a work tree when
checking out into a new one, 2014-11-30) dropped git-checkout's
unconditional NEED_WORK_TREE requirement and instead performed worktree
setup conditionally based upon presence or absence of the --to option.
Now that --to has been retired and git-checkout is no longer responsible
for linked worktree creation, the NEED_WORK_TREE requirement can be
re-instated.

This effectively reverts 3473ad0, except for the tests it added which
now check bare repository behavior of "git worktree add" instead.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: retire --to option
Eric Sunshine [Mon, 6 Jul 2015 17:30:55 +0000 (13:30 -0400)] 
checkout: retire --to option

Now that "git worktree add" has achieved user-facing feature-parity with
"git checkout --to", retire the latter.

Move the actual linked worktree creation functionality,
prepare_linked_checkout() and its helpers, verbatim from checkout.c to
worktree.c.

This effectively reverts changes to checkout.c by 529fef2 (checkout:
support checking out into a new working directory, 2014-11-30) with the
exception of merge_working_tree() and switch_branches() which still
require specialized knowledge that a the checkout is occurring in a
newly-created linked worktree (signaled to them by the private
GIT_CHECKOUT_NEW_WORKTREE environment variable).

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agotests: worktree: retrofit "checkout --to" tests for "worktree add"
Eric Sunshine [Mon, 6 Jul 2015 17:30:54 +0000 (13:30 -0400)] 
tests: worktree: retrofit "checkout --to" tests for "worktree add"

With the introduction of "git worktree add", "git checkout --to" is
slated for removal. Therefore, retrofit linked worktree creation tests
to use "git worktree add" instead.

(The test to check exclusivity of "checkout --to" and "checkout <paths>"
is dropped altogether since it becomes meaningless with retirement of
"checkout --to".)

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: add -b/-B options
Eric Sunshine [Mon, 6 Jul 2015 17:30:53 +0000 (13:30 -0400)] 
worktree: add -b/-B options

One of git-worktree's roles is to populate the new worktree, much like
git-checkout, and thus, for convenience, ought to support several of the
same shortcuts. Toward this goal, add -b/-B options to create a new
branch and check it out in the new worktree.

(For brevity, only -b is mentioned in the synopsis; -B is omitted.)

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: add --detach option
Eric Sunshine [Mon, 6 Jul 2015 17:30:52 +0000 (13:30 -0400)] 
worktree: add --detach option

One of git-worktree's roles is to populate the new worktree, much like
git-checkout, and thus, for convenience, ought to support several of the
same shortcuts. Toward this goal, add a --detach option to detach HEAD
in the new worktree.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: add --force option
Eric Sunshine [Mon, 6 Jul 2015 17:30:51 +0000 (13:30 -0400)] 
worktree: add --force option

By default, "git worktree add" refuses to create a new worktree when
the requested branch is already checked out elsewhere. Add a --force
option to override this safeguard.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: introduce "add" command
Eric Sunshine [Mon, 6 Jul 2015 17:30:50 +0000 (13:30 -0400)] 
worktree: introduce "add" command

The plan is to relocate "git checkout --to" functionality to "git
worktree add". As a first step, introduce a bare-bones git-worktree
"add" command along with documentation. At this stage, "git worktree
add" merely invokes "git checkout --to" behind the scenes, but an
upcoming patch will move the actual functionality
(checkout.c:prepare_linked_checkout() and its helpers) to worktree.c.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: drop 'checkout_opts' dependency from prepare_linked_checkout
Eric Sunshine [Mon, 6 Jul 2015 17:30:49 +0000 (13:30 -0400)] 
checkout: drop 'checkout_opts' dependency from prepare_linked_checkout

The plan is to relocate "git checkout --to" functionality to "git
worktree add", however, worktree.c won't have access to the 'struct
checkout_opts' passed to prepare_linked_worktree(), which it consults
for the pathname of the new worktree and the argv[] of the command it
should run to populate the new worktree. Facilitate relocation of
prepare_linked_worktree() by instead having it accept the pathname and
argv[] directly, thus eliminating the final references to 'struct
checkout_opts'.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: make --to unconditionally verbose
Eric Sunshine [Mon, 6 Jul 2015 17:30:48 +0000 (13:30 -0400)] 
checkout: make --to unconditionally verbose

prepare_linked_checkout() respects git-checkout's --quiet flag, however,
the plan is to relocate "git checkout --to" functionality to "git
worktree add", and git-worktree does not (yet) have a --quiet flag.
Consequently, make prepare_linked_checkout() unconditionally verbose to
ease eventual code movement to worktree.c.

(A --quiet flag can be added to git-worktree later if there is demand
for it.)

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: prepare_linked_checkout: drop now-unused 'new' argument
Eric Sunshine [Mon, 6 Jul 2015 17:30:47 +0000 (13:30 -0400)] 
checkout: prepare_linked_checkout: drop now-unused 'new' argument

The only references to 'new' were folded out by the last two patches.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: relocate --to's "no branch specified" check
Eric Sunshine [Mon, 6 Jul 2015 17:30:46 +0000 (13:30 -0400)] 
checkout: relocate --to's "no branch specified" check

The plan is to relocate "git checkout --to" functionality to "git
worktree add", however, this check expects a 'struct branch_info' which
git-worktree won't have at hand. It will, however, have access to its
own command-line from which it can pick up the branch name. Therefore,
as a preparatory step, rather than having prepare_linked_checkout()
perform this check, make it the caller's responsibility.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: fix bug with --to and relative HEAD
Eric Sunshine [Mon, 6 Jul 2015 17:30:45 +0000 (13:30 -0400)] 
checkout: fix bug with --to and relative HEAD

Given "git checkout --to <path> HEAD~1", the new worktree's HEAD should
begin life at the current branch's HEAD~1, however, it actually ends up
at HEAD~2. This happens because:

    1. git-checkout resolves HEAD~1

    2. to satisfy is_git_directory(), prepare_linked_worktree() creates
       a HEAD for the new worktree with the value of the resolved HEAD~1

    3. git-checkout re-invokes itself with the same arguments within the
       new worktree to populate the worktree

    4. the sub git-checkout resolves HEAD~1 relative to its own HEAD,
       which is the resolved HEAD~1 from the original invocation,
       resulting unexpectedly and incorrectly in HEAD~2 (relative to the
       original)

Fix this by unconditionally assigning the current worktree's HEAD as the
value of the new worktree's HEAD.

As a side-effect, this change also eliminates a dependence within
prepare_linked_checkout() upon 'struct branch_info'. The plan is to
eventually relocate "git checkout --to" functionality to "git worktree
add", and worktree.c won't have knowledge of 'struct branch_info', so
removal of this dependency is a step toward that goal.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: add EXAMPLES section
Eric Sunshine [Mon, 6 Jul 2015 17:30:44 +0000 (13:30 -0400)] 
Documentation/git-worktree: add EXAMPLES section

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: add high-level 'lock' overview
Eric Sunshine [Mon, 6 Jul 2015 17:30:43 +0000 (13:30 -0400)] 
Documentation/git-worktree: add high-level 'lock' overview

Due to the (current) absence of a "git worktree lock" command, locking
a worktree's administrative files to prevent automatic pruning is a
manual task, necessarily requiring low-level understanding of linked
worktree functionality. However, this level of detail does not belong
in the high-level DESCRIPTION section, so add a generalized discussion
of locking to DESCRIPTION and move the technical information to DETAILS.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: split technical info from general description
Eric Sunshine [Mon, 6 Jul 2015 17:30:42 +0000 (13:30 -0400)] 
Documentation/git-worktree: split technical info from general description

The DESCRIPTION section should provide a high-level overview of linked
worktree functionality to bring users up to speed quickly, without
overloading them with low-level details, so relocate the technical
information to a new DETAILS section.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: add BUGS section
Eric Sunshine [Mon, 6 Jul 2015 17:30:41 +0000 (13:30 -0400)] 
Documentation/git-worktree: add BUGS section

Relocate submodule warning to BUGS and enumerate missing commands.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation: move linked worktree description from checkout to worktree
Eric Sunshine [Mon, 6 Jul 2015 17:30:40 +0000 (13:30 -0400)] 
Documentation: move linked worktree description from checkout to worktree

Now that the git-worktree command exists, its documentation page is the
natural place for the linked worktree description to reside. Relocate
the "MULTIPLE WORKING TREES" description verbatim from git-checkout.txt
to git-worktree.txt.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-worktree: associate options with commands
Eric Sunshine [Mon, 6 Jul 2015 17:30:39 +0000 (13:30 -0400)] 
Documentation/git-worktree: associate options with commands

git-worktree options affect some worktree commands but not others, but
this is not necessarily obvious from the option descriptions. Make this
clear by indicating explicitly which commands are affected by which
options.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoDocumentation/git-checkout: fix incorrect worktree prune command
Eric Sunshine [Mon, 6 Jul 2015 17:30:38 +0000 (13:30 -0400)] 
Documentation/git-checkout: fix incorrect worktree prune command

This was missed when "git prune --worktrees" became "git worktree prune".

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoworktree: new place for "git prune --worktrees"
Nguyễn Thái Ngọc Duy [Mon, 29 Jun 2015 12:51:18 +0000 (19:51 +0700)] 
worktree: new place for "git prune --worktrees"

Commit 23af91d (prune: strategies for linked checkouts - 2014-11-30)
adds "--worktrees" to "git prune" without realizing that "git prune" is
for object database only. This patch moves the same functionality to a
new command "git worktree".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
9 years agocheckout: don't check worktrees when not necessary
Nguyễn Thái Ngọc Duy [Fri, 12 Jun 2015 10:49:24 +0000 (17:49 +0700)] 
checkout: don't check worktrees when not necessary

When --patch or pathspecs are passed to git checkout, the working tree
will not be switching branch, so there's no need to check if the branch
that we are running checkout on is already checked out.

Original-patch-by: Spencer Baugh <sbaugh@catern.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoprune --worktrees: fix expire vs worktree existence condition
Max Kirillov [Mon, 30 Mar 2015 20:47:47 +0000 (23:47 +0300)] 
prune --worktrees: fix expire vs worktree existence condition

`git prune --worktrees` was pruning worktrees which were non-existent OR
expired, while it rather should prune those which are orphaned AND
expired, as git-checkout documentation describes. Fix it.

Add test 'not prune proper checkouts', which uses valid but expired
worktree.

Modify test 'not prune recent checkouts' to remove the worktree before
pruning - link in worktrees still must survive. In older form it is
useless because would pass always when the other test passes.

Signed-off-by: Max Kirillov <max@max630.net>
Acked-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agot1501: fix test with split index
Thomas Gummerer [Tue, 24 Mar 2015 19:21:40 +0000 (20:21 +0100)] 
t1501: fix test with split index

t1501-worktree.sh does not copy the shared index in the "relative
$GIT_WORK_TREE and git subprocesses" test, which makes the test fail
when GIT_TEST_SPLIT_INDEX is set.  Copy the shared index as well in
order to fix this.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agot2026: fix broken &&-chain
Junio C Hamano [Fri, 20 Mar 2015 17:44:12 +0000 (10:44 -0700)] 
t2026: fix broken &&-chain

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agot2026 needs procondition SANITY
Torsten Bögershausen [Tue, 27 Jan 2015 15:38:49 +0000 (16:38 +0100)] 
t2026 needs procondition SANITY

When running t0026 as root 'prune directories with unreadable gitdir' fails.
Skip this test if SANITY is not set (the use of POSIXPERM is wrong here)

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogit-checkout.txt: a note about multiple checkout support for submodules
Nguyễn Thái Ngọc Duy [Sat, 3 Jan 2015 09:41:27 +0000 (16:41 +0700)] 
git-checkout.txt: a note about multiple checkout support for submodules

The goal seems to be using multiple checkouts to reduce disk space.
But we have not reached an agreement how things should be. There are a
couple options.

 - You may want to keep $SUB repos elsewhere (perhaps in a central
   place) outside $SUPER. This is also true for nested submodules
   where a superproject may be a submodule of another superproject.

 - You may want to keep all $SUB repos in $SUPER/modules (or some
   other place in $SUPER)

 - We could even push it further and merge all $SUB repos into $SUPER
   instead of storing them separately. But that would at least require
   ref namespace enabled.

On top of that, git-submodule.sh expects $GIT_DIR/config to be
per-worktree, at least for the submodule.* part. Here I think we have
two options, either update config.c to also read
$GIT_DIR/config.worktree (which is per worktree) in addition to
$GIT_DIR/config (shared) and store worktree-specific vars in the new
place, or update git-submodule.sh to read/write submodule.* directly
from $GIT_DIR/config.submodule (per worktree).

These take time to address properly. Meanwhile, make a note to the
user that they should not use multiple worktrees in submodule context.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: add --ignore-other-wortrees
Nguyễn Thái Ngọc Duy [Sat, 3 Jan 2015 09:41:26 +0000 (16:41 +0700)] 
checkout: add --ignore-other-wortrees

Noticed-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: pass whole struct to parse_branchname_arg instead of individual flags
Nguyễn Thái Ngọc Duy [Sat, 3 Jan 2015 09:41:25 +0000 (16:41 +0700)] 
checkout: pass whole struct to parse_branchname_arg instead of individual flags

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogit-common-dir: make "modules/" per-working-directory directory
Max Kirillov [Sun, 30 Nov 2014 08:24:59 +0000 (15:24 +0700)] 
git-common-dir: make "modules/" per-working-directory directory

Each working directory of main repository has its own working directory
of submodule, and in most cases they should be checked out to different
revisions. So they should be separated.

It looks logical to make submodule instances in different working
directories to reuse the submodule directory in the common dir of
the main repository, and probably this is how "checkout --to" should
initialize them called on the main repository, but they also should work
fine being completely separated clones.

Testfile t7410-submodule-checkout-to.sh demostrates the behavior.

Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: do not fail if target is an empty directory
Max Kirillov [Sun, 30 Nov 2014 08:24:58 +0000 (15:24 +0700)] 
checkout: do not fail if target is an empty directory

Non-recursive checkout creates empty directpries in place of submodules.
If then I try to "checkout --to" submodules there, it refuses to do so,
because directory already exists.

Fix by allowing checking out to empty directory. Add test and modify the
existing one so that it uses non-empty directory.

Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agot2025: add a test to make sure grafts is working from a linked checkout
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:57 +0000 (15:24 +0700)] 
t2025: add a test to make sure grafts is working from a linked checkout

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: don't require a work tree when checking out into a new one
Dennis Kaarsemaker [Sun, 30 Nov 2014 08:24:56 +0000 (15:24 +0700)] 
checkout: don't require a work tree when checking out into a new one

For normal use cases, it does not make sense for 'checkout' to work on
a bare repository, without a worktree. But "checkout --to" is an
exception because it _creates_ a new worktree. Allow this option to
run on bare repositories.

People who check out from a bare repository should remember that
core.logallrefupdates is off by default and it should be turned back
on. `--to` cannot do this automatically behind the user's back because
some user may deliberately want no reflog.

For people interested in repository setup/discovery code,
is_bare_repository_cfg (aka "core.bare") is unchanged by this patch,
which means 'true' by default for bare repos. Fortunately when we get
the repo through a linked checkout, is_bare_repository_cfg is never
used. So all is still good.

[nd: commit message]

Signed-off-by: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogit_path(): keep "info/sparse-checkout" per work-tree
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:55 +0000 (15:24 +0700)] 
git_path(): keep "info/sparse-checkout" per work-tree

Currently git_path("info/sparse-checkout") resolves to
$GIT_COMMON_DIR/info/sparse-checkout in multiple worktree mode. It
makes more sense for the sparse checkout patterns to be per worktree,
so you can have multiple checkouts with different parts of the tree.

With this, "git checkout --to <new>" on a sparse checkout will create
<new> as a full checkout. Which is expected, it's how a new checkout
is made. The user can reshape the worktree afterwards.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocount-objects: report unused files in $GIT_DIR/worktrees/...
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:54 +0000 (15:24 +0700)] 
count-objects: report unused files in $GIT_DIR/worktrees/...

In linked checkouts, borrowed parts like config is taken from
$GIT_COMMON_DIR. $GIT_DIR/config is never used. Report them as
garbage.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogc: support prune --worktrees
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:53 +0000 (15:24 +0700)] 
gc: support prune --worktrees

Helped-by: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogc: factor out gc.pruneexpire parsing code
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:52 +0000 (15:24 +0700)] 
gc: factor out gc.pruneexpire parsing code

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogc: style change -- no SP before closing parenthesis
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:51 +0000 (15:24 +0700)] 
gc: style change -- no SP before closing parenthesis

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: clean up half-prepared directories in --to mode
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:50 +0000 (15:24 +0700)] 
checkout: clean up half-prepared directories in --to mode

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: reject if the branch is already checked out elsewhere
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:49 +0000 (15:24 +0700)] 
checkout: reject if the branch is already checked out elsewhere

One branch obviously can't be checked out at two places (but detached
heads are ok). Give the user a choice in this case: --detach, -b
new-branch, switch branch in the other checkout first or simply 'cd'
and continue to work there.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoprune: strategies for linked checkouts
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:48 +0000 (15:24 +0700)] 
prune: strategies for linked checkouts

(alias R=$GIT_COMMON_DIR/worktrees/<id>)

 - linked checkouts are supposed to keep its location in $R/gitdir up
   to date. The use case is auto fixup after a manual checkout move.

 - linked checkouts are supposed to update mtime of $R/gitdir. If
   $R/gitdir's mtime is older than a limit, and it points to nowhere,
   worktrees/<id> is to be pruned.

 - If $R/locked exists, worktrees/<id> is not supposed to be pruned. If
   $R/locked exists and $R/gitdir's mtime is older than a really long
   limit, warn about old unused repo.

 - "git checkout --to" is supposed to make a hard link named $R/link
   pointing to the .git file on supported file systems to help detect
   the user manually deleting the checkout. If $R/link exists and its
   link count is greated than 1, the repo is kept.

Helped-by: Marc Branchaud <marcnarc@xiplink.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocheckout: support checking out into a new working directory
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:47 +0000 (15:24 +0700)] 
checkout: support checking out into a new working directory

"git checkout --to" sets up a new working directory with a .git file
pointing to $GIT_DIR/worktrees/<id>. It then executes "git checkout"
again on the new worktree with the same arguments except "--to" is
taken out. The second checkout execution, which is not contaminated
with any info from the current repository, will actually check out and
everything that normal "git checkout" does.

Helped-by: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agouse new wrapper write_file() for simple file writing
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:46 +0000 (15:24 +0700)] 
use new wrapper write_file() for simple file writing

This fixes common problems in these code about error handling,
forgetting to close the file handle after fprintf() fails, or not
printing out the error string..

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agowrapper.c: wrapper to open a file, fprintf then close
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:45 +0000 (15:24 +0700)] 
wrapper.c: wrapper to open a file, fprintf then close

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agosetup.c: support multi-checkout repo setup
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:44 +0000 (15:24 +0700)] 
setup.c: support multi-checkout repo setup

The repo setup procedure is updated to detect $GIT_DIR/commondir and
set $GIT_COMMON_DIR properly.

The core.worktree is ignored when $GIT_COMMON_DIR is set. This is
because the config file is shared in multi-checkout setup, but
checkout directories _are_ different. Making core.worktree effective
in all checkouts mean it's back to a single checkout.

Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agosetup.c: detect $GIT_COMMON_DIR check_repository_format_gently()
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:43 +0000 (15:24 +0700)] 
setup.c: detect $GIT_COMMON_DIR check_repository_format_gently()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agosetup.c: convert check_repository_format_gently to use strbuf
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:42 +0000 (15:24 +0700)] 
setup.c: convert check_repository_format_gently to use strbuf

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agosetup.c: detect $GIT_COMMON_DIR in is_git_directory()
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:41 +0000 (15:24 +0700)] 
setup.c: detect $GIT_COMMON_DIR in is_git_directory()

If the file "$GIT_DIR/commondir" exists, it contains the value of
$GIT_COMMON_DIR.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agosetup.c: convert is_git_directory() to use strbuf
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:40 +0000 (15:24 +0700)] 
setup.c: convert is_git_directory() to use strbuf

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogit-stash: avoid hardcoding $GIT_DIR/logs/....
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:39 +0000 (15:24 +0700)] 
git-stash: avoid hardcoding $GIT_DIR/logs/....

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years ago*.sh: avoid hardcoding $GIT_DIR/hooks/...
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:38 +0000 (15:24 +0700)] 
*.sh: avoid hardcoding $GIT_DIR/hooks/...

If $GIT_COMMON_DIR is set, it should be $GIT_COMMON_DIR/hooks/, not
$GIT_DIR/hooks/. Just let rev-parse --git-path handle it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogit-sh-setup.sh: use rev-parse --git-path to get $GIT_DIR/objects
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:37 +0000 (15:24 +0700)] 
git-sh-setup.sh: use rev-parse --git-path to get $GIT_DIR/objects

If $GIT_COMMON_DIR is set, $GIT_OBJECT_DIRECTORY should be
$GIT_COMMON_DIR/objects, not $GIT_DIR/objects. Just let rev-parse
--git-path handle it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years ago$GIT_COMMON_DIR: a new environment variable
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:36 +0000 (15:24 +0700)] 
$GIT_COMMON_DIR: a new environment variable

This variable is intended to support multiple working directories
attached to a repository. Such a repository may have a main working
directory, created by either "git init" or "git clone" and one or more
linked working directories. These working directories and the main
repository share the same repository directory.

In linked working directories, $GIT_COMMON_DIR must be defined to point
to the real repository directory and $GIT_DIR points to an unused
subdirectory inside $GIT_COMMON_DIR. File locations inside the
repository are reorganized from the linked worktree view point:

 - worktree-specific such as HEAD, logs/HEAD, index, other top-level
   refs and unrecognized files are from $GIT_DIR.

 - the rest like objects, refs, info, hooks, packed-refs, shallow...
   are from $GIT_COMMON_DIR (except info/sparse-checkout, but that's
   a separate patch)

Scripts are supposed to retrieve paths in $GIT_DIR with "git rev-parse
--git-path", which will take care of "$GIT_DIR vs $GIT_COMMON_DIR"
business.

The redirection is done by git_path(), git_pathdup() and
strbuf_git_path(). The selected list of paths goes to $GIT_COMMON_DIR,
not the other way around in case a developer adds a new
worktree-specific file and it's accidentally promoted to be shared
across repositories (this includes unknown files added by third party
commands)

The list of known files that belong to $GIT_DIR are:

ADD_EDIT.patch BISECT_ANCESTORS_OK BISECT_EXPECTED_REV BISECT_LOG
BISECT_NAMES CHERRY_PICK_HEAD COMMIT_MSG FETCH_HEAD HEAD MERGE_HEAD
MERGE_MODE MERGE_RR NOTES_EDITMSG NOTES_MERGE_WORKTREE ORIG_HEAD
REVERT_HEAD SQUASH_MSG TAG_EDITMSG fast_import_crash_* logs/HEAD
next-index-* rebase-apply rebase-merge rsync-refs-* sequencer/*
shallow_*

Path mapping is NOT done for git_path_submodule(). Multi-checkouts are
not supported as submodules.

Helped-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agocommit: use SEQ_DIR instead of hardcoding "sequencer"
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:35 +0000 (15:24 +0700)] 
commit: use SEQ_DIR instead of hardcoding "sequencer"

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agofast-import: use git_path() for accessing .git dir instead of get_git_dir()
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:34 +0000 (15:24 +0700)] 
fast-import: use git_path() for accessing .git dir instead of get_git_dir()

This allows git_path() to redirect info/fast-import to another place
if needed

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoreflog: avoid constructing .lock path with git_path
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:33 +0000 (15:24 +0700)] 
reflog: avoid constructing .lock path with git_path

Among pathnames in $GIT_DIR, e.g. "index" or "packed-refs", we want to
automatically and silently map some of them to the $GIT_DIR of the
repository we are borrowing from via $GIT_COMMON_DIR mechanism.  When
we formulate the pathname for its lockfile, we want it to be in the
same location as its final destination.  "index" is not shared and
needs to remain in the borrowing repository, while "packed-refs" is
shared and needs to go to the borrowed repository.

git_path() could be taught about the ".lock" suffix and map
"index.lock" and "packed-refs.lock" the same way their basenames are
mapped, but instead the caller can help by asking where the basename
(e.g. "index") is mapped to git_path() and then appending ".lock"
after the mapping is done.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years ago*.sh: respect $GIT_INDEX_FILE
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:32 +0000 (15:24 +0700)] 
*.sh: respect $GIT_INDEX_FILE

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogit_path(): be aware of file relocation in $GIT_DIR
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:31 +0000 (15:24 +0700)] 
git_path(): be aware of file relocation in $GIT_DIR

We allow the user to relocate certain paths out of $GIT_DIR via
environment variables, e.g. GIT_OBJECT_DIRECTORY, GIT_INDEX_FILE and
GIT_GRAFT_FILE. Callers are not supposed to use git_path() or
git_pathdup() to get those paths. Instead they must use
get_object_directory(), get_index_file() and get_graft_file()
respectively. This is inconvenient and could be missed in review (for
example, there's git_path("objects/info/alternates") somewhere in
sha1_file.c).

This patch makes git_path() and git_pathdup() understand those
environment variables. So if you set GIT_OBJECT_DIRECTORY to /foo/bar,
git_path("objects/abc") should return /foo/bar/abc. The same is done
for the two remaining env variables.

"git rev-parse --git-path" is the wrapper for script use.

This patch kinda reverts a0279e1 (setup_git_env: use git_pathdup
instead of xmalloc + sprintf - 2014-06-19) because using git_pathdup
here would result in infinite recursion:

  setup_git_env() -> git_pathdup("objects") -> .. -> adjust_git_path()
  -> get_object_directory() -> oops, git_object_directory is NOT set
  yet -> setup_git_env()

I wanted to make git_pathdup_literal() that skips adjust_git_path().
But that won't work because later on when $GIT_COMMON_DIR is
introduced, git_pathdup_literal("objects") needs adjust_git_path() to
replace $GIT_DIR with $GIT_COMMON_DIR.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agopath.c: group git_path(), git_pathdup() and strbuf_git_path() together
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:30 +0000 (15:24 +0700)] 
path.c: group git_path(), git_pathdup() and strbuf_git_path() together

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agopath.c: rename vsnpath() to do_git_path()
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:29 +0000 (15:24 +0700)] 
path.c: rename vsnpath() to do_git_path()

The name vsnpath() gives an impression that this is general path
handling function. It's not. This is the underlying implementation of
git_path(), git_pathdup() and strbuf_git_path() which will prefix
$GIT_DIR in the result string.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agogit_snpath(): retire and replace with strbuf_git_path()
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:28 +0000 (15:24 +0700)] 
git_snpath(): retire and replace with strbuf_git_path()

In the previous patch, git_snpath() is modified to allocate a new
strbuf buffer because vsnpath() needs that. But that makes it
awkward because git_snpath() receives a pre-allocated buffer from
outside and has to copy data back. Rename it to strbuf_git_path()
and make it receive strbuf directly.

Using git_path() in update_refs_for_switch() which used to call
git_snpath() is safe because that function and all of its callers do
not keep any pointer to the round-robin buffer pool allocated by
get_pathname().

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agopath.c: make get_pathname() call sites return const char *
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:27 +0000 (15:24 +0700)] 
path.c: make get_pathname() call sites return const char *

Before the previous commit, get_pathname returns an array of PATH_MAX
length. Even if git_path() and similar functions does not use the
whole array, git_path() caller can, in theory.

After the commit, get_pathname() may return a buffer that has just
enough room for the returned string and git_path() caller should never
write beyond that.

Make git_path(), mkpath() and git_path_submodule() return a const
buffer to make sure callers do not write in it at all.

This could have been part of the previous commit, but the "const"
conversion is too much distraction from the core changes in path.c.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agopath.c: make get_pathname() return strbuf instead of static buffer
Nguyễn Thái Ngọc Duy [Sun, 30 Nov 2014 08:24:26 +0000 (15:24 +0700)] 
path.c: make get_pathname() return strbuf instead of static buffer

We've been avoiding PATH_MAX whenever possible. This patch makes
get_pathname() return a strbuf and updates the callers to take
advantage of this. The code is simplified as we no longer need to
worry about buffer overflow.

vsnpath() behavior is changed slightly: previously it always clears
the buffer before writing, now it just appends. Fortunately this is a
static function and all of its callers prepare the buffer properly:
git_path() gets the buffer from get_pathname() which resets the
buffer, the remaining call sites start with STRBUF_INIT'd buffer.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoGit 2.2 v2.2.0
Junio C Hamano [Wed, 26 Nov 2014 21:18:34 +0000 (13:18 -0800)] 
Git 2.2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoRelNotes: spelling & grammar tweaks
Marc Branchaud [Fri, 21 Nov 2014 23:10:04 +0000 (18:10 -0500)] 
RelNotes: spelling & grammar tweaks

Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agoGit 2.2.0-rc3 v2.2.0-rc3
Junio C Hamano [Fri, 21 Nov 2014 20:10:56 +0000 (12:10 -0800)] 
Git 2.2.0-rc3

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 years agol10n: remove a superfluous translation for push.c
Jiang Xin [Thu, 20 Nov 2014 08:12:34 +0000 (16:12 +0800)] 
l10n: remove a superfluous translation for push.c

Ralf reported that '--recurse-submodules' option in push.c should not be
translated [1].  Before his commit is merged, remove superfluous
translations for push.c.

[1] http://www.spinics.net/lists/git/msg241964.html

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
9 years agol10n: de.po: translate 2 messages
Ralf Thielow [Thu, 20 Nov 2014 06:15:15 +0000 (07:15 +0100)] 
l10n: de.po: translate 2 messages

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
9 years agol10n: de.po: translate 2 new messages
Ralf Thielow [Tue, 18 Nov 2014 18:06:51 +0000 (19:06 +0100)] 
l10n: de.po: translate 2 new messages

Signed-off-by: Phillip Sz <phillip.szelat@gmail.com>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
9 years agol10n: batch updates for one trivial change
Jiang Xin [Thu, 20 Nov 2014 02:53:48 +0000 (10:53 +0800)] 
l10n: batch updates for one trivial change

In order to catch up with the release of Git 2.2.0 final, make a batch
l10n update for the new l10n change brought by commit d52adf1 (trailer:
display a trailer without its trailing newline).

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
9 years agol10n: git.pot: v2.2.0 round 2 (1 updated)
Jiang Xin [Thu, 20 Nov 2014 02:03:10 +0000 (10:03 +0800)] 
l10n: git.pot: v2.2.0 round 2 (1 updated)

Generate po/git.pot from v2.2.0-rc2-23-gca0107e for git v2.2.0 l10n
round 2.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
9 years agoMerge branch 'sv/submitting-final-patch'
Junio C Hamano [Wed, 19 Nov 2014 21:48:01 +0000 (13:48 -0800)] 
Merge branch 'sv/submitting-final-patch'

* sv/submitting-final-patch:
  SubmittingPatches: final submission is To: maintainer and CC: list

9 years agoMerge branch 'sn/tutorial-status-output-example'
Junio C Hamano [Wed, 19 Nov 2014 21:47:59 +0000 (13:47 -0800)] 
Merge branch 'sn/tutorial-status-output-example'

* sn/tutorial-status-output-example:
  gittutorial: fix output of 'git status'

9 years agoMerge branch 'mh/doc-remote-helper-xref'
Junio C Hamano [Wed, 19 Nov 2014 21:47:55 +0000 (13:47 -0800)] 
Merge branch 'mh/doc-remote-helper-xref'

* mh/doc-remote-helper-xref:
  doc: add some crossrefs between manual pages

9 years agoMerge branch 'tb/no-relative-file-url'
Junio C Hamano [Wed, 19 Nov 2014 21:47:53 +0000 (13:47 -0800)] 
Merge branch 'tb/no-relative-file-url'

* tb/no-relative-file-url:
  t5705: the file:// URL should be absolute

9 years agoMerge branch 'cc/interpret-trailers'
Junio C Hamano [Wed, 19 Nov 2014 21:47:49 +0000 (13:47 -0800)] 
Merge branch 'cc/interpret-trailers'

Small fixes to a new experimental command already in 'master'.

* cc/interpret-trailers:
  trailer: display a trailer without its trailing newline
  trailer: ignore comment lines inside the trailers

9 years agoMerge git://github.com/git-l10n/git-po
Junio C Hamano [Tue, 18 Nov 2014 18:27:46 +0000 (10:27 -0800)] 
Merge git://github.com/git-l10n/git-po

* 'master' of git://github.com/git-l10n/git-po:
  l10n: Update Catalan translation

9 years agoMerge branch 'jc/doc-commit-only'
Junio C Hamano [Tue, 18 Nov 2014 18:19:38 +0000 (10:19 -0800)] 
Merge branch 'jc/doc-commit-only'

* jc/doc-commit-only:
  Documentation/git-commit: clarify that --only/--include records the working tree contents

9 years agoMerge branch 'ta/tutorial-modernize'
Junio C Hamano [Tue, 18 Nov 2014 18:18:28 +0000 (10:18 -0800)] 
Merge branch 'ta/tutorial-modernize'

* ta/tutorial-modernize:
  gittutorial.txt: remove reference to ancient Git version

9 years agoMerge branch 'da/difftool'
Junio C Hamano [Tue, 18 Nov 2014 18:16:54 +0000 (10:16 -0800)] 
Merge branch 'da/difftool'

Fix-up to a new feature in 'master'.

* da/difftool:
  difftool: honor --trust-exit-code for builtin tools

10 years agol10n: Update Catalan translation
Alex Henrie [Tue, 18 Nov 2014 03:22:48 +0000 (20:22 -0700)] 
l10n: Update Catalan translation

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>