lockfile.c: remove PATH_MAX limitation (except in resolve_symlink)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
lockfile.c: remove PATH_MAX limit in resolve_symlink()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
lockfile.c: store absolute path

Locked paths can be saved in a linked list so that if something wrong
happens, *.lock are removed. For relative paths, this works fine if we
keep cwd the same, which is true 99% of time except:

- update-index and read-tree hold the lock on $GIT_DIR/index really
  early, then later on may call setup_work_tree() to move cwd.

- Suppose a lock is being held (e.g. by "git add") then somewhere
  down the line, somebody calls real_path (e.g. "link_alt_odb_entry"),
  which temporarily moves cwd away and back.

During that time when cwd is moved (either permanently or temporarily)
and we decide to die(), attempts to remove relative *.lock will fail,
and the next operation will complain that some files are still locked.

Avoid this case by turning relative paths to absolute before storing
the path in "filename" field.

Reported-by: Yue Lin Ho <yuelinho777@gmail.com>
Helped-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
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>
Merge branch 'ta/doc-config' into jch

* ta/doc-config:
  add documentation for writing config files
Merge branch 'tf/maint-doc-push' into jch

* tf/maint-doc-push:
  git-push: fix link in man page
Merge branch 'hv/submodule-config' into jch

* hv/submodule-config:
  do not die on error of parsing fetchrecursesubmodules option
  use new config API for worktree configurations of submodules
  extract functions for submodule config set and lookup
  implement submodule config cache for lookup of submodule names
Merge branch 'jc/reopen-lock-file' into jch

Needed in the "commit -p" code path to update the cache tree in the
index (e.g. for dt/cache-tree-repair topic).

* jc/reopen-lock-file:
  lockfile: allow reopening a closed but still locked file
Merge branch 'dt/cache-tree-repair' into jch

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

* dt/cache-tree-repair:
  cache-tree: Write updated cache-tree after commit
  cache-tree: subdirectory tests
  test-dump-cache-tree: invalid trees are not errors
  cache-tree: create/update cache-tree on checkout

# Conflicts:
# 	builtin/checkout.c
# 	builtin/commit.c
Merge branch 'nd/multiple-work-trees' into jch

A replacement for contrib/workdir/git-new-workdir that does not
rely on symbolic links and make sharing of objects and refs safer
by making the borrowee and borrowers aware of each other.

* nd/multiple-work-trees: (31 commits)
  checkout: don't require a work tree when checking out into a new one
  git_path(): keep "info/sparse-checkout" per work-tree
  count-objects: report unused files in $GIT_DIR/repos/...
  gc: support prune --repos
  gc: factor out gc.pruneexpire parsing code
  gc: style change -- no SP before closing parenthesis
  prune: strategies for linked checkouts
  checkout: detach if the branch is already checked out elsewhere
  checkout: clean up half-prepared directories in --to mode
  checkout: support checking out into a new working directory
  use new wrapper write_file() for simple file writing
  wrapper.c: wrapper to open a file, fprintf then close
  setup.c: support multi-checkout repo setup
  setup.c: detect $GIT_COMMON_DIR check_repository_format_gently()
  setup.c: convert check_repository_format_gently to use strbuf
  setup.c: detect $GIT_COMMON_DIR in is_git_directory()
  setup.c: convert is_git_directory() to use strbuf
  git-stash: avoid hardcoding $GIT_DIR/logs/....
  *.sh: avoid hardcoding $GIT_DIR/hooks/...
  git-sh-setup.sh: use rev-parse --git-path to get $GIT_DIR/objects
  ...

# Conflicts:
# 	refs.c
# 	refs.h
# 	trace.c
Merge branch 'rs/strbuf-getcwd' into jch

* rs/strbuf-getcwd:
  use strbuf_add_absolute_path() to add absolute paths
  abspath: convert absolute_path() to strbuf
  use xgetcwd() to set $GIT_DIR
  use xgetcwd() to get the current directory or die
  wrapper: add xgetcwd()
  abspath: convert real_path_internal() to strbuf
  abspath: use strbuf_getcwd() to remember original working directory
  setup: convert setup_git_directory_gently_1 et al. to strbuf
  unix-sockets: use strbuf_getcwd()
  strbuf: add strbuf_getcwd()
Merge branch 'mm/config-edit-global' into jch

