setup_git_directory_gently() only modified the value of its *nongit_ok
argument if we were not in a git repository. Now it will always set it
to 0 when we are inside a repository.
Also remove now unnecessary initializations in the callers of this
function.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
An earlier commit d089ebaa (setup: sanitize absolute and funny paths) made
get_pathspec() aware of absolute paths, but with a botched interface that
forced the callers to count the resulting pathspecs in order to detect
an error of giving a path that is outside the work tree.
This fixes it, by dying inside the function.
We had ls-tree test that relied on a misfeature in the original
implementation of its pathspec handling. Leading slashes were silently
removed from them. However we allow giving absolute pathnames (people
want to cut and paste from elsewhere) that are inside work tree these
days, so a pathspec that begin with slash _should_ be treated as a full
path. The test is adjusted to match the updated rule for get_pathspec().
Earlier I mistook three tests given by Robin that they should succeed, but
these are attempts to add path outside work tree, which should fail
loudly. These tests also have been fixed.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This function tests whether there is a C: style prefix in the argument.
It returns always 0 on Unix.
With this functions a number of conditionals #ifdef __MINGW32__/#endif
can be removed.
The getcwd() replacement was simplified: It tried to elide the translation
of backslashes to slashes if there was no drive prfix, but this
optimization is wrong: We could be looking at an UNC path, which we also
want to translate.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
We recognized the drive letter and colon, but we did not copy them. So far
this was not a problem since the only call site used the same pointer for
source and destination. But better safe than sorry.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This change removes all obvious useless if-before-free tests.
E.g., it replaces code like this:
if (some_expression)
free (some_expression);
with the now-equivalent:
free (some_expression);
It is equivalent not just because POSIX has required free(NULL)
to work for a long time, but simply because it has worked for
so long that no reasonable porting target fails the test.
Here's some evidence from nearly 1.5 years ago:
http://www.winehq.org/pipermail/wine-patches/2006-October/031544.html
FYI, the change below was prepared by running the following:
git ls-files -z | xargs -0 \
perl -0x3b -pi -e \
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+(free\s*\(\s*\1\s*\))/$2/s'
Note however, that it doesn't handle brace-enclosed blocks like
"if (x) { free (x); }". But that's ok, since there were none like
that in git sources.
Beware: if you do use the above snippet, note that it can
produce syntactically invalid C code. That happens when the
affected "if"-statement has a matching "else".
E.g., it would transform this
if (x)
free (x);
else
foo ();
into this:
free (x);
else
foo ();
There were none of those here, either.
If you're interested in automating detection of the useless
tests, you might like the useless-if-before-free script in gnulib:
[it *does* detect brace-enclosed free statements, and has a --name=S
option to make it detect free-like functions with different names]
http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=build-aux/useless-if-before-free
Addendum:
Remove one more (in imap-send.c), spotted by Jean-Luc Herren <jlh@gmx.ch>.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
* jc/setup:
builtin-mv: minimum fix to avoid losing files
git-add: adjust to the get_pathspec() changes.
Make blame accept absolute paths
setup: sanitize absolute and funny paths in get_pathspec()
sanitary_path_copy() is only used by prefix_path(). A helper function
is_dir_sep() is introduced that checks for both '/' and '\\' on Windows.
Note that the remaining checks for '/' in prefix_path() don't need to
to be converted to is_dir_sep() since they operate on the sanitized path.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
The prefix_path() function called from get_pathspec() is
responsible for translating list of user-supplied pathspecs to
list of pathspecs that is relative to the root of the work
tree. When working inside a subdirectory, the user-supplied
pathspecs are taken to be relative to the current subdirectory.
Among special path components in pathspecs, we used to accept
and interpret only "." ("the directory", meaning a no-op) and
".." ("up one level") at the beginning. Everything else was
passed through as-is.
For example, if you are in Documentation/ directory of the
project, you can name Documentation/howto/maintain-git.txt as:
howto/maintain-git.txt
../Documentation/howto/maitain-git.txt
../././Documentation/howto/maitain-git.txt
but not as:
howto/./maintain-git.txt
$(pwd)/howto/maintain-git.txt
This patch updates prefix_path() in several ways:
- If the pathspec is not absolute, prefix (i.e. the current
subdirectory relative to the root of the work tree, with
terminating slash, if not empty) and the pathspec is
concatenated first and used in the next step. Otherwise,
that absolute pathspec is used in the next step.
- Then special path components "." (no-op) and ".." (up one
level) are interpreted to simplify the path. It is an error
to have too many ".." to cause the intermediate result to
step outside of the input to this step.
- If the original pathspec was not absolute, the result from
the previous step is the resulting "sanitized" pathspec.
Otherwise, the result from the previous step is still
absolute, and it is an error if it does not begin with the
directory that corresponds to the root of the work tree. The
directory is stripped away from the result and is returned.
- In any case, the resulting pathspec in the array
get_pathspec() returns omit the ones that caused errors.
With this patch, the last two examples also behave as expected.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup_git_directory_gently has done the check already.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The previous implementation translated '\' to '/' on non-Windows, too
(in those cases where the prefix was actually prepended to the path).
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
* maint:
git-am -i: report rewritten title
git grep shows the same hit repeatedly for unmerged paths
Do check_repository_format() early (re-fix)
Do check_repository_format() early
Add missing inside_work_tree setting in setup_git_directory_gently
This pushes check_repository_format() (actually _gently() version)
to setup_git_directory_gently() in order to prevent from
using unsupported repositories.
New setup_git_directory_gently()'s behaviour is stop searching
for a valid gitdir and return as if there is no gitdir if a
unsupported repository is found. Warning will be thrown in these
cases.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Repository version check is only performed when
setup_git_directory() is called. This makes sure
setup_git_directory_gently() does the check too.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Using the helper function to test for absolute paths makes porting easier.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Remove getpagesize() from sha1_file.c because is it now
included in git-compat-util.h.
Conflicts:
Makefile
compat/mingw.c
git-compat-util.h
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
We check in cmd_blame() if the specified path is there, but we
failed to set up the working tree before that.
While at it, make setup_work_tree() just return if it was run
before.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Create a setup_work_tree() that can be used from any command requiring
a working tree conditionally.
Signed-off-by: Mike Hommey <mh@glandium.org>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Conflicts:
Makefile
RelNotes
builtin-ls-files.c
builtin-tag.c
cache.h
compat/mingw.c
config.c
connect.c
cpio.sh
diff.c
exec_cmd.c
git-gui/Makefile
git-gui/lib/commit.tcl
git-gui/lib/console.tcl
git-mergetool.sh
lockfile.c
path.c
rsh.c
run-command.c
setup.c
show-index.c
spawn-pipe.c
t/Makefile
t/t0000-basic.sh
t/t1300-repo-config.sh
t/t7501-commit.sh
t/test-lib.sh
Resolve as follows
--- Makefile
- mingw/devel removes
SHELL_PATH = /bin/sh
PERL_PATH = /bin/perl
This looks ok. Both are set early in the Makefile to sensible values.
mingw accepts to execute /usr/bin/perl.
- NO_SYMLINKS is no longer needed. Should be auto-detected.
- According to our 0e2bdc35af
we want
NO_R_TO_GCC_LINKER = YesPlease
take our before their change.
- Conflict prefix, SCRIPT_SH:
our 7999f434d7 set prefix =
their 4a7c98dbaf removes cpio emulator
resolve to achieve both.
- Conflict NO_MEMMEM, THREADED_DELTA_SEARCH: take theirs
--- RelNotes
take our: removed file
--- builtin-ls-files.c
Conflict write_name_quoted: take their change.
--- builtin-tag.c
Conflict strip CR
our 7734ad404c adds strip CR
their fd17f5b5f7 modifies code to use strbuf
resolve by removing our code. TODO: we probably need a replacement?
--- cache.h
Conflict is_absolute_path()
our ef5af72062 ifdef
their 637fc51696 ifndef
both achieve the same.
our is a bit more strict but we take their code because we want
to reduce differences to mingw.
--- compat/mingw.c
Conflict at end of file:
our 194c1dbb5a adds git_exit()
resolve by taking their first, followed by our.
--- config.c
Conflict 'fd ='
our 0a453a237e merge junio/master
introduced strange 'fd ='. Resolve by removing 'fd ='.
--- connect.c
- Conflict 'host must have at least 2 chars ...' take their code.
- git_connect(): take their implementation.
--- cpio.sh
Accepted their delete file.
--- diff.c
Resolve using their implementation.
--- exec_cmd.c
Resolve using their implementation.
--- git-gui/**
Resolve using our implementation.
--- git-mergetool.sh
Resolve using their implementation
--- lockfile.c
trivial resolution (empty line removed)
--- path.c
Conflict 'tmp': accepting their implementation, trying TMP, TEMP on all platforms.
--- rsh.c
Accept their delete file.
--- run-command.c
Resolve using their implementation
--- setup.c
Resolve using their implementation
--- show-index.c
Conflict PRIuMAX
our 89697a4c15 fix warning
their 5be507fc95 PRIuMAX
resolve fixing warning in their code.
--- spawn-pipe.c
Conflict environ vs lookup_prog: resolve taking neither
--- t/Makefile
our d1f83218dc --no-hardlinks
their c603988c10 automtically detect symlink support
Resolve using our --no-hardlinks but removing --no-symlinks.
--- t/0000-basic.sh
Resolve using their implementation.
--- t/t1300-repo-config.sh
Resolve using their implementation.
--- t/t7501-commit.sh
Resolve using their implementation.
--- t/test-lib.sh
our d1f83218dc --no-hardlink
their c603988c10 automatically detect symlink support
Resolve using our --no-hardlinks but removing --no-symlinks.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
When both GIT_DIR and GIT_WORK_TREE are set, and
setup_git_directory_gently() changes the current working
directory accordingly, it should also set inside_work_tree = 1.
Without this, work_tree handling code in setup_git_directory()
will be activated. If you stay in root work tree (no prefix),
it does not harm. It does if you work from a subdirectory though.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
There are a few programs, such as config and diff, which allow running
without a git repository. Therefore, they have to call
setup_git_directory_gently().
However, when GIT_DIR and GIT_WORK_TREE were set, and the current
directory was a subdirectory of the work tree,
setup_git_directory_gently() would return a bogus NULL prefix.
This patch fixes that.
Noticed by REPLeffect on IRC.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
The old behaviour was to unilaterally default to the cwd is the work tree
when GIT_DIR was set, but GIT_WORK_TREE wasn't, no matter if we are inside
the GIT_DIR, or if GIT_DIR is actually something like ../../../.git.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c caches results of many getenv calls.
Under MinGW setenv(X) invalidates all previous values returned by getenv(X)
so cached values become dangling pointers.
Replaced all setenv(GIT_DIR, ...) with set_git_dir
Signed-off-by: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>