* Re: Re* [PATCH v3 19/22] resolve_ref(): emit warnings for improperly-formatted references
From: Michael Haggerty @ 2011-10-12 2:56 UTC (permalink / raw)
To: Junio C Hamano
Cc: Jeff King, git, cmn, A Large Angry SCM, Daniel Barkalow,
Sverre Rabbelier
In-Reply-To: <7vehyjcckp.fsf@alter.siamese.dyndns.org>
On 10/12/2011 01:50 AM, Junio C Hamano wrote:
> It starts sounding like that the ill-thought-out warning should be ripped
> out regardless of what other things we do.
ISTM that the warning is proving its worth already by illuminating some
questionable practices (treating any file in $GIT_DIR as a potential
reference) :-)
However, it might be that fixing 100% of the questionable practices is
too much work. In that case, I suggest that the warning not be ripped
out altogether, but rather that the warning only be emitted for invalid
references whose names start with "refs/".
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
^ permalink raw reply
* Re: Re* [PATCH v3 19/22] resolve_ref(): emit warnings for improperly-formatted references
From: Jeff King @ 2011-10-12 2:11 UTC (permalink / raw)
To: Junio C Hamano
Cc: Michael Haggerty, git, cmn, A Large Angry SCM, Daniel Barkalow,
Sverre Rabbelier
In-Reply-To: <7vehyjcckp.fsf@alter.siamese.dyndns.org>
On Tue, Oct 11, 2011 at 04:50:46PM -0700, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > It looks like we also use it in remote.c:count_refspec_match, but I
> > haven't figured out if that can trigger a warning or not.
>
> It starts sounding like that the ill-thought-out warning should be ripped
> out regardless of what other things we do.
Maybe. I think it is not the warning that is wrong, but that it is
exposing a slightly hack-ish part of git (that we consider things like
$GIT_DIR/config as possible refs, and just silently reject them because
they happen not to have the right format).
On the other hand, it has been working fine that way for years, so maybe
it is not worth changing now.
At any rate, I think the changes should be all or nothing. If the
warning goes away, fine. But if the warning stays, and dwim_ref is going
to have special rules for looking in the top-level $GIT_DIR, then things
like shorten_unambiguous_ref need to respect those rules, or we've just
created a new bug.
-Peff
^ permalink raw reply
* Re: Re* [PATCH v3 19/22] resolve_ref(): emit warnings for improperly-formatted references
From: Junio C Hamano @ 2011-10-11 23:50 UTC (permalink / raw)
To: Jeff King
Cc: Michael Haggerty, git, cmn, A Large Angry SCM, Daniel Barkalow,
Sverre Rabbelier
In-Reply-To: <20111011230749.GA29785@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> It looks like we also use it in remote.c:count_refspec_match, but I
> haven't figured out if that can trigger a warning or not.
It starts sounding like that the ill-thought-out warning should be ripped
out regardless of what other things we do.
^ permalink raw reply
* Re: [PATCH] Make is_gitfile a non-static generic function
From: Junio C Hamano @ 2011-10-11 23:45 UTC (permalink / raw)
To: Phil Hord; +Cc: git@vger.kernel.org
In-Reply-To: <4E94C8AB.3040807@cisco.com>
Phil Hord <hordp@cisco.com> writes:
> The new is_gitfile is an amalgam of similar functional checks
> from different places in the code....
> diff --git a/builtin/clone.c b/builtin/clone.c
> index 488f48e..5110399 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -120,13 +120,7 @@ static char *get_repo_path(const char *repo, int
> *is_bundle)
> return xstrdup(absolute_path(path));
> } else if (S_ISREG(st.st_mode) && st.st_size > 8) {
> /* Is it a "gitfile"? */
> - char signature[8];
> - int len, fd = open(path, O_RDONLY);
> - if (fd < 0)
> - continue;
> - len = read_in_full(fd, signature, 8);
> - close(fd);
> - if (len != 8 || strncmp(signature, "gitdir: ", 8))
> + if (!is_gitfile(path))
> continue;
> path = read_gitfile(path);
> if (path) {
> diff --git a/cache.h b/cache.h
> index 601f6f6..7a8d9f9 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -441,6 +441,7 @@ extern const char *get_git_work_tree(void);
> extern const char *read_gitfile(const char *path);
> extern const char *resolve_gitdir(const char *suspect);
> extern void set_git_work_tree(const char *tree);
> +extern int is_gitfile(const char *path);
> #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
> diff --git a/transport.c b/transport.c
> index f3195c0..d08a826 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -859,7 +859,11 @@ static int is_local(const char *url)
> has_dos_drive_prefix(url);
> }
> -static int is_gitfile(const char *url)
> +/*
> + * See if the referenced file looks like a 'gitfile'.
> + * Does not try to determine if the referenced gitdir is actually valid.
> + */
> +int is_gitfile(const char *url)
> {
> struct stat st;
> char buf[9];
After looking at this patch and the way the other caller in transport.c
uses it, I am more and more convinced that "is_gitfile()" is a stupid and
horrible mistake.
The caller in transport.c says "I am about to read from a regular file,
and usually I would treat it as a bundle, but I want to avoid that
codepath if that regular file is not a bundle. So I use the codepath only
when that file is not a gitfile".
It should be saying "Is it a bundle? Then I'd use the codepath to read
from the bundle" to begin with. Otherwise the code will break when we add
yet another regular file we can fetch from that is not a bundle nor a
gitfile.
I think the hand-crafted check in builtin/clone.c you removed originated
from laziness to avoid teaching read_gitfile() to read potential gitfile
silently (and signal errors by simply returning NULL). I also suspect the
codepath may become simpler if we had a way to ask "Is this a bundle?".
I think read_bundle_header() in bundle.c can be refactored to a silent
interface that allows us to ask "Is this a bundle?" question properly.
^ permalink raw reply
* Re: [PATCH] Make is_gitfile a non-static generic function
From: Junio C Hamano @ 2011-10-11 23:26 UTC (permalink / raw)
To: Phil Hord; +Cc: git@vger.kernel.org
In-Reply-To: <4E94C8AB.3040807@cisco.com>
Phil Hord <hordp@cisco.com> writes:
> I'm not sure this function belongs in transport.c anymore, but
> I left it here to minimize conflicts. I think a better home would
> be path.c, but maybe not. If someone has a preference,
> please let me know.
I would think either transport.c or setup.c is more appropriate than
path.c; the last one is more of "pathname manipulation utility bag of
functions" and does not have much to do with the "Git"-ness of the path
they deal with.
I am not sure if is_gitfile() is a good name for a global function,
though. Also I think the interface to the function should be updated so
that the caller can choose to receive the target path when the function
returns with positive answer, making "read_gitfile()" unnecessary for such
a caller.
As a matter of fact, couldn't we somehow unify these two slightly
different implementations around the same theme, making is_gitfile()
function unnecessary? As far as I can tell, the only difference between
these functions is how they fail when given a non-gitfile, and many
callers just call read_gitfile() without first asking if it is a gitfile.
^ permalink raw reply
* Re: [PATCH 0/6] Negation magic pathspec
From: Junio C Hamano @ 2011-10-11 23:17 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> I'm still struggling with read_directory() rewrite so that struct
> pathspec can be used throughout git, but now realized we can at least
> enable magic for certain commands and die() on those that don't.
> This may help move magic pathspec patches forward.
I actually was thinking that teaching those that take bare "const char **"
to take "struct pathspec *" is much more important conversion before
adding more magic to those that already do take "struct pathspec *". The
ones that ask "does this path match the pathspec" would automatically
start honoring negative or quantum or whatever magic once we teach
the magic to match_pathspec(), but the ones that take "const char **" will
have no way of doing so before getting converted to "struct pathspec *"
interface. If some parts of the system knows more magic and people start
playing with them, the lack of the support in codepaths that haven't been
converted will become real pain point.
That is not to say that these 6 patch series are wasted patches. I just
think it may be doing things in a wrong order.
^ permalink raw reply
* Re: Re* [PATCH v3 19/22] resolve_ref(): emit warnings for improperly-formatted references
From: Jeff King @ 2011-10-11 23:07 UTC (permalink / raw)
To: Junio C Hamano
Cc: Michael Haggerty, git, cmn, A Large Angry SCM, Daniel Barkalow,
Sverre Rabbelier
In-Reply-To: <7v39ezffq5.fsf_-_@alter.siamese.dyndns.org>
On Tue, Oct 11, 2011 at 01:14:26PM -0700, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> >> I think we've discussed tightening it a few years ago already.
> >>
> >> HEAD, MERGE_HEAD, FETCH_HEAD, etc. all are "^[_A-Z]*$" and it may even be
> >> a good idea to insist "^[_A-Z]*HEAD$" or even "^([A-Z][A-Z]*_)?HEAD$".
> >
> > Perhaps like this? Only compile tested...
>
> Not quite. There are at least three bugs in the patch.
>
> - Some subsystems use random refnames like NOTES_MERGE_PARTIAL that would
> not match "^([A-Z][A-Z]*_)?HEAD$". The rule needs to be relaxed;
>
> - dwim_ref() can be fed "refs/heads/master" and is expected to dwim it to
> the master branch.
>
> - These codepaths get pointer+length so that it can be told to parse only
> the first 4 bytes in "HEAD:$path".
One more bug. :)
We also look at ref_rev_parse_rules in shorten_unambiguous_ref. So even
with your patch, I still get the warning with:
$ git branch config
$ git for-each-ref --format='%(refname:short)' refs/heads/
It looks like we also use it in remote.c:count_refspec_match, but I
haven't figured out if that can trigger a warning or not.
-Peff
^ permalink raw reply
* Re: Git Bug - diff in commit message.
From: Junio C Hamano @ 2011-10-11 23:00 UTC (permalink / raw)
To: git; +Cc: Michael Witten, anikey
In-Reply-To: <7vpqj9vh87.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> In the longer term, I think "git-rebase--am.sh" should be rewritten to
> have format-patch avoid the cost of actually generating the patch text,
> and the "mailinfo" call that comes above the context shown in this patch
> should be made conditional---when using "am" for rebasing we do not really
> care anything but the commit object names, and everything else is figured
> out from the commit this codepath.
And here is a quick hack to do that using "log --cherry-pick --right-only".
git-am.sh | 44 ++++++++++++++++++++++++--------------------
git-rebase--am.sh | 12 +++++++++---
2 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 9042432..b79ccc5 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -641,32 +641,36 @@ do
# by the user, or the user can tell us to do so by --resolved flag.
case "$resume" in
'')
- git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
- <"$dotest/$msgnum" >"$dotest/info" ||
- stop_here $this
-
- # skip pine's internal folder data
- sane_grep '^Author: Mail System Internal Data$' \
- <"$dotest"/info >/dev/null &&
- go_next && continue
-
- test -s "$dotest/patch" || {
- eval_gettextln "Patch is empty. Was it split wrong?
-If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
-To restore the original branch and stop patching run \"\$cmdline --abort\"."
- stop_here $this
- }
rm -f "$dotest/original-commit" "$dotest/author-script"
- if test -f "$dotest/rebasing" &&
+
+ if test -f "$dotest/rebasing"
+ then
commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
-e q "$dotest/$msgnum") &&
- test "$(git cat-file -t "$commit")" = commit
- then
+ test "$(git cat-file -t "$commit")" = commit || {
+ stop_here $this
+ }
git cat-file commit "$commit" |
sed -e '1,/^$/d' >"$dotest/msg-clean"
- echo "$commit" > "$dotest/original-commit"
- get_author_ident_from_commit "$commit" > "$dotest/author-script"
+ echo "$commit" >"$dotest/original-commit"
+ get_author_ident_from_commit "$commit" >"$dotest/author-script"
+ git diff-tree -p --root "$commit" >"$dotest/patch"
else
+ git mailinfo $keep $no_inbody_headers \
+ $scissors $utf8 "$dotest/msg" "$dotest/patch" \
+ <"$dotest/$msgnum" >"$dotest/info" ||
+ stop_here $this
+
+ # skip pine's internal folder data
+ sane_grep '^Author: Mail System Internal Data$' \
+ <"$dotest"/info >/dev/null &&
+ go_next && continue
+ test -s "$dotest/patch" || {
+ eval_gettextln "Patch is empty. Was it split wrong?
+If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
+To restore the original branch and stop patching run \"\$cmdline --abort\"."
+ stop_here $this
+ }
{
sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
echo
diff --git a/git-rebase--am.sh b/git-rebase--am.sh
[...]
^ permalink raw reply related
* Re: Re* [PATCH v3 19/22] resolve_ref(): emit warnings for improperly-formatted references
From: Jeff King @ 2011-10-11 22:54 UTC (permalink / raw)
To: Junio C Hamano
Cc: Lars Hjemli, Michael Haggerty, git, cmn, A Large Angry SCM,
Daniel Barkalow, Sverre Rabbelier
In-Reply-To: <7vpqi3dxkr.fsf@alter.siamese.dyndns.org>
On Tue, Oct 11, 2011 at 02:31:48PM -0700, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > But in the code, it is spelled RENAMED-REF (with a dash). And as far as
> > I can tell, does not actually create a reflog. And it's not documented
> > anywhere, so I suspect nobody is using it. Maybe it is worth switching
> > that name.
>
> Or even better get rid of it?
Fine by me. I'm not sure anyone is even aware that it exists. Just to
double-check, I grepped the list archives, and the biggest mention of it
was its presence causing a weird bug:
http://thread.gmane.org/gmane.comp.version-control.git/143737
Googling turns up only confusion, nobody actually using it or
recommending that it be used.
OTOH, it does actually serialize branch renames, since we take a lock on
it. Maybe that's important. Cc'ing Lars. Certainly renaming it would be
the conservative choice.
-Peff
PS I mentioned above that it does not actually create a reflog. Digging
in the code more, I think it is capable of it, but my git.git clone had
RENAMED-REF, but no reflog. I would have thought core.logAllRefUpdates
would turn it on, but maybe there is a funny interaction with things not
in refs/.
^ permalink raw reply
* [PATCH] Make is_gitfile a non-static generic function
From: Phil Hord @ 2011-10-11 22:52 UTC (permalink / raw)
To: git@vger.kernel.org, Phil Hord
In-Reply-To: <4E94C70E.3080003@cisco.com>
The new is_gitfile is an amalgam of similar functional checks
from different places in the code. All these places do
slightly different checks on the suspect gitfile (for their
own good reasons). But the lack of common code leads to bugs
and maintenance problems. Help move the code forward by making
is_gitfile() a common function that everyone can use for this
purpose.
Signed-off-by: Phil Hord <hordp@cisco.com>
---
I'm not sure this function belongs in transport.c anymore, but
I left it here to minimize conflicts. I think a better home would
be path.c, but maybe not. If someone has a preference,
please let me know.
builtin/clone.c | 8 +-------
cache.h | 1 +
transport.c | 6 +++++-
3 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 488f48e..5110399 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -120,13 +120,7 @@ static char *get_repo_path(const char *repo, int
*is_bundle)
return xstrdup(absolute_path(path));
} else if (S_ISREG(st.st_mode) && st.st_size > 8) {
/* Is it a "gitfile"? */
- char signature[8];
- int len, fd = open(path, O_RDONLY);
- if (fd < 0)
- continue;
- len = read_in_full(fd, signature, 8);
- close(fd);
- if (len != 8 || strncmp(signature, "gitdir: ", 8))
+ if (!is_gitfile(path))
continue;
path = read_gitfile(path);
if (path) {
diff --git a/cache.h b/cache.h
index 601f6f6..7a8d9f9 100644
--- a/cache.h
+++ b/cache.h
@@ -441,6 +441,7 @@ extern const char *get_git_work_tree(void);
extern const char *read_gitfile(const char *path);
extern const char *resolve_gitdir(const char *suspect);
extern void set_git_work_tree(const char *tree);
+extern int is_gitfile(const char *path);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
diff --git a/transport.c b/transport.c
index f3195c0..d08a826 100644
--- a/transport.c
+++ b/transport.c
@@ -859,7 +859,11 @@ static int is_local(const char *url)
has_dos_drive_prefix(url);
}
-static int is_gitfile(const char *url)
+/*
+ * See if the referenced file looks like a 'gitfile'.
+ * Does not try to determine if the referenced gitdir is actually valid.
+ */
+int is_gitfile(const char *url)
{
struct stat st;
char buf[9];
--
1.7.7.334.gfc143d
^ permalink raw reply related
* [PATCH 6/6] Implement negative pathspec
From: Nguyễn Thái Ngọc Duy @ 2011-10-11 22:44 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
I really like the mnemonic ^ but it's regex. ":^Documentation" looks
nicer than ":~Documentation". Do we plan on supporting regex in
pathspec too?
We should mention these magic in a less obscure document. Glossary is
mostly for developer discussions. git-diff may be a good place
because it's one of the two frequently used commands (the other one
is grep) that benefit magic the most (with a short reference from
git.txt)
Documentation/glossary-content.txt | 8 +++---
cache.h | 1 +
dir.c | 2 +
setup.c | 1 +
tree-walk.c | 37 +++++++++++++++++++++++++++++++++--
5 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 3595b58..9a2765d 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -319,12 +319,12 @@ top `/`;;
The magic word `top` (mnemonic: `/`) makes the pattern match
from the root of the working tree, even when you are running
the command from inside a subdirectory.
+
+exclude `~`;;
+ The magic word `exclude` (mnemonic: `~`) excludes paths that
+ match the pattern.
--
+
-Currently only the slash `/` is recognized as the "magic signature",
-but it is envisioned that we will support more types of magic in later
-versions of git.
-+
A pathspec with only a colon means "there is no pathspec". This form
should not be combined with other pathspec.
diff --git a/cache.h b/cache.h
index 719d4a3..75fe589 100644
--- a/cache.h
+++ b/cache.h
@@ -541,6 +541,7 @@ extern int ie_modified(const struct index_state *, struct cache_entry *, struct
*/
#define PATHSPEC_FROMTOP (1<<0)
#define PATHSPEC_NOGLOB (1<<1)
+#define PATHSPEC_NEGATE (1<<2)
struct pathspec {
const char **raw; /* get_pathspec() result, not freed by free_pathspec() */
diff --git a/dir.c b/dir.c
index d38af0f..46dd35f 100644
--- a/dir.c
+++ b/dir.c
@@ -1305,6 +1305,8 @@ int parse_pathspec(struct pathspec *pathspec, const char *prefix,
pitem->magic |= PATHSPEC_NOGLOB;
else
pathspec->magic &= ~PATHSPEC_NOGLOB;
+ if (pitem->magic & PATHSPEC_NEGATE)
+ pathspec->magic |= PATHSPEC_NEGATE;
pitem++;
dst++;
}
diff --git a/setup.c b/setup.c
index b074210..42beb9b 100644
--- a/setup.c
+++ b/setup.c
@@ -111,6 +111,7 @@ static struct pathspec_magic {
const char *name;
} pathspec_magic[] = {
{ PATHSPEC_FROMTOP, '/', "top" },
+ { PATHSPEC_NEGATE, '~', "exclude" },
};
/*
diff --git a/tree-walk.c b/tree-walk.c
index db07fd6..936b5da 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -580,15 +580,17 @@ static int match_dir_prefix(const char *base, int baselen,
* - zero for no
* - negative for "no, and no subsequent entries will be either"
*/
-int tree_entry_interesting(const struct name_entry *entry,
- struct strbuf *base, int base_offset,
- const struct pathspec *ps)
+static int tree_entry_interesting_1(const struct name_entry *entry,
+ struct strbuf *base, int base_offset,
+ const struct pathspec *ps, int negative_magic)
{
int i;
int pathlen, baselen = base->len - base_offset;
int never_interesting = ps->magic & PATHSPEC_NOGLOB ? -1 : 0;
+ int has_effective_pathspec = 0;
if (!ps->nr) {
+no_pathspec:
if (!ps->recursive || ps->max_depth == -1)
return 2;
return !!within_depth(base->buf + base_offset, baselen,
@@ -604,6 +606,12 @@ int tree_entry_interesting(const struct name_entry *entry,
const char *base_str = base->buf + base_offset;
int matchlen = item->len;
+ if ((!negative_magic && !(item->magic & PATHSPEC_NEGATE)) ||
+ ( negative_magic && (item->magic & PATHSPEC_NEGATE)))
+ has_effective_pathspec = 1;
+ else
+ continue;
+
if (baselen >= matchlen) {
/* If it doesn't match, move along... */
if (!match_dir_prefix(base_str, baselen, match, matchlen))
@@ -663,5 +671,28 @@ match_wildcards:
if (ps->recursive && S_ISDIR(entry->mode))
return 1;
}
+
+ /* the same effect with ps->nr == 0 */
+ if (!has_effective_pathspec)
+ goto no_pathspec;
+
return never_interesting; /* No matches */
}
+
+int tree_entry_interesting(const struct name_entry *entry,
+ struct strbuf *base, int base_offset,
+ const struct pathspec *ps)
+{
+ int next_ret, ret;
+
+ ret = tree_entry_interesting_1(entry, base, base_offset, ps, 0);
+ if (ps->magic & PATHSPEC_NEGATE) {
+ next_ret = tree_entry_interesting_1(entry, base, base_offset, ps, 1);
+ switch (next_ret) {
+ case 2: ret = -1; break;
+ case 1: ret = 0; break;
+ default: break;
+ }
+ }
+ return ret;
+}
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply related
* [PATCH 5/6] Convert simple init_pathspec() cases to parse_pathspec()
From: Nguyễn Thái Ngọc Duy @ 2011-10-11 22:44 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
These commands can now take advantage of new pathspec magic, if both
tree_entry_interesting() and match_pathspec_depth() support them properly
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/grep.c | 4 +---
builtin/ls-tree.c | 2 +-
builtin/reset.c | 2 +-
revision.c | 9 +++++----
4 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index a286692..e171a9d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -759,7 +759,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
const char *show_in_pager = NULL, *default_pager = "dummy";
struct grep_opt opt;
struct object_array list = OBJECT_ARRAY_INIT;
- const char **paths = NULL;
struct pathspec pathspec;
struct string_list path_list = STRING_LIST_INIT_NODUP;
int i;
@@ -1020,8 +1019,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
verify_filename(prefix, argv[j]);
}
- paths = get_pathspec(prefix, argv + i);
- init_pathspec(&pathspec, paths);
+ parse_pathspec(&pathspec, prefix, -1, argv + i);
pathspec.max_depth = opt.max_depth;
pathspec.recursive = 1;
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index f0fa7dd..b717bb2 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -166,7 +166,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
if (get_sha1(argv[0], sha1))
die("Not a valid object name %s", argv[0]);
- init_pathspec(&pathspec, get_pathspec(prefix, argv + 1));
+ parse_pathspec(&pathspec, prefix, -1, argv + 1);
for (i = 0; i < pathspec.nr; i++)
pathspec.items[i].magic = PATHSPEC_NOGLOB;
pathspec.magic |= PATHSPEC_NOGLOB;
diff --git a/builtin/reset.c b/builtin/reset.c
index 811e8e2..8126e69 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -176,7 +176,7 @@ static int read_from_tree(const char *prefix, const char **argv,
struct diff_options opt;
memset(&opt, 0, sizeof(opt));
- diff_tree_setup_paths(get_pathspec(prefix, (const char **)argv), &opt);
+ parse_pathspec(&opt.pathspec, prefix, -1, argv);
opt.output_format = DIFF_FORMAT_CALLBACK;
opt.format_callback = update_index_from_diff;
opt.format_callback_data = &index_was_discarded;
diff --git a/revision.c b/revision.c
index 9bae329..cba32e8 100644
--- a/revision.c
+++ b/revision.c
@@ -1770,8 +1770,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
*/
ALLOC_GROW(prune_data.path, prune_data.nr+1, prune_data.alloc);
prune_data.path[prune_data.nr++] = NULL;
- init_pathspec(&revs->prune_data,
- get_pathspec(revs->prefix, prune_data.path));
+ parse_pathspec(&revs->prune_data, revs->prefix, -1, prune_data.path);
}
if (revs->def == NULL)
@@ -1804,12 +1803,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
revs->limited = 1;
if (revs->prune_data.nr) {
- diff_tree_setup_paths(revs->prune_data.raw, &revs->pruning);
+ /* Careful, we share a lot of pointers here, do not free 1st arg */
+ memcpy(&revs->pruning.pathspec, &revs->prune_data, sizeof(struct pathspec));
/* Can't prune commits with rename following: the paths change.. */
if (!DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES))
revs->prune = 1;
if (!revs->full_diff)
- diff_tree_setup_paths(revs->prune_data.raw, &revs->diffopt);
+ /* Careful, we share a lot of pointers here, do not free 1st arg */
+ memcpy(&revs->diffopt.pathspec, &revs->prune_data, sizeof(struct pathspec));
}
if (revs->combine_merges)
revs->ignore_merges = 0;
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply related
* [PATCH 4/6] Implement parse_pathspec()
From: Nguyễn Thái Ngọc Duy @ 2011-10-11 22:44 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
This function is the same as get_pathspec() except that it produces
struct pathspec directly.
no_prefix code path is necessary because init_pathspec() can be called
without get_pathspec_old() in "diff --no-index" case. Without this
exception, prefix_path() will be eventually called and die because
there is not worktree.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
cache.h | 5 ++++
dir.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++----------------
setup.c | 4 +-
3 files changed, 68 insertions(+), 23 deletions(-)
diff --git a/cache.h b/cache.h
index 17df06f..719d4a3 100644
--- a/cache.h
+++ b/cache.h
@@ -443,6 +443,9 @@ extern void set_git_work_tree(const char *tree);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
+struct pathspec_item;
+extern const char *prefix_pathspec(struct pathspec_item *item, const char *prefix,
+ int prefixlen, const char *elt);
extern const char **get_pathspec(const char *prefix, const char **pathspec);
extern const char *pathspec_prefix(const char *prefix, const char **pathspec);
extern void setup_work_tree(void);
@@ -554,6 +557,8 @@ struct pathspec {
};
extern int init_pathspec(struct pathspec *, const char **);
+extern int parse_pathspec(struct pathspec *pathspec, const char *prefix,
+ int argc, const char **argv);
extern void free_pathspec(struct pathspec *);
extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
diff --git a/dir.c b/dir.c
index 6c82615..d38af0f 100644
--- a/dir.c
+++ b/dir.c
@@ -18,6 +18,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, in
int check_only, const struct path_simplify *simplify);
static int get_dtype(struct dirent *de, const char *path, int len);
+static const char *no_prefix = "We do not want outside repository check.";
+
/* helper string functions with support for the ignore_case flag */
int strcmp_icase(const char *a, const char *b)
{
@@ -1252,34 +1254,62 @@ static int pathspec_item_cmp(const void *a_, const void *b_)
return strcmp(a->match, b->match);
}
-int init_pathspec(struct pathspec *pathspec, const char **paths)
+extern const char *prefix_pathspec(struct pathspec_item *item, const char *prefix,
+ int prefixlen, const char *elt);
+int parse_pathspec(struct pathspec *pathspec, const char *prefix,
+ int argc, const char **argv)
{
- const char **p = paths;
- int i;
+ struct pathspec_item *pitem;
+ const char **dst;
+ int prefixlen;
memset(pathspec, 0, sizeof(*pathspec));
- if (!p)
- return 0;
- while (*p)
- p++;
- pathspec->raw = paths;
- pathspec->nr = p - paths;
- pathspec->magic = PATHSPEC_NOGLOB;
- if (!pathspec->nr)
+
+ if (argc == -1) {
+ argc = 0;
+ for (dst = argv; *dst; dst++)
+ argc++;
+ }
+
+ if ((!prefix || prefix == no_prefix) && !argc)
return 0;
- pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
- memset(pathspec->items, 0, sizeof(struct pathspec_item)*pathspec->nr);
- for (i = 0; i < pathspec->nr; i++) {
- struct pathspec_item *item = pathspec->items+i;
- const char *path = paths[i];
+ if (!argc) {
+ static const char *spec[2];
+ spec[0] = prefix;
+ spec[1] = NULL;
+ init_pathspec(pathspec, spec);
+ pathspec->items[0].plain_len = pathspec->items[0].len;
+ return 0;
+ }
- item->match = path;
- item->len = strlen(path);
- if (no_wildcard(path))
- item->magic |= PATHSPEC_NOGLOB;
+ prefixlen = prefix && prefix != no_prefix ? strlen(prefix) : 0;
+ pathspec->nr = argc; /* be optimistic, lower it later if necessary */
+ pathspec->items = xmalloc(sizeof(struct pathspec_item) * argc);
+ pathspec->raw = argv;
+ pathspec->magic = PATHSPEC_NOGLOB;
+ pitem = pathspec->items;
+ dst = argv;
+
+ while (*argv) {
+ if (prefix == no_prefix) {
+ memset(pitem, 0, sizeof(*pitem));
+ pitem->match = *argv;
+ pitem->len = strlen(pitem->match);
+ }
+ else
+ prefix_pathspec(pitem, prefix, prefixlen, *argv);
+ *dst = *argv++;
+ if (pitem->match && pitem->len) {
+ if (no_wildcard(pitem->match + pitem->plain_len))
+ pitem->magic |= PATHSPEC_NOGLOB;
+ else
+ pathspec->magic &= ~PATHSPEC_NOGLOB;
+ pitem++;
+ dst++;
+ }
else
- pathspec->magic &= ~PATHSPEC_NOGLOB;
+ pathspec->nr--;
}
qsort(pathspec->items, pathspec->nr,
@@ -1288,8 +1318,18 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
return 0;
}
+int init_pathspec(struct pathspec *pathspec, const char **paths)
+{
+ const char **p = paths;
+ while (p && *p)
+ p++;
+ return parse_pathspec(pathspec, no_prefix, p - paths, paths);
+}
+
void free_pathspec(struct pathspec *pathspec)
{
+ /* memory leak: pathspec_item->match likely be xstrdup'd by
+ prefix_pathspec */
free(pathspec->items);
pathspec->items = NULL;
}
diff --git a/setup.c b/setup.c
index 8f1c2c0..b074210 100644
--- a/setup.c
+++ b/setup.c
@@ -126,8 +126,8 @@ static struct pathspec_magic {
* the prefix part must always match literally, and a single stupid
* string cannot express such a case.
*/
-static const char *prefix_pathspec(struct pathspec_item *item, const char *prefix,
- int prefixlen, const char *elt)
+const char *prefix_pathspec(struct pathspec_item *item, const char *prefix,
+ int prefixlen, const char *elt)
{
unsigned magic = 0;
const char *copyfrom = elt;
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply related
* [PATCH 3/6] Convert prefix_pathspec() to produce struct pathspec_item
From: Nguyễn Thái Ngọc Duy @ 2011-10-11 22:44 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
New field plain_len is used to mark the first part of 'match' where no
magic can be applied. It's not used though. tree_entry_interesting()
should learn to utilize it.
Now we can show get_pathspec() what magic a pathspec has. Make sure
only certain magic is accepted because more will come in future and
not all of them can be converted to plain string like
PATHSPEC_FROMTOP.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
match_pathspec_depth() should also check for unsupported magic..
cache.h | 1 +
setup.c | 22 +++++++++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/cache.h b/cache.h
index fe46f1e..17df06f 100644
--- a/cache.h
+++ b/cache.h
@@ -548,6 +548,7 @@ struct pathspec {
struct pathspec_item {
const char *match;
int len;
+ int plain_len; /* match[0..plain_len-1] does not have any kind of magic*/
unsigned magic;
} *items;
};
diff --git a/setup.c b/setup.c
index 35db910..8f1c2c0 100644
--- a/setup.c
+++ b/setup.c
@@ -126,7 +126,8 @@ static struct pathspec_magic {
* the prefix part must always match literally, and a single stupid
* string cannot express such a case.
*/
-static const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
+static const char *prefix_pathspec(struct pathspec_item *item, const char *prefix,
+ int prefixlen, const char *elt)
{
unsigned magic = 0;
const char *copyfrom = elt;
@@ -181,10 +182,17 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
copyfrom++;
}
+ memset(item, 0, sizeof(*item));
+ item->magic = magic;
+
if (magic & PATHSPEC_FROMTOP)
- return xstrdup(copyfrom);
- else
- return prefix_path(prefix, prefixlen, copyfrom);
+ item->match = xstrdup(copyfrom);
+ else {
+ item->match = prefix_path(prefix, prefixlen, copyfrom);
+ item->plain_len = prefixlen;
+ }
+ item->len = strlen(item->match);
+ return 0;
}
const char **get_pathspec(const char *prefix, const char **pathspec)
@@ -208,7 +216,11 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
dst = pathspec;
prefixlen = prefix ? strlen(prefix) : 0;
while (*src) {
- *(dst++) = prefix_pathspec(prefix, prefixlen, *src);
+ struct pathspec_item item;
+ prefix_pathspec(&item, prefix, prefixlen, *src);
+ if (item.magic & ~PATHSPEC_FROMTOP)
+ die("Unsupported magic pathspec %s", *src);
+ *(dst++) = item.match;
src++;
}
*dst = NULL;
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply related
* [PATCH 2/6] Replace has_wildcard with PATHSPEC_NOGLOB
From: Nguyễn Thái Ngọc Duy @ 2011-10-11 22:44 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
Note though "noglob" magic is not implemented yet, only its definition
for internal use.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 4 ++--
cache.h | 22 ++++++++++++++++++++--
dir.c | 11 +++++++----
setup.c | 17 -----------------
tree-walk.c | 7 +++----
6 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index e8a800d..e687157 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -326,7 +326,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
matchbuf[0] = prefix;
matchbuf[1] = NULL;
init_pathspec(&pathspec, matchbuf);
- pathspec.items[0].use_wildcard = 0;
+ pathspec.items[0].magic = PATHSPEC_NOGLOB;
} else
init_pathspec(&pathspec, NULL);
if (read_tree(tree, 1, &pathspec))
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 6b666e1..f0fa7dd 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -168,8 +168,8 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
init_pathspec(&pathspec, get_pathspec(prefix, argv + 1));
for (i = 0; i < pathspec.nr; i++)
- pathspec.items[i].use_wildcard = 0;
- pathspec.has_wildcard = 0;
+ pathspec.items[i].magic = PATHSPEC_NOGLOB;
+ pathspec.magic |= PATHSPEC_NOGLOB;
tree = parse_tree_indirect(sha1);
if (!tree)
die("not a tree object");
diff --git a/cache.h b/cache.h
index 82e12c8..fe46f1e 100644
--- a/cache.h
+++ b/cache.h
@@ -521,16 +521,34 @@ extern int index_name_is_other(const struct index_state *, const char *, int);
extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
+/*
+ * Magic pathspec
+ *
+ * NEEDSWORK: These need to be moved to dir.h or even to a new
+ * pathspec.h when we restructure get_pathspec() users to use the
+ * "struct pathspec" interface.
+ *
+ * Possible future magic semantics include stuff like:
+ *
+ * { PATHSPEC_NOGLOB, '!', "noglob" },
+ * { PATHSPEC_ICASE, '\0', "icase" },
+ * { PATHSPEC_RECURSIVE, '*', "recursive" },
+ * { PATHSPEC_REGEXP, '\0', "regexp" },
+ *
+ */
+#define PATHSPEC_FROMTOP (1<<0)
+#define PATHSPEC_NOGLOB (1<<1)
+
struct pathspec {
const char **raw; /* get_pathspec() result, not freed by free_pathspec() */
int nr;
- unsigned int has_wildcard:1;
+ unsigned magic;
unsigned int recursive:1;
int max_depth;
struct pathspec_item {
const char *match;
int len;
- unsigned int use_wildcard:1;
+ unsigned magic;
} *items;
};
diff --git a/dir.c b/dir.c
index 08281d2..6c82615 100644
--- a/dir.c
+++ b/dir.c
@@ -230,7 +230,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
return MATCHED_RECURSIVELY;
}
- if (item->use_wildcard && !fnmatch(match, name, 0))
+ if (!(item->magic & PATHSPEC_NOGLOB) && !fnmatch(match, name, 0))
return MATCHED_FNMATCH;
return 0;
@@ -1264,19 +1264,22 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
p++;
pathspec->raw = paths;
pathspec->nr = p - paths;
+ pathspec->magic = PATHSPEC_NOGLOB;
if (!pathspec->nr)
return 0;
pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
+ memset(pathspec->items, 0, sizeof(struct pathspec_item)*pathspec->nr);
for (i = 0; i < pathspec->nr; i++) {
struct pathspec_item *item = pathspec->items+i;
const char *path = paths[i];
item->match = path;
item->len = strlen(path);
- item->use_wildcard = !no_wildcard(path);
- if (item->use_wildcard)
- pathspec->has_wildcard = 1;
+ if (no_wildcard(path))
+ item->magic |= PATHSPEC_NOGLOB;
+ else
+ pathspec->magic &= ~PATHSPEC_NOGLOB;
}
qsort(pathspec->items, pathspec->nr,
diff --git a/setup.c b/setup.c
index 08f605b..35db910 100644
--- a/setup.c
+++ b/setup.c
@@ -105,23 +105,6 @@ void verify_non_filename(const char *prefix, const char *arg)
"Use '--' to separate filenames from revisions", arg);
}
-/*
- * Magic pathspec
- *
- * NEEDSWORK: These need to be moved to dir.h or even to a new
- * pathspec.h when we restructure get_pathspec() users to use the
- * "struct pathspec" interface.
- *
- * Possible future magic semantics include stuff like:
- *
- * { PATHSPEC_NOGLOB, '!', "noglob" },
- * { PATHSPEC_ICASE, '\0', "icase" },
- * { PATHSPEC_RECURSIVE, '*', "recursive" },
- * { PATHSPEC_REGEXP, '\0', "regexp" },
- *
- */
-#define PATHSPEC_FROMTOP (1<<0)
-
static struct pathspec_magic {
unsigned bit;
char mnemonic; /* this cannot be ':'! */
diff --git a/tree-walk.c b/tree-walk.c
index 808bb55..db07fd6 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -586,7 +586,7 @@ int tree_entry_interesting(const struct name_entry *entry,
{
int i;
int pathlen, baselen = base->len - base_offset;
- int never_interesting = ps->has_wildcard ? 0 : -1;
+ int never_interesting = ps->magic & PATHSPEC_NOGLOB ? -1 : 0;
if (!ps->nr) {
if (!ps->recursive || ps->max_depth == -1)
@@ -625,7 +625,7 @@ int tree_entry_interesting(const struct name_entry *entry,
&never_interesting))
return 1;
- if (ps->items[i].use_wildcard) {
+ if (!(ps->items[i].magic & PATHSPEC_NOGLOB)) {
if (!fnmatch(match + baselen, entry->path, 0))
return 1;
@@ -636,12 +636,11 @@ int tree_entry_interesting(const struct name_entry *entry,
if (ps->recursive && S_ISDIR(entry->mode))
return 1;
}
-
continue;
}
match_wildcards:
- if (!ps->items[i].use_wildcard)
+ if (ps->items[i].magic & PATHSPEC_NOGLOB)
continue;
/*
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply related
* [PATCH 1/6] Recognize magic pathspec as filenames
From: Nguyễn Thái Ngọc Duy @ 2011-10-11 22:44 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
.. so that "git log :/" works, not so sure this is correct though
setup.c | 16 +++++++---------
1 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/setup.c b/setup.c
index 27c1d47..08f605b 100644
--- a/setup.c
+++ b/setup.c
@@ -58,15 +58,8 @@ static void NORETURN die_verify_filename(const char *prefix, const char *arg)
unsigned char sha1[20];
unsigned mode;
- /*
- * Saying "'(icase)foo' does not exist in the index" when the
- * user gave us ":(icase)foo" is just stupid. A magic pathspec
- * begins with a colon and is followed by a non-alnum; do not
- * let get_sha1_with_mode_1(only_to_die=1) to even trigger.
- */
- if (!(arg[0] == ':' && !isalnum(arg[1])))
- /* try a detailed diagnostic ... */
- get_sha1_with_mode_1(arg, sha1, &mode, 1, prefix);
+ /* try a detailed diagnostic ... */
+ get_sha1_with_mode_1(arg, sha1, &mode, 1, prefix);
/* ... or fall back the most general message. */
die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
@@ -85,6 +78,11 @@ void verify_filename(const char *prefix, const char *arg)
{
if (*arg == '-')
die("bad flag '%s' used after filename", arg);
+
+ /* If it's magic pathspec, just assume it's file name */
+ if (arg[0] == ':' && is_pathspec_magic(arg[1]))
+ return;
+
if (check_filename(prefix, arg))
return;
die_verify_filename(prefix, arg);
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply related
* [PATCH 0/6] Negation magic pathspec
From: Nguyễn Thái Ngọc Duy @ 2011-10-11 22:44 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
After the last round toying with .gitignore mechanism as a way to
exclude paths, I have finally got back to the negative pathspec.
I'm still struggling with read_directory() rewrite so that struct
pathspec can be used throughout git, but now realized we can at least
enable magic for certain commands and die() on those that don't.
This may help move magic pathspec patches forward.
The nice thing about this series is that negative pathspec patch is
small and simple, much less headache to review than the previous
version (and as a consequence, not as powerful).
So here it is to gather comments whether we should go this way. Very
much WIP, I have not even run "make test".
Nguyễn Thái Ngọc Duy (6):
Recognize magic pathspec as filenames
Replace has_wildcard with PATHSPEC_NOGLOB
Convert prefix_pathspec() to produce struct pathspec_item
Implement parse_pathspec()
Convert simple init_pathspec() cases to parse_pathspec()
Implement negative pathspec
Documentation/glossary-content.txt | 8 ++--
builtin/grep.c | 4 +-
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 6 +-
builtin/reset.c | 2 +-
cache.h | 29 +++++++++++-
dir.c | 85 +++++++++++++++++++++++++++--------
revision.c | 9 ++--
setup.c | 56 +++++++++++-------------
tree-walk.c | 44 ++++++++++++++++---
10 files changed, 169 insertions(+), 76 deletions(-)
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply
* Re: [RFC] teach --edit to git rebase
From: Jean Privat @ 2011-10-11 22:36 UTC (permalink / raw)
To: git
In-Reply-To: <CAMQw0oOBEjW3yS2+wcktXDuEuUiHKjfbK2qDzKvBOiwxo7Zkow@mail.gmail.com>
> An other alternative is to use a simple git alias for myself (and do
> not bother the git community) but I do not know how to automatize the
> command 'git rebase --interactive' I suppose I need more complex
> infrastructure in the existing 'git rebase' (Maybe I did not look
> enough and there is a way to do it with a git alias).
Hum. I just found that I can do something like :
[alias]
edit=!GIT_EDITOR='sed -i -e 1s/pick/edit/ --' git rebase -i
-no-autosquash $1^
The main thing that bothers me is that after the rebase, the head is
detached (why?)
The other thing is that the error messages for invalid usages are far
for perfect
$ git edit toto
fatal: Needed a single revision
invalid upstream toto^
$ git edit --root toto
error: unknown option `root^'
usage: git rebase [-i] [options] [--onto <newbase>] [<upstream>] [<branch>]
[...]
-Jean
^ permalink raw reply
* Re: Symmetric of rebase / more intelligent cherry-pick
From: Jonathan Nieder @ 2011-10-11 22:23 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Lionel Elie Mamane, Christian Couder, Michael J Gruber
In-Reply-To: <7vty7fdxql.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
> We actually have half of that filtering in "--cherry-pick" that was
> introduced in d7a17ca (git-log --cherry-pick A...B, 2007-04-09).
>
> Perhaps the recent cherry-pick that allows multiple commits to be picked
> should use that option (i.e. a "log --cherry-pick --right-only ..@{u}"
> equivalent) when coming up with which commits to apply?
No UI ideas from me, but I have a script like this sitting in $HOME/bin:
base=$1 topic=$2
git rev-list $base..HEAD |
git diff-tree -s --pretty=raw --stdin |
sed -ne 's/(cherry picked from commit \([0-9a-f]*\))/\1/p' |
xargs git cherry-pick -x -s \
--cherry-pick --right-only --no-merges HEAD...$topic \
--not $base
^ permalink raw reply
* Re: [RESEND PATCH v3] Configurable hyperlinking in gitk
From: Junio C Hamano @ 2011-10-11 22:13 UTC (permalink / raw)
To: Jeff Epler, Paul Mackerras, Jakub Narebski
Cc: git, Marc Branchaud, Chris Packham
In-Reply-To: <20111011183722.GA26646@unpythonic.net>
Jeff Epler <jepler@unpythonic.net> writes:
> I'm aware of no problems with this patch, and a number of people have
> commented that it is useful to them.
Hmmm, "didn't generate any discussion" does not mesh very well with "a
number of people are happy". Which one should I trust?
> * Documented that these are POSIX EREs; hopefully that's OK. I see
> in CodingGuidelines that in git itself "a subset of BREs" are used,
> so maybe even this is too much power. And hopefully tcl's
> re_syntax really is close enough to an ERE superset that this isn't
> a terrible lie about the initial implementation either.
I think it is better to be honest and say these are fed to the native
regexp engine of Tcl somewhere in the documentation.
Declaring "these are POSIX EREs" invites a user to expect they truly
are. When the pattern the user wrote triggers a strange Tcl extension to
cause unexpected things to match, the documentation needs to help the user
to understand why. I understand the longer-term wish to reuse these in
gitweb and elsewhere, but it becomes even more important that it is
clearly documented that these "regexp" are fed to native regexp engines of
Tcl and Perl depending on the program that they are used in. Unless the
documentation spells it out, the user will not be able to decide how to
work the implementation around, avoiding constructs that would behave
differently between Tcl and Perl.
Doesn't tcl have/use pcre these days, by the way? If we envision that this
will be shared with gitweb, perhaps using that might be a better option to
reduce potential confusion.
> * Added a Signed-Off-By, since I've had a number of positive feedbacks
> and the only problems I've heard of (since patch v2) are the ones
> related to 'eval' in git-web--browse.
By the way, "This patch is good" does not have anything to do with signing
off a patch.
Paul wanted to keep gitk sources separately available from the rest of the
git. After all, that is how gitk project started. Even after 5569bf9 (Do a
cross-project merge of Paul Mackerras' gitk visualizer, 2005-06-22), we
kept it so that git://git.kernel.org/pub/scm/gitk/gitk was the primary
project to make changes to gitk, and git.git pulled from it (it is an
assymmetric pull, as gitk cannot pull from git without contaminating its
history with the changes to the rest of git).
I do not know how motivated Paul is to keep gitk part separated in its own
project these days. I do not think the /pub/scm/gitk/gitk repository has
been re-populated yet. Assuming that it will eventually come back on-line,
could you send the gitk part of this change to Paul (i.e. the diff header
of your patch should read "diff --git a/gitk b/gitk") and another separate
patch to Documentation/ part?
Paul, if you are orphaning gitk, I do _not_ mind start taking patches that
touch gitk myself directly into git tree.
But I would still need reviewers who are motivated and interested in
enhancing and maintaining gitk.
> +linkify.<name>.regexp::
> + Specify a regular expression in the POSIX Extended Regular Expression
> + syntax defining a class of strings to automatically convert to
> + hyperlinks. This regular expression many not span multiple lines.
> + You must also specify 'linkify.<name>.subst'.
Saying "You must ..." without explicitly saying "why" is a bad style. If
the reader already _knows_ the .regexp is used to supply captured
substring to the corresponding .subst, then it is obvious that whenever
you have .regexp you need a matching .subst, but that is not even
explained here.
How about this?
A string that matches this regexp is converted to a hyperlink
using the value of corresponding `linkify.<name>.subst` variable.
The regular expression is passed to the regexp engine of Tcl (in
gitk) or Perl (in gitweb).
> +linkify.<name>.subst::
> + Specify a substitution that results in the target URL for the
> + related regular expression. Back-references like '\1' refer
> + to capturing groups in the associated regular expression.
> + You must also specify 'linkify.<name>.regexp'.
Likewise.
A string matched the value of the corresponding
`linkify.<name>.regexp` variable is rewritten to this URL. The
value of this variable can contain back-references like `\1` to
refer to capturing groups in the associated regular expression.
^ permalink raw reply
* Re: [PATCH] Fix is_gitfile() for files larger than PATH_MAX
From: Phil Hord @ 2011-10-11 22:10 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
In-Reply-To: <CABURp0ru7aCW_oUZO8eaFpau5DAHDgwWLqHSL1QMjbUDkqrANg@mail.gmail.com>
On Tue, Oct 11, 2011 at 4:58 PM, Phil Hord <phil.hord@gmail.com> wrote:
> I've caught this and have it in
> a re-roll, but I got mired up and haven't submitted it again. I'll
> try to do so today.
On 2nd thought, my other changes are cleanup and not so much a re-roll
of this (except for a couple of code style edits pointed out by Junio,
but I guess those can slide).
I'll send the cleanups and generalities in another patch.
Thanks for the catch, Johannes.
Phil
^ permalink raw reply
* Re: Re* [PATCH v3 19/22] resolve_ref(): emit warnings for improperly-formatted references
From: Junio C Hamano @ 2011-10-11 21:31 UTC (permalink / raw)
To: Jeff King
Cc: Junio C Hamano, Michael Haggerty, git, cmn, A Large Angry SCM,
Daniel Barkalow, Sverre Rabbelier
In-Reply-To: <20111011203903.GA23069@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> But in the code, it is spelled RENAMED-REF (with a dash). And as far as
> I can tell, does not actually create a reflog. And it's not documented
> anywhere, so I suspect nobody is using it. Maybe it is worth switching
> that name.
Or even better get rid of it?
>> - dwim_ref() can be fed "refs/heads/master" and is expected to dwim it to
>> the master branch.
>
> It looks like your code will allow any subdirectory. I had thought to
> limit it to "refs/". Otherwise, my "config" example could be
> "objects/pack", or "lost-found/commits", "remotes/foo", or something.
> Obviously the longer the name, the smaller the possibility of an
> accidental collision. But I couldn't think of any other subdirectory
> into which refs should go.
I wanted to start as loose as possible to avoid negatively impacting
existing users, later to tighten. As fsck and friends never look outside
of refs/, I think the prefix refs/ is a reasonable restriction that is
safe.
^ permalink raw reply
* Re: Symmetric of rebase / more intelligent cherry-pick
From: Junio C Hamano @ 2011-10-11 21:28 UTC (permalink / raw)
To: git; +Cc: Lionel Elie Mamane
In-Reply-To: <7v8vorfhhu.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> Lionel Elie Mamane <lionel@mamane.lu> writes:
>
>> git cherry-pick ..UPSTREAM
>> *nearly* does what I want, except that it lacks rebase's intelligence
>> of skipping commits that do the same textual changes as a commit
>> already in the current branch.
>
> I think in the longer term "--ignore-if-in-upstream" that is known only to
> format-patch, which is the true source the intelligence of rebase you
> observed comes from, should be factored out into a helper function that
> can be used to filter output from get_revision() in other commands, or
> perhaps get_revision() itself might want to learn it.
We actually have half of that filtering in "--cherry-pick" that was
introduced in d7a17ca (git-log --cherry-pick A...B, 2007-04-09).
Perhaps the recent cherry-pick that allows multiple commits to be picked
should use that option (i.e. a "log --cherry-pick --right-only ..@{u}"
equivalent) when coming up with which commits to apply?
^ permalink raw reply
* [RFC] teach --edit to git rebase
From: Jean Privat @ 2011-10-11 21:21 UTC (permalink / raw)
To: git
The idea of this patch is to allow a simple edition of a buggy commit
in the history.
## Motivation
The motivation behind the option is that sometime I have to do a
simple fixup of a previous commit.
Usually the way to do it is just to commit the fix on the top of the
branch (git commit --fixup) then doing a 'git rebase --autosquash'.
However, the way is often not optimal if the context of commit on the
top of the branch is different from the context of the buggy commit,
thus the rebase with a fixup will lead to a conflict when git will
apply the fixup patch to the buggy commit (and a second conflict
later).
An other way is to do a 'git rebase --interactive' with an edit in the
todo list (instead of a pick). This is what I propose to simplify.
## Proposal
My idea is to add a --edit option to 'git rebase' in order to
automatize the 'git rebase --interactive' workflow.
Currently:
$ git rebase -i commit-to-fix^
# replace the first 'pick' with 'edit' then save and quit
$ hack hack hack...
$ git commit --amend # or whatever you want to do like split commit
$ git rebase --continue # and resolve possible conflicts
With the --edit option:
$ git rebase --edit commit_to_fix # note: no caret, no editor ! yeah !
$ hack hack hack...
$ git commit --amend # or what ever like split commit
$ git rebase --continue # and resolve possible conflicts
Note that for a more complex history modification, a standard git
rebase with reordering, squashing and stuff the way to go is a good
old git rebase --interactive.
## Implementation proposal
Yes I know "show me the code" but because I am lazy I prefer ask 1-if
the proposal makes sense, and 2-if the following way of doing it makes
sense.
The idea is to extend git-rebase and git-rebase-interactive.
* detect and check the option --edit in git-rebase
* automatically prepare the todolist in git-rebase-interactive without
launching the editor.
## Alternative proposals
A weak point of the proposal it that it is a new option to a
overloaded git command (git rebase). In fact is is even a new synopsis
to git rebase since the --edit option will be incompatible with
--interactive (it is an automatic interactive) and with --onto (since
there is no real point to ``move'' the base if you want to fixup a
single commit).
A counter proposal could be to not extend the command 'git rebase' but
add a new git command (for instance 'git edit buggy_commit') but since
the edit may[1] lead to conflicts the user has to do some 'git edit
--continue' to finish the editing (or 'git edit --abort' if bored). It
will also require to adapt a lot of tinny things because hint
messages, error messages, and prompts will talk about 'rebase' and not
'edit'.
[1] In fact, it is probable that the *may* is in fact a *will* since
if no conflict arise, it is likable that a simple 'commit --fixup'
(followed by a later 'git rebase --autosquash') will just work and be
simpler.
An other alternative is to use a simple git alias for myself (and do
not bother the git community) but I do not know how to automatize the
command 'git rebase --interactive' I suppose I need more complex
infrastructure in the existing 'git rebase' (Maybe I did not look
enough and there is a way to do it with a git alias).
A last alternative is do do nothing. What I propose is just a way to
1-do not need a caret ('git rebase --edit commit' instead of 'git
rebase --interactive commit^') and 2-avoid launching the editor.
Therefore, maybe the itch do not really need a patch.
-- Jean Privat
^ permalink raw reply
* Re: [RFC/WIP PATCH] Use config value rebase.editor as editor when starting git rebase -i
From: Peter Oberndorfer @ 2011-10-11 21:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <7vipnvfk70.fsf@alter.siamese.dyndns.org>
On Dienstag, 11. Oktober 2011, Junio C Hamano wrote:
> Peter Oberndorfer <kumbayo84@arcor.de> writes:
>
> > Using $GIT_EDITOR or core.editor config var for this is not possible
> > since it is also used to start the commit message editor for reword action.
>
> Your tool _could_ be smart about this issue and inspect the contents to
> launch a real editor when it is fed a material not for sequencing, but
> that feels hacky.
I already tried this, but my first version did not redirect stdin/stdout
so vi stayed in background and the whole thing just hung.
I did not try further because i assumed more problems would appear
when redirecting stdin/stdout...
> > * GIT_EDITOR env var is not honored anymore after this change.
>
> Care to explain? "git var" knows magic about a few variables like
> GIT_EDITOR and GIT_PAGER.
>
> $ git config core.editor vim
> $ GIT_EDITOR=vi EDITOR=emacs git var GIT_EDITOR
> vi
> $ unset GIT_EDITOR; EDITOR=emacs git var GIT_EDITOR
> emacs
Sorry i was wrong, i missed that git var looks at $GIT_EDITOR.
So the sequence for choosing the sequencer editor is:
$GIT_SEQUENCE_EDITOR
config sequence.editor
var GIT_EDITOR
Which looks OK to me.
> > * Should git_rebase_editor be in git-rebase--interactive.sh instead
>
> Probably yes.
OK, will do.
>
> > * How should the config be called?
>
> Given that in the longer term we would be using a unified sequencer
> machinery for not just rebase-i but for am and cherry-pick, I would advise
> against calling this anything "rebase". How does "sequence.edit" sound?
>
I do not really care very much, but how about sequence.editor?
Sounds more similar to core.editor
> You need to be prepared to adjust your code to deal with new kinds of
> sequencing insns in the insn sheet and possibly a format change of the
> insn sheet itself.
I assume instruction sheet is the commented out part that looks like:
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
Currently all lines starting with # are ignored.
(They are also not written to the output when finished
which is a point I might have to change...)
Also the instructions are currently not taken from this instruction sheet.
They are all hardcoded.
Thanks for the feedback
Greetings Peter
^ 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