Start "git config --edit --global" from a skeletal per-user
configuration file contents, instead of a total blank, when the
user does not already have any.  This immediately reduces the need
for a later "Have you forgotten setting core.user?" and we can add
more to the template as we gain more experience.

* mm/config-edit-global:
  commit: advertise config --global --edit on guessed identity
  home_config_paths(): let the caller ignore xdg path
  config --global --edit: create a template file if needed
Merge branch 'rs/init-no-duplicate-real-path' into jch

* rs/init-no-duplicate-real-path:
  init: avoid superfluous real_path() calls
### match next
Merge branch 'ta/config-set' into jch

Add in-core caching layer to let us avoid reading the same
configuration files number of times.

* ta/config-set:
  test-config: add tests for the config_set API
  add `config_set` API for caching config-like files
Merge branch 'jc/test-lazy-prereq' into jch

Test-script clean-up.

Will hold.

* jc/test-lazy-prereq:
  tests: drop GIT_*_TIMING_TESTS environment variable support
Merge branch 'mt/patch-id-stable' into jch

Teaches "git patch-id" to compute the patch ID that does not change
when the files in a single patch is reordered. As this new algorithm
is backward incompatible, the last bit to flip it to be the default
is left out of 'master' for now.

Will hold.

* mt/patch-id-stable:
  patch-id: change default to stable
Merge branch 'cc/interpret-trailers' into jch

A new filter to programatically edit the tail end of the commit log
messages.

What is the status of this one?  I think I saw reviews by Michael
but after that I do not recall seeing any updates.

* cc/interpret-trailers:
  Documentation: add documentation for 'git interpret-trailers'
  trailer: add tests for commands in config file
  trailer: execute command from 'trailer.<name>.command'
  trailer: add tests for "git interpret-trailers"
  trailer: add interpret-trailers command
  trailer: put all the processing together and print
  trailer: parse trailers from file or stdin
  trailer: process command line trailer arguments
  trailer: read and process config information
  trailer: process trailers from input message and arguments
  trailer: add data structures and basic functions
Merge branch 'rs/ref-transaction-1' into jch

The second batch of the transactional ref update series.

* rs/ref-transaction-1:
  refs.c: make delete_ref use a transaction
  refs.c: make prune_ref use a transaction to delete the ref
  refs.c: remove lock_ref_sha1
  refs.c: remove the update_ref_write function
  refs.c: remove the update_ref_lock function
  refs.c: make lock_ref_sha1 static
  walker.c: use ref transaction for ref updates
  fast-import.c: use a ref transaction when dumping tags
  receive-pack.c: use a reference transaction for updating the refs
  refs.c: change update_ref to use a transaction
  branch.c: use ref transaction for all ref updates
  fast-import.c: change update_branch to use ref transactions
  sequencer.c: use ref transactions for all ref updates
  commit.c: use ref transactions for updates
  replace.c: use the ref transaction functions for updates
  tag.c: use ref transactions when doing updates
  refs.c: add transaction.status and track OPEN/CLOSED/ERROR
  refs.c: make ref_transaction_begin take an err argument
  refs.c: update ref_transaction_delete to check for error and return status
  refs.c: change ref_transaction_create to do error checking and return status

# Conflicts:
# 	sequencer.c
# 	walker.c
Merge branch 'rs/ref-transaction' into jch

* rs/ref-transaction:
  refs.c: fix handling of badly named refs
  refs.c: make write_ref_sha1 static
  fetch.c: change s_update_ref to use a ref transaction
  refs.c: propagate any errno==ENOTDIR from _commit back to the callers
  refs.c: pass a skip list to name_conflict_fn
  refs.c: call lock_ref_sha1_basic directly from commit
  refs.c: move the check for valid refname to lock_ref_sha1_basic
  refs.c: pass NULL as *flags to read_ref_full
  refs.c: pass the ref log message to _create/delete/update instead of _commit
  refs.c: add an err argument to delete_ref_loose
  wrapper.c: add a new function unlink_or_msg
  wrapper.c: simplify warn_if_unremovable

# Conflicts:
# 	builtin/log.c
# 	git-compat-util.h
# 	refs.c
# 	walker.c
Merge branch 'cb/mergetool-difftool' into jch

* cb/mergetool-difftool:
  difftool: don't assume that default sh is sane
  mergetool: don't require a work tree for --tool-help