* Re: [PATCH] mingw: allow hooks to be .exe files
From: Johannes Schindelin @ 2017-01-30 12:29 UTC (permalink / raw)
To: Stefan Beller; +Cc: Junio C Hamano, Jeff King, git@vger.kernel.org
In-Reply-To: <CAGZ79kaa5WJmZkyFROfkfNb3++t37qAuAebKJTon2iD2bh+sWw@mail.gmail.com>
Hi Stefan,
On Fri, 27 Jan 2017, Stefan Beller wrote:
> On Fri, Jan 27, 2017 at 2:29 AM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > Hi Junio,
> >
> > On Thu, 26 Jan 2017, Junio C Hamano wrote:
> >
> >> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> >>
> >> > On Wed, 25 Jan 2017, Jeff King wrote:
> >> >
> >> > v2 coming,
>
> The commit message, while technically correct, seems a bit off. This is
> because the commit message only talks about .exe extensions, but the
> change in code doesn't even have the string "exe" mentioned once.
>
> With this discussion here, it is easy for me to connect the dots, but it
> would be nice to have the full picture in the commit message.
I just sent out v3, using a slightly tweaked version of the commit message
you proposed.
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH] fixup! worktree move: new command
From: Johannes Schindelin @ 2017-01-30 12:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Nguyễn Thái Ngọc Duy
In-Reply-To: <xmqqwpdgz8zq.fsf@gitster.mtv.corp.google.com>
Hi Junio,
On Fri, 27 Jan 2017, Junio C Hamano wrote:
> The tip of 'pu' (or anything beyond the tip of 'jch') is not always
> expected to pass test or even build, [...]
This makes `pu` a lot less useful than it could be.
And we could easily improve the situation simply by changing the rule ever
so slightly: when a build, or a test, fails in `pu` and there exists a
fix, this fix should go into `pu` ASAP.
As you point out later in your mail, the fixup! or SQUASH! commit is a
very convenient reminder that a particular branch is still "under
construction". That is, changing the rule as I proposed above will not
only help the Continuous Integration [*1*] to avoid reporting duplicates,
it will also help us improve the project faster.
Ciao,
Johannes
Footnote *1*: It appears that there may be the misconception floating
around that Continuous Integration is designed to annoy developers by
pointing out unportable or unbuildable code. Once you realize, though,
that it detects and reports code that is below our existing code's
quality, no doubt you will agree that it is a convenient tool to relieve
reviewers from tedious work that can be done by a machine as well.
^ permalink raw reply
* [PATCH v2] help: improve is_executable() on Windows
From: Johannes Schindelin @ 2017-01-30 12:40 UTC (permalink / raw)
To: git; +Cc: Heiko Voigt, Junio C Hamano
In-Reply-To: <c1c6ccae4e60608259809914e8ff3d3d5e1ead5a.1485524999.git.johannes.schindelin@gmx.de>
From: Heiko Voigt <hvoigt@hvoigt.net>
On Windows, executables need to have the file extension `.exe`, or they
are not executables. Hence, to support scripts, Git for Windows also
looks for a she-bang line by opening the file in question, and executing
it via the specified script interpreter.
To figure out whether files in the `PATH` are executable, `git help` has
code that imitates this behavior. With one exception: it *always* opens
the files and looks for a she-bang line *or* an `MZ` tell-tale
(nevermind that files with the magic `MZ` but without file extension
`.exe` would still not be executable).
Opening this many files leads to performance problems that are even more
serious when a virus scanner is running. Therefore, let's change the
code to look for the file extension `.exe` early, and avoid opening the
file altogether if we already know that it is executable.
See the following measurements (in seconds) as an example, where we
execute a simple program that simply lists the directory contents and
calls open() on every listed file:
With virus scanner running (coldcache):
$ ./a.exe /libexec/git-core/
before open (git-add.exe): 0.000000
after open (git-add.exe): 0.412873
before open (git-annotate.exe): 0.000175
after open (git-annotate.exe): 0.397925
before open (git-apply.exe): 0.000243
after open (git-apply.exe): 0.399996
before open (git-archive.exe): 0.000147
after open (git-archive.exe): 0.397783
before open (git-bisect--helper.exe): 0.000160
after open (git-bisect--helper.exe): 0.397700
before open (git-blame.exe): 0.000160
after open (git-blame.exe): 0.399136
...
With virus scanner running (hotcache):
$ ./a.exe /libexec/git-core/
before open (git-add.exe): 0.000000
after open (git-add.exe): 0.000325
before open (git-annotate.exe): 0.000229
after open (git-annotate.exe): 0.000177
before open (git-apply.exe): 0.000167
after open (git-apply.exe): 0.000150
before open (git-archive.exe): 0.000154
after open (git-archive.exe): 0.000156
before open (git-bisect--helper.exe): 0.000132
after open (git-bisect--helper.exe): 0.000180
before open (git-blame.exe): 0.000718
after open (git-blame.exe): 0.000724
...
With this patch I get:
$ time git help git
Launching default browser to display HTML ...
real 0m8.723s
user 0m0.000s
sys 0m0.000s
and without
$ time git help git
Launching default browser to display HTML ...
real 1m37.734s
user 0m0.000s
sys 0m0.031s
both tests with cold cache and giving the machine some time to settle
down after restart.
[jes: adjusted the commit message]
Signed-off-by: Heiko Voigt <heiko.voigt@mahr.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Published-As: https://github.com/dscho/git/releases/tag/help-is-exe-v2
Fetch-It-Via: git fetch https://github.com/dscho/git help-is-exe-v2
help.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/help.c b/help.c
index 53e2a67e00..bc6cd19cf3 100644
--- a/help.c
+++ b/help.c
@@ -105,7 +105,22 @@ static int is_executable(const char *name)
return 0;
#if defined(GIT_WINDOWS_NATIVE)
-{ /* cannot trust the executable bit, peek into the file instead */
+ /*
+ * On Windows there is no executable bit. The file extension
+ * indicates whether it can be run as an executable, and Git
+ * has special-handling to detect scripts and launch them
+ * through the indicated script interpreter. We test for the
+ * file extension first because virus scanners may make
+ * it quite expensive to open many files.
+ */
+ if (ends_with(name, ".exe"))
+ return S_IXUSR;
+
+{
+ /*
+ * Now that we know it does not have an executable extension,
+ * peek into the file instead.
+ */
char buf[3] = { 0 };
int n;
int fd = open(name, O_RDONLY);
@@ -113,8 +128,8 @@ static int is_executable(const char *name)
if (fd >= 0) {
n = read(fd, buf, 2);
if (n == 2)
- /* DOS executables start with "MZ" */
- if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
+ /* look for a she-bang */
+ if (!strcmp(buf, "#!"))
st.st_mode |= S_IXUSR;
close(fd);
}
base-commit: 4e59582ff70d299f5a88449891e78d15b4b3fabe
--
2.11.1.windows.prerelease.2.9.g3014b57
^ permalink raw reply related
* Re: [PATCH] checkout: convert post_checkout_hook() to struct object_id
From: Johannes Schindelin @ 2017-01-30 13:01 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano, brian m. carlson
In-Reply-To: <b30e5d34-436a-af5f-dbad-b1df464bf303@web.de>
[-- Attachment #1: Type: text/plain, Size: 180 bytes --]
Hi René,
On Sat, 28 Jan 2017, René Scharfe wrote:
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
These three SHA-1 -> OID patches all appear correct to me.
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH] help: correct behavior for is_executable on Windows
From: Johannes Schindelin @ 2017-01-30 12:44 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Heiko Voigt
In-Reply-To: <xmqqd1f8z6lt.fsf@gitster.mtv.corp.google.com>
Hi Junio,
On Fri, 27 Jan 2017, Junio C Hamano wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
> > From: Heiko Voigt <hvoigt@hvoigt.net>
> >
> > The previous implementation said that the filesystem information on
> > Windows is not reliable to determine whether a file is executable. To
> > gather this information it was peeking into the first two bytes of a
> > file to see whether it looks executable.
> >
> > Apart from the fact that on Windows executables are defined as such by
> > their extension (and Git has special code to support "executing"
> > scripts when they have a she-bang line) it leads to serious
> > performance problems: not only do we have to open many files now, it
> > gets even slower when a virus scanner is running.
>
> Heiko, around here (before going into the details of how severe the
> problem is and how wonderful the result applying of this change is) is
> the best place to summarize the solution. E.g.
>
> Because the definition of "executable" on Windows is based
> on the file extension, update the function to declare that a
> file with ".exe" extension without opening and reading the
> early bytes from it. This avoids serious performance issues.
>
> I paraphrased the rest only so that the description of the solution
> (i.e. "instead of opening and peeking, we trust .exe suffix") fits well
> in the surrounding text; the important part is to say what the change
> does clearly.
I adjusted the commit message. It was tweaked a little differently from
what you suggested, as I preferred to condense the information a bit more.
> I agree with the reasoning and the execution of the patch, except
> that
>
> - "correct behaviour" in the title makes it appear that this is a
> correctness thing, but this is primarily a performance fix.
Primarily. But not only. The magic `MZ` without the file extension `.exe`
is pretty useless, as the file could not be executed, still.
To avoid further turnaround, though, I also edited the contentious
"correct" to read "improve" now.
> - It is a bit strange that "MZ" is dropped in the same patch
> without any mention.
I fixed that in the commit message.
Ciao,
Johannes
^ permalink raw reply
* Re: [PATCH v4] t/Makefile: add a rule to re-run previously-failed tests
From: Johannes Schindelin @ 2017-01-30 15:35 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Jeff King, Sverre Rabbelier,
Ævar Arnfjörð Bjarmason, Matthieu Moy
In-Reply-To: <xmqq4m0kz65d.fsf@gitster.mtv.corp.google.com>
Hi Junio,
On Fri, 27 Jan 2017, Junio C Hamano wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
> > This patch automates the process of determining which tests failed
> > previously and re-running them.
> > ...
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> I stored both versions in files and compared them, and it seems the
> single word change in the proposed commit log message is the only
> difference. I would have written "Automate the process...", though.
Yes, we have different styles. Thanks for letting my commit keep my commit
message this time ;-)
> If you are resending, touching up to cover all points raised by a
> reviewer and doing nothing else, having "Reviewed-by: Jeff King
> <peff@peff.net>" would have been nicer.
TBH I am not at all sure that I know when to add those footers and when
not. After having been asked to remove such a footer, I decided to *not*
include them by default.
Having gray zones about the footers strikes me as similar to having gray
zones in the coding style guidelines: it sure gives the contributors more
freedom, but it also creates uncertainty and as a consequence takes up a
lot of reviewing space and time (hence taking away space and time from
reviewing the code for bugs).
In other words: while I appreciate the idea of giving contributors such as
myself a lot of leeway, I would love even more to be able to automate away
tedious and boring tasks (such as adding Tested-by: or Reviewed-by:
footers, or for that matter, addressing code style issues before any
reviewer has to shed bikes so that they can focus on the parts of the
review that no machine can do for them).
Ciao,
Johannes
^ permalink raw reply
* Re: [PATCH 1/5] add SWAP macro
From: Johannes Schindelin @ 2017-01-30 15:39 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
In-Reply-To: <0bdb58a6-3a7f-2218-4b70-c591ae90e95e@web.de>
[-- Attachment #1: Type: text/plain, Size: 543 bytes --]
Hi René,
On Sat, 28 Jan 2017, René Scharfe wrote:
> Add a macro for exchanging the values of variables. It allows users to
> avoid repetition and takes care of the temporary variable for them. It
> also makes sure that the storage sizes of its two parameters are the
> same. Its memcpy(1) calls are optimized away by current compilers.
How certain are we that "current compilers" optimize that away? And about
which "current compilers" are we talking? GCC? GCC 6? Clang? Clang 3?
Clang 3.8.*? Visual C 2005+?
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 1/5] add SWAP macro
From: Johannes Schindelin @ 2017-01-30 16:01 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
In-Reply-To: <0bdb58a6-3a7f-2218-4b70-c591ae90e95e@web.de>
[-- Attachment #1: Type: text/plain, Size: 1634 bytes --]
Hi René,
On Sat, 28 Jan 2017, René Scharfe wrote:
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 87237b092b..66cd466eea 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -527,6 +527,16 @@ static inline int ends_with(const char *str, const char *suffix)
> return strip_suffix(str, suffix, &len);
> }
>
> +#define SWAP(a, b) do { \
> + void *_swap_a_ptr = &(a); \
> + void *_swap_b_ptr = &(b); \
> + unsigned char _swap_buffer[sizeof(a)]; \
> + memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \
> + memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) + \
> + BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \
> + memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \
> +} while (0)
> +
> #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
It may seem as a matter of taste, or maybe not: I prefer this without the
_swap_a_ptr (and I would also prefer not to use identifiers starting with
an underscore, as section 7.1.3 Reserved Identifiers of the C99 standard
says they are reserved):
+#define SWAP(a, b) do { \
+ unsigned char swap_buffer_[sizeof(a)]; \
+ memcpy(swap_buffer_, &(a), sizeof(a)); \
+ memcpy(&(a), &(b), sizeof(a) + \
+ BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \
+ memcpy(&(b), swap_buffer_, sizeof(a)); \
+} while (0)
One idea to address the concern that not all C compilers people use to
build Git may optimize away those memcpy()s: we could also introduce a
SWAP_PRIMITIVE_TYPE (or SWAP2 or SIMPLE_SWAP or whatever) that accepts
only primitive types. But since __typeof__() is not portable...
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 3/5] use SWAP macro
From: Johannes Schindelin @ 2017-01-30 16:03 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
In-Reply-To: <187c2b39-40cf-7e07-b489-d40cdf5f9145@web.de>
[-- Attachment #1: Type: text/plain, Size: 661 bytes --]
Hi René,
On Sat, 28 Jan 2017, René Scharfe wrote:
> diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
> index 806dd7a885..8ce00480cd 100644
> --- a/builtin/diff-tree.c
> +++ b/builtin/diff-tree.c
> @@ -147,9 +147,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
> tree1 = opt->pending.objects[0].item;
> tree2 = opt->pending.objects[1].item;
> if (tree2->flags & UNINTERESTING) {
> - struct object *tmp = tree2;
> - tree2 = tree1;
> - tree1 = tmp;
> + SWAP(tree2, tree1);
> }
Is there a way to transform away the curly braces for blocks that become
single-line blocks, too?
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 4/5] diff: use SWAP macro
From: Johannes Schindelin @ 2017-01-30 16:04 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
In-Reply-To: <84944ecd-d14e-b5e9-7566-9ab2b68c02fb@web.de>
[-- Attachment #1: Type: text/plain, Size: 780 bytes --]
Hi René,
On Sat, 28 Jan 2017, René Scharfe wrote:
> Use the macro SWAP to exchange the value of pairs of variables instead
> of swapping them manually with the help of a temporary variable. The
> resulting code is shorter and easier to read.
>
> The two cases were not transformed by the semantic patch swap.cocci
> because it's extra careful and handles only cases where the types of all
> variables are the same -- and here we swap two ints and use an unsigned
> temporary variable for that. Nevertheless the conversion is safe, as
> the value range is preserved with and without the patch.
One way to make this more obvious would be to change the type to signed
first, and then transform (which then would catch these cases too,
right?).
Ciao,
Dscho
^ permalink raw reply
* gitconfig get out of sync with submodule entries on branch switch
From: Benjamin Schindler @ 2017-01-30 16:21 UTC (permalink / raw)
To: git
Hi
Consider the following usecase: I have the master branch where I have a
submodule A. I create a branch where I rename the submodule to be in the
directory B. After doing all of this, everything looks good.
Now, I switch back to master. The first oddity is, that it fails to
remove the folder B because there are still files in there:
bschindler@metis ~/Projects/submodule_test (testbranch) $ git checkout
master
warning: unable to rmdir other_submodule: Directory not empty
Switched to branch 'master'
Git submodule deinit on B fails because the submodule is not known to
git anymore (after all, the folder B exists only in the other branch). I
can easily just remove the folder B from disk and initialize the
submodule A again, so all seems good.
However, what is not good is that the submodule b is still known in
.git/config. This is in particular a problem for us, because I know a
number of tools which use git config to retrieve the submodule list. Is
it therefore a bug that upon branch switch, the submodule gets
deregistered, but its entry in .git/config remains?
thanks a lot
Benjamin Schindler
P.s. I did not subscribe to the mailing list, please add me at least do
CC. Thanks
^ permalink raw reply
* Re: [PATCH 5/5] graph: use SWAP macro
From: Johannes Schindelin @ 2017-01-30 16:16 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano
In-Reply-To: <af5a7205-7703-f5ad-4ea2-b20ab4c01c80@web.de>
[-- Attachment #1: Type: text/plain, Size: 709 bytes --]
Hi René,
On Sat, 28 Jan 2017, René Scharfe wrote:
> Exchange the values of graph->columns and graph->new_columns using the
> macro SWAP instead of hand-rolled code. The result is shorter and
> easier to read.
>
> This transformation was not done by the semantic patch swap.cocci
> because there's an unrelated statement between the second and the last
> step of the exchange, so it didn't match the expected pattern.
Is it really true that Coccinelle cannot be told to look for a code block
that declares a variable that is then used *only* in the lines we want to
match and replace?
I never used the tool, and a quick web search did not clarify the picture,
either...
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 1/5] add SWAP macro
From: René Scharfe @ 2017-01-30 16:48 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Git List, Junio C Hamano
In-Reply-To: <alpine.DEB.2.20.1701301637570.3469@virtualbox>
Am 30.01.2017 um 16:39 schrieb Johannes Schindelin:
> Hi René,
>
> On Sat, 28 Jan 2017, René Scharfe wrote:
>
>> Add a macro for exchanging the values of variables. It allows users to
>> avoid repetition and takes care of the temporary variable for them. It
>> also makes sure that the storage sizes of its two parameters are the
>> same. Its memcpy(1) calls are optimized away by current compilers.
>
> How certain are we that "current compilers" optimize that away? And about
> which "current compilers" are we talking? GCC? GCC 6? Clang? Clang 3?
> Clang 3.8.*? Visual C 2005+?
GCC 4.4.7 and clang 3.2 on x86-64 compile the macro to the same object
code as a manual swap ; see https://godbolt.org/g/F4b9M9. Both were
released 2012. That website doesn't offer Visual C(++), but since you
added the original macro in e5a94313c0 ("Teach git-apply about '-R'",
2006) I guess we have that part covered. ;)
René
^ permalink raw reply
* Re: git-daemon shallow checkout fail
From: Johannes Schindelin @ 2017-01-30 16:52 UTC (permalink / raw)
To: Bob Proulx; +Cc: git
In-Reply-To: <20170129002932.GA19359@dismay.proulx.com>
Hi Bob,
On Sat, 28 Jan 2017, Bob Proulx wrote:
> And the server side says:
>
> [26071] Request upload-pack for '/test-project.git'
> [26071] fatal: Unable to create temporary file '/srv/git/test-project.git/shallow_xKwnvZ': Permission denied
> [26055] [26071] Disconnected (with error)
Assuming that you can rebuild your Git with debug symbols and without
optimization (simply remove the -O2 from CFLAGS in the Makefile, I never
had any luck with single-stepping in gdb when compiled with -O2), you
could attach gdb to the git-daemon and/or upload-pack process. Setting a
breakpoint on die_builtin in the failing process should give you a good
idea why things are failing, at least looking at the stacktrace.
A few more tidbits from a cursory look at the Git source code with `git
grep` and the likes:
- that error message comes from shallow.c's setup_temporary_shallow()
function
- that function is only called from fetch-pack and receive-pack, neither
of which should be called by upload-pack, so it is a puzzle
- adding a test case to t5570-git-daemon.sh that tests specifically your
described scenario seems *not* to fail:
-- snip --
diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh
index 225a022e8a..0256c9aded 100755
--- a/t/t5570-git-daemon.sh
+++ b/t/t5570-git-daemon.sh
@@ -186,5 +186,17 @@ test_expect_success 'hostname cannot break out of directory' '
git clone --bare "$GIT_DAEMON_URL/escape.git" tmp.git
'
+test_expect_success POSIXPERM 'shallow clone from read-only server' '
+ test_when_finished "rm -rf tmp.git" &&
+ repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/readonly.git" &&
+ git init --bare "$repo" &&
+ git push "$repo" HEAD &&
+ >"$repo"/git-daemon-export-ok &&
+ chmod a-w "$repo" &&
+ test_must_fail \
+ env GIT_OVERRIDE_VIRTUAL_HOST=.. \
+ git clone --depth 1 "$GIT_DAEMON_URL/readonly.git" tmp.git
+'
+
stop_git_daemon
test_done
-- snap --
- I even modified t/lib-git-daemon.sh to start the daemon as `nobody` and
kill it as `root`, and I won't share that patch because it is as
ugly, but *even then* the test succeeded.
So my suspicion is that the repository you try to serve may already be
shallow, or something else funky is going on that has not been included in
your report.
The most direct way to get to the bottom of this may be to do something
like this:
-- snip --
diff --git a/shallow.c b/shallow.c
index 11f7dde9d9..30f5c96d50 100644
--- a/shallow.c
+++ b/shallow.c
@@ -288,12 +288,18 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
static struct tempfile temporary_shallow;
+static int debug_me;
+
const char *setup_temporary_shallow(const struct sha1_array *extra)
{
struct strbuf sb = STRBUF_INIT;
int fd;
if (write_shallow_commits(&sb, 0, extra)) {
+error("About to create shallow_XXXXXX: pid = %d", getpid());
+while (!debug_me) {
+ sleep(1);
+}
fd = xmks_tempfile(&temporary_shallow, git_path("shallow_XXXXXX"));
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
-- snap --
Then let it run, wait for the error message "About to create
shallow_XXXXXX" and then attach with a gdb started as nobody via `attach
<pid>` to see the stack trace.
That should give you an idea where that code path is hit (unexpectedly).
Ciao,
Johannes
^ permalink raw reply related
* Re: [PATCH v3] mingw: allow hooks to be .exe files
From: Junio C Hamano @ 2017-01-30 16:51 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, Jeff King, Stefan Beller
In-Reply-To: <78a73c9d0a8e38fcc61302d0495533dcc4fab076.1485779272.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> Executable files in Windows need to have the extension '.exe', otherwise
> they do not work. Extend the hooks to not just look at the hard coded
> names, but also at the names extended by the custom STRIP_EXTENSION,
> which is defined as '.exe' in Windows.
Will replace, and looks good enough for 'next'. Let's stop
iterating and go incremental if/as needed.
Thanks.
^ permalink raw reply
* Re: [PATCH 1/5] add SWAP macro
From: René Scharfe @ 2017-01-30 16:59 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Git List, Junio C Hamano
In-Reply-To: <alpine.DEB.2.20.1701301643260.3469@virtualbox>
Am 30.01.2017 um 17:01 schrieb Johannes Schindelin:
> Hi René,
>
> On Sat, 28 Jan 2017, René Scharfe wrote:
>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index 87237b092b..66cd466eea 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -527,6 +527,16 @@ static inline int ends_with(const char *str, const char *suffix)
>> return strip_suffix(str, suffix, &len);
>> }
>>
>> +#define SWAP(a, b) do { \
>> + void *_swap_a_ptr = &(a); \
>> + void *_swap_b_ptr = &(b); \
>> + unsigned char _swap_buffer[sizeof(a)]; \
>> + memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \
>> + memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) + \
>> + BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \
>> + memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \
>> +} while (0)
>> +
>> #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
>
> It may seem as a matter of taste, or maybe not: I prefer this without the
> _swap_a_ptr (and I would also prefer not to use identifiers starting with
> an underscore, as section 7.1.3 Reserved Identifiers of the C99 standard
> says they are reserved):
>
> +#define SWAP(a, b) do { \
> + unsigned char swap_buffer_[sizeof(a)]; \
> + memcpy(swap_buffer_, &(a), sizeof(a)); \
> + memcpy(&(a), &(b), sizeof(a) + \
> + BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \
> + memcpy(&(b), swap_buffer_, sizeof(a)); \
> +} while (0)
We can move the underscore to the end, but using a and b directly will
give surprising results if the parameters have side effects. E.g. if
you want to swap the first two elements of two arrays you might want to
do this:
SWAP(*x++, *y++);
SWAP(*x++, *y++);
And that would increment twice as much as one would guess and access
unexpected elements.
> One idea to address the concern that not all C compilers people use to
> build Git may optimize away those memcpy()s: we could also introduce a
> SWAP_PRIMITIVE_TYPE (or SWAP2 or SIMPLE_SWAP or whatever) that accepts
> only primitive types. But since __typeof__() is not portable...
I wouldn't worry too much about such a solution before seeing that SWAP
(even with memcpy(3) -- this function is probably optimized quite
heavily on most platforms) causes an actual performance problem.
René
^ permalink raw reply
* Re: [PATCH v2] help: improve is_executable() on Windows
From: Junio C Hamano @ 2017-01-30 17:03 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, Heiko Voigt
In-Reply-To: <4b93fe44ff9020ed80e4fd93a24a6ffa647e7678.1485780050.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> From: Heiko Voigt <hvoigt@hvoigt.net>
>
> On Windows, executables need to have the file extension `.exe`, or they
> are not executables. Hence, to support scripts, Git for Windows also
> looks for a she-bang line by opening the file in question, and executing
> it via the specified script interpreter.
>
> To figure out whether files in the `PATH` are executable, `git help` has
> code that imitates this behavior. With one exception: it *always* opens
> the files and looks for a she-bang line *or* an `MZ` tell-tale
> (nevermind that files with the magic `MZ` but without file extension
> `.exe` would still not be executable).
>
> Opening this many files leads to performance problems that are even more
> serious when a virus scanner is running. Therefore, let's change the
> code to look for the file extension `.exe` early, and avoid opening the
> file altogether if we already know that it is executable.
Much more readable than the initial round. Will queue; thanks.
^ permalink raw reply
* Re: [PATCH v2] git-p4: Fix git-p4.mapUser on Windows
From: Junio C Hamano @ 2017-01-30 17:07 UTC (permalink / raw)
To: Luke Diamand; +Cc: Lars Schneider, Git Users, George Vanburgh
In-Reply-To: <CAE5ih7-qug9n-Df2gA27iTjSQo67tAnPhTJWQhyvR_PP9h3rcg@mail.gmail.com>
Luke Diamand <luke@diamand.org> writes:
> On 27 January 2017 at 17:33, Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Luke, Lars, this version seems to be in line with the conclusion of
>> your earlier reviews, e.g.
>>
>> <CAE5ih7_+Vc9oqKdjo8h2vgZPup4pto9wd=sBb=W6hCs4tuW2Jg@mail.gmail.com>
>>
>> Even though it looks OK to my eyes, I'll wait for Acks or further
>> refinement suggestions from either of you two before acting on this
>> patch.
>
> It looks good to me. The tests all pass, and the change looks correct.
Thanks, queued.
^ permalink raw reply
* Re: [PATCH 4/5] diff: use SWAP macro
From: René Scharfe @ 2017-01-30 17:26 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Git List, Junio C Hamano
In-Reply-To: <alpine.DEB.2.20.1701301704110.3469@virtualbox>
Am 30.01.2017 um 17:04 schrieb Johannes Schindelin:
> Hi René,
>
> On Sat, 28 Jan 2017, René Scharfe wrote:
>
>> Use the macro SWAP to exchange the value of pairs of variables instead
>> of swapping them manually with the help of a temporary variable. The
>> resulting code is shorter and easier to read.
>>
>> The two cases were not transformed by the semantic patch swap.cocci
>> because it's extra careful and handles only cases where the types of all
>> variables are the same -- and here we swap two ints and use an unsigned
>> temporary variable for that. Nevertheless the conversion is safe, as
>> the value range is preserved with and without the patch.
>
> One way to make this more obvious would be to change the type to signed
> first, and then transform (which then would catch these cases too,
> right?).
I'm not sure it would be more obvious, but it would certainly make the
type change more explicit. In diff-index.c we might even want to change
the type of the swapped values from int to unsigned, which is more
fitting for file modes. In diff.c we'd need to add a separate variable,
as tmp is shared with other (unsigned) swaps.
René
^ permalink raw reply
* Re: git-daemon shallow checkout fail
From: Jeff King @ 2017-01-30 17:27 UTC (permalink / raw)
To: git
In-Reply-To: <20170129002932.GA19359@dismay.proulx.com>
On Sat, Jan 28, 2017 at 05:29:32PM -0700, Bob Proulx wrote:
> However the problem driving me crazy is that this only fails this way
> on one machine. Unfortunately failing on the machine I need to use.
> If I try this same setup on any other machine I try then there is no
> failure and it works okay. Therefore I conclude that in the failing
> case it is trying to write a shallow_XXXXXX file in the repository but
> in all of the passing cases it does not. I browsed through the
> git-daemon source but couldn't deduce the flow yet.
>
> Does anyone know why one system would try to create shallow_XXXXXX
> files in the repository while another one would not?
It depends on the git version on the server. The interesting code is in
upload-pack.c, which is spawned by git-daemon to serve a fetch or clone
request.
See commit b790e0f67 (upload-pack: send shallow info over stdin to
pack-objects, 2014-03-11), which lays out the history. Since that commit
(in git v2.0.0), there should be no tmpfile needed.
> Of course git-daemon running as nobody can't create a temporary file
> shallow_XXXXXX in the /srv/git/test-project.git because it has no
> permissions by design. But why does this work on other systems and
> not work on my target system?
>
> git --version # from today's git clone build
> git version 2.11.0.485.g4e59582
This shouldn't be happening with git v2.11. Are you sure that the "git
daemon" invocation is running that same version? I notice you set up a
restricted PATH. Is it possible that /usr/local/bin or /usr/bin has an
older version of git?
-Peff
^ permalink raw reply
* Re: [PATCH 3/5] use SWAP macro
From: René Scharfe @ 2017-01-30 17:18 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Git List, Junio C Hamano
In-Reply-To: <alpine.DEB.2.20.1701301702120.3469@virtualbox>
Am 30.01.2017 um 17:03 schrieb Johannes Schindelin:
> Hi René,
>
> On Sat, 28 Jan 2017, René Scharfe wrote:
>
>> diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
>> index 806dd7a885..8ce00480cd 100644
>> --- a/builtin/diff-tree.c
>> +++ b/builtin/diff-tree.c
>> @@ -147,9 +147,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
>> tree1 = opt->pending.objects[0].item;
>> tree2 = opt->pending.objects[1].item;
>> if (tree2->flags & UNINTERESTING) {
>> - struct object *tmp = tree2;
>> - tree2 = tree1;
>> - tree1 = tmp;
>> + SWAP(tree2, tree1);
>> }
>
> Is there a way to transform away the curly braces for blocks that become
> single-line blocks, too?
Interesting question. I guess this can be done by using a Python script
(see contrib/coccinelle/strbuf.cocci for an example). I'll leave this
as homework for readers interested in Coccinelle, at least for a while. :)
René
^ permalink raw reply
* Re: [PATCH 5/5] graph: use SWAP macro
From: René Scharfe @ 2017-01-30 17:41 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Git List, Junio C Hamano
In-Reply-To: <alpine.DEB.2.20.1701301714450.3469@virtualbox>
Am 30.01.2017 um 17:16 schrieb Johannes Schindelin:
> Hi René,
>
> On Sat, 28 Jan 2017, René Scharfe wrote:
>
>> Exchange the values of graph->columns and graph->new_columns using the
>> macro SWAP instead of hand-rolled code. The result is shorter and
>> easier to read.
>>
>> This transformation was not done by the semantic patch swap.cocci
>> because there's an unrelated statement between the second and the last
>> step of the exchange, so it didn't match the expected pattern.
>
> Is it really true that Coccinelle cannot be told to look for a code block
> that declares a variable that is then used *only* in the lines we want to
> match and replace?
Hope I parsed your question correctly; my answer would be that it can't
be true because that's basically what the proposed semantic patch does:
@ swap @
type T;
T tmp, a, b;
@@
- tmp = a;
- a = b;
- b = tmp;
+ SWAP(a, b);
@ extends swap @
identifier unused;
@@
{
...
- T unused;
... when != unused
}
The first part (up to the "+") looks for a opportunities to use SWAP,
and the second part looks for blocks where that transformation was done
and we declare identifiers that are/became unused.
It did not match the code in graph.c because the pattern was basically:
tmp = a;
a = b;
something = totally_different;
b = tmp;
Coccinelle can be told to ignore such unrelated code by adding "... when
!= tmp" etc. (which matches context lines that don't reference tmp), but
that's slooow. (Perhaps I just did it wrong, though.)
René
^ permalink raw reply
* Re: gitconfig get out of sync with submodule entries on branch switch
From: Brandon Williams @ 2017-01-30 17:51 UTC (permalink / raw)
To: Benjamin Schindler; +Cc: git, sbeller
In-Reply-To: <0f14df64-1aa2-e671-9785-4e5e0a076ae6@gmail.com>
On 01/30, Benjamin Schindler wrote:
> Hi
>
> Consider the following usecase: I have the master branch where I
> have a submodule A. I create a branch where I rename the submodule
> to be in the directory B. After doing all of this, everything looks
> good.
> Now, I switch back to master. The first oddity is, that it fails to
> remove the folder B because there are still files in there:
>
> bschindler@metis ~/Projects/submodule_test (testbranch) $ git
> checkout master
> warning: unable to rmdir other_submodule: Directory not empty
> Switched to branch 'master'
>
> Git submodule deinit on B fails because the submodule is not known
> to git anymore (after all, the folder B exists only in the other
> branch). I can easily just remove the folder B from disk and
> initialize the submodule A again, so all seems good.
>
> However, what is not good is that the submodule b is still known in
> .git/config. This is in particular a problem for us, because I know
> a number of tools which use git config to retrieve the submodule
> list. Is it therefore a bug that upon branch switch, the submodule
> gets deregistered, but its entry in .git/config remains?
>
> thanks a lot
> Benjamin Schindler
>
> P.s. I did not subscribe to the mailing list, please add me at least
> do CC. Thanks
submodules and checkout don't really play nicely with each other at the
moment. Stefan (cc'd) is currently working on a patch series to improve
the behavior of checkout with submodules. Currently, if you want to
ensure you have a good working state after a checkout you should run
`git submodule update` to update all of the submoules. As far as your
submodule still being listed in the config, that should be expected
given the scenario you described.
If I'm understanding you correctly, A and B are both the same submodule
just renamed on a different branch. The moment you add a submoule to a
repository it is given a name which is fixed. Typically this is the
path from the root of the repository. The thing is, since you are able
to freely move a submodule, its path can change. To account for this
there is the .gitmodules file which allows you to do a lookup from
submodule name to the path at which it exists (or vice versa). The
submodules that are stored in .git/config are those which are
'initialize' or rather the submodules in which you are interested in and
will be updated by `git submodule update`. So given your scenario you
should only have a single submodule in .git/config and the .gitmodules
file should have a single entry with a differing path for each branch.
Hopefully this gives you a bit more information to work with. Since
Stefan has been working with this more recently than me he may have some
more input.
--
Brandon Williams
^ permalink raw reply
* [PATCH v3 16/27] attr: convert git_all_attrs() to use "struct attr_check"
From: Brandon Williams @ 2017-01-30 18:06 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Stefan Beller, Brandon Williams
In-Reply-To: <20170128020207.179015-17-bmwill@google.com>
From: Junio C Hamano <gitster@pobox.com>
This updates the other two ways the attribute check is done via an
array of "struct attr_check_item" elements. These two niches
appear only in "git check-attr".
* The caller does not know offhand what attributes it wants to ask
about and cannot use attr_check_initl() to prepare the
attr_check structure.
* The caller may not know what attributes it wants to ask at all,
and instead wants to learn everything that the given path has.
Such a caller can call attr_check_alloc() to allocate an empty
attr_check, and then call attr_check_append() to add attribute names
one by one.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Brandon Williams <bmwill@google.com>
---
This is the correct 16/27 patch that doesn't have the rebase mistake discoverd
by Stefan.
attr.c | 30 +++++++++-----------------
attr.h | 9 +++-----
builtin/check-attr.c | 60 ++++++++++++++++++++++++++--------------------------
3 files changed, 43 insertions(+), 56 deletions(-)
diff --git a/attr.c b/attr.c
index e3298516a..40818246f 100644
--- a/attr.c
+++ b/attr.c
@@ -906,32 +906,22 @@ int git_check_attrs(const char *path, int num, struct attr_check_item *check)
return 0;
}
-int git_all_attrs(const char *path, int *num, struct attr_check_item **check)
+void git_all_attrs(const char *path, struct attr_check *check)
{
- int i, count, j;
+ int i;
- collect_some_attrs(path, 0, NULL);
+ attr_check_reset(check);
+ collect_some_attrs(path, check->nr, check->items);
- /* Count the number of attributes that are set. */
- count = 0;
- for (i = 0; i < attr_nr; i++) {
- const char *value = check_all_attr[i].value;
- if (value != ATTR__UNSET && value != ATTR__UNKNOWN)
- ++count;
- }
- *num = count;
- ALLOC_ARRAY(*check, count);
- j = 0;
for (i = 0; i < attr_nr; i++) {
+ const char *name = check_all_attr[i].attr->name;
const char *value = check_all_attr[i].value;
- if (value != ATTR__UNSET && value != ATTR__UNKNOWN) {
- (*check)[j].attr = check_all_attr[i].attr;
- (*check)[j].value = value;
- ++j;
- }
+ struct attr_check_item *item;
+ if (value == ATTR__UNSET || value == ATTR__UNKNOWN)
+ continue;
+ item = attr_check_append(check, git_attr(name));
+ item->value = value;
}
-
- return 0;
}
int git_check_attr(const char *path, struct attr_check *check)
diff --git a/attr.h b/attr.h
index e611b139a..9f2729842 100644
--- a/attr.h
+++ b/attr.h
@@ -56,13 +56,10 @@ int git_check_attrs(const char *path, int, struct attr_check_item *);
extern int git_check_attr(const char *path, struct attr_check *check);
/*
- * Retrieve all attributes that apply to the specified path. *num
- * will be set to the number of attributes on the path; **check will
- * be set to point at a newly-allocated array of git_attr_check
- * objects describing the attributes and their values. *check must be
- * free()ed by the caller.
+ * Retrieve all attributes that apply to the specified path.
+ * check holds the attributes and their values.
*/
-int git_all_attrs(const char *path, int *num, struct attr_check_item **check);
+extern void git_all_attrs(const char *path, struct attr_check *check);
enum git_attr_direction {
GIT_ATTR_CHECKIN,
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 889264a5b..40cdff13e 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -24,12 +24,13 @@ static const struct option check_attr_options[] = {
OPT_END()
};
-static void output_attr(int cnt, struct attr_check_item *check,
- const char *file)
+static void output_attr(struct attr_check *check, const char *file)
{
int j;
+ int cnt = check->nr;
+
for (j = 0; j < cnt; j++) {
- const char *value = check[j].value;
+ const char *value = check->items[j].value;
if (ATTR_TRUE(value))
value = "set";
@@ -42,36 +43,38 @@ static void output_attr(int cnt, struct attr_check_item *check,
printf("%s%c" /* path */
"%s%c" /* attrname */
"%s%c" /* attrvalue */,
- file, 0, git_attr_name(check[j].attr), 0, value, 0);
+ file, 0,
+ git_attr_name(check->items[j].attr), 0, value, 0);
} else {
quote_c_style(file, NULL, stdout, 0);
- printf(": %s: %s\n", git_attr_name(check[j].attr), value);
+ printf(": %s: %s\n",
+ git_attr_name(check->items[j].attr), value);
}
-
}
}
static void check_attr(const char *prefix,
- int cnt, struct attr_check_item *check,
+ struct attr_check *check,
+ int collect_all,
const char *file)
{
char *full_path =
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
- if (check != NULL) {
- if (git_check_attrs(full_path, cnt, check))
- die("git_check_attrs died");
- output_attr(cnt, check, file);
+
+ if (collect_all) {
+ git_all_attrs(full_path, check);
} else {
- if (git_all_attrs(full_path, &cnt, &check))
- die("git_all_attrs died");
- output_attr(cnt, check, file);
- free(check);
+ if (git_check_attr(full_path, check))
+ die("git_check_attr died");
}
+ output_attr(check, file);
+
free(full_path);
}
static void check_attr_stdin_paths(const char *prefix,
- int cnt, struct attr_check_item *check)
+ struct attr_check *check,
+ int collect_all)
{
struct strbuf buf = STRBUF_INIT;
struct strbuf unquoted = STRBUF_INIT;
@@ -85,7 +88,7 @@ static void check_attr_stdin_paths(const char *prefix,
die("line is badly quoted");
strbuf_swap(&buf, &unquoted);
}
- check_attr(prefix, cnt, check, buf.buf);
+ check_attr(prefix, check, collect_all, buf.buf);
maybe_flush_or_die(stdout, "attribute to stdout");
}
strbuf_release(&buf);
@@ -100,7 +103,7 @@ static NORETURN void error_with_usage(const char *msg)
int cmd_check_attr(int argc, const char **argv, const char *prefix)
{
- struct attr_check_item *check;
+ struct attr_check *check;
int cnt, i, doubledash, filei;
if (!is_bare_repository())
@@ -160,28 +163,25 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
error_with_usage("No file specified");
}
- if (all_attrs) {
- check = NULL;
- } else {
- check = xcalloc(cnt, sizeof(*check));
+ check = attr_check_alloc();
+ if (!all_attrs) {
for (i = 0; i < cnt; i++) {
- const char *name;
- struct git_attr *a;
- name = argv[i];
- a = git_attr(name);
+ struct git_attr *a = git_attr(argv[i]);
if (!a)
return error("%s: not a valid attribute name",
- name);
- check[i].attr = a;
+ argv[i]);
+ attr_check_append(check, a);
}
}
if (stdin_paths)
- check_attr_stdin_paths(prefix, cnt, check);
+ check_attr_stdin_paths(prefix, check, all_attrs);
else {
for (i = filei; i < argc; i++)
- check_attr(prefix, cnt, check, argv[i]);
+ check_attr(prefix, check, all_attrs, argv[i]);
maybe_flush_or_die(stdout, "attribute to stdout");
}
+
+ attr_check_free(check);
return 0;
}
--
2.11.0.483.g087da7b7c-goog
^ permalink raw reply related
* [PATCH v3 15/27] attr: (re)introduce git_check_attr() and struct attr_check
From: Brandon Williams @ 2017-01-30 18:05 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Stefan Beller, Brandon Williams
In-Reply-To: <20170128020207.179015-16-bmwill@google.com>
From: Junio C Hamano <gitster@pobox.com>
A common pattern to check N attributes for many paths is to
(1) prepare an array A of N attr_check_item items;
(2) call git_attr() to intern the N attribute names and fill A;
(3) repeatedly call git_check_attrs() for path with N and A;
A look-up for these N attributes for a single path P scans the
entire attr_stack, starting from the .git/info/attributes file and
then .gitattributes file in the directory the path P is in, going
upwards to find .gitattributes file found in parent directories.
An earlier commit 06a604e6 (attr: avoid heavy work when we know the
specified attr is not defined, 2014-12-28) tried to optimize out
this scanning for one trivial special case: when the attribute being
sought is known not to exist, we do not have to scan for it. While
this may be a cheap and effective heuristic, it would not work well
when N is (much) more than 1.
What we would want is a more customized way to skip irrelevant
entries in the attribute stack, and the definition of irrelevance
is tied to the set of attributes passed to git_check_attrs() call,
i.e. the set of attributes being sought. The data necessary for
this optimization needs to live alongside the set of attributes, but
a simple array of git_attr_check_elem simply does not have any place
for that.
Introduce "struct attr_check" that contains N, the number of
attributes being sought, and A, the array that holds N
attr_check_item items, and a function git_check_attr() that
takes a path P and this structure as its parameters. This structure
can later be extended to hold extra data necessary for optimization.
Also, to make it easier to write the first two steps in common
cases, introduce git_attr_check_initl() helper function, which takes
a NULL-terminated list of attribute names and initialize this
structure.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Brandon Williams <bmwill@google.com>
---
This is the correct 15/27 patch that doesn't have the rebase mistake discovered
by Stefan.
attr.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
attr.h | 17 +++++++++++++++
2 files changed, 91 insertions(+)
diff --git a/attr.c b/attr.c
index 2f180d609..e3298516a 100644
--- a/attr.c
+++ b/attr.c
@@ -370,6 +370,75 @@ static void free_attr_elem(struct attr_stack *e)
free(e);
}
+struct attr_check *attr_check_alloc(void)
+{
+ return xcalloc(1, sizeof(struct attr_check));
+}
+
+struct attr_check *attr_check_initl(const char *one, ...)
+{
+ struct attr_check *check;
+ int cnt;
+ va_list params;
+ const char *param;
+
+ va_start(params, one);
+ for (cnt = 1; (param = va_arg(params, const char *)) != NULL; cnt++)
+ ;
+ va_end(params);
+
+ check = attr_check_alloc();
+ check->nr = cnt;
+ check->alloc = cnt;
+ check->items = xcalloc(cnt, sizeof(struct attr_check_item));
+
+ check->items[0].attr = git_attr(one);
+ va_start(params, one);
+ for (cnt = 1; cnt < check->nr; cnt++) {
+ const struct git_attr *attr;
+ param = va_arg(params, const char *);
+ if (!param)
+ die("BUG: counted %d != ended at %d",
+ check->nr, cnt);
+ attr = git_attr(param);
+ if (!attr)
+ die("BUG: %s: not a valid attribute name", param);
+ check->items[cnt].attr = attr;
+ }
+ va_end(params);
+ return check;
+}
+
+struct attr_check_item *attr_check_append(struct attr_check *check,
+ const struct git_attr *attr)
+{
+ struct attr_check_item *item;
+
+ ALLOC_GROW(check->items, check->nr + 1, check->alloc);
+ item = &check->items[check->nr++];
+ item->attr = attr;
+ return item;
+}
+
+void attr_check_reset(struct attr_check *check)
+{
+ check->nr = 0;
+}
+
+void attr_check_clear(struct attr_check *check)
+{
+ free(check->items);
+ check->items = NULL;
+ check->alloc = 0;
+ check->nr = 0;
+}
+
+void attr_check_free(struct attr_check *check)
+{
+ attr_check_clear(check);
+ free(check);
+}
+
static const char *builtin_attr[] = {
"[attr]binary -diff -merge -text",
NULL,
@@ -865,6 +934,11 @@ int git_all_attrs(const char *path, int *num, struct attr_check_item **check)
return 0;
}
+int git_check_attr(const char *path, struct attr_check *check)
+{
+ return git_check_attrs(path, check->nr, check->items);
+}
+
void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate)
{
enum git_attr_direction old = direction;
diff --git a/attr.h b/attr.h
index efc7bb3b3..e611b139a 100644
--- a/attr.h
+++ b/attr.h
@@ -29,6 +29,22 @@ struct attr_check_item {
const char *value;
};
+struct attr_check {
+ int nr;
+ int alloc;
+ struct attr_check_item *items;
+};
+
+extern struct attr_check *attr_check_alloc(void);
+extern struct attr_check *attr_check_initl(const char *, ...);
+
+extern struct attr_check_item *attr_check_append(struct attr_check *check,
+ const struct git_attr *attr);
+
+extern void attr_check_reset(struct attr_check *check);
+extern void attr_check_clear(struct attr_check *check);
+extern void attr_check_free(struct attr_check *check);
+
/*
* Return the name of the attribute represented by the argument. The
* return value is a pointer to a null-delimited string that is part
@@ -37,6 +53,7 @@ struct attr_check_item {
extern const char *git_attr_name(const struct git_attr *);
int git_check_attrs(const char *path, int, struct attr_check_item *);
+extern int git_check_attr(const char *path, struct attr_check *check);
/*
* Retrieve all attributes that apply to the specified path. *num
--
2.11.0.483.g087da7b7c-goog
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox