* [PATCH 3/4] color-words: expand docs with precise semantics
From: Thomas Rast @ 2009-01-14 22:26 UTC (permalink / raw)
To: git; +Cc: Johannes Schindelin, Santi Béjar, Junio C Hamano
In-Reply-To: <alpine.DEB.1.00.0901142104400.3586@pacific.mpi-cbg.de>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Documentation/diff-options.txt | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 2c1fa4b..8689a92 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -91,12 +91,17 @@ endif::git-format-patch[]
Turn off colored diff, even when the configuration file
gives the default to color output.
---color-words[=regex]::
- Show colored word diff, i.e. color words which have changed.
+--color-words[=<regex>]::
+ Show colored word diff, i.e., color words which have changed.
+ By default, words are separated by whitespace.
+
-Optionally, you can pass a regular expression that tells Git what the
-words are that you are looking for; The default is to interpret any
-stretch of non-whitespace as a word.
+When a <regex> is specified, every non-overlapping match of the
+<regex> is considered a word. Anything between these matches is
+considered whitespace and ignored(!) for the purposes of finding
+differences. You may want to append `|[^[:space:]]` to your regular
+expression to make sure that it matches all non-whitespace characters.
+A match that contains a newline is silently truncated(!) at the
+newline.
--no-renames::
Turn off rename detection, even when the configuration
--
1.6.1.142.ge070e
^ permalink raw reply related
* [PATCH 2/4] color-words: enable REG_NEWLINE to help user
From: Thomas Rast @ 2009-01-14 22:26 UTC (permalink / raw)
To: git; +Cc: Johannes Schindelin, Santi Béjar, Junio C Hamano
In-Reply-To: <alpine.DEB.1.00.0901142104400.3586@pacific.mpi-cbg.de>
We silently truncate a match at the newline, which may lead to
unexpected behaviour, e.g., when matching "<[^>]*>" against
<foo
bar>
since then "<foo" becomes a word (and "bar>" doesn't!) even though the
regex said only angle-bracket-delimited things can be words.
To alleviate the problem slightly, use REG_NEWLINE so that negated
classes can't match a newline. Of course newlines can still be
matched explicitly.
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
diff.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c
index cc42adf..3f07ac1 100644
--- a/diff.c
+++ b/diff.c
@@ -1536,7 +1536,8 @@ static void builtin_diff(const char *name_a,
ecbdata.diff_words->word_regex = (regex_t *)
xmalloc(sizeof(regex_t));
if (regcomp(ecbdata.diff_words->word_regex,
- o->word_regex, REG_EXTENDED))
+ o->word_regex,
+ REG_EXTENDED | REG_NEWLINE))
die ("Invalid regular expression: %s",
o->word_regex);
}
--
1.6.1.142.ge070e
^ permalink raw reply related
* [PATCH 1/4] color-words: fix quoting in t4034
From: Thomas Rast @ 2009-01-14 22:26 UTC (permalink / raw)
To: git; +Cc: Johannes Schindelin, Santi Béjar, Junio C Hamano
In-Reply-To: <alpine.DEB.1.00.0901142104400.3586@pacific.mpi-cbg.de>
Since the single quotes match the ones used to quote the test text
itself, they'd be dropped. Use double quotes instead.
---
I'd squash this into Dscho's 4/4, so no SoB.
t/t4034-diff-words.sh | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index f4810e9..6ad1c1f 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -80,7 +80,7 @@ EOF
test_expect_success 'word diff with a regular expression' '
- word_diff --color-words='[a-z]+'
+ word_diff --color-words="[a-z]+"
'
@@ -98,7 +98,7 @@ EOF
test_expect_success "test parsing words for newline" '
- word_diff --color-words='a+'
+ word_diff --color-words="a+"
'
--
1.6.1.142.ge070e
^ permalink raw reply related
* Re: [PATCH take 3 0/4] color-words improvements
From: Boyd Stephen Smith Jr. @ 2009-01-14 22:24 UTC (permalink / raw)
To: Johannes Schindelin
Cc: Thomas Rast, Teemu Likonen, Junio C Hamano, git, Santi Béjar
In-Reply-To: <alpine.DEB.1.00.0901142258250.3586@pacific.mpi-cbg.de>
[-- Attachment #1: Type: text/plain, Size: 1317 bytes --]
On Wednesday 2009 January 14 16:06:48 Johannes Schindelin wrote:
>On Wed, 14 Jan 2009, Thomas Rast wrote:
>> Bug aside, examples like this one make me wonder if we should force a
>> "last resort" match for `[^[:space:]]`. For example,
>>
>> -aaa [aaa]
>> +aaa (aaa) aaa
>>
>> would still give you
>>
>> aaa (aaa)<GREEN> aaa<RESET>
>>
>> which may be unexpected.
>
>But why should it be unexpected? If people say that every length of "a"
>makes a word, and consequently everything else is clutter, then that's
>that, no?
I think some people are going to have problems with the strict dichotomy
between "part of a word" and "ignorable whitespace" that is being set up.
It makes sense technically, but it could confuse.
Imagine with --diff-words=[A-Z][A-Za-z]* and the following change:
-To be Or Not To be.
+To ignore Or Not To treat whitespace differently.
I think there is value in being able to ignore anything that's not a word,
so the documentation that mentions adding '|[^[:space:]]' to your regex
seems sufficient to me.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply
* Re: git-svn clone -s fails to setup branches in git if the most recent svn commit was not to trunk
From: Boyd Stephen Smith Jr. @ 2009-01-14 22:04 UTC (permalink / raw)
To: Adam Soltys; +Cc: git
In-Reply-To: <loom.20090114T211218-628@post.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 429 bytes --]
On Wednesday 2009 January 14 15:27:01 Adam Soltys wrote:
<snip: git-svn weirdness when the last commit is to a branch/tag>
I already knew about this bug, but here is my "+1 please fix" mail.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply
* Re: [PATCH take 3 0/4] color-words improvements
From: Thomas Rast @ 2009-01-14 22:11 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Teemu Likonen, Junio C Hamano, git, Santi Béjar
In-Reply-To: <alpine.DEB.1.00.0901142258250.3586@pacific.mpi-cbg.de>
[-- Attachment #1: Type: text/plain, Size: 263 bytes --]
Johannes Schindelin wrote:
> Which reminds me... should we activate REG_EXTENDED by default?
We (you :-) do, and I think so. Consider that funcname is not even
documented any more, in favour of xfuncname.
--
Thomas Rast
trast@{inf,student}.ethz.ch
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply
* cygwin git diff crash
From: Jeremy Ramer @ 2009-01-14 22:09 UTC (permalink / raw)
To: Git Mailing List
Ok this is a weird issue and it's probably cygwin's fault, but I
haven't found any way to fix it so I' thought I would throw it out
here for comment.
I am using git 1.6.0.4 on cygwin. I have a repo where if any file has
changes and git detects as mode 100644 I get this error:
$git diff
3 [main] git 2744 C:\cygwin\bin\git.exe: *** fatal error - could
not load user32, Win32 error
If I change the mode to 100755 git diff will work fine.
$chmod a+x test.cpp
$git diff
diff --git a/test.cpp b/test.cpp
old mode 100644
new mode 100755
index 7c0dfcd..20987a7
--- a/test.cpp
+++ b/test.cpp
@@ -6,9 +6,11 @@ int main()
void func()
{
+ int a;^M
}
void func2()
{
+ int b;^M
}
Anybody have a clue as to why this might occur? I have seen this in
many of the repo's I use, but it is not repeatable. I tried making a
test repo but could not reproduce.
Thanks!
Jeremy
^ permalink raw reply related
* Re: [PATCH take 3 0/4] color-words improvements
From: Johannes Schindelin @ 2009-01-14 22:06 UTC (permalink / raw)
To: Thomas Rast; +Cc: Teemu Likonen, Junio C Hamano, git, Santi Béjar
In-Reply-To: <200901142059.09005.trast@student.ethz.ch>
Hi,
On Wed, 14 Jan 2009, Thomas Rast wrote:
> Teemu Likonen wrote:
> > -aaa (aaa)
> > +aaa (aaa) aaa
>
> Bug aside, examples like this one make me wonder if we should force a
> "last resort" match for `[^[:space:]]`. For example,
>
> -aaa [aaa]
> +aaa (aaa) aaa
>
> would still give you
>
> aaa (aaa)<GREEN> aaa<RESET>
>
> which may be unexpected.
But why should it be unexpected? If people say that every length of "a"
makes a word, and consequently everything else is clutter, then that's
that, no?
So people might be surprised, but then they should have said something
like
[-.+#@"'$%^&*([{<>~|]*[A-Za-z][A-Za-z0-9]*[-.+#@"'$%&*)\]}>|]*
instead.
Although I have to say that for some applications, it is a pity that
even POSIX extended regular expressions knows neither lookahead nor
lookbehind.
Which reminds me... should we activate REG_EXTENDED by default?
Ciao,
Dscho
^ permalink raw reply
* Re: Google Summer of Code 2009
From: Stephan Beyer @ 2009-01-14 22:01 UTC (permalink / raw)
To: Jakub Narebski; +Cc: Shawn O. Pearce, git, Daniel Barkalow, Christian Couder
In-Reply-To: <m3privyn20.fsf@localhost.localdomain>
Hi,
Jakub Narebski wrote:
> By the way, do you know what happened with git-sequencer project?
>
> If I remember correctly there was agreement on sequences mini-language
> (I think), and there was git-sequencer prototype in shell, using
> git-cherry-pick if I remember correctly, and even git-rebase and
> git-am etc reworked to make use of git-sequencer. Stephan Beyer wrote
> that he has some preliminary version of builtin git-sequencer (in C),
> and that it makes git-rebase--interactive and like faster than current
> implementation... but builtin sequencer never materialized on git
> mailing list as a patch, if I remember correctly, and of course it was
> not merged into git either.
You remember and conclude correctly.
As Christian pointed out, we are working on it. Development didn't make
any real progress for a long time because of different personal reasons.
(If you're interested: an important exam at the end of September,
some other work besides, wrong priorities in time management,
some kind of "burnout" after the exam which made me avoid any kind of
productive work for a long time... it went away in between but came back
later...)
Now, again, I'm highly motivated to get it merged into pu or next before
the end of January. I hope, Christian or Daniel will kick me in the back
if this is not going to happen :-)
The next days some tiny and some bigger patches will follow. Commits
that have been lying around in my repo for a _long_ time.
In this time I try to address the rest of my TODO list which emerged
from a very chaotic sticky note[1] and is, well, just chaotic.
It contains items about...
- some internal changes (simplifications, code reuse),
- some changes in the output of sequencer,
- some better code documentation (one item for a part of sequencer
itself, one item for its test suite t3350),
- check some stuff and fix if needed
(e.g. whether sequencer changes this or that behavior (for
rebase or am) that I haven't taken care of yet),
- and the last item is to check/incorporate the git-rebase --root
patches and/or fix sequencer to work with them (if needed).
(I haven't taken one look at these patches, so I don't know
if it's really necessary.)
It's not too much, but every single change can generate a bug
and, thus, hassle. :-)
Well, this is the current state of the git-sequencer project.
Thanks for the question and the prodding in the other thread (although
the problem there was solved much simpler without sequencer.)
Regards,
Stephan
Footnotes.
1. I mean those fancy yellow desktop notes provided by tools like
"knotes" -- now uninstalled from my desktop machine, because
there are *useful* tools like outliners that _help_ to
manage ideas, todo lists, etc in a non-chaotic way.
--
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
^ permalink raw reply
* [PATCH] git-rev-parse(1): restore vital table header
From: jidanni @ 2009-01-14 21:34 UTC (permalink / raw)
To: gitster; +Cc: git
A vital table header is restored. Else the new user may be confused as
to the implied relationship betwixt the two columns.
Signed-off-by: jidanni <jidanni@jidanni.org>
---
Documentation/git-rev-parse.txt | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 2921da3..45ea114 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -318,6 +318,7 @@ all of its parents.
Here are a handful of examples:
+ Range Reaches
D G H D
D F G H I J D F
^G D H D
--
1.6.0.6
^ permalink raw reply related
* git-svn clone -s fails to setup branches in git if the most recent svn commit was not to trunk
From: Adam Soltys @ 2009-01-14 21:27 UTC (permalink / raw)
To: git
I ran the following command to clone from an svn repository that followed the
standard svn folder layout and had two branches:
svn clone -s svn://path/to/my_repo
I then typed:
git branch -r
Which returned:
origin/HEAD
origin/master
I was expecting to see the branches and tags from the svn /branches and /tags
folders but they did not appear.
I checked out origin/HEAD and origin/master to see what was there and I found
they contained code from a subversion branch that was originally in the
/branches folder. I noticed that this particular branch was the last place
committed to in the svn repo. So I checked something into the /trunk of the svn
repo, nuked the git repo, and ran the git svn clone command again. This time it
worked as expected and "git branch -r" showed me all my tags and branches.
^ permalink raw reply
* [PATCH] [TOPGIT] make creating a commit from a topgit branch a function
From: Uwe Kleine-König @ 2009-01-14 21:27 UTC (permalink / raw)
To: git; +Cc: martin f. krafft, Petr Baudis
In-Reply-To: <1231968443-13960-1-git-send-email-u.kleine-koenig@pengutronix.de>
This helps avoiding code duplication for the next commit.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
tg-export.sh | 27 ++++++++++++++++++---------
1 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/tg-export.sh b/tg-export.sh
index 9e6940f..dea24d9 100644
--- a/tg-export.sh
+++ b/tg-export.sh
@@ -71,14 +71,11 @@ pretty_tree()
git write-tree)
}
-# collapsed_commit NAME
-# Produce a collapsed commit of branch NAME.
-collapsed_commit()
+create_tg_commit()
{
name="$1"
-
- rm -f "$playground/^pre" "$playground/^post"
- >"$playground/^body"
+ tree="$2"
+ parent="$3"
# Get commit message and authorship information
git cat-file blob "$name:.topmsg" | git mailinfo "$playground/^msg" /dev/null > "$playground/^info"
@@ -92,6 +89,20 @@ collapsed_commit()
test -n "$GIT_AUTHOR_EMAIL" && export GIT_AUTHOR_EMAIL
test -n "$GIT_AUTHOR_DATE" && export GIT_AUTHOR_DATE
+ (printf '%s\n\n' "$SUBJECT"; cat "$playground/^msg") |
+ git stripspace |
+ git commit-tree "$tree" -p "$parent"
+}
+
+# collapsed_commit NAME
+# Produce a collapsed commit of branch NAME.
+collapsed_commit()
+{
+ name="$1"
+
+ rm -f "$playground/^pre" "$playground/^post"
+ >"$playground/^body"
+
# Determine parent
parent="$(cut -f 1 "$playground/$name^parents")"
if [ "$(cat "$playground/$name^parents" | wc -l)" -gt 1 ]; then
@@ -107,9 +118,7 @@ collapsed_commit()
if branch_empty "$name"; then
echo "$parent";
else
- (printf '%s\n\n' "$SUBJECT"; cat "$playground/^msg") |
- git stripspace |
- git commit-tree "$(pretty_tree "$name")" -p "$parent"
+ create_tg_commit "$name" "$(pretty_tree $name)" "$parent"
fi;
echo "$name" >>"$playground/^ticker"
--
1.5.6.5
^ permalink raw reply related
* [PATCH] [TOPGIT] make tg remote idempotent
From: Uwe Kleine-König @ 2009-01-14 21:27 UTC (permalink / raw)
To: git; +Cc: martin f. krafft, Petr Baudis
Before this patch each call to tg remote added three config entries
no matter if they already existed. After some time my .git/config was
crowded.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
tg-remote.sh | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tg-remote.sh b/tg-remote.sh
index c3e8bd3..7f7a1b0 100644
--- a/tg-remote.sh
+++ b/tg-remote.sh
@@ -27,9 +27,9 @@ git config "remote.$name.url" >/dev/null || die "unknown remote '$name'"
## Configure the remote
-git config --add "remote.$name.fetch" "+refs/top-bases/*:refs/remotes/$name/top-bases/*"
-git config --add "remote.$name.push" "+refs/top-bases/*:refs/top-bases/*"
-git config --add "remote.$name.push" "+refs/heads/*:refs/heads/*"
+git config --replace-all "remote.$name.fetch" "+refs/top-bases/*:refs/remotes/$name/top-bases/*" "+refs/top-bases/*:refs/remotes/$name/top-bases/*"
+git config --replace-all "remote.$name.push" "+refs/top-bases/*:refs/top-bases/*" "+refs/top-bases/*:refs/top-bases/*"
+git config --replace-all "remote.$name.push" "+refs/heads/*:refs/heads/*" "+refs/heads/*:refs/heads/*"
info "Remote $name can now follow TopGit topic branches."
if [ -z "$populate" ]; then
--
1.5.6.5
^ permalink raw reply related
* Re: [PATCH next v3] git-notes: add test case for multi-line notes
From: Johannes Schindelin @ 2009-01-14 21:10 UTC (permalink / raw)
To: Tor Arne Vestbø; +Cc: Johannes Sixt, Jeff King, Junio C Hamano, git
In-Reply-To: <496E51A3.8050908@gmail.com>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 434 bytes --]
Hi,
On Wed, 14 Jan 2009, Tor Arne Vestbø wrote:
> The tests adds a third commit with a multi-line note. The output of
> git log -2 is then checked to see if the note lines are wrapped
> correctly, and that there's a line separator between the two commits.
>
> Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>
> ---
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Maybe squash the test into the fix?
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH take 3 0/4] color-words improvements
From: Johannes Schindelin @ 2009-01-14 21:07 UTC (permalink / raw)
To: Thomas Rast; +Cc: Junio C Hamano, git, Santi Béjar
In-Reply-To: <200901142104.16134.trast@student.ethz.ch>
Hi,
On Wed, 14 Jan 2009, Thomas Rast wrote:
> Johannes Schindelin wrote:
> >
> > The only "funny" thing I realized is that the lines which are output
> > by emit_line() add a RESET at the end of the line, and I do not do that
> > in color_fwrite_lines().
>
> Umm.... but you seem to do?
Oh, right! I think the culprit is in fn_out_diff_words_aux(), which calls
fwrite() directly for the common words.
> Ack on the new regex semantics, though I'd have implemented it via dying
> on '\n' instead of silently splitting there (and restarting a new
> match!).
Hmm. I'd rather not die() in the middle of it.
Maybe we can even handle newlines correctly by replacing them with NULs
which libxdiff handles just fine?
> Thus, Ack on 4/4 once the boundary bug is fixed. Thanks for your work!
Phew. I was almost convinced you would hate me for my criticiscm.
Thanks,
Dscho
^ permalink raw reply
* [PATCH next v3] git-notes: add test case for multi-line notes
From: Tor Arne Vestbø @ 2009-01-14 20:57 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Jeff King, Johannes Schindelin, Junio C Hamano, git
In-Reply-To: <496E1D77.6000307@viscovery.net>
The tests adds a third commit with a multi-line note. The output of
git log -2 is then checked to see if the note lines are wrapped
correctly, and that there's a line separator between the two commits.
Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>
---
t/t3301-notes.sh | 32 +++++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index ba42c45..9393a25 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -59,7 +59,37 @@ EOF
test_expect_success 'show notes' '
! (git cat-file commit HEAD | grep b1) &&
git log -1 > output &&
- git diff expect output
+ test_cmp expect output
+'
+test_expect_success 'create multi-line notes (setup)' '
+ : > a3 &&
+ git add a3 &&
+ test_tick &&
+ git commit -m 3rd &&
+ MSG="b3
+c3c3c3c3
+d3d3d3" git notes edit
+'
+
+cat > expect-multiline << EOF
+commit 1584215f1d29c65e99c6c6848626553fdd07fd75
+Author: A U Thor <author@example.com>
+Date: Thu Apr 7 15:15:13 2005 -0700
+
+ 3rd
+
+Notes:
+ b3
+ c3c3c3c3
+ d3d3d3
+EOF
+
+printf "\n" >> expect-multiline
+cat expect >> expect-multiline
+
+test_expect_success 'show multi-line notes' '
+ git log -2 > output &&
+ test_cmp expect-multiline output
'
test_done
--
1.6.0.2.GIT
^ permalink raw reply related
* [PATCH replacement for take 3 4/4] color-words: take an optional regular expression describing words
From: Johannes Schindelin @ 2009-01-14 20:46 UTC (permalink / raw)
To: Thomas Rast; +Cc: git, Santi Béjar, Junio C Hamano, Teemu Likonen
In-Reply-To: <alpine.DEB.1.00.0901142142120.3586@pacific.mpi-cbg.de>
In some applications, words are not delimited by white space. To
allow for that, you can specify a regular expression describing
what makes a word with
git diff --color-words='[A-Za-z0-9]+'
Note that words cannot contain newline characters.
As suggested by Thomas Rast, the words are the exact matches of the
regular expression.
Note that a regular expression beginning with a '^' will match only
a word at the beginning of the hunk, not a word at the beginning of
a line, and is probably not what you want.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
This basically contains the fix I sent earlier.
As for the documentation, I would not have any issue with your
patch replacing my documentation in favor of yours.
Documentation/diff-options.txt | 6 +++-
diff.c | 64 ++++++++++++++++++++++++++++++++++-----
diff.h | 1 +
t/t4034-diff-words.sh | 39 ++++++++++++++++++++++++
4 files changed, 100 insertions(+), 10 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 1f8ce97..e546bfa 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -94,8 +94,12 @@ endif::git-format-patch[]
Turn off colored diff, even when the configuration file
gives the default to color output.
---color-words::
+--color-words[=regex]::
Show colored word diff, i.e. color words which have changed.
++
+Optionally, you can pass a regular expression that tells Git what the
+words are that you are looking for; The default is to interpret any
+stretch of non-whitespace as a word.
--no-renames::
Turn off rename detection, even when the configuration
diff --git a/diff.c b/diff.c
index fe8b1f0..1408717 100644
--- a/diff.c
+++ b/diff.c
@@ -333,12 +333,14 @@ static void diff_words_append(char *line, unsigned long len,
len--;
memcpy(buffer->text.ptr + buffer->text.size, line, len);
buffer->text.size += len;
+ buffer->text.ptr[buffer->text.size] = '\0';
}
struct diff_words_data {
struct diff_words_buffer minus, plus;
const char *current_plus;
FILE *file;
+ regex_t *word_regex;
};
static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
@@ -374,17 +376,49 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
diff_words->current_plus = plus_end;
}
+/* This function starts looking at *begin, and returns 0 iff a word was found. */
+static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex,
+ int *begin, int *end)
+{
+ if (word_regex && *begin < buffer->size) {
+ regmatch_t match[1];
+ if (!regexec(word_regex, buffer->ptr + *begin, 1, match, 0)) {
+ char *p = memchr(buffer->ptr + *begin + match[0].rm_so,
+ '\n', match[0].rm_eo - match[0].rm_so);
+ *end = p ? p - buffer->ptr : match[0].rm_eo + *begin;
+ *begin += match[0].rm_so;
+ return *begin >= *end;
+ }
+ return -1;
+ }
+
+ /* find the next word */
+ while (*begin < buffer->size && isspace(buffer->ptr[*begin]))
+ (*begin)++;
+ if (*begin >= buffer->size)
+ return -1;
+
+ /* find the end of the word */
+ *end = *begin + 1;
+ while (*end < buffer->size && !isspace(buffer->ptr[*end]))
+ (*end)++;
+
+ return 0;
+}
+
/*
* This function splits the words in buffer->text, stores the list with
* newline separator into out, and saves the offsets of the original words
* in buffer->orig.
*/
-static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out)
+static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out,
+ regex_t *word_regex)
{
int i, j;
+ long alloc = 0;
out->size = 0;
- out->ptr = xmalloc(buffer->text.size);
+ out->ptr = NULL;
/* fake an empty "0th" word */
ALLOC_GROW(buffer->orig, 1, buffer->orig_alloc);
@@ -392,11 +426,8 @@ static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out)
buffer->orig_nr = 1;
for (i = 0; i < buffer->text.size; i++) {
- if (isspace(buffer->text.ptr[i]))
- continue;
- for (j = i + 1; j < buffer->text.size &&
- !isspace(buffer->text.ptr[j]); j++)
- ; /* find the end of the word */
+ if (find_word_boundaries(&buffer->text, word_regex, &i, &j))
+ return;
/* store original boundaries */
ALLOC_GROW(buffer->orig, buffer->orig_nr + 1,
@@ -406,6 +437,7 @@ static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out)
buffer->orig_nr++;
/* store one word */
+ ALLOC_GROW(out->ptr, out->size + j - i + 1, alloc);
memcpy(out->ptr + out->size, buffer->text.ptr + i, j - i);
out->ptr[out->size + j - i] = '\n';
out->size += j - i + 1;
@@ -435,9 +467,10 @@ static void diff_words_show(struct diff_words_data *diff_words)
memset(&xpp, 0, sizeof(xpp));
memset(&xecfg, 0, sizeof(xecfg));
- diff_words_fill(&diff_words->minus, &minus);
- diff_words_fill(&diff_words->plus, &plus);
+ diff_words_fill(&diff_words->minus, &minus, diff_words->word_regex);
+ diff_words_fill(&diff_words->plus, &plus, diff_words->word_regex);
xpp.flags = XDF_NEED_MINIMAL;
+ /* as only the hunk header will be parsed, we need a 0-context */
xecfg.ctxlen = 0;
xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
&xpp, &xecfg, &ecb);
@@ -476,6 +509,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
free (ecbdata->diff_words->minus.orig);
free (ecbdata->diff_words->plus.text.ptr);
free (ecbdata->diff_words->plus.orig);
+ free(ecbdata->diff_words->word_regex);
free(ecbdata->diff_words);
ecbdata->diff_words = NULL;
}
@@ -1498,6 +1532,14 @@ static void builtin_diff(const char *name_a,
ecbdata.diff_words =
xcalloc(1, sizeof(struct diff_words_data));
ecbdata.diff_words->file = o->file;
+ if (o->word_regex) {
+ ecbdata.diff_words->word_regex = (regex_t *)
+ xmalloc(sizeof(regex_t));
+ if (regcomp(ecbdata.diff_words->word_regex,
+ o->word_regex, REG_EXTENDED))
+ die ("Invalid regular expression: %s",
+ o->word_regex);
+ }
}
xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
&xpp, &xecfg, &ecb);
@@ -2513,6 +2555,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
DIFF_OPT_CLR(options, COLOR_DIFF);
else if (!strcmp(arg, "--color-words"))
options->flags |= DIFF_OPT_COLOR_DIFF | DIFF_OPT_COLOR_DIFF_WORDS;
+ else if (!prefixcmp(arg, "--color-words=")) {
+ options->flags |= DIFF_OPT_COLOR_DIFF | DIFF_OPT_COLOR_DIFF_WORDS;
+ options->word_regex = arg + 14;
+ }
else if (!strcmp(arg, "--exit-code"))
DIFF_OPT_SET(options, EXIT_WITH_STATUS);
else if (!strcmp(arg, "--quiet"))
diff --git a/diff.h b/diff.h
index 4d5a327..23cd90c 100644
--- a/diff.h
+++ b/diff.h
@@ -98,6 +98,7 @@ struct diff_options {
int stat_width;
int stat_name_width;
+ const char *word_regex;
/* this is set by diffcore for DIFF_FORMAT_PATCH */
int found_changes;
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index b22195f..f4810e9 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -63,4 +63,43 @@ test_expect_success 'word diff with runs of whitespace' '
'
+cat > expect <<\EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index 330b04f..5ed8eff 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<BROWN>@@ -1,3 +1,7 @@<RESET>
+h(4),<GREEN>hh<RESET>[44]
+<RESET>
+a = b + c<RESET>
+
+<GREEN>aa = a<RESET>
+
+<GREEN>aeff = aeff * ( aaa<RESET> )
+EOF
+
+test_expect_success 'word diff with a regular expression' '
+
+ word_diff --color-words='[a-z]+'
+
+'
+
+echo 'aaa (aaa)' > pre
+echo 'aaa (aaa) aaa' > post
+
+cat > expect <<\EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index c29453b..be22f37 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<BROWN>@@ -1 +1 @@<RESET>
+aaa (aaa) <GREEN>aaa<RESET>
+EOF
+
+test_expect_success "test parsing words for newline" '
+
+ word_diff --color-words='a+'
+
+'
+
test_done
--
1.6.1.295.g5d331
^ permalink raw reply related
* [PATCH replacement for take 3 3/4] color-words: change algorithm to allow for 0-character word boundaries
From: Johannes Schindelin @ 2009-01-14 20:44 UTC (permalink / raw)
To: Thomas Rast; +Cc: git, Santi Béjar, Junio C Hamano, Teemu Likonen
In-Reply-To: <alpine.DEB.1.00.0901142104400.3586@pacific.mpi-cbg.de>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 8924 bytes --]
Up until now, the color-words code assumed that word boundaries are
identical to white space characters.
Therefore, it could get away with a very simple scheme: it copied the
hunks, substituted newlines for each white space character, called
libxdiff with the processed text, and then identified the text to
output by the offsets (which agreed since the original text had the
same length).
This code was ugly, for a number of reasons:
- it was impossible to introduce 0-character word boundaries,
- we had to print everything word by word, and
- the code needed extra special handling of newlines in the removed part.
Fix all of these issues by processing the text such that
- we build word lists, separated by newlines,
- we remember the original offsets for every word, and
- after calling libxdiff on the wordlists, we parse the hunk headers, and
find the corresponding offsets, and then
- we print the removed/added parts in one go.
The pre and post samples in the test were provided by Santi Béjar.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
I changed the test script to avoid repeating the same three-command
mantra all the time.
diff.c | 153 +++++++++++++++++++++++++++----------------------
t/t4034-diff-words.sh | 66 +++++++++++++++++++++
2 files changed, 151 insertions(+), 68 deletions(-)
create mode 100755 t/t4034-diff-words.sh
diff --git a/diff.c b/diff.c
index 6d87ea5..fe8b1f0 100644
--- a/diff.c
+++ b/diff.c
@@ -319,8 +319,10 @@ static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
struct diff_words_buffer {
mmfile_t text;
long alloc;
- long current; /* output pointer */
- int suppressed_newline;
+ struct diff_words_orig {
+ const char *begin, *end;
+ } *orig;
+ int orig_nr, orig_alloc;
};
static void diff_words_append(char *line, unsigned long len,
@@ -335,80 +337,81 @@ static void diff_words_append(char *line, unsigned long len,
struct diff_words_data {
struct diff_words_buffer minus, plus;
+ const char *current_plus;
FILE *file;
};
-static void print_word(FILE *file, struct diff_words_buffer *buffer, int len, int color,
- int suppress_newline)
-{
- const char *ptr;
- int eol = 0;
-
- if (len == 0)
- return;
-
- ptr = buffer->text.ptr + buffer->current;
- buffer->current += len;
-
- if (ptr[len - 1] == '\n') {
- eol = 1;
- len--;
- }
-
- fputs(diff_get_color(1, color), file);
- fwrite(ptr, len, 1, file);
- fputs(diff_get_color(1, DIFF_RESET), file);
-
- if (eol) {
- if (suppress_newline)
- buffer->suppressed_newline = 1;
- else
- putc('\n', file);
- }
-}
-
static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
{
struct diff_words_data *diff_words = priv;
+ int minus_first, minus_len, plus_first, plus_len;
+ const char *minus_begin, *minus_end, *plus_begin, *plus_end;
- if (diff_words->minus.suppressed_newline) {
- if (line[0] != '+')
- putc('\n', diff_words->file);
- diff_words->minus.suppressed_newline = 0;
- }
+ if (line[0] != '@' || parse_hunk_header(line, len,
+ &minus_first, &minus_len, &plus_first, &plus_len))
+ return;
- len--;
- switch (line[0]) {
- case '-':
- print_word(diff_words->file,
- &diff_words->minus, len, DIFF_FILE_OLD, 1);
- break;
- case '+':
- print_word(diff_words->file,
- &diff_words->plus, len, DIFF_FILE_NEW, 0);
- break;
- case ' ':
- print_word(diff_words->file,
- &diff_words->plus, len, DIFF_PLAIN, 0);
- diff_words->minus.current += len;
- break;
- }
+ minus_begin = diff_words->minus.orig[minus_first].begin;
+ minus_end = minus_len == 0 ? minus_begin :
+ diff_words->minus.orig[minus_first + minus_len - 1].end;
+ plus_begin = diff_words->plus.orig[plus_first].begin;
+ plus_end = plus_len == 0 ? plus_begin :
+ diff_words->plus.orig[plus_first + plus_len - 1].end;
+
+ if (diff_words->current_plus != plus_begin)
+ fwrite(diff_words->current_plus,
+ plus_begin - diff_words->current_plus, 1,
+ diff_words->file);
+ if (minus_begin != minus_end)
+ color_fwrite_lines(diff_words->file,
+ diff_get_color(1, DIFF_FILE_OLD),
+ minus_end - minus_begin, minus_begin);
+ if (plus_begin != plus_end)
+ color_fwrite_lines(diff_words->file,
+ diff_get_color(1, DIFF_FILE_NEW),
+ plus_end - plus_begin, plus_begin);
+
+ diff_words->current_plus = plus_end;
}
/*
- * This function splits the words in buffer->text, and stores the list with
- * newline separator into out.
+ * This function splits the words in buffer->text, stores the list with
+ * newline separator into out, and saves the offsets of the original words
+ * in buffer->orig.
*/
static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out)
{
- int i;
- out->size = buffer->text.size;
- out->ptr = xmalloc(out->size);
- memcpy(out->ptr, buffer->text.ptr, out->size);
- for (i = 0; i < out->size; i++)
- if (isspace(out->ptr[i]))
- out->ptr[i] = '\n';
- buffer->current = 0;
+ int i, j;
+
+ out->size = 0;
+ out->ptr = xmalloc(buffer->text.size);
+
+ /* fake an empty "0th" word */
+ ALLOC_GROW(buffer->orig, 1, buffer->orig_alloc);
+ buffer->orig[0].begin = buffer->orig[0].end = buffer->text.ptr;
+ buffer->orig_nr = 1;
+
+ for (i = 0; i < buffer->text.size; i++) {
+ if (isspace(buffer->text.ptr[i]))
+ continue;
+ for (j = i + 1; j < buffer->text.size &&
+ !isspace(buffer->text.ptr[j]); j++)
+ ; /* find the end of the word */
+
+ /* store original boundaries */
+ ALLOC_GROW(buffer->orig, buffer->orig_nr + 1,
+ buffer->orig_alloc);
+ buffer->orig[buffer->orig_nr].begin = buffer->text.ptr + i;
+ buffer->orig[buffer->orig_nr].end = buffer->text.ptr + j;
+ buffer->orig_nr++;
+
+ /* store one word */
+ memcpy(out->ptr + out->size, buffer->text.ptr + i, j - i);
+ out->ptr[out->size + j - i] = '\n';
+ out->size += j - i + 1;
+
+ i = j - 1;
+ }
}
/* this executes the word diff on the accumulated buffers */
@@ -419,22 +422,34 @@ static void diff_words_show(struct diff_words_data *diff_words)
xdemitcb_t ecb;
mmfile_t minus, plus;
+ /* special case: only removal */
+ if (!diff_words->plus.text.size) {
+ color_fwrite_lines(diff_words->file,
+ diff_get_color(1, DIFF_FILE_OLD),
+ diff_words->minus.text.size, diff_words->minus.text.ptr);
+ diff_words->minus.text.size = 0;
+ return;
+ }
+
+ diff_words->current_plus = diff_words->plus.text.ptr;
+
memset(&xpp, 0, sizeof(xpp));
memset(&xecfg, 0, sizeof(xecfg));
diff_words_fill(&diff_words->minus, &minus);
diff_words_fill(&diff_words->plus, &plus);
xpp.flags = XDF_NEED_MINIMAL;
- xecfg.ctxlen = diff_words->minus.alloc + diff_words->plus.alloc;
+ xecfg.ctxlen = 0;
xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
&xpp, &xecfg, &ecb);
free(minus.ptr);
free(plus.ptr);
+ if (diff_words->current_plus != diff_words->plus.text.ptr +
+ diff_words->plus.text.size)
+ fwrite(diff_words->current_plus,
+ diff_words->plus.text.ptr + diff_words->plus.text.size
+ - diff_words->current_plus, 1,
+ diff_words->file);
diff_words->minus.text.size = diff_words->plus.text.size = 0;
-
- if (diff_words->minus.suppressed_newline) {
- putc('\n', diff_words->file);
- diff_words->minus.suppressed_newline = 0;
- }
}
typedef unsigned long (*sane_truncate_fn)(char *line, unsigned long len);
@@ -458,7 +473,9 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
diff_words_show(ecbdata->diff_words);
free (ecbdata->diff_words->minus.text.ptr);
+ free (ecbdata->diff_words->minus.orig);
free (ecbdata->diff_words->plus.text.ptr);
+ free (ecbdata->diff_words->plus.orig);
free(ecbdata->diff_words);
ecbdata->diff_words = NULL;
}
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
new file mode 100755
index 0000000..b22195f
--- /dev/null
+++ b/t/t4034-diff-words.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+test_description='word diff colors'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+ git config diff.color.old red
+ git config diff.color.new green
+
+'
+
+decrypt_color () {
+ sed \
+ -e 's/.\[1m/<WHITE>/g' \
+ -e 's/.\[31m/<RED>/g' \
+ -e 's/.\[32m/<GREEN>/g' \
+ -e 's/.\[36m/<BROWN>/g' \
+ -e 's/.\[m/<RESET>/g'
+}
+
+word_diff () {
+ test_must_fail git diff --no-index "$@" pre post > output &&
+ decrypt_color < output > output.decrypted &&
+ test_cmp expect output.decrypted
+}
+
+cat > pre <<\EOF
+h(4)
+
+a = b + c
+EOF
+
+cat > post <<\EOF
+h(4),hh[44]
+
+a = b + c
+
+aa = a
+
+aeff = aeff * ( aaa )
+EOF
+
+cat > expect <<\EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index 330b04f..5ed8eff 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<BROWN>@@ -1,3 +1,7 @@<RESET>
+<RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET>
+<RESET>
+a = b + c<RESET>
+
+<GREEN>aa = a<RESET>
+
+<GREEN>aeff = aeff * ( aaa )<RESET>
+EOF
+
+test_expect_success 'word diff with runs of whitespace' '
+
+ word_diff --color-words
+
+'
+
+test_done
--
1.6.1.295.g5d331
^ permalink raw reply related
* Re: [PATCH] color-words: make regex configurable via attributes
From: Thomas Rast @ 2009-01-14 20:17 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, Santi Béjar, Junio C Hamano
In-Reply-To: <alpine.DEB.1.00.0901142104400.3586@pacific.mpi-cbg.de>
[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]
Johannes Schindelin wrote:
> How about making this an extra paragraph?
Sure, why not. Though I'm still in favour of taking some longer
version, possibly from my old series.
> On Wed, 14 Jan 2009, Thomas Rast wrote:
> > +- `cpp` suitable for source code in the C and C++ languages.
> > +
>
> How about "written in C or C++"?
I was just trying to be consistent with all other items; all
programming languages are listed as "Foo language".
> > +A built-in pattern is provided for all languages listed in the last
> > +section.
>
> Wow. But how about "previous section"?
Indeed, thanks.
> > +#define PATTERNS(name, pattern, wordregex) \
> > + { name, NULL, -1, { pattern, REG_EXTENDED }, NULL, wordregex }
>
> You could get rid of that NULL if...
[...]
> ... you inserted word_regex before textconv. In a way, I find this more
> logical, since both funcname and word_regex have sensible defaults
> (provided by you), whereas textconv is strictly a user's option.
Ok, I'll do that.
--
Thomas Rast
trast@{inf,student}.ethz.ch
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply
* Re: git merge and cherry-pick and duplicated commits?
From: Junio C Hamano @ 2009-01-14 20:16 UTC (permalink / raw)
To: skillzero; +Cc: git
In-Reply-To: <2729632a0901141033p47b4d8dah46f5bac27307d306@mail.gmail.com>
skillzero@gmail.com writes:
> Related to this, is there a way to easily find the common merge base
> given a bunch of a branches? When I want to fix a bug, I want to say
> "Given branches A, B, C, D, and E, where should I fork my bug fix
> branch from so that I can merge this branch into all those branches
> without getting duplicate commits?".
You do not necessarily have to fork from, nor merge into, any of them.
If you fixed a bug, you would hopefully know where the bug was injected at
into your history. You may have bisected it down to one commit $BAD. You
can fork your fix on top of that $BAD commit:
$ git checkout -b fix-bug-foo $BAD
All of the branches that share the commit have the bug, so your fix could
be merged to all of them if you really wanted to, and you should do so if
these A...E branches are meant to be consumed on their own.
But if the branches A...E you are about are for developing independent
topics, and if their theme won't get affected by the bug, it is much
better not to merge the fix in. You will have the merge for the fix in
your integration branch anyway. It is preferable not to contaminate an
independent topic branch whose purpose is to cook its own theme with an
unrelated bugfix, even if it is brought in as a merge.
^ permalink raw reply
* Re: [PATCH] color-words: make regex configurable via attributes
From: Johannes Schindelin @ 2009-01-14 20:12 UTC (permalink / raw)
To: Thomas Rast; +Cc: git, Santi Béjar, Junio C Hamano
In-Reply-To: <1231962401-26974-1-git-send-email-trast@student.ethz.ch>
Hi,
On Wed, 14 Jan 2009, Thomas Rast wrote:
> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
> index 2c1fa4b..ef0e2f5 100644
> --- a/Documentation/diff-options.txt
> +++ b/Documentation/diff-options.txt
> @@ -97,6 +97,9 @@ endif::git-format-patch[]
> Optionally, you can pass a regular expression that tells Git what the
> words are that you are looking for; The default is to interpret any
> stretch of non-whitespace as a word.
> +The regex can also be set via a diff driver, see
> +linkgit:gitattributes[1]; giving it explicitly overrides any diff
> +driver setting.
How about making this an extra paragraph?
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 8af22ec..17707ba 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -317,6 +317,8 @@ patterns are available:
>
> - `bibtex` suitable for files with BibTeX coded references.
>
> +- `cpp` suitable for source code in the C and C++ languages.
> +
How about "written in C or C++"?
> +A built-in pattern is provided for all languages listed in the last
> +section.
Wow. But how about "previous section"?
> diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
> index 0ed7e53..d6731d1 100755
> --- a/t/t4034-diff-words.sh
> +++ b/t/t4034-diff-words.sh
That was fast!
> +test_expect_success 'use default supplied by driver' '
> +
> + test_must_fail git diff --no-index --color-words \
> + pre post > output &&
> + decrypt_color < output > output.decrypted &&
> + test_cmp expect-by-chars output.decrypted
> +
> +'
I am actually just about to post new revisions of the last two patches
where this would read
test_expect_success 'use default supplied by driver' '
word_diff --color-words
'
instead...
I don't want to get bitten by stupid mistakes again, though, so I let it
run with valgrind while glancing over the code. Stay tuned.
> +#define PATTERNS(name, pattern, wordregex) \
> + { name, NULL, -1, { pattern, REG_EXTENDED }, NULL, wordregex }
You could get rid of that NULL if...
> diff --git a/userdiff.h b/userdiff.h
> index ba29457..2aab13e 100644
> --- a/userdiff.h
> +++ b/userdiff.h
> @@ -12,6 +12,7 @@ struct userdiff_driver {
> int binary;
> struct userdiff_funcname funcname;
> const char *textconv;
> + const char *word_regex;
> };
... you inserted word_regex before textconv. In a way, I find this more
logical, since both funcname and word_regex have sensible defaults
(provided by you), whereas textconv is strictly a user's option.
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.
From: Ted Pavlic @ 2009-01-14 20:08 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Shawn O. Pearce, git
In-Reply-To: <7vvdsj6lfq.fsf@gitster.siamese.dyndns.org>
>> Would you like me to modify the commit message and resubmit?
>
> Luckily or unluckily, you need to do that anyway, as your patches are
> whitespace damaged.
>
> Please don't send "format=flowed".
Ok. Resubmitted using 'git send-email'. I think the submissions look
much better now.<?>
--Ted
--
Ted Pavlic <ted@tedpavlic.com>
Please visit my ALS association page:
http://web.alsa.org/goto/tedpavlic
My family appreciates your support in the fight to defeat ALS.
^ permalink raw reply
* Re: [PATCH take 3 0/4] color-words improvements
From: Thomas Rast @ 2009-01-14 20:04 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Junio C Hamano, git, Santi Béjar
In-Reply-To: <alpine.DEB.1.00.0901141840100.3586@pacific.mpi-cbg.de>
[-- Attachment #1: Type: text/plain, Size: 592 bytes --]
Johannes Schindelin wrote:
>
> The only "funny" thing I realized is that the lines which are output
> by emit_line() add a RESET at the end of the line, and I do not do that
> in color_fwrite_lines().
Umm.... but you seem to do?
Ack on the new regex semantics, though I'd have implemented it via
dying on '\n' instead of silently splitting there (and restarting a
new match!). [I actually _have_ implemented it, but your patch beat
me to it. :-)]
Thus, Ack on 4/4 once the boundary bug is fixed. Thanks for your
work!
--
Thomas Rast
trast@{inf,student}.ethz.ch
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply
* [PATCH 1/3] bash-completion: Support running when set -u is enabled
From: ted @ 2009-01-14 20:02 UTC (permalink / raw)
To: spearce; +Cc: git, gitster, Ted Pavlic
From: Ted Pavlic <ted@tedpavlic.com>
Under "set -u" semantics, it is an error to access undefined
variables. Some user environments may enable this setting in the
interactive shell.
In any context where the completion functions access an undefined
variable, accessing a default empty string (aka "${1-}" instead of
"$1") is a reasonable way to code the function, as it silences
the undefined variable error while still supplying an empty string.
In this patch, functions that should always take an argument still use
$1. Functions that have optional arguments use ${1-}.
Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
---
contrib/completion/git-completion.bash | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 7b074d7..5d1515c 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -52,7 +52,7 @@ esac
__gitdir ()
{
- if [ -z "$1" ]; then
+ if [ -z "${1-}" ]; then
if [ -n "$__git_dir" ]; then
echo "$__git_dir"
elif [ -d .git ]; then
@@ -111,7 +111,7 @@ __git_ps1 ()
fi
fi
- if [ -n "$1" ]; then
+ if [ -n "${1-}" ]; then
printf "$1" "${b##refs/heads/}$r"
else
printf " (%s)" "${b##refs/heads/}$r"
@@ -143,8 +143,8 @@ __gitcomp ()
;;
*)
local IFS=$'\n'
- COMPREPLY=($(compgen -P "$2" \
- -W "$(__gitcomp_1 "$1" "$4")" \
+ COMPREPLY=($(compgen -P "${2-}" \
+ -W "$(__gitcomp_1 "${1-}" "${4-}")" \
-- "$cur"))
;;
esac
@@ -152,13 +152,13 @@ __gitcomp ()
__git_heads ()
{
- local cmd i is_hash=y dir="$(__gitdir "$1")"
+ local cmd i is_hash=y dir="$(__gitdir "${1-}")"
if [ -d "$dir" ]; then
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
refs/heads
return
fi
- for i in $(git ls-remote "$1" 2>/dev/null); do
+ for i in $(git ls-remote "${1-}" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
@@ -170,13 +170,13 @@ __git_heads ()
__git_tags ()
{
- local cmd i is_hash=y dir="$(__gitdir "$1")"
+ local cmd i is_hash=y dir="$(__gitdir "${1-}")"
if [ -d "$dir" ]; then
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
refs/tags
return
fi
- for i in $(git ls-remote "$1" 2>/dev/null); do
+ for i in $(git ls-remote "${1-}" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
@@ -188,7 +188,7 @@ __git_tags ()
__git_refs ()
{
- local i is_hash=y dir="$(__gitdir "$1")"
+ local i is_hash=y dir="$(__gitdir "${1-}")"
local cur="${COMP_WORDS[COMP_CWORD]}" format refs
if [ -d "$dir" ]; then
case "$cur" in
--
1.6.1.87.g15624
^ permalink raw reply related
* [PATCH 3/3] bash-completion: Added comments to remind about required arguments
From: ted @ 2009-01-14 20:02 UTC (permalink / raw)
To: spearce; +Cc: git, gitster, Ted Pavlic
In-Reply-To: <1231963342-24461-2-git-send-email-ted@tedpavlic.com>
From: Ted Pavlic <ted@tedpavlic.com>
Adds a few simple comments above commands that take arguments. These
comments are meant to remind developers of potential problems that can
occur when the script is sourced on systems with "set -u." Any
function which "requires" arguments really ought to be called with
explicit arguments given.
Also adds a #!bash to the top of bash completions so that editing
software can always identify that the file is of sh type.
Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
---
contrib/completion/git-completion.bash | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 201f9a6..f8b845a 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1,3 +1,4 @@
+#!bash
#
# bash completion support for core Git.
#
@@ -50,6 +51,8 @@ case "$COMP_WORDBREAKS" in
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
esac
+# __gitdir accepts 0 or 1 arguments (i.e., location)
+# returns location of .git repo
__gitdir ()
{
if [ -z "${1-}" ]; then
@@ -67,6 +70,8 @@ __gitdir ()
fi
}
+# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
+# returns text to add to bash PS1 prompt (includes branch name)
__git_ps1 ()
{
local g="$(git rev-parse --git-dir 2>/dev/null)"
@@ -119,6 +124,7 @@ __git_ps1 ()
fi
}
+# __gitcomp_1 requires 2 arguments
__gitcomp_1 ()
{
local c IFS=' '$'\t'$'\n'
@@ -131,6 +137,8 @@ __gitcomp_1 ()
done
}
+# __gitcomp accepts 1, 2, 3, or 4 arguments
+# generates completion reply with compgen
__gitcomp ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -150,6 +158,7 @@ __gitcomp ()
esac
}
+# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
__git_heads ()
{
local cmd i is_hash=y dir="$(__gitdir "${1-}")"
@@ -168,6 +177,7 @@ __git_heads ()
done
}
+# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
__git_tags ()
{
local cmd i is_hash=y dir="$(__gitdir "${1-}")"
@@ -186,6 +196,7 @@ __git_tags ()
done
}
+# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
__git_refs ()
{
local i is_hash=y dir="$(__gitdir "${1-}")"
@@ -218,6 +229,7 @@ __git_refs ()
done
}
+# __git_refs2 requires 1 argument (to pass to __git_refs)
__git_refs2 ()
{
local i
@@ -226,6 +238,7 @@ __git_refs2 ()
done
}
+# __git_refs_remotes requires 1 argument (to pass to ls-remote)
__git_refs_remotes ()
{
local cmd i is_hash=y
@@ -470,6 +483,7 @@ __git_aliases ()
done
}
+# __git_aliased_command requires 1 argument
__git_aliased_command ()
{
local word cmdline=$(git --git-dir="$(__gitdir)" \
@@ -482,6 +496,7 @@ __git_aliased_command ()
done
}
+# __git_find_subcommand requires 1 argument
__git_find_subcommand ()
{
local word subcommand c=1
--
1.6.1.87.g15624
^ 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