* [PATCH v2] http: use strbuf API in quote_ref_url
From: Tay Ray Chuan @ 2009-03-07 16:47 UTC (permalink / raw)
To: git, Johannes Schindelin
In addition, ''quote_ref_url'' inserts a slash between the base URL and
remote ref path only if needed. Previously, this insertion wasn't
contingent on the lack of a separating slash.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
Differences from v1:
*use buf when checking for '/'
*remove for's braces
http.c | 30 ++++++++++--------------------
1 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/http.c b/http.c
index cdedeb6..1691498 100644
--- a/http.c
+++ b/http.c
@@ -577,31 +577,21 @@ static inline int hex(int v)
static char *quote_ref_url(const char *base, const char *ref)
{
+ struct strbuf buf = STRBUF_INIT;
const char *cp;
- char *dp, *qref;
- int len, baselen, ch;
+ int ch;
- baselen = strlen(base);
- len = baselen + 2; /* '/' after base and terminating NUL */
- for (cp = ref; (ch = *cp) != 0; cp++, len++)
+ strbuf_addstr(&buf, base);
+ if (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/')
+ strbuf_addstr(&buf, "/");
+
+ for (cp = ref; (ch = *cp) != 0; cp++)
if (needs_quote(ch))
- len += 2; /* extra two hex plus replacement % */
- qref = xmalloc(len);
- memcpy(qref, base, baselen);
- dp = qref + baselen;
- *(dp++) = '/';
- for (cp = ref; (ch = *cp) != 0; cp++) {
- if (needs_quote(ch)) {
- *dp++ = '%';
- *dp++ = hex((ch >> 4) & 0xF);
- *dp++ = hex(ch & 0xF);
- }
+ strbuf_addf(&buf, "%%%02x", ch);
else
- *dp++ = ch;
- }
- *dp = 0;
+ strbuf_addch(&buf, *cp);
- return qref;
+ return strbuf_detach(&buf, NULL);
}
int http_fetch_ref(const char *base, struct ref *ref)
--
1.6.2.rc1
^ permalink raw reply related
* git am --rebasing clobbers commit encoding
From: Nikolaus Schulz @ 2009-03-07 16:38 UTC (permalink / raw)
To: git
Hi,
commit 5e835cac "rebase: do not munge commit log message", aiming to fix
rebasing of commits with multiple lines in the first paragraph of the
commit message, has broken rebasing of commits which are not encoded in
i18n.commitEncoding.
Here's the patch from 5e835cac:
diff --git a/git-am.sh b/git-am.sh
index 245e1db..5a7695e 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -327,11 +327,20 @@ do
echo "Patch is empty. Was it split wrong?"
stop_here $this
}
- SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
- case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
-
- (echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
- git stripspace > "$dotest/msg-clean"
+ if test -f "$dotest/rebasing" &&
+ commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
+ -e q "$dotest/$msgnum") &&
+ test "$(git cat-file -t "$commit")" = commit
+ then
+ git cat-file commit "$commit" |
+ sed -e '1,/^$/d' >"$dotest/msg-clean"
+ else
+ SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
+ case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
+
+ (echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
+ git stripspace > "$dotest/msg-clean"
+ fi
;;
esac
The problem is, that "git cat-file commit .. | sed -e '1,/^$/d'"
discards the commit encoding header. The commit message is taken as-is,
but later committed with the current i18n.commitEncoding.
I'm working on several machines, some of which use the legacy latin1
encoding; if I push a latin1-encoded commit to a machine using utf-8,
and rebase it there, the commits messages are corrupted.
This is particularly unlucky since with correct commit messages (no
multiple lines in first paragraph), "$dotest/msg" is perfectly fine, and
the above patch is not needed anyway.
Unfortunately, I don't see an easy way to fix this. It seems to me that
recoding commit messages isn't really supported: commits are _always_
done with the configured i18n.commitencoding, and the only place where
recoding takes place is processing of patches sent by email, where
git-mailinfo recodes the commit message. And commit 5e835cac has
bypassed git-mailinfo in git-am for rebasing.
I guess we cannot call iconv(1) after git cat-file because that's not
portable, and there is no plumbing command that can be used from a shell
script to convert the encoding of a commit; the functionality is in
utf8.c:reencode_string(), so only C code can use it.
Nikolaus
^ permalink raw reply related
* [JGit] Push to new Amazon S3 does not work? ("funny refname")
From: Daniel Cheng @ 2009-03-07 16:05 UTC (permalink / raw)
To: git
Pushing to new Amazon S3 repository does not work.
It say "funny refname" without pushing anything:
<<<<<<<<<
$ jgit push s3 master
To amazon-s3://0NQ4APQ8R7S6HQ65TWR2@egitsdiz/1.git
! [remote rejected] master -> master (funny refname)
$ s3cmd la
DIR s3://egitsdiz/1.git/
$
>>>>>>>>>
Any idea what's happening here?
The code is in WalkPushConnection.java line 137:
<<<<<<<<<
134 final List<RemoteRefUpdate> updates = new ArrayList<RemoteRefUpdate>();
135 for (final RemoteRefUpdate u : refUpdates.values()) {
136 final String n = u.getRemoteName();
137 if (!n.startsWith("refs/") || !Repository.isValidRefName(n)) {
138 u.setStatus(Status.REJECTED_OTHER_REASON);
139 u.setMessage("funny refname");
140 continue;
141 }
>>>>>>>>>
u.getRemoteName() gives "master" here.
Removing n.startsWith("refs/") would generate a bad `packed-refs`
file in later code.
I tried to fix this, but failed to do so without breaking GitSsh transports
^ permalink raw reply
* Re: jGit Eclipse Plugin Feature
From: Tor Arne Vestbø @ 2009-03-07 15:58 UTC (permalink / raw)
To: Robert Navarro; +Cc: git
In-Reply-To: <efe536470903070205w1dbff989je6dd6126d09e4a74@mail.gmail.com>
Robert Navarro wrote:
> Hello,
>
> Sorry about my last "subscribe" email, skipped over this part in the
> wiki...."You don't even need to be subscribed to post, just send an
> email to: "
>
> Anyways.....I wasn't sure where to post this but I'll give it a shot
> here.....I know there is an eclipse jGit plugin in the works and I
> wanted to know if it would be possible to get a remember or recently
> used servers feature added to the push/pull feature.
I have done some initial prototyping of a Remotes View. I'll see if I
can bring that to life somehow.
Tor Arne
^ permalink raw reply
* Re: [PATCH] http: use strbuf API in quote_ref_url
From: Johannes Schindelin @ 2009-03-07 15:57 UTC (permalink / raw)
To: Tay Ray Chuan; +Cc: git
In-Reply-To: <49B29554.30805@gmail.com>
Hi,
On Sat, 7 Mar 2009, Tay Ray Chuan wrote:
> In addition, ''quote_ref_url'' inserts a slash between the base URL and
> remote ref path only if needed. Previously, this insertion wasn't
> contingent on the lack of a separating slash.
>
> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
I would prefer to give my ACK explicitely... :-)
> http.c | 29 ++++++++++-------------------
> 1 files changed, 10 insertions(+), 19 deletions(-)
>
> diff --git a/http.c b/http.c
> index cdedeb6..9de4130 100644
> --- a/http.c
> +++ b/http.c
> @@ -577,31 +577,22 @@ static inline int hex(int v)
>
> static char *quote_ref_url(const char *base, const char *ref)
> {
> + struct strbuf buf = STRBUF_INIT;
> const char *cp;
> - char *dp, *qref;
> - int len, baselen, ch;
> + int ch;
> +
> + strbuf_addstr(&buf, base);
> + if (strcmp(base+strlen(base)-1, "/") && strcmp(ref, "/"))
> + strbuf_addstr(&buf, "/");
I would not have scratched my head that much if it read like this:
if (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/')
strbuf_addch(&buf, '/');
> for (cp = ref; (ch = *cp) != 0; cp++) {
> - if (needs_quote(ch)) {
> - *dp++ = '%';
> - *dp++ = hex((ch >> 4) & 0xF);
> - *dp++ = hex(ch & 0xF);
> - }
> + if (needs_quote(ch))
> + strbuf_addf(&buf, "%%%02x", ch);
> else
> - *dp++ = ch;
> + strbuf_addch(&buf, *cp);
> }
Seems as if you could remove even the curly brackets here.
Other than that, it indeed looks like an ACK from me...
Ciao,
Dscho
^ permalink raw reply
* git-mergetool changes file rights?
From: Grzegorz Kossakowski @ 2009-03-07 15:55 UTC (permalink / raw)
To: git
Hello,
I've stumbled upon very weird problem:
grek@linux-p3yg:~/asf/git/infrastructure/apache-git-mirrors/bin> git --version
git version 1.6.1.3
grek@linux-p3yg:~/asf/git/infrastructure/apache-git-mirrors/bin> ls -l
razem 40
-rwxr-xr-x 1 grek users 773 mar 7 16:47 create-repo.sh
-rwxr-xr-x 1 grek users 3219 mar 7 16:50 email-update.sh
-rwxr-xr-x 1 grek users 3219 mar 7 16:50 email-update.sh.orig
-rwxr-xr-x 1 grek users 2086 mar 7 16:47 move-svn-project.sh
-rwxr-xr-x 1 grek users 1464 mar 7 16:47 update-authors.sh
-rwxr-xr-x 1 grek users 156 mar 6 16:16 update-daily.sh
-rwxr-xr-x 1 grek users 371 mar 7 16:47 update-every-minute.sh
-rwxr-xr-x 1 grek users 215 mar 7 16:47 update-gitweb.sh
-rwxr-xr-x 1 grek users 1104 mar 7 16:47 update-repo.sh
-rwxr-xr-x 1 grek users 188 mar 7 16:47 update.sh
grek@linux-p3yg:~/asf/git/infrastructure/apache-git-mirrors/bin> git mergetool
merge tool candidates: kdiff3 kdiff3 tkdiff xxdiff meld gvimdiff opendiff emerge vimdiff
Merging the files: email-update.sh
Normal merge conflict for 'email-update.sh':
{local}: modified
{remote}: modified
Hit return to start merge resolution tool (kdiff3):
error: open("bin/email-update.sh"): Permission denied
error: unable to index file bin/email-update.sh
fatal: updating files failed
grek@linux-p3yg:~/asf/git/infrastructure/apache-git-mirrors/bin> ls -l
razem 40
-rwxr-xr-x 1 grek users 773 mar 7 16:47 create-repo.sh
---x------ 1 grek users 3219 mar 7 16:53 email-update.sh
-rwxr-xr-x 1 grek users 3219 mar 7 16:53 email-update.sh.orig
-rwxr-xr-x 1 grek users 2086 mar 7 16:47 move-svn-project.sh
-rwxr-xr-x 1 grek users 1464 mar 7 16:47 update-authors.sh
-rwxr-xr-x 1 grek users 156 mar 6 16:16 update-daily.sh
-rwxr-xr-x 1 grek users 371 mar 7 16:47 update-every-minute.sh
-rwxr-xr-x 1 grek users 215 mar 7 16:47 update-gitweb.sh
-rwxr-xr-x 1 grek users 1104 mar 7 16:47 update-repo.sh
-rwxr-xr-x 1 grek users 188 mar 7 16:47 update.sh
Notice rights for email-update.sh.
What's going on here?
--
Best regards,
Grzegorz Kossakowski
^ permalink raw reply
* [PATCH] MinGW: fix diff --no-index /dev/null ...
From: Johannes Schindelin @ 2009-03-07 15:51 UTC (permalink / raw)
To: git, gitster; +Cc: Johannes Sixt
In-Reply-To: <cover.1236441065u.git.johannes.schindelin@gmx.de>
When launching "diff --no-index" with a parameter "/dev/null", the MSys
bash converts the "/dev/null" to a "nul", which usually makes sense. But
diff --no-index got confused and tried to access a _file_ called "nul".
While at it, the comment in t4012, expressed as ":# <text>" was turned
into ": <text>" so that MSys' path name mangling does not kick in.
With this patch, t4012 passes in msysGit.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
diff-no-index.c | 4 ++++
t/t4012-diff-binary.sh | 2 +-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 0a14268..598687b 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -38,6 +38,10 @@ static int get_mode(const char *path, int *mode)
if (!path || !strcmp(path, "/dev/null"))
*mode = 0;
+#ifdef _WIN32
+ else if (!strcasecmp(path, "nul"))
+ *mode = 0;
+#endif
else if (!strcmp(path, "-"))
*mode = create_ce_mode(0666);
else if (lstat(path, &st))
diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh
index 3cf5b5c..f64aa48 100755
--- a/t/t4012-diff-binary.sh
+++ b/t/t4012-diff-binary.sh
@@ -87,7 +87,7 @@ nul_to_q() {
test_expect_success 'diff --no-index with binary creation' '
echo Q | q_to_nul >binary &&
- (:# hide error code from diff, which just indicates differences
+ (: hide error code from diff, which just indicates differences
git diff --binary --no-index /dev/null binary >current ||
true
) &&
--
1.6.2.327.g0fa6c
^ permalink raw reply related
* [PATCH] http: use strbuf API in quote_ref_url
From: Tay Ray Chuan @ 2009-03-07 15:40 UTC (permalink / raw)
To: git, Johannes Schindelin
In addition, ''quote_ref_url'' inserts a slash between the base URL and
remote ref path only if needed. Previously, this insertion wasn't
contingent on the lack of a separating slash.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
http.c | 29 ++++++++++-------------------
1 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/http.c b/http.c
index cdedeb6..9de4130 100644
--- a/http.c
+++ b/http.c
@@ -577,31 +577,22 @@ static inline int hex(int v)
static char *quote_ref_url(const char *base, const char *ref)
{
+ struct strbuf buf = STRBUF_INIT;
const char *cp;
- char *dp, *qref;
- int len, baselen, ch;
+ int ch;
+
+ strbuf_addstr(&buf, base);
+ if (strcmp(base+strlen(base)-1, "/") && strcmp(ref, "/"))
+ strbuf_addstr(&buf, "/");
- baselen = strlen(base);
- len = baselen + 2; /* '/' after base and terminating NUL */
- for (cp = ref; (ch = *cp) != 0; cp++, len++)
- if (needs_quote(ch))
- len += 2; /* extra two hex plus replacement % */
- qref = xmalloc(len);
- memcpy(qref, base, baselen);
- dp = qref + baselen;
- *(dp++) = '/';
for (cp = ref; (ch = *cp) != 0; cp++) {
- if (needs_quote(ch)) {
- *dp++ = '%';
- *dp++ = hex((ch >> 4) & 0xF);
- *dp++ = hex(ch & 0xF);
- }
+ if (needs_quote(ch))
+ strbuf_addf(&buf, "%%%02x", ch);
else
- *dp++ = ch;
+ strbuf_addch(&buf, *cp);
}
- *dp = 0;
- return qref;
+ return strbuf_detach(&buf, NULL);
}
int http_fetch_ref(const char *base, struct ref *ref)
--
1.6.2.rc1
^ permalink raw reply related
* [PATCH, acked] git-p4: remove tabs from usermap file
From: Pete Wyckoff @ 2009-03-07 15:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Simon Hausmann, git
Some users have tabs in their names, oddly enough. This
causes problems when loading the usercache from disk,
as split separates the fields on the wrong tabs. When
fast-import's parse_ident() tries to parse the committer
field, it is unhappy about the unbalanced <..> angle brackets.
It is easy enough to convert the tabs to single spaces.
Signed-off-by: Pete Wyckoff <pw@padd.com>
Acked-by: Simon Hausmann <simon@lst.de>
---
contrib/fast-import/git-p4 | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 3832f60..342529d 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1142,7 +1142,7 @@ class P4Sync(Command):
s = ''
for (key, val) in self.users.items():
- s += "%s\t%s\n" % (key, val)
+ s += "%s\t%s\n" % (key.expandtabs(1), val.expandtabs(1))
open(self.getUserCacheFilename(), "wb").write(s)
self.userMapFromPerforceServer = True
--
1.6.0.6
^ permalink raw reply related
* [PATCH] Brown paper bag fix for MinGW 64-bit stat
From: Johannes Schindelin @ 2009-03-07 14:37 UTC (permalink / raw)
To: git, gitster; +Cc: Johannes Sixt
In-Reply-To: <cover.1236436185u.git.johannes.schindelin@gmx.de>
When overriding the identifier "stat" so that "struct stat" will be
substituted with "struct _stati64" everywhere, I tried to fix the calls
to the _function_ stat(), too, but I forgot to change the earlier
attempt "stat64" to "_stati64" there.
So, the stat() calls were overridden by calls to _stati64() instead.
Unfortunately, there is a function _stati64() so that I missed that
calls to stat() were not actually overridden by calls to mingw_lstat(),
but t4200-rerere.sh showed the error.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Aaargh.
I am very, very sorry.
Actually, it was quite funny that t4200 displayed the bug; I
_guess_ it was due to a time zone issue, as the times were exactly
one hour off (and the machine I tested on is at UTC+0100 right now).
And due to that bug, "rerere gc" would not collect the garbage.
So even if the C runtime provides a _stati64() function that
pretends to work, it does not, and this patch is absolutely necessary.
Now, if only the tests would not take ages to run on Windows...
then I would not be tempted to skip them when sending the next patches.
compat/mingw.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/compat/mingw.h b/compat/mingw.h
index 92fb310..a0b74fb 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -169,7 +169,7 @@ int mingw_lstat(const char *file_name, struct stat *buf);
int mingw_fstat(int fd, struct stat *buf);
#define fstat mingw_fstat
#define lstat mingw_lstat
-#define stat64(x,y) mingw_lstat(x,y)
+#define _stati64(x,y) mingw_lstat(x,y)
int mingw_utime(const char *file_name, const struct utimbuf *times);
#define utime mingw_utime
--
1.6.2.327.g0fa6c
^ permalink raw reply related
* Re: [PATCH 3/3] builtin-merge: add support for default merge options
From: Jay Soffian @ 2009-03-07 13:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, jean-luc malet
In-Reply-To: <7vzlfxpzqq.fsf@gitster.siamese.dyndns.org>
On Sat, Mar 7, 2009 at 2:18 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Note that you do not have to cover branch.*.remote and other things in the
> same patch. The first one could just handle branch.*.mergeoptions and you
> can let later patches to implement the fallbacks for other variables.
Oh, indeed, but I think I do need to provide all the patches at once.
Otherwise it will just be very confusing and I anticipate a user
asking "how come I can use branch.*.mergeoptions, but none of the
other branch.*.foo settings work?"
And to be honest, that concern extends beyond branch.*. "How come git
foo allows defaults, but git bar does not?" seems like a valid
question, and while "because no one implemented defaults for foo and
bar" is a valid answer, it isn't a very satisfying one (to me).
This thread is what inspired me to start the "what's so evil about
overriding builtins with aliases" thread (please don't address that
here, I got it from the other thread). But I still wonder if we should
provide defaults consistently instead of piecemeal. For example:
[defaults]
merge = --no-ff
But I suppose that will be objected to as confusing/complicated/likely
to have side-effects.
j.
^ permalink raw reply
* [PATCH] cleanup: add isascii()
From: René Scharfe @ 2009-03-07 13:06 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
Add a standard definition of isascii() and use it to replace an open
coded high-bit test in pretty.c. While we're there, write the ESC
char as the more commonly used '\033' instead of as 0x1b to enhance
its grepability.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
git-compat-util.h | 2 ++
pretty.c | 3 +--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index dcf4127..878d83d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -319,6 +319,7 @@ static inline int has_extension(const char *filename, const char *ext)
}
/* Sane ctype - no locale, and works with signed chars */
+#undef isascii
#undef isspace
#undef isdigit
#undef isalpha
@@ -332,6 +333,7 @@ extern unsigned char sane_ctype[256];
#define GIT_GLOB_SPECIAL 0x08
#define GIT_REGEX_SPECIAL 0x10
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
+#define isascii(x) (((x) & ~0x7f) == 0)
#define isspace(x) sane_istest(x,GIT_SPACE)
#define isdigit(x) sane_istest(x,GIT_DIGIT)
#define isalpha(x) sane_istest(x,GIT_ALPHA)
diff --git a/pretty.c b/pretty.c
index f499294..c018408 100644
--- a/pretty.c
+++ b/pretty.c
@@ -83,8 +83,7 @@ static int get_one_line(const char *msg)
/* High bit set, or ISO-2022-INT */
int non_ascii(int ch)
{
- ch = (ch & 0xff);
- return ((ch & 0x80) || (ch == 0x1b));
+ return !isascii(ch) || ch == '\033';
}
static int is_rfc2047_special(char ch)
--
1.6.2
^ permalink raw reply related
* [PATCH] Documentation: fix badly indented paragraphs in "--bisect-all" description
From: Christian Couder @ 2009-03-07 12:37 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, John Tapsell
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Documentation/rev-list-options.txt | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 5076322..7dd237c 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -568,11 +568,11 @@ This outputs all the commit objects between the included and excluded
commits, ordered by their distance to the included and excluded
commits. The farthest from them is displayed first. (This is the only
one displayed by `--bisect`.)
-
++
This is useful because it makes it easy to choose a good commit to
test when you want to avoid to test some of them for some reason (they
may not compile for example).
-
++
This option can be used along with `--bisect-vars`, in this case,
after all the sorted commit objects, there will be the same text as if
`--bisect-vars` had been used alone.
--
1.6.2.rc2.2.g08c84
^ permalink raw reply related
* [PATCH 5/5] grep: add support for coloring with external greps
From: René Scharfe @ 2009-03-07 12:34 UTC (permalink / raw)
To: Git Mailing List
Cc: Nguyễn Thái Ngọc Duy, Junio C Hamano,
Thiago Alves
In-Reply-To: <1236428699.6486.41.camel@ubuntu.ubuntu-domain>
Add the config variable color.grep.external, which can be used to
switch on coloring of external greps. To enable auto coloring with
GNU grep, one needs to set color.grep.external to --color=always to
defeat the pager started by git grep. The value of the config
variable will be passed to the external grep only if it would
colorize internal grep's output, so automatic terminal detected
works. The default is to not pass any option, because the external
grep command could be a program without color support.
Also set the environment variables GREP_COLOR and GREP_COLORS to
pass the configured color for matches to the external grep. This
works with GNU grep; other variables could be added as needed.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
Documentation/config.txt | 12 +++++++++++-
builtin-grep.c | 36 ++++++++++++++++++++++++++++++++++++
grep.h | 1 +
3 files changed, 48 insertions(+), 1 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index b75dada..4d42bff 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -553,9 +553,19 @@ color.grep::
`never`), never. When set to `true` or `auto`, use color only
when the output is written to the terminal. Defaults to `false`.
+color.grep.external::
+ The string value of this variable is passed to an external 'grep'
+ command as a command line option if match highlighting is turned
+ on. If set to an empty string, no option is passed at all,
+ turning off coloring for external 'grep' calls; this is the default.
+ For GNU grep, set it to `--color=always` to highlight matches even
+ when a pager is used.
+
color.grep.match::
Use customized color for matches. The value of this variable
- may be specified as in color.branch.<slot>.
+ may be specified as in color.branch.<slot>. It is passed using
+ the environment variables 'GREP_COLOR' and 'GREP_COLORS' when
+ calling an external 'grep'.
color.interactive::
When set to `always`, always use colors for interactive prompts
diff --git a/builtin-grep.c b/builtin-grep.c
index e2c0f01..9e7e766 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -30,6 +30,10 @@ static int grep_config(const char *var, const char *value, void *cb)
opt->color = git_config_colorbool(var, value, -1);
return 0;
}
+ if (!strcmp(var, "grep.color.external") ||
+ !strcmp(var, "color.grep.external")) {
+ return git_config_string(&(opt->color_external), var, value);
+ }
if (!strcmp(var, "grep.color.match") ||
!strcmp(var, "color.grep.match")) {
if (!value)
@@ -287,6 +291,21 @@ static int flush_grep(struct grep_opt *opt,
return status;
}
+static void grep_add_color(struct strbuf *sb, const char *escape_seq)
+{
+ size_t orig_len = sb->len;
+
+ while (*escape_seq) {
+ if (*escape_seq == 'm')
+ strbuf_addch(sb, ';');
+ else if (*escape_seq != '\033' && *escape_seq != '[')
+ strbuf_addch(sb, *escape_seq);
+ escape_seq++;
+ }
+ if (sb->len > orig_len && sb->buf[sb->len - 1] == ';')
+ strbuf_setlen(sb, sb->len - 1);
+}
+
static int external_grep(struct grep_opt *opt, const char **paths, int cached)
{
int i, nr, argc, hit, len, status;
@@ -357,6 +376,23 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
push_arg("-e");
push_arg(p->pattern);
}
+ if (opt->color) {
+ struct strbuf sb = STRBUF_INIT;
+
+ grep_add_color(&sb, opt->color_match);
+ setenv("GREP_COLOR", sb.buf, 1);
+
+ strbuf_reset(&sb);
+ strbuf_addstr(&sb, "mt=");
+ grep_add_color(&sb, opt->color_match);
+ strbuf_addstr(&sb, ":sl=:cx=:fn=:ln=:bn=:se=");
+ setenv("GREP_COLORS", sb.buf, 1);
+
+ strbuf_release(&sb);
+
+ if (opt->color_external && strlen(opt->color_external) > 0)
+ push_arg(opt->color_external);
+ }
hit = 0;
argc = nr;
diff --git a/grep.h b/grep.h
index 73b33ab..a67005d 100644
--- a/grep.h
+++ b/grep.h
@@ -80,6 +80,7 @@ struct grep_opt {
unsigned null_following_name:1;
int color;
char color_match[COLOR_MAXLEN];
+ const char *color_external;
int regflags;
unsigned pre_context;
unsigned post_context;
--
1.6.2
^ permalink raw reply related
* [PATCH 4/5] grep: color patterns in output
From: René Scharfe @ 2009-03-07 12:32 UTC (permalink / raw)
To: Git Mailing List
Cc: Nguyễn Thái Ngọc Duy, Junio C Hamano,
Thiago Alves
In-Reply-To: <1236428699.6486.41.camel@ubuntu.ubuntu-domain>
Coloring matches makes them easier to spot in the output.
Add two options and two parameters: color.grep (to turn coloring on
or off), color.grep.match (to set the color of matches), --color
and --no-color (to turn coloring on or off, respectively).
The output of external greps is not changed.
This patch is based on earlier ones by Nguyễn Thái Ngọc Duy and
Thiago Alves.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
Documentation/config.txt | 9 ++++
Documentation/git-grep.txt | 8 ++++
builtin-grep.c | 32 +++++++++++++++
grep.c | 90 ++++++++++++++++++++++++++++++++++++++------
grep.h | 3 +
5 files changed, 130 insertions(+), 12 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index f5152c5..b75dada 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -548,6 +548,15 @@ color.diff.<slot>::
whitespace errors). The values of these variables may be specified as
in color.branch.<slot>.
+color.grep::
+ When set to `always`, always highlight matches. When `false` (or
+ `never`), never. When set to `true` or `auto`, use color only
+ when the output is written to the terminal. Defaults to `false`.
+
+color.grep.match::
+ Use customized color for matches. The value of this variable
+ may be specified as in color.branch.<slot>.
+
color.interactive::
When set to `always`, always use colors for interactive prompts
and displays (such as those used by "git-add --interactive").
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index 553da6c..fccb82d 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -17,6 +17,7 @@ SYNOPSIS
[-l | --files-with-matches] [-L | --files-without-match]
[-z | --null]
[-c | --count] [--all-match]
+ [--color | --no-color]
[-A <post-context>] [-B <pre-context>] [-C <context>]
[-f <file>] [-e] <pattern>
[--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
@@ -105,6 +106,13 @@ OPTIONS
Instead of showing every matched line, show the number of
lines that match.
+--color::
+ Show colored matches.
+
+--no-color::
+ Turn off match highlighting, even when the configuration file
+ gives the default to color output.
+
-[ABC] <context>::
Show `context` trailing (`A` -- after), or leading (`B`
-- before), or both (`C` -- context) lines, and place a
diff --git a/builtin-grep.c b/builtin-grep.c
index 3f12ba3..e2c0f01 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -22,6 +22,24 @@
static int builtin_grep;
+static int grep_config(const char *var, const char *value, void *cb)
+{
+ struct grep_opt *opt = cb;
+
+ if (!strcmp(var, "grep.color") || !strcmp(var, "color.grep")) {
+ opt->color = git_config_colorbool(var, value, -1);
+ return 0;
+ }
+ if (!strcmp(var, "grep.color.match") ||
+ !strcmp(var, "color.grep.match")) {
+ if (!value)
+ return config_error_nonbool(var);
+ color_parse(value, var, opt->color_match);
+ return 0;
+ }
+ return git_color_default_config(var, value, cb);
+}
+
/*
* git grep pathspecs are somewhat different from diff-tree pathspecs;
* pathname wildcards are allowed.
@@ -536,6 +554,12 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
opt.pattern_tail = &opt.pattern_list;
opt.regflags = REG_NEWLINE;
+ strcpy(opt.color_match, GIT_COLOR_RED GIT_COLOR_BOLD);
+ opt.color = -1;
+ git_config(grep_config, &opt);
+ if (opt.color == -1)
+ opt.color = git_use_color_default;
+
/*
* If there is no -- then the paths must exist in the working
* tree. If there is no explicit pattern specified with -e or
@@ -732,6 +756,14 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
opt.relative = 0;
continue;
}
+ if (!strcmp("--color", arg)) {
+ opt.color = 1;
+ continue;
+ }
+ if (!strcmp("--no-color", arg)) {
+ opt.color = 0;
+ continue;
+ }
if (!strcmp("--", arg)) {
/* later processing wants to have this at argv[1] */
argv--;
diff --git a/grep.c b/grep.c
index bdcff7b..cace1c8 100644
--- a/grep.c
+++ b/grep.c
@@ -253,18 +253,6 @@ static int word_char(char ch)
return isalnum(ch) || ch == '_';
}
-static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
- const char *name, unsigned lno, char sign)
-{
- if (opt->null_following_name)
- sign = '\0';
- if (opt->pathname)
- printf("%s%c", name, sign);
- if (opt->linenum)
- printf("%d%c", lno, sign);
- printf("%.*s\n", (int)(eol-bol), bol);
-}
-
static void show_name(struct grep_opt *opt, const char *name)
{
printf("%s%c", name, opt->null_following_name ? '\0' : '\n');
@@ -437,6 +425,84 @@ static int match_line(struct grep_opt *opt, char *bol, char *eol,
return 0;
}
+static int match_next_pattern(struct grep_pat *p, char *bol, char *eol,
+ enum grep_context ctx,
+ regmatch_t *pmatch, int eflags)
+{
+ regmatch_t match;
+
+ if (!match_one_pattern(p, bol, eol, ctx, &match, eflags))
+ return 0;
+ if (match.rm_so < 0 || match.rm_eo < 0)
+ return 0;
+ if (pmatch->rm_so >= 0 && pmatch->rm_eo >= 0) {
+ if (match.rm_so > pmatch->rm_so)
+ return 1;
+ if (match.rm_so == pmatch->rm_so && match.rm_eo < pmatch->rm_eo)
+ return 1;
+ }
+ pmatch->rm_so = match.rm_so;
+ pmatch->rm_eo = match.rm_eo;
+ return 1;
+}
+
+static int next_match(struct grep_opt *opt, char *bol, char *eol,
+ enum grep_context ctx, regmatch_t *pmatch, int eflags)
+{
+ struct grep_pat *p;
+ int hit = 0;
+
+ pmatch->rm_so = pmatch->rm_eo = -1;
+ if (bol < eol) {
+ for (p = opt->pattern_list; p; p = p->next) {
+ switch (p->token) {
+ case GREP_PATTERN: /* atom */
+ case GREP_PATTERN_HEAD:
+ case GREP_PATTERN_BODY:
+ hit |= match_next_pattern(p, bol, eol, ctx,
+ pmatch, eflags);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return hit;
+}
+
+static void show_line(struct grep_opt *opt, char *bol, char *eol,
+ const char *name, unsigned lno, char sign)
+{
+ int rest = eol - bol;
+
+ if (opt->null_following_name)
+ sign = '\0';
+ if (opt->pathname)
+ printf("%s%c", name, sign);
+ if (opt->linenum)
+ printf("%d%c", lno, sign);
+ if (opt->color) {
+ regmatch_t match;
+ enum grep_context ctx = GREP_CONTEXT_BODY;
+ int ch = *eol;
+ int eflags = 0;
+
+ *eol = '\0';
+ while (next_match(opt, bol, eol, ctx, &match, eflags)) {
+ printf("%.*s%s%.*s%s",
+ match.rm_so, bol,
+ opt->color_match,
+ match.rm_eo - match.rm_so, bol + match.rm_so,
+ GIT_COLOR_RESET);
+ bol += match.rm_eo;
+ rest -= match.rm_eo;
+ eflags = REG_NOTBOL;
+ }
+ *eol = ch;
+ }
+ printf("%.*s\n", rest, bol);
+}
+
static int grep_buffer_1(struct grep_opt *opt, const char *name,
char *buf, unsigned long size, int collect_hits)
{
diff --git a/grep.h b/grep.h
index d2a8674..73b33ab 100644
--- a/grep.h
+++ b/grep.h
@@ -1,5 +1,6 @@
#ifndef GREP_H
#define GREP_H
+#include "color.h"
enum grep_pat_token {
GREP_PATTERN,
@@ -77,6 +78,8 @@ struct grep_opt {
unsigned relative:1;
unsigned pathname:1;
unsigned null_following_name:1;
+ int color;
+ char color_match[COLOR_MAXLEN];
int regflags;
unsigned pre_context;
unsigned post_context;
--
1.6.2
^ permalink raw reply related
* [PATCH v2] git-p4: remove unnecessary semicolons at end of lines.
From: Sam Hocevar @ 2009-03-07 12:26 UTC (permalink / raw)
To: git
In-Reply-To: <20090306155322.GC12880@zoy.org>
Signed-off-by: Sam Hocevar <sam@zoy.org>
---
This is a properly formatted version of the previous patch.
contrib/fast-import/git-p4 | 46 ++++++++++++++++++++++----------------------
1 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 3832f60..7ea5ac6 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -12,7 +12,7 @@ import optparse, sys, os, marshal, popen2, subprocess, shelve
import tempfile, getopt, sha, os.path, time, platform
import re
-from sets import Set;
+from sets import Set
verbose = False
@@ -240,7 +240,7 @@ def p4Cmd(cmd):
result = {}
for entry in list:
result.update(entry)
- return result;
+ return result
def p4Where(depotPath):
if not depotPath.endswith("/"):
@@ -281,7 +281,7 @@ def currentGitBranch():
def isValidGitDir(path):
if (os.path.exists(path + "/HEAD")
and os.path.exists(path + "/refs") and os.path.exists(path + "/objects")):
- return True;
+ return True
return False
def parseRevision(ref):
@@ -328,8 +328,8 @@ def extractSettingsGitLog(log):
def gitBranchExists(branch):
proc = subprocess.Popen(["git", "rev-parse", branch],
- stderr=subprocess.PIPE, stdout=subprocess.PIPE);
- return proc.wait() == 0;
+ stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ return proc.wait() == 0
_gitConfig = {}
def gitConfig(key):
@@ -492,7 +492,7 @@ class P4RollBack(Command):
maxChange = int(args[0])
if "p4ExitCode" in p4Cmd("changes -m 1"):
- die("Problems executing p4");
+ die("Problems executing p4")
if self.rollbackLocalBranches:
refPrefix = "refs/heads/"
@@ -663,7 +663,7 @@ class P4Submit(Command):
if response == "s":
print "Skipping! Good luck with the next patches..."
for f in editedFiles:
- p4_system("revert \"%s\"" % f);
+ p4_system("revert \"%s\"" % f)
for f in filesToAdd:
system("rm %s" %f)
return
@@ -734,7 +734,7 @@ class P4Submit(Command):
if os.environ.has_key("P4EDITOR"):
editor = os.environ.get("P4EDITOR")
else:
- editor = os.environ.get("EDITOR", defaultEditor);
+ editor = os.environ.get("EDITOR", defaultEditor)
system(editor + " " + fileName)
response = "y"
@@ -753,9 +753,9 @@ class P4Submit(Command):
p4_write_pipe("submit -i", submitTemplate)
else:
for f in editedFiles:
- p4_system("revert \"%s\"" % f);
+ p4_system("revert \"%s\"" % f)
for f in filesToAdd:
- p4_system("revert \"%s\"" % f);
+ p4_system("revert \"%s\"" % f)
system("rm %s" %f)
os.remove(fileName)
@@ -977,9 +977,9 @@ class P4Sync(Command):
if "p4ExitCode" in filedata[0]:
die("Problems executing p4. Error: [%d]."
- % (filedata[0]['p4ExitCode']));
+ % (filedata[0]['p4ExitCode']))
- j = 0;
+ j = 0
contents = {}
while j < len(filedata):
stat = filedata[j]
@@ -1303,8 +1303,8 @@ class P4Sync(Command):
def importNewBranch(self, branch, maxChange):
# make fast-import flush all changes to disk and update the refs using the checkpoint
# command so that we can try to find the branch parent in the git history
- self.gitStream.write("checkpoint\n\n");
- self.gitStream.flush();
+ self.gitStream.write("checkpoint\n\n")
+ self.gitStream.flush()
branchPrefix = self.depotPaths[0] + branch + "/"
range = "@1,%s" % maxChange
#print "prefix" + branchPrefix
@@ -1364,12 +1364,12 @@ class P4Sync(Command):
fullBranch = self.projectName + branch
if fullBranch not in self.p4BranchesInGit:
if not self.silent:
- print("\n Importing new branch %s" % fullBranch);
+ print("\n Importing new branch %s" % fullBranch)
if self.importNewBranch(branch, change - 1):
parent = ""
self.p4BranchesInGit.append(fullBranch)
if not self.silent:
- print("\n Resuming with change %s" % change);
+ print("\n Resuming with change %s" % change)
if self.verbose:
print "parent determined through known branches: %s" % parent
@@ -1485,7 +1485,7 @@ class P4Sync(Command):
self.branch = self.refPrefix + "master"
if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
system("git update-ref %s refs/heads/p4" % self.branch)
- system("git branch -D p4");
+ system("git branch -D p4")
# create it /after/ importing, when master exists
if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes and gitBranchExists(self.branch):
system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch))
@@ -1591,7 +1591,7 @@ class P4Sync(Command):
self.loadUserMapFromCache()
self.labels = {}
if self.detectLabels:
- self.getLabels();
+ self.getLabels()
if self.detectBranches:
## FIXME - what's a P4 projectName ?
@@ -1615,7 +1615,7 @@ class P4Sync(Command):
importProcess = subprocess.Popen(["git", "fast-import"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE);
+ stderr=subprocess.PIPE)
self.gitOutput = importProcess.stdout
self.gitStream = importProcess.stdin
self.gitError = importProcess.stderr
@@ -1688,9 +1688,9 @@ class P4Rebase(Command):
def rebase(self):
if os.system("git update-index --refresh") != 0:
- die("Some files in your working directory are modified and different than what is in your index. You can use git update-index <filename> to bring the index up-to-date or stash away all your changes with git stash.");
+ die("Some files in your working directory are modified and different than what is in your index. You can use git update-index <filename> to bring the index up-to-date or stash away all your changes with git stash.")
if len(read_pipe("git diff-index HEAD --")) > 0:
- die("You have uncommited changes. Please commit them before rebasing or stash them away with git stash.");
+ die("You have uncommited changes. Please commit them before rebasing or stash them away with git stash.")
[upstream, settings] = findUpstreamBranchPoint()
if len(upstream) == 0:
@@ -1866,7 +1866,7 @@ def main():
description = cmd.description,
formatter = HelpFormatter())
- (cmd, args) = parser.parse_args(sys.argv[2:], cmd);
+ (cmd, args) = parser.parse_args(sys.argv[2:], cmd)
global verbose
verbose = cmd.verbose
if cmd.needsGit:
@@ -1877,7 +1877,7 @@ def main():
if os.path.exists(cmd.gitdir):
cdup = read_pipe("git rev-parse --show-cdup").strip()
if len(cdup) > 0:
- chdir(cdup);
+ chdir(cdup)
if not isValidGitDir(cmd.gitdir):
if isValidGitDir(cmd.gitdir + "/.git"):
--
1.6.1.3
^ permalink raw reply related
* [PATCH v5] git-p4: improve performance when importing huge files by reducing the number of string concatenations while constraining memory usage.
From: Sam Hocevar @ 2009-03-07 12:25 UTC (permalink / raw)
To: git
In-Reply-To: <20090306101339.GB12880@zoy.org>
Signed-off-by: Sam Hocevar <sam@zoy.org>
---
This is a properly formatted version of the previous patch.
contrib/fast-import/git-p4 | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 3832f60..db0ea0a 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -984,11 +984,22 @@ class P4Sync(Command):
while j < len(filedata):
stat = filedata[j]
j += 1
+ data = []
text = ''
+ # Append data every 8192 chunks to 1) ensure decent performance
+ # by not making too many string concatenations and 2) avoid
+ # excessive memory usage by purging "data" often enough. p4
+ # sends 4k chunks, so we should not use more than 32 MiB of
+ # additional memory while rebuilding the file data.
while j < len(filedata) and filedata[j]['code'] in ('text', 'unicode', 'binary'):
- text += filedata[j]['data']
+ data.append(filedata[j]['data'])
del filedata[j]['data']
+ if len(data) > 8192:
+ text += ''.join(data)
+ data = []
j += 1
+ text += ''.join(data)
+ data = None
if not stat.has_key('depotFile'):
sys.stderr.write("p4 print fails with: %s\n" % repr(stat))
--
1.6.1.3
^ permalink raw reply related
* [PATCH 3/5] grep: add pmatch and eflags arguments to match_one_pattern()
From: René Scharfe @ 2009-03-07 12:30 UTC (permalink / raw)
To: Git Mailing List
Cc: Nguyễn Thái Ngọc Duy, Junio C Hamano,
Thiago Alves
In-Reply-To: <1236428699.6486.41.camel@ubuntu.ubuntu-domain>
Push pmatch and eflags to the callers of match_one_pattern(), which
allows them to specify regex execution flags and to get the location
of a match.
Since we only use the first element of the matches array and aren't
interested in submatches, no provision is made for callers to
provide a larger array.
eflags are ignored for fixed patterns, but that's OK, since they
only have a meaning in connection with regular expressions
containing ^ or $.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
grep.c | 21 ++++++++++-----------
1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/grep.c b/grep.c
index f455182..bdcff7b 100644
--- a/grep.c
+++ b/grep.c
@@ -309,11 +309,11 @@ static struct {
};
static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
- enum grep_context ctx)
+ enum grep_context ctx,
+ regmatch_t *pmatch, int eflags)
{
int hit = 0;
int saved_ch = 0;
- regmatch_t pmatch[10];
if ((p->token != GREP_PATTERN) &&
((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
@@ -332,14 +332,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
}
again:
- if (!p->fixed) {
- regex_t *exp = &p->regexp;
- hit = !regexec(exp, bol, ARRAY_SIZE(pmatch),
- pmatch, 0);
- }
- else {
+ if (p->fixed)
hit = !fixmatch(p->pattern, bol, pmatch);
- }
+ else
+ hit = !regexec(&p->regexp, bol, 1, pmatch, eflags);
if (hit && p->word_regexp) {
if ((pmatch[0].rm_so < 0) ||
@@ -385,10 +381,11 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
enum grep_context ctx, int collect_hits)
{
int h = 0;
+ regmatch_t match;
switch (x->node) {
case GREP_NODE_ATOM:
- h = match_one_pattern(x->u.atom, bol, eol, ctx);
+ h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
break;
case GREP_NODE_NOT:
h = !match_expr_eval(x->u.unary, bol, eol, ctx, 0);
@@ -427,12 +424,14 @@ static int match_line(struct grep_opt *opt, char *bol, char *eol,
enum grep_context ctx, int collect_hits)
{
struct grep_pat *p;
+ regmatch_t match;
+
if (opt->extended)
return match_expr(opt, bol, eol, ctx, collect_hits);
/* we do not call with collect_hits without being extended */
for (p = opt->pattern_list; p; p = p->next) {
- if (match_one_pattern(p, bol, eol, ctx))
+ if (match_one_pattern(p, bol, eol, ctx, &match, 0))
return 1;
}
return 0;
--
1.6.2
^ permalink raw reply related
* [PATCH 2/5] grep: remove grep_opt argument from match_expr_eval()
From: René Scharfe @ 2009-03-07 12:28 UTC (permalink / raw)
To: Git Mailing List
Cc: Nguyễn Thái Ngọc Duy, Junio C Hamano,
Thiago Alves
In-Reply-To: <1236428699.6486.41.camel@ubuntu.ubuntu-domain>
The only use of the struct grep_opt argument of match_expr_eval()
is to pass the option word_regexp to match_one_pattern(). By adding
a pattern flag for it we can reduce the number of function arguments
of these two functions, as a cleanup and preparation for adding more
in the next patch.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
grep.c | 34 +++++++++++++++++-----------------
grep.h | 1 +
2 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/grep.c b/grep.c
index db341b6..f455182 100644
--- a/grep.c
+++ b/grep.c
@@ -39,6 +39,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
{
int err;
+ p->word_regexp = opt->word_regexp;
+
if (opt->fixed || is_fixed(p->pattern))
p->fixed = 1;
if (opt->regflags & REG_ICASE)
@@ -306,7 +308,8 @@ static struct {
{ "committer ", 10 },
};
-static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol, char *eol, enum grep_context ctx)
+static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
+ enum grep_context ctx)
{
int hit = 0;
int saved_ch = 0;
@@ -338,7 +341,7 @@ static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol
hit = !fixmatch(p->pattern, bol, pmatch);
}
- if (hit && opt->word_regexp) {
+ if (hit && p->word_regexp) {
if ((pmatch[0].rm_so < 0) ||
(eol - bol) <= pmatch[0].rm_so ||
(pmatch[0].rm_eo < 0) ||
@@ -378,35 +381,32 @@ static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol
return hit;
}
-static int match_expr_eval(struct grep_opt *o,
- struct grep_expr *x,
- char *bol, char *eol,
- enum grep_context ctx,
- int collect_hits)
+static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
+ enum grep_context ctx, int collect_hits)
{
int h = 0;
switch (x->node) {
case GREP_NODE_ATOM:
- h = match_one_pattern(o, x->u.atom, bol, eol, ctx);
+ h = match_one_pattern(x->u.atom, bol, eol, ctx);
break;
case GREP_NODE_NOT:
- h = !match_expr_eval(o, x->u.unary, bol, eol, ctx, 0);
+ h = !match_expr_eval(x->u.unary, bol, eol, ctx, 0);
break;
case GREP_NODE_AND:
- if (!match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0))
+ if (!match_expr_eval(x->u.binary.left, bol, eol, ctx, 0))
return 0;
- h = match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
+ h = match_expr_eval(x->u.binary.right, bol, eol, ctx, 0);
break;
case GREP_NODE_OR:
if (!collect_hits)
- return (match_expr_eval(o, x->u.binary.left,
+ return (match_expr_eval(x->u.binary.left,
bol, eol, ctx, 0) ||
- match_expr_eval(o, x->u.binary.right,
+ match_expr_eval(x->u.binary.right,
bol, eol, ctx, 0));
- h = match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0);
+ h = match_expr_eval(x->u.binary.left, bol, eol, ctx, 0);
x->u.binary.left->hit |= h;
- h |= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 1);
+ h |= match_expr_eval(x->u.binary.right, bol, eol, ctx, 1);
break;
default:
die("Unexpected node type (internal error) %d", x->node);
@@ -420,7 +420,7 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,
enum grep_context ctx, int collect_hits)
{
struct grep_expr *x = opt->pattern_expression;
- return match_expr_eval(opt, x, bol, eol, ctx, collect_hits);
+ return match_expr_eval(x, bol, eol, ctx, collect_hits);
}
static int match_line(struct grep_opt *opt, char *bol, char *eol,
@@ -432,7 +432,7 @@ static int match_line(struct grep_opt *opt, char *bol, char *eol,
/* we do not call with collect_hits without being extended */
for (p = opt->pattern_list; p; p = p->next) {
- if (match_one_pattern(opt, p, bol, eol, ctx))
+ if (match_one_pattern(p, bol, eol, ctx))
return 1;
}
return 0;
diff --git a/grep.h b/grep.h
index 5102ce3..d2a8674 100644
--- a/grep.h
+++ b/grep.h
@@ -31,6 +31,7 @@ struct grep_pat {
enum grep_header_field field;
regex_t regexp;
unsigned fixed:1;
+ unsigned word_regexp:1;
};
enum grep_expr_node {
--
1.6.2
^ permalink raw reply related
* [PATCH 1/5] grep: micro-optimize hit collection for AND nodes
From: René Scharfe @ 2009-03-07 12:27 UTC (permalink / raw)
To: Git Mailing List
Cc: Nguyễn Thái Ngọc Duy, Junio C Hamano,
Thiago Alves
In-Reply-To: <1236428699.6486.41.camel@ubuntu.ubuntu-domain>
In addition to returning if an expression matches a line,
match_expr_eval() updates the expression's hit flag if the parameter
collect_hits is set. It never sets collect_hits for children of AND
nodes, though, so their hit flag will never be updated. Because of
that we can return early if the first child didn't match, no matter
if collect_hits is set or not.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
grep.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/grep.c b/grep.c
index 062b2b6..db341b6 100644
--- a/grep.c
+++ b/grep.c
@@ -394,13 +394,9 @@ static int match_expr_eval(struct grep_opt *o,
h = !match_expr_eval(o, x->u.unary, bol, eol, ctx, 0);
break;
case GREP_NODE_AND:
- if (!collect_hits)
- return (match_expr_eval(o, x->u.binary.left,
- bol, eol, ctx, 0) &&
- match_expr_eval(o, x->u.binary.right,
- bol, eol, ctx, 0));
- h = match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0);
- h &= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
+ if (!match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0))
+ return 0;
+ h = match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
break;
case GREP_NODE_OR:
if (!collect_hits)
--
1.6.2
^ permalink raw reply related
* [PATCH 0/5] grep: color search patterns
From: René Scharfe @ 2009-03-07 12:24 UTC (permalink / raw)
To: Git Mailing List
Cc: Nguyễn Thái Ngọc Duy, Junio C Hamano,
Thiago Alves
Match coloring is a major missing feature of git grep. It makes reading
the output much easier and brings grep onto the same visual level as the
other colorized git commands.
Two earlier attempts to implement this feature didn't go in. They
didn't support support pattern expressions (--and, --or etc.) or
external greps, unlike this series.
[PATCH 1/5] grep: micro-optimize hit collection for AND nodes
[PATCH 2/5] grep: remove grep_opt argument from match_expr_eval()
These are cleanup patches and unrelated to coloring. They touch the
same code, though, so it's a good idea to take this opportunity to
beautify the code a bit before adding new features.
[PATCH 3/5] grep: add pmatch and eflags arguments to match_one_pattern()
The two arguments added by this patch are used by the next one.
[PATCH 4/5] grep: color patterns in output
Add color support to internal git grep.
[PATCH 5/5] grep: add support for coloring with external greps
Extends color support to external greps.
^ permalink raw reply
* [PATCH] http: add_fill_function checks if function has been added
From: Tay Ray Chuan @ 2009-03-07 12:21 UTC (permalink / raw)
To: git
This patch ensures that the same fill function is called once so to
prevent any possible issues.
Nevertheless, calling a fill function repeatedly in
''fill_active_slots'' will not lead to any obvious change in existing
behavior, though performance might be affected.
''add_fill_action'' checks if the function to be added has already been
added. Allocation of memory for the list ''fill_chain*'' is postponed
until the check passes, unlike previously.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
http.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/http.c b/http.c
index ee58799..cdedeb6 100644
--- a/http.c
+++ b/http.c
@@ -408,13 +408,17 @@ static struct fill_chain *fill_cfg = NULL;
void add_fill_function(void *data, int (*fill)(void *))
{
- struct fill_chain *new = xmalloc(sizeof(*new));
+ struct fill_chain *new;
struct fill_chain **linkp = &fill_cfg;
+ for (;*linkp; linkp = &(*linkp)->next)
+ if ((*linkp)->fill == fill)
+ return;
+
+ new = xmalloc(sizeof(*new));
new->data = data;
new->fill = fill;
new->next = NULL;
- while (*linkp)
- linkp = &(*linkp)->next;
+
*linkp = new;
}
--
1.6.2.rc1
^ permalink raw reply related
* Clone a repo and checkout a specifc remote branch
From: Paolo Ciarrocchi @ 2009-03-07 11:42 UTC (permalink / raw)
To: git list
Hi list,
I've got a few questions from a friend that used git for the first
time, I answered to all of them but the following.
Scenario:
He knows the URl of a git repository which contains a few branches. He
is interested only to a single specific branch.
He expected to manage to clone the specific remote branch with a
single command, instead he had to learn the following procedure:
$ git clone git://uri_of_the_repo localdir
$ cd localdir
$ git branch
* master
# OK, so now he cloned the whole repository and checked out the master branch
$ git checkout mybranch origin/coolbranch
Wouldn't be an improvement to let the user to specify which remote
branch he want to be checked out after a clone?
Something like:
$ git clone git://uri_of_the_repo:coolbranch localdir
to get a clone of the whole repository and to check out the
origin/coolbranch remote branch?
I quickly discussed this scenario on the #git channel and a user
suggested to use the following procedure:
$ git init
$ git fetch git://uri_of_the_repo coolbranch
which was new to me, I tried it as follow:
$ git fetch git://git.kernel.org/pub/scm/git/git.git man
remote: Counting objects: 7319, done.←[K
remote: Compressing objects: 100% (1536/1536), done.←[K
remote: Total 7319 (delta 5640), reused 7290 (delta 5625)←[K
Receiving objects: 100% (7319/7319), 1.40 MiB | 110 KiB/s, done.
Resolving deltas: 100% (5640/5640), done.
From git://git.kernel.org/pub/scm/git/git
* branch man -> FETCH_HEAD
but now I don't understand how to checkout the branch :-/
Ciao,
--
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/
^ permalink raw reply
* Re: Rebasing local patches
From: Johannes Schindelin @ 2009-03-07 11:41 UTC (permalink / raw)
To: Nicolas Morey-Chaisemartin; +Cc: git@vger.kernel.org
In-Reply-To: <49B237E2.3080606@morey-chaisemartin.com>
Hi,
On Sat, 7 Mar 2009, Nicolas Morey-Chaisemartin wrote:
> On one of our project, we depend on an external source which uses git.
> On our side of the project, we create some patches (this part is not the
> problem), but only some of them are intended to be pushed (ie pulled by)
> the external source. So basically, we have a set of patches on local
> branch that we rebase every so and then against master to keep our
> version up-to-date with the external one.
>
> Is this the right way to do it?
Looks sane.
> Then, internally we have a centralized repository and many personal
> ones. When the need to go to the next version, one of the developper
> rebases the company patches branch afaisnt master and push it into the
> centralized repo.
>
> What is the best way for the other developpers to get up-to-date with
> the rebased branch?
>
> git pull --rebase seems to me like a good way to keep local modifications.
Indeed.
You could also work from release branches, i.e. whenever you rebase your
company-specific changes onto the upstream, you could start a new branch.
Or even better: you could "merge -s ours" the pre-rebase commit. The
history would then look something like this:
new UPSTREAM - A' - B' - C' - M
/
old UPSTREAM - A - B - C --------------'
The ' commits are the rewritten versions of the original company-specific
ones, made by the rebase.
If you do it that way, not only will you not lose the history of your
project, but your users can happily continue to merge instead of having to
rebase.
> I noticed that when the branch was rebased on the centralized and repo
> and origin/our_patches is up-to-date in mine.
>
> If I checkout another branch and then ckecout our_branches, I got a
> message telling my our_patches and the one from the server have diverged
> (or you are two commits behind...).
>
> How can you get this info directly without leaving/rejoining your
> branch?
It is also part of "git status"' output.
Ciao,
Dscho
^ permalink raw reply
* Re: [PATCH/RFD] builtin-revert.c: release index lock when cherry-picking an empty commit
From: Johannes Schindelin @ 2009-03-07 11:15 UTC (permalink / raw)
To: Chris Johnsen; +Cc: git, Junio C Hamano, Miklos Vajna
In-Reply-To: <1236418251-16947-1-git-send-email-chris_johnsen@pobox.com>
Hi,
On Sat, 7 Mar 2009, Chris Johnsen wrote:
> When a cherry-pick of an empty commit is done, release the lock
> held on the index.
>
> The fix is the same as was applied to similar code in 4271666046.
>
> Signed-off-by: Chris Johnsen <chris_johnsen@pobox.com>
> ---
> [...]
Thanks for the detailed explanation, and the patch!
I wonder, though, if the real root of the problem is that there is
copied code. IOW I think it would be better to introduce a global
function that writes the index to a tree. A quick "git grep
commit_locked_index" reveals quite a few code sites...
Thanks,
Dscho
^ permalink raw reply
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