* Re: [PATCH] Add some fancy colors in the test library when terminal supports it.
From: Christian Couder @ 2007-10-23 4:08 UTC (permalink / raw)
To: Pierre Habouzit; +Cc: Shawn O. Pearce, git
In-Reply-To: <20071022081341.GC32763@artemis.corp>
Hi Pierre,
Le lundi 22 octobre 2007, Pierre Habouzit a écrit :
> +
> +say_color () {
> + [ "$nocolor" = 0 ] && [ "$1" != '-1' ] && tput setaf "$1"
> + shift
> + echo "* $*"
> + tput op
> +}
> +
> error () {
> - echo "* error: $*"
> + say_color 9 "* error: $*"
This will print something like "* * error: ..." instead of "* error: ..."
The following should work:
> + say_color 9 "error: $*"
By the way, where do the 9 here and the 10 and the -1 below come from ?
"man 5 terminfo" says that only values form 0 to 7 are portably defined.
Maybe 9 is a bold red and 10 a bold green, or something like that, but it
doesn't seem to work on my konsole.
Anyway, perhaps having:
_red=1
_green=2
and then using "say_color $_red stuff" might be easier to understand and
change if needed.
Thanks for this good idea,
Christian.
^ permalink raw reply
* Re: [PATCH 1/2] Added basic color support to git add --interactive
From: Jeff King @ 2007-10-23 4:03 UTC (permalink / raw)
To: Dan Zwell
Cc: Shawn O. Pearce, Wincent Colaiuta, Git Mailing List,
Jonathan del Strother, Johannes Schindelin, Frank Lichtenheld
In-Reply-To: <20071022163244.4af72973@danzwell.com>
On Mon, Oct 22, 2007 at 04:32:44PM -0500, Dan Zwell wrote:
> +my ($use_color, $prompt_color, $header_color, $help_color);
> +my $color_config = qx(git config --get color.interactive);
> +if ($color_config=~/true|always/ || -t STDOUT && $color_config=~/auto/) {
> + $use_color = "true";
> + # Sane (visible) defaults:
> + $prompt_color = "blue bold";
> + $header_color = "bold";
> + $help_color = "red bold";
Bad indentation?
> +sub print_colored {
> + my $color = shift;
> + my @strings = @_;
> +
> + if ($use_color) {
> + print Term::ANSIColor::color($color);
> + print(@strings);
> + print Term::ANSIColor::color("reset");
> + } else {
> + print @strings;
> + }
> +}
This does nothing for embedded newlines in the strings, which means that
you can end up with ${COLOR}text\n${RESET}, which fouls up changed
backgrounds. See commit 50f575fc. Since the strings you are printing are
small, I don't see any problem with making a copy, using a regex to
insert the color coding, and printing that (I think I even posted
example code in a previous thread on this subject).
-Peff
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Shawn O. Pearce @ 2007-10-23 4:05 UTC (permalink / raw)
To: Theodore Tso; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023020044.GA27132@thunk.org>
Theodore Tso <tytso@mit.edu> wrote:
> On Mon, Oct 22, 2007 at 06:29:59PM -0700, Junio C Hamano wrote:
> > Well, the policy is never to commit directly on top of next
> > (iow, only merge other topics and nothing else). Otherwise it
> > becomes hard to allow individual topics graduate to 'master'
> > independently.
>
> I see. So if it's non-trivial enough that you want it to "cook" in
> next for a cycle, you'll create a topic branch for it (based off of
> 'master'), and then force a merge into 'next'?
Yes. Because 'next' always has commits in it that never appear in
'master'. So any topic forked from master must merge into next.
It can't be a fast-forward. No forced merging required.
Of course this isn't true for a new project. That first topic
that forked from master to *create* next will be a fast-forward
as it creates next. But that's no big deal. The second topic will
merge into next, and that first topic can still be merged back into
master without merging next (or the second topic).
I was also doing the same thing Junio already explained to manage
next and pu while he was away. Except I shortcut his:
git checkout pu
git reset --hard next
as:
git branch -f pu next
git checkout pu
as I'm was usually already sitting on next. This saved my poor
little laptop from a second of IO chugging as it slewed around
between the two versions. There were no files to update as it
switched from next to pu, and pu was already setup for merging
the proposed topics. :-)
--
Shawn.
^ permalink raw reply
* [PATCH trailing ws fixed] use only the PATH for exec'ing git commands
From: Scott Parish @ 2007-10-23 4:08 UTC (permalink / raw)
Cc: git
In-Reply-To: <20071022190102.GA23714@steel.home>
We need to correctly set up PATH for non-c based git commands. Since we
already do this, we can just use that PATH and execvp, instead of looping
over the paths with execve.
This patch adds a setup_path() function to exec_cmd.c, which sets
the PATH order correctly for our search order. execv_git_cmd() is
stripped down to setting up argv and calling execvp(). git.c's main()
only only needs to call setup_path().
Signed-off-by: Scott R Parish <srp@srparish.net>
---
exec_cmd.c | 121 ++++++++++++++++++++++++++----------------------------------
exec_cmd.h | 1 +
git.c | 43 +++------------------
3 files changed, 60 insertions(+), 105 deletions(-)
diff --git a/exec_cmd.c b/exec_cmd.c
index 8b681d0..c228dbf 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -29,85 +29,68 @@ const char *git_exec_path(void)
return builtin_exec_path;
}
+static void add_path(struct strbuf *out, const char *path)
+{
+ if (path && strlen(path)) {
+ if (is_absolute_path(path))
+ strbuf_addstr(out, path);
+ else
+ strbuf_addstr(out, make_absolute_path(path));
+
+ strbuf_addch(out, ':');
+ }
+}
+
+void setup_path(const char *cmd_path)
+{
+ const char *old_path = getenv("PATH");
+ struct strbuf new_path;
+
+ strbuf_init(&new_path, 0);
+
+ add_path(&new_path, argv_exec_path);
+ add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
+ add_path(&new_path, builtin_exec_path);
+ add_path(&new_path, cmd_path);
+
+ if (old_path)
+ strbuf_addstr(&new_path, old_path);
+ else
+ strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
+
+ setenv("PATH", new_path.buf, 1);
+
+ strbuf_release(&new_path);
+}
int execv_git_cmd(const char **argv)
{
- char git_command[PATH_MAX + 1];
- int i;
- const char *paths[] = { argv_exec_path,
- getenv(EXEC_PATH_ENVIRONMENT),
- builtin_exec_path };
-
- for (i = 0; i < ARRAY_SIZE(paths); ++i) {
- size_t len;
- int rc;
- const char *exec_dir = paths[i];
- const char *tmp;
-
- if (!exec_dir || !*exec_dir) continue;
-
- if (*exec_dir != '/') {
- if (!getcwd(git_command, sizeof(git_command))) {
- fprintf(stderr, "git: cannot determine "
- "current directory: %s\n",
- strerror(errno));
- break;
- }
- len = strlen(git_command);
-
- /* Trivial cleanup */
- while (!prefixcmp(exec_dir, "./")) {
- exec_dir += 2;
- while (*exec_dir == '/')
- exec_dir++;
- }
-
- rc = snprintf(git_command + len,
- sizeof(git_command) - len, "/%s",
- exec_dir);
- if (rc < 0 || rc >= sizeof(git_command) - len) {
- fprintf(stderr, "git: command name given "
- "is too long.\n");
- break;
- }
- } else {
- if (strlen(exec_dir) + 1 > sizeof(git_command)) {
- fprintf(stderr, "git: command name given "
- "is too long.\n");
- break;
- }
- strcpy(git_command, exec_dir);
- }
-
- len = strlen(git_command);
- rc = snprintf(git_command + len, sizeof(git_command) - len,
- "/git-%s", argv[0]);
- if (rc < 0 || rc >= sizeof(git_command) - len) {
- fprintf(stderr,
- "git: command name given is too long.\n");
- break;
- }
+ struct strbuf cmd;
+ const char *tmp;
- /* argv[0] must be the git command, but the argv array
- * belongs to the caller, and my be reused in
- * subsequent loop iterations. Save argv[0] and
- * restore it on error.
- */
+ strbuf_init(&cmd, 0);
+ strbuf_addf(&cmd, "git-%s", argv[0]);
- tmp = argv[0];
- argv[0] = git_command;
+ /* argv[0] must be the git command, but the argv array
+ * belongs to the caller, and my be reused in
+ * subsequent loop iterations. Save argv[0] and
+ * restore it on error.
+ */
+ tmp = argv[0];
+ argv[0] = cmd.buf;
- trace_argv_printf(argv, -1, "trace: exec:");
+ trace_argv_printf(argv, -1, "trace: exec:");
- /* execve() can only ever return if it fails */
- execve(git_command, (char **)argv, environ);
+ /* execvp() can only ever return if it fails */
+ execvp(cmd.buf, (char **)argv);
- trace_printf("trace: exec failed: %s\n", strerror(errno));
+ trace_printf("trace: exec failed: %s\n", strerror(errno));
- argv[0] = tmp;
- }
- return -1;
+ argv[0] = tmp;
+ strbuf_release(&cmd);
+
+ return -1;
}
diff --git a/exec_cmd.h b/exec_cmd.h
index da99287..a892355 100644
--- a/exec_cmd.h
+++ b/exec_cmd.h
@@ -3,6 +3,7 @@
extern void git_set_argv_exec_path(const char *exec_path);
extern const char* git_exec_path(void);
+extern void setup_path(const char *);
extern int execv_git_cmd(const char **argv); /* NULL terminated */
extern int execl_git_cmd(const char *cmd, ...);
diff --git a/git.c b/git.c
index f659338..a639e42 100644
--- a/git.c
+++ b/git.c
@@ -6,28 +6,6 @@
const char git_usage_string[] =
"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
-static void prepend_to_path(const char *dir, int len)
-{
- const char *old_path = getenv("PATH");
- char *path;
- int path_len = len;
-
- if (!old_path)
- old_path = "/usr/local/bin:/usr/bin:/bin";
-
- path_len = len + strlen(old_path) + 1;
-
- path = xmalloc(path_len + 1);
-
- memcpy(path, dir, len);
- path[len] = ':';
- memcpy(path + len + 1, old_path, path_len - len);
-
- setenv("PATH", path, 1);
-
- free(path);
-}
-
static int handle_options(const char*** argv, int* argc, int* envchanged)
{
int handled = 0;
@@ -403,7 +381,7 @@ int main(int argc, const char **argv)
{
const char *cmd = argv[0] ? argv[0] : "git-help";
char *slash = strrchr(cmd, '/');
- const char *exec_path = NULL;
+ const char *cmd_path = NULL;
int done_alias = 0;
/*
@@ -413,10 +391,7 @@ int main(int argc, const char **argv)
*/
if (slash) {
*slash++ = 0;
- if (*cmd == '/')
- exec_path = cmd;
- else
- exec_path = xstrdup(make_absolute_path(cmd));
+ cmd_path = cmd;
cmd = slash;
}
@@ -451,16 +426,12 @@ int main(int argc, const char **argv)
cmd = argv[0];
/*
- * We execute external git command via execv_git_cmd(),
- * which looks at "--exec-path" option, GIT_EXEC_PATH
- * environment, and $(gitexecdir) in Makefile while built,
- * in this order. For scripted commands, we prepend
- * the value of the exec_path variable to the PATH.
+ * We use PATH to find git commands, but we prepend some higher
+ * precidence paths: the "--exec-path" option, the GIT_EXEC_PATH
+ * environment, and the $(gitexecdir) from the Makefile at build
+ * time.
*/
- if (exec_path)
- prepend_to_path(exec_path, strlen(exec_path));
- exec_path = git_exec_path();
- prepend_to_path(exec_path, strlen(exec_path));
+ setup_path(cmd_path);
while (1) {
/* See if it's an internal command */
--
gitgui.0.8.4.11176.gd9205-dirty
^ permalink raw reply related
* Re: [PATCH 2/2] Let git-add--interactive read colors from git-config
From: Jeff King @ 2007-10-23 4:27 UTC (permalink / raw)
To: Dan Zwell
Cc: Shawn O. Pearce, Wincent Colaiuta, Git Mailing List,
Jonathan del Strother, Johannes Schindelin, Frank Lichtenheld
In-Reply-To: <20071022164048.71a3dceb@danzwell.com>
On Mon, Oct 22, 2007 at 04:40:48PM -0500, Dan Zwell wrote:
> Note: the code to parse git-style color strings to perl-style color
> strings should eventually be added to Git.pm so that other (perl)
> parts of git can be configured to read colors from .gitconfig in
> a nicer way. A git-style string is "ul red black", while perl
> likes strings like "underline red on_black".
Why not do it as part of this patch, then?
> + # Sane (visible) defaults:
> + if (! @git_prompt_color) {
> + @git_prompt_color = ("blue", "bold");
> + }
I think it might be a bit more readable to keep the assignment and
defaults together:
my @git_prompt_color = split /\s+/,
qx(git config --get color.interactive.prompt) || 'blue bold';
Though I wonder why we are splitting here at all, since we just end up
converting the list into a scalar below. And if we just turned that into
a function, we could get a nice:
my $prompt_color = git_color_to_ansicolor(
qx(git config --get color.interactive.prompt) || 'blue bold');
-Peff
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Shawn O. Pearce @ 2007-10-23 4:27 UTC (permalink / raw)
To: Theodore Tso; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023012140.GC22997@thunk.org>
Theodore Tso <tytso@mit.edu> wrote:
> On Mon, Oct 22, 2007 at 06:15:09PM -0700, Junio C Hamano wrote:
> >
> > Sorry, WI is for "what's in", WC is for "what's cooking". I
> > should remove PU and RB from there.
>
> I assume PU is what you used to build your proposed-update branch?
Actually I found PU of some use:
git branch -f pu next
git checkout pu
./Meta/PU --continue
its a little sluggish to list, but made it pretty easy to pick
topics for merging into pu. git-rerere really makes it easy to
recover conflicts in pu during future rebuilds of pu.
> based off of master, and then merged into next. Or maybe I'm not
> understanding how to make the WC and git-topic.perl script work and
> sing for me perfectly?
The other tidbits I managed to learn by trial and error here was
to make sure I did the following:
- make sure master is fully merged into next
- make sure next is fully merged into pu
- Run "Meta/git-topic.perl --base=master | less"
It wasn't uncommon for me to merge master->next, next->pu, run
git-topic, then reset both next and pu *back* to what I had last
published (remote tracking branches updated during push make this
easy) before moving on with my next and pu updating activities.
Of course take my notes above with a grain of salt; I only worked
this way for a week and it took me a couple of days to come up with
the above. Junio may very well have it streamlined even more.
--
Shawn.
^ permalink raw reply
* Re: [PATCH] Let git-add--interactive read "git colors" from git-config
From: Jeff King @ 2007-10-23 4:29 UTC (permalink / raw)
To: Dan Zwell
Cc: Shawn O. Pearce, Wincent Colaiuta, Git Mailing List,
Jonathan del Strother, Johannes Schindelin, Frank Lichtenheld
In-Reply-To: <20071022211958.045895ac@danzwell.com>
On Mon, Oct 22, 2007 at 09:19:58PM -0500, Dan Zwell wrote:
> This patch is againts Shawn Pearce's "pu" branch.
Don't do that. The code in 'pu' is a mess of half-working features. If
your patch is accepted, then it has to be picked apart from those
half-working features that aren't being accepted (which hopefully isn't
hard if nobody has been working in the same area, but can be quite
ugly). Base your work on 'master' if possible, or 'next' if it relies
on features only in next. If it relies on some topic branch that is
_only_ in pu, then mention explicitly which topic.
-Peff
^ permalink raw reply
* Re: [PATCH] don't set-group-id on directories on apple
From: Scott Parish @ 2007-10-23 4:30 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
In-Reply-To: <20071022142945.GO16291@srparish.net>
On Mon, Oct 22, 2007 at 07:29:45AM -0700, Scott Parish wrote:
> On Mon, Oct 22, 2007 at 03:16:01PM +0100, Johannes Schindelin wrote:
>
> > On Mon, 22 Oct 2007, Scott R Parish wrote:
> >
> > > "git init --shared=all" was failing because chmod was returning EPERM.
> >
> > Not here.
> >
> > Is it possible that you have stricter permission settings?
I finally figured it out. I keep my home directory encrypted, but
its pretty slow (especially compiles) and i don't care who steals
open source code i'm playing with, so i keep that in /Users/Shared.
Since mkdir() on darwin keeps the parents group by default, the
group on my git clone was wheel, which i'm not a member of.
sRp
--
Scott Parish
http://srparish.net/
^ permalink raw reply
* Re: git.el fails on non-git managed files
From: Shawn O. Pearce @ 2007-10-23 4:31 UTC (permalink / raw)
To: racin; +Cc: git
In-Reply-To: <1193077008.471ce910f15c5@imp.free.fr>
racin@free.fr wrote:
> I found the following on the development version of git.el: saving
> non-git-managed files in Emacs threw an error.
>
> It is due to a simple error in the call to condition-case in a
> recently added function, git-update-save-file.
>
> I attached the patch for your convenience.
I'm not sure what happened, but I didn't receive a patch with
your email. Would you mind resending it to the list? You may
also want to file a bug with your distribution to get the Emacs
bindings included.
--
Shawn.
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Theodore Tso @ 2007-10-23 4:33 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023040522.GX14735@spearce.org>
On Tue, Oct 23, 2007 at 12:05:22AM -0400, Shawn O. Pearce wrote:
>
> Yes. Because 'next' always has commits in it that never appear in
> 'master'. So any topic forked from master must merge into next.
> It can't be a fast-forward. No forced merging required.
Why is it the case that 'next' always commits that never appear in
'master'. So far in how I've been doing things that hasn't been the
case. When I do a "git checkout master; git merge next", it's always
been a fast-forward merge.
Oh, I see. That's because if you put some trivial changes in
'master', and then pull those changes into next, there will be merge
commits in 'next' that will never be in 'master. Is that it?
I had been trying to avoid that case by always putting new commits,
even trivial ones, into 'next', and then having them drop into
'master' at the next cycle; so 'master' was always trailing 'next',
but they were always the same commit string (i.e., 'master' was always
a subset of 'next').
Aside from the WC script not working right, are there other
disadvantages to my doing things that way as opposed to the way the
Junio has been running the git repository?
- Ted
^ permalink raw reply
* Re: [PATCH] execv_git_cmd(): also try PATH if everything else fails.
From: Shawn O. Pearce @ 2007-10-23 4:34 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Scott Parish, git
In-Reply-To: <Pine.LNX.4.64.0710221135100.25221@racer.site>
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> On Mon, 22 Oct 2007, Shawn O. Pearce wrote:
> > Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > > Earlier, we tried to find the git commands in several possible exec
> > > dirs. Now, if all of these failed, try to find the git command in
> > > PATH.
> > ...
> > > diff --git a/exec_cmd.c b/exec_cmd.c
> > > index 9b74ed2..70b84b0 100644
> > > --- a/exec_cmd.c
> > > +++ b/exec_cmd.c
> > > @@ -36,7 +36,8 @@ int execv_git_cmd(const char **argv)
> > > int i;
> > > const char *paths[] = { current_exec_path,
> > > getenv(EXEC_PATH_ENVIRONMENT),
> > > - builtin_exec_path };
> > > + builtin_exec_path,
> > > + "" };
> >
> > So if the user sets GIT_EXEC_PATH="" and exports it we'll search $PATH
> > before the builtin exec path that Git was compiled with? Are we sure we
> > want to do that?
>
> I thought the proper way to unset EXEC_PATH was to "unset GIT_EXEC_PATH".
> In that case, getenv(EXEC_PATH_ENVIRONMENT) returns NULL and we're fine,
> no?
Sure. But can't you also export an environment variable that is
set to the empty string? At least on UNIX. Windows thinks unset
and empty string are the same thing.
--
Shawn.
^ permalink raw reply
* Re: [PATCH] Let git-add--interactive read "git colors" from git-config
From: Shawn O. Pearce @ 2007-10-23 4:40 UTC (permalink / raw)
To: Jeff King
Cc: Dan Zwell, Wincent Colaiuta, Git Mailing List,
Jonathan del Strother, Johannes Schindelin, Frank Lichtenheld
In-Reply-To: <20071023042956.GC28312@coredump.intra.peff.net>
Jeff King <peff@peff.net> wrote:
> On Mon, Oct 22, 2007 at 09:19:58PM -0500, Dan Zwell wrote:
>
> > This patch is againts Shawn Pearce's "pu" branch.
>
> Don't do that. The code in 'pu' is a mess of half-working features. If
> your patch is accepted, then it has to be picked apart from those
> half-working features that aren't being accepted (which hopefully isn't
> hard if nobody has been working in the same area, but can be quite
> ugly). Base your work on 'master' if possible, or 'next' if it relies
> on features only in next. If it relies on some topic branch that is
> _only_ in pu, then mention explicitly which topic.
And even when you base work on things in next, don't base it on the
tip of next. Base it on a specific topic that is merged into next.
Next is also a mess of features, but they are more likely to be in
a working state than the features in pu.
Topics in next will merge to master at different times. If your
changes depend on more than one topic that may make it more difficult
for the maintainer to merge your topic to master.
Fortunately In Dan's case the only topic in pu that impacted
git-add--interactive was his dz/color-addi topic, so this probably
applies to the tip of it just as well as it does to the tip of pu.
--
Shawn.
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Shawn O. Pearce @ 2007-10-23 4:46 UTC (permalink / raw)
To: Theodore Tso; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023043321.GC27132@thunk.org>
Theodore Tso <tytso@mit.edu> wrote:
> On Tue, Oct 23, 2007 at 12:05:22AM -0400, Shawn O. Pearce wrote:
> >
> > Yes. Because 'next' always has commits in it that never appear in
> > 'master'. So any topic forked from master must merge into next.
> > It can't be a fast-forward. No forced merging required.
>
> Why is it the case that 'next' always commits that never appear in
> 'master'. So far in how I've been doing things that hasn't been the
> case. When I do a "git checkout master; git merge next", it's always
> been a fast-forward merge.
>
> Oh, I see. That's because if you put some trivial changes in
> 'master', and then pull those changes into next, there will be merge
> commits in 'next' that will never be in 'master. Is that it?
Exactly. This of course means that next has been growing in distance
from master for quite some time. It has well over 1000 commits now
in git.git that aren't in master. Most of those will never merge
there either.
> I had been trying to avoid that case by always putting new commits,
> even trivial ones, into 'next', and then having them drop into
> 'master' at the next cycle; so 'master' was always trailing 'next',
> but they were always the same commit string (i.e., 'master' was always
> a subset of 'next').
>
> Aside from the WC script not working right, are there other
> disadvantages to my doing things that way as opposed to the way the
> Junio has been running the git repository?
The reason Junio does what he does is flexibility.
By merging only individual topics forked from master into next you
can merge those individual topics into master at different points
in time. For example db/fetch-pack has been in next for many weeks
and hasn't yet merged into master, yet jc/am-quiet was forked after
db/fetch-pack started and has already merged into master.
Your way would make jc/am-quiet wait until db/fetch-pack was ready.
That's a big risk in the sense that your tree is "blocked" and even
simple changes are held up by ones that suddenly became a lot more
complex then you originally thought they were going to be.
--
Shawn.
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Theodore Tso @ 2007-10-23 4:56 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023044657.GC14735@spearce.org>
On Tue, Oct 23, 2007 at 12:46:57AM -0400, Shawn O. Pearce wrote:
> By merging only individual topics forked from master into next you
> can merge those individual topics into master at different points
> in time. For example db/fetch-pack has been in next for many weeks
> and hasn't yet merged into master, yet jc/am-quiet was forked after
> db/fetch-pack started and has already merged into master.
>
> Your way would make jc/am-quiet wait until db/fetch-pack was ready.
> That's a big risk in the sense that your tree is "blocked" and even
> simple changes are held up by ones that suddenly became a lot more
> complex then you originally thought they were going to be.
Yes, true. Alternatively, what I've been doing is that if I wasn't
sure that a particular topic was ready to go to 'master' very shortly
after it went into 'next', I would never let it go into 'next', but
rather keep it in 'pu' (which is OK, because pu is constantly getting
rewound). But I guess the downside of that is you might get fewer
testers for the code, because fewer people are probably tracking and
testing 'pu' as compared to 'next'.
Right?
- Ted
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Shawn O. Pearce @ 2007-10-23 5:07 UTC (permalink / raw)
To: Theodore Tso; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023045632.GD27132@thunk.org>
Theodore Tso <tytso@mit.edu> wrote:
> On Tue, Oct 23, 2007 at 12:46:57AM -0400, Shawn O. Pearce wrote:
> > By merging only individual topics forked from master into next you
> > can merge those individual topics into master at different points
> > in time. For example db/fetch-pack has been in next for many weeks
> > and hasn't yet merged into master, yet jc/am-quiet was forked after
> > db/fetch-pack started and has already merged into master.
> >
> > Your way would make jc/am-quiet wait until db/fetch-pack was ready.
> > That's a big risk in the sense that your tree is "blocked" and even
> > simple changes are held up by ones that suddenly became a lot more
> > complex then you originally thought they were going to be.
>
> Yes, true. Alternatively, what I've been doing is that if I wasn't
> sure that a particular topic was ready to go to 'master' very shortly
> after it went into 'next', I would never let it go into 'next', but
> rather keep it in 'pu' (which is OK, because pu is constantly getting
> rewound). But I guess the downside of that is you might get fewer
> testers for the code, because fewer people are probably tracking and
> testing 'pu' as compared to 'next'.
>
> Right?
Yes, that's a good point.
I think in Git part of the reason less people track pu is because
its very volatile. Not because of the rewind policy, but becuase
sometimes the code there doesn't work properly so using it for real
"production" work is pretty risky. On the other hand most of the
code that merges into next has been reasonbly well reviewed and
tested, so following it for "production" work is not as risky.
Junio has in the past proposed rewinding next, especially after a
significant release (e.g. 1.5.3). A bunch of folks (myself included
if I recall correctly) didn't want to do this, as we create topic
branches locally from things in next and sometimes make commits
over them to improve the topic further. But I also make topic
branches for things in pu, so I might as well just shut up and
not complain. :-)
Of course another thought that just came to mind is it is very easy
for me to review next with a
git log -p --reverse origin/next..build-next
just before merging it into my build branch and compiling it locally.
If next rewound frequently (as pu does) this would be more difficult.
--
Shawn.
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Theodore Tso @ 2007-10-23 5:30 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023050726.GD14735@spearce.org>
On Tue, Oct 23, 2007 at 01:07:26AM -0400, Shawn O. Pearce wrote:
> Junio has in the past proposed rewinding next, especially after a
> significant release (e.g. 1.5.3).
Hmm, yes. I think I'd want to rewind next after a while; the thought
of next drifting hundreds or thousands of commits away from master
just gives me the heebee-jeebies. I'm sure it mostly works, but it
just feels wrong. :-)
> A bunch of folks (myself included if I recall correctly) didn't want
> to do this, as we create topic branches locally from things in next
> and sometimes make commits over them to improve the topic further.
I guess I don't see why this would be a hardship; would a quick rebase
on the topic branches more or less take care of the problem?
I guess that brings up another question; I've been regularly rebasing
the topics branches as master and next advances... probably more out
of superstition than anything else. Is that a bad idea for any reason?
Hmm... I guess some of this would be really good to get into the Howto
section of the user guide when talking about git workflows!
- Ted
^ permalink raw reply
* Re: [PATCH] Add color to git-add--interactive diffs (Total different idea to solve the problem)
From: Peter Baumann @ 2007-10-23 5:34 UTC (permalink / raw)
To: Johannes Schindelin
Cc: Tom Tobin, Dan Zwell, Jonathan del Strother, Shawn O. Pearce,
Git Mailing List
In-Reply-To: <Pine.LNX.4.64.0710230054130.25221@racer.site>
On Tue, Oct 23, 2007 at 12:55:44AM +0100, Johannes Schindelin wrote:
> Hi,
>
> On Mon, 22 Oct 2007, Peter Baumann wrote:
>
> > Wouldn't it make more sense to implement the diff coloring inside git
> > apply so that you could use something like
> >
> > diff file1 file2|git apply --color
> >
> > to make the generated diff with colors [1]? It already implements the
> > same semantic for generating a diffstat, using
> >
> > diff file1 file2|git apply --stat
>
> No. In both cases, "git diff" realises that the output is no terminal,
> and switches off color generation. (Just try with diff.color=true instead
> of =auto.)
>
I didn't mean git-diff here, instead I meant diff, so no coloring involved
on the diff side. The git-apply would be enhanced to do the coloring on
every diff it gets on its STDIN.
In the git-add -i case, the perl script whould do something along these
lines:
foreach my $file (@files) {
# read in the diff of a file *WITHOUT* using color
@diff = `git-diff-files $file`;
# ... store it away for later use in hunk selection ...
# print out a nice colored diff for the user
`echo @diff | git apply --color`
}
Instead of handcoding the colorization in the git-add--interactive perl
script, just enhance git-apply to do the colorization *after the fact* for
you on _any_ patch you throw at it in its STDIN.
-Peter
^ permalink raw reply
* Re: best git practices, was Re: Git User's Survey 2007 unfinished summary continued
From: Steffen Prohaska @ 2007-10-23 5:38 UTC (permalink / raw)
To: Jakub Narebski
Cc: Andreas Ericsson, Johannes Schindelin, Federico Mena Quintero,
git
In-Reply-To: <8fe92b430710221635x752c561ejcee14e2526010cc9@mail.gmail.com>
On Oct 23, 2007, at 1:35 AM, Jakub Narebski wrote:
> On 10/22/07, Andreas Ericsson <ae@op5.se> wrote:
>> Johannes Schindelin wrote:
>>> On Mon, 22 Oct 2007, Andreas Ericsson wrote:
>>>
>>>> If I were to suggest any improvements, it'd be to change the
>>>> semantics of
>>>> git-pull to always update the local branches set up to be merged
>>>> with the
>>>> remote tracking branches when they, prior to fetching, pointed
>>>> to the same
>>>> commit, such that when
>>>>
>>>> $ git show-ref master
>>>> d4027a816dd0b416dc8c7b37e2c260e6905f11b6 refs/heads/master
>>>> d4027a816dd0b416dc8c7b37e2c260e6905f11b6 refs/remotes/origin/master
>>>>
>>>> refs/heads/master gets set to refs/remotes/origin/master post-
>>>> fetch.
>>>
>>> In general, this should fail. Because you are expected to have
>>> local
>>> changes in the local branches.
>>
>>
>> BS argument. Git knows when I haven't got any changes on my local
>> branches, and it can be fairly safely assumed that when I feel like
>> making any, I'd like to make them off as fresh a tip as possible
>> unless
>> I explicitly tell git otherwise.
> [cut]
>
> It would be I think possible to make git behave as you want,
> although I'd rather
> (at least at first) have behaviour described above turned on by
> some option
> or config variable. I guess that it would be not that hard to make
> script to do
> what you ant (and probably it would be best if you tried your idea
> that way).
>
> There are the following caveats.
> 1. For each local branch that is to be updated on pull, this branch
> must be marked as tracking some branch of some repository. This has to
> be explicitely done; for example by creating those branches using
> --track option.
True, and only the branches matching the remote currently pulled
should be considered. Tracking branches pointing to a different
remote need to be skipped.
> 2. Git can do a merge with conflicts _only_ if that branch is checked
> out.
Andreas' proposal contains an important requirement that
avoids this problem. His proposal states "when they, prior
to fetching, pointed to the same commit [the head in remotes
pointed to]". That is only fast-forwards are needed, which
never have merge conflicts.
> So for all local branches which you want to get updated using
> "git pull --update-all <repo>" (or something like that), the merge
> with remote branch should be either fast-forward, trivial merge, or
> merge without conflicts. "git pull --update-all <repo>" would return
> then list of updated branches and list of branches which cannot be
> updated.
Maybe Andreas' proposal could be extended as you describe.
But I don't think any merging should automatically be done. I'd
only support fast forwards. Merging always includes a risk
of unexpected changes to the code; even if there are no merge
conflicts detected by git. I think it is reasonable to leave
all such cases to the user for manual resolution. Supporting
fast-forward should be sufficient.
Steffen
^ permalink raw reply
* Re: What's cooking in git/spearce.git (topics)
From: Shawn O. Pearce @ 2007-10-23 5:42 UTC (permalink / raw)
To: Theodore Tso; +Cc: Junio C Hamano, Johannes Schindelin, git
In-Reply-To: <20071023053003.GE27132@thunk.org>
Theodore Tso <tytso@mit.edu> wrote:
> On Tue, Oct 23, 2007 at 01:07:26AM -0400, Shawn O. Pearce wrote:
> > Junio has in the past proposed rewinding next, especially after a
> > significant release (e.g. 1.5.3).
>
> Hmm, yes. I think I'd want to rewind next after a while; the thought
> of next drifting hundreds or thousands of commits away from master
> just gives me the heebee-jeebies. I'm sure it mostly works, but it
> just feels wrong. :-)
There's been a couple of times in git history where Junio has basically
done this to whack next back into line:
git checkout next
git diff next master | git apply --index
git commit -m "Whack next back in line"
Because we've found a change or two lurking in there that shouldn't
have been there after a while. I think it was related to a merge
conflict that happened in next but didn't in master or something
like that. But usually this difference exists as there's usually
always something cooking in next.
> > A bunch of folks (myself included if I recall correctly) didn't want
> > to do this, as we create topic branches locally from things in next
> > and sometimes make commits over them to improve the topic further.
>
> I guess I don't see why this would be a hardship; would a quick rebase
> on the topic branches more or less take care of the problem?
Yes. But you need the prior value of the branch so you can do
something easy like:
git checkout yourtopic
git rebase --onto $newtopic $oldtopic
which means you probably need to look through the logs for not just
pu but also pu@{1}. A script to break out the topic branches from
pu post fetch and store them as proper tracking branches would make
this easier, but that much. If you plan ahead you can save that
$oldtopic point so you can do something like this:
git log pu ; # find $newtopic
git checkout yourtopic
git rebase --onto $newtopic base-yourtopic
git tag -f base-yourtopic $newtopic
> I guess that brings up another question; I've been regularly rebasing
> the topics branches as master and next advances... probably more out
> of superstition than anything else. Is that a bad idea for any reason?
It keeps the history shorter in gitk. But otherwise it isn't bad.
Unless you are running into a lot of conflicts every time you rebase
and its wasting your time. ;-)
I prefer to rebase the topics until they've merged to an integration
branch that doesn't rewind (e.g. master or next in git.git).
That way they have the shortest line possible in gitk between the
final merge and the start point.
There are good reasons why there's an "author" and a "committer"
field in commits. Rebasing will change the committer field's
timestamp, but not the author field. And author comes from the
email, to preserve the original date of development.
> Hmm... I guess some of this would be really good to get into the Howto
> section of the user guide when talking about git workflows!
Yea, I think so too. We've adopted this model in git.git because
it works for our community. A lot of other communities aren't
too far away, as we have a lot of crossover in members. E.g. we
learned a lot from the kernel community.
--
Shawn.
^ permalink raw reply
* [PATCH 0/9] Make git-svn fetch ~1.7x faster
From: Adam Roben @ 2007-10-23 5:46 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
This patch series makes git-svn fetch about 1.7x faster by reducing the number
of forks/execs that occur for each file retrieved from Subversion. To do so, a
few new options are added to git-cat-file and git-hash-object to allow
continuous input on stdin and continuous output on stdout, so that one instance
of each of these commands can be kept running for the duration of the fetch.
The series is based on top of next. I considered basing it on top of the
parse_options work since I touch the option parsing in these two commands, but
I didn't know how wise it would be to base a patch series on something in pu.
I tried to add some new tests for cat-file and hash-object to ensure that I
didn't break old behavior, but I'm not very experienced with the git test suite
and I'm sure my tests could use some improvement. This is the most invasive
change I've yet made to git, so comments are more than welcome.
-Adam
--
Documentation/git-cat-file.txt | 11 +++-
Documentation/git-hash-object.txt | 5 +-
builtin-cat-file.c | 96 +++++++++++++++++++++----
git-svn.perl | 94 +++++++++++++++++++------
hash-object.c | 29 ++++++++-
perl/Git.pm | 56 +++++++++++++++
t/t1005-cat-file.sh | 139 +++++++++++++++++++++++++++++++++++++
t/t1006-hash-object.sh | 49 +++++++++++++
8 files changed, 438 insertions(+), 41 deletions(-)
--
^ permalink raw reply
* [PATCH 1/9] Add tests for git cat-file
From: Adam Roben @ 2007-10-23 5:46 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Adam Roben
In-Reply-To: <1193118397-4696-1-git-send-email-aroben@apple.com>
Signed-off-by: Adam Roben <aroben@apple.com>
---
t/t1005-cat-file.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 91 insertions(+), 0 deletions(-)
create mode 100755 t/t1005-cat-file.sh
diff --git a/t/t1005-cat-file.sh b/t/t1005-cat-file.sh
new file mode 100755
index 0000000..2fdc446
--- /dev/null
+++ b/t/t1005-cat-file.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+test_description='git cat-file'
+
+. ./test-lib.sh
+
+function maybe_remove_timestamp()
+{
+ if test -z "$2"; then
+ echo "$1"
+ else
+ echo "$1" | sed -e 's/ [0-9]\{10\} [+-][0-9]\{4\}$//'
+ fi
+}
+
+function run_tests()
+{
+ type=$1
+ sha1=$2
+ size=$3
+ content=$4
+ pretty_content=$5
+ no_timestamp=$6
+
+ test_expect_success \
+ "$type exists" \
+ "git cat-file -e $hello_sha1"
+ test_expect_success \
+ "Type of $type is correct" \
+ "test $type = \"$(git cat-file -t $sha1)\""
+ test_expect_success \
+ "Size of $type is correct" \
+ "test $size = \"$(git cat-file -s $sha1)\""
+ test -z "$content" || test_expect_success \
+ "Content of $type is correct" \
+ "test \"$(maybe_remove_timestamp "$content" $no_timestamp)\" = \"$(maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_timestamp)\""
+ test_expect_success \
+ "Pretty content of $type is correct" \
+ "test \"$(maybe_remove_timestamp "$pretty_content" $no_timestamp)\" = \"$(maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_timestamp)\""
+}
+
+hello_content="Hello World"
+hello_size=$(echo "$hello_content" | wc -c)
+hello_sha1=557db03de997c86a4a028e1ebd3a1ceb225be238
+
+echo "$hello_content" > hello
+
+git update-index --add hello
+
+run_tests 'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
+
+tree_sha1=$(git write-tree)
+tree_size=33
+tree_pretty_content="100644 blob $hello_sha1 hello"
+
+run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
+
+commit_message="Intial commit"
+commit_sha1=$(echo "$commit_message" | git commit-tree $tree_sha1)
+commit_size=177
+commit_content="tree $tree_sha1
+author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
+
+$commit_message"
+
+run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
+
+tag_header="object $hello_sha1
+type blob
+tag hellotag
+tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+tag_description="This is a tag"
+tag_content="$tag_header
+
+$tag_description"
+tag_pretty_content="$tag_header
+Thu Jan 1 00:00:00 1970 +0000
+
+$tag_description"
+
+tag_sha1=$(echo "$tag_content" | git mktag)
+tag_size=$(echo "$tag_content" | wc -c)
+
+run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_pretty_content"
+
+test_expect_success \
+ "Reach a blob from a tag pointing to it" \
+ "test \"$hello_content\" = \"$(git cat-file blob $tag_sha1)\""
+
+test_done
--
1.5.3.4.1333.ga2f32
^ permalink raw reply related
* [PATCH 3/9] git-cat-file: Make option parsing a little more flexible
From: Adam Roben @ 2007-10-23 5:46 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Adam Roben
In-Reply-To: <1193118397-4696-3-git-send-email-aroben@apple.com>
This will make it easier to add newer options later.
Signed-off-by: Adam Roben <aroben@apple.com>
---
builtin-cat-file.c | 42 ++++++++++++++++++++++++++++++------------
1 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index 34a63d1..3a0be4a 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -143,23 +143,41 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
return 0;
}
+static const char cat_file_usage[] = "git-cat-file [-t|-s|-e|-p|<type>] <sha1>";
+
int cmd_cat_file(int argc, const char **argv, const char *prefix)
{
- int opt;
- const char *exp_type, *obj_name;
+ int i, opt = 0;
+ const char *exp_type = 0, *obj_name = 0;
git_config(git_default_config);
- if (argc != 3)
- usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
- exp_type = argv[1];
- obj_name = argv[2];
-
- opt = 0;
- if ( exp_type[0] == '-' ) {
- opt = exp_type[1];
- if ( !opt || exp_type[2] )
- opt = -1; /* Not a single character option */
+
+ for (i = 1; i < argc; ++i) {
+ const char *arg = argv[i];
+
+ if (!strcmp(arg, "-t") || !strcmp(arg, "-s") || !strcmp(arg, "-e") || !strcmp(arg, "-p")) {
+ exp_type = arg;
+ opt = exp_type[1];
+ continue;
+ }
+
+ if (arg[0] == '-')
+ usage(cat_file_usage);
+
+ if (!exp_type) {
+ exp_type = arg;
+ continue;
+ }
+
+ if (obj_name)
+ usage(cat_file_usage);
+
+ obj_name = arg;
+ break;
}
+ if (!exp_type || !obj_name)
+ usage(cat_file_usage);
+
return cat_one_file(opt, exp_type, obj_name);
}
--
1.5.3.4.1333.ga2f32
^ permalink raw reply related
* [PATCH 2/9] git-cat-file: Small refactor of cmd_cat_file
From: Adam Roben @ 2007-10-23 5:46 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Adam Roben
In-Reply-To: <1193118397-4696-2-git-send-email-aroben@apple.com>
I separated the logic of parsing the arguments from the logic of fetching and
outputting the data. cat_one_file now does the latter.
Signed-off-by: Adam Roben <aroben@apple.com>
---
builtin-cat-file.c | 38 ++++++++++++++++++++++----------------
1 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index f132d58..34a63d1 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -76,31 +76,16 @@ static void pprint_tag(const unsigned char *sha1, const char *buf, unsigned long
write_or_die(1, cp, endp - cp);
}
-int cmd_cat_file(int argc, const char **argv, const char *prefix)
+static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
{
unsigned char sha1[20];
enum object_type type;
void *buf;
unsigned long size;
- int opt;
- const char *exp_type, *obj_name;
-
- git_config(git_default_config);
- if (argc != 3)
- usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
- exp_type = argv[1];
- obj_name = argv[2];
if (get_sha1(obj_name, sha1))
die("Not a valid object name %s", obj_name);
- opt = 0;
- if ( exp_type[0] == '-' ) {
- opt = exp_type[1];
- if ( !opt || exp_type[2] )
- opt = -1; /* Not a single character option */
- }
-
buf = NULL;
switch (opt) {
case 't':
@@ -157,3 +142,24 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
write_or_die(1, buf, size);
return 0;
}
+
+int cmd_cat_file(int argc, const char **argv, const char *prefix)
+{
+ int opt;
+ const char *exp_type, *obj_name;
+
+ git_config(git_default_config);
+ if (argc != 3)
+ usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
+ exp_type = argv[1];
+ obj_name = argv[2];
+
+ opt = 0;
+ if ( exp_type[0] == '-' ) {
+ opt = exp_type[1];
+ if ( !opt || exp_type[2] )
+ opt = -1; /* Not a single character option */
+ }
+
+ return cat_one_file(opt, exp_type, obj_name);
+}
--
1.5.3.4.1333.ga2f32
^ permalink raw reply related
* [PATCH 4/9] git-cat-file: Add --stdin option
From: Adam Roben @ 2007-10-23 5:46 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Adam Roben
In-Reply-To: <1193118397-4696-4-git-send-email-aroben@apple.com>
This lets you specify object names on stdin instead of on the command line.
Signed-off-by: Adam Roben <aroben@apple.com>
---
Documentation/git-cat-file.txt | 6 +++++-
builtin-cat-file.c | 26 ++++++++++++++++++++++----
t/t1005-cat-file.sh | 14 ++++++++++++++
3 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt
index afa095c..588d71a 100644
--- a/Documentation/git-cat-file.txt
+++ b/Documentation/git-cat-file.txt
@@ -8,7 +8,7 @@ git-cat-file - Provide content or type/size information for repository objects
SYNOPSIS
--------
-'git-cat-file' [-t | -s | -e | -p | <type>] <object>
+'git-cat-file' [-t | -s | -e | -p | <type>] [--stdin | <object>]
DESCRIPTION
-----------
@@ -23,6 +23,10 @@ OPTIONS
For a more complete list of ways to spell object names, see
"SPECIFYING REVISIONS" section in gitlink:git-rev-parse[1].
+--stdin::
+ Read object names from stdin instead of specifying one on the
+ command line.
+
-t::
Instead of the content, show the object type identified by
<object>.
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index 3a0be4a..0f1ffe5 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -143,12 +143,14 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
return 0;
}
-static const char cat_file_usage[] = "git-cat-file [-t|-s|-e|-p|<type>] <sha1>";
+static const char cat_file_usage[] = "git-cat-file [-t|-s|-e|-p|<type>] [--stdin | <sha1>]";
int cmd_cat_file(int argc, const char **argv, const char *prefix)
{
int i, opt = 0;
+ int read_stdin = 0;
const char *exp_type = 0, *obj_name = 0;
+ struct strbuf buf;
git_config(git_default_config);
@@ -161,6 +163,11 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
continue;
}
+ if (!strcmp(arg, "--stdin")) {
+ read_stdin = 1;
+ continue;
+ }
+
if (arg[0] == '-')
usage(cat_file_usage);
@@ -169,15 +176,26 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
continue;
}
- if (obj_name)
+ if (obj_name || read_stdin)
usage(cat_file_usage);
obj_name = arg;
break;
}
- if (!exp_type || !obj_name)
+ if (!read_stdin) {
+ if (!exp_type || !obj_name)
usage(cat_file_usage);
+ return cat_one_file(opt, exp_type, obj_name);
+ }
- return cat_one_file(opt, exp_type, obj_name);
+ strbuf_init(&buf, 0);
+ while (strbuf_getline(&buf, stdin, '\n') != EOF) {
+ int error = cat_one_file(opt, exp_type, buf.buf);
+ if (error)
+ return error;
+ }
+ strbuf_release(&buf);
+
+ return 0;
}
diff --git a/t/t1005-cat-file.sh b/t/t1005-cat-file.sh
index 2fdc446..49eb89d 100755
--- a/t/t1005-cat-file.sh
+++ b/t/t1005-cat-file.sh
@@ -88,4 +88,18 @@ test_expect_success \
"Reach a blob from a tag pointing to it" \
"test \"$hello_content\" = \"$(git cat-file blob $tag_sha1)\""
+sha1s="$hello_sha1
+$tree_sha1
+$commit_sha1
+$tag_sha1"
+
+sizes="$hello_size
+$tree_size
+$commit_size
+$tag_size"
+
+test_expect_success \
+ "Pass object hashes on stdin" \
+ "test \"$sizes\" = \"$(echo "$sha1s" | git cat-file -s --stdin)\""
+
test_done
--
1.5.3.4.1333.ga2f32
^ permalink raw reply related
* [PATCH 5/9] git-cat-file: Add --separator option
From: Adam Roben @ 2007-10-23 5:46 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Adam Roben
In-Reply-To: <1193118397-4696-5-git-send-email-aroben@apple.com>
This lets the user specify a string to be printed in between the output from
each object passed on stdin.
Signed-off-by: Adam Roben <aroben@apple.com>
---
Documentation/git-cat-file.txt | 7 ++++++-
builtin-cat-file.c | 28 +++++++++++++++++++++++++---
t/t1005-cat-file.sh | 36 +++++++++++++++++++++++++++++++++++-
3 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt
index 588d71a..7a59a5e 100644
--- a/Documentation/git-cat-file.txt
+++ b/Documentation/git-cat-file.txt
@@ -8,7 +8,7 @@ git-cat-file - Provide content or type/size information for repository objects
SYNOPSIS
--------
-'git-cat-file' [-t | -s | -e | -p | <type>] [--stdin | <object>]
+'git-cat-file' [-t | -s | -e | -p | <type>] [--stdin [--separator <string>] | <object>]
DESCRIPTION
-----------
@@ -27,6 +27,11 @@ OPTIONS
Read object names from stdin instead of specifying one on the
command line.
+--separator::
+ A string to print in between the output for each object passed on
+ stdin. A newline will be appended to the separator each time it is
+ printed.
+
-t::
Instead of the content, show the object type identified by
<object>.
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index 0f1ffe5..9ae3184 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -92,6 +92,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
type = sha1_object_info(sha1, NULL);
if (type > 0) {
printf("%s\n", typename(type));
+ fflush(stdout);
return 0;
}
break;
@@ -100,6 +101,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
type = sha1_object_info(sha1, &size);
if (type > 0) {
printf("%lu\n", size);
+ fflush(stdout);
return 0;
}
break;
@@ -143,14 +145,16 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
return 0;
}
-static const char cat_file_usage[] = "git-cat-file [-t|-s|-e|-p|<type>] [--stdin | <sha1>]";
+static const char cat_file_usage[] = "git-cat-file [-t|-s|-e|-p|<type>] [--stdin [--separator <string>] | <sha1>]";
+
+static const char *separator;
int cmd_cat_file(int argc, const char **argv, const char *prefix)
{
int i, opt = 0;
int read_stdin = 0;
const char *exp_type = 0, *obj_name = 0;
- struct strbuf buf;
+ struct strbuf buf, sbuf;
git_config(git_default_config);
@@ -168,6 +172,13 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
continue;
}
+ if (!strcmp(arg, "--separator")) {
+ if (++i == argc)
+ usage(cat_file_usage);
+ separator = argv[i];
+ continue;
+ }
+
if (arg[0] == '-')
usage(cat_file_usage);
@@ -184,18 +195,29 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
}
if (!read_stdin) {
- if (!exp_type || !obj_name)
+ if (!exp_type || !obj_name || separator)
usage(cat_file_usage);
return cat_one_file(opt, exp_type, obj_name);
}
+ if (separator) {
+ strbuf_init(&sbuf, 0);
+ strbuf_addstr(&sbuf, separator);
+ strbuf_addch(&sbuf, '\n');
+ }
+
strbuf_init(&buf, 0);
while (strbuf_getline(&buf, stdin, '\n') != EOF) {
int error = cat_one_file(opt, exp_type, buf.buf);
if (error)
return error;
+ if (separator)
+ write_or_die(1, sbuf.buf, sbuf.len);
}
strbuf_release(&buf);
+ if (separator)
+ strbuf_release(&sbuf);
+
return 0;
}
diff --git a/t/t1005-cat-file.sh b/t/t1005-cat-file.sh
index 49eb89d..52a3efd 100755
--- a/t/t1005-cat-file.sh
+++ b/t/t1005-cat-file.sh
@@ -99,7 +99,41 @@ $commit_size
$tag_size"
test_expect_success \
- "Pass object hashes on stdin" \
+ "Print sizes for object hashes on stdin" \
"test \"$sizes\" = \"$(echo "$sha1s" | git cat-file -s --stdin)\""
+separator="TESTSEPARATOR"
+
+separated_sizes="$hello_size
+$separator
+$tree_size
+$separator
+$commit_size
+$separator
+$tag_size
+$separator"
+
+test_expect_success \
+ "Print sizes for object hashes on stdin with --separator" \
+ "test \"$separated_sizes\" = \"$(echo "$sha1s" | git cat-file -s --stdin --separator $separator)\""
+
+sha1s="$hello_sha1
+$hello_sha1"
+
+contents="$hello_content
+$hello_content"
+
+separated_contents="$hello_content
+$separator
+$hello_content
+$separator"
+
+test_expect_success \
+ "Print objects for object hashes on stdin" \
+ "test \"$contents\" = \"$(echo "$sha1s" | git cat-file blob --stdin)\""
+
+test_expect_success \
+ "Print objects for object hashes on stdin with --separator" \
+ "test \"$separated_contents\" = \"$(echo "$sha1s" | git cat-file blob --stdin --separator $separator)\""
+
test_done
--
1.5.3.4.1333.ga2f32
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox