* [PATCH] Teach fmt-patch to write individual files.
@ 2006-05-04 23:16 Johannes Schindelin
2006-05-05 0:09 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2006-05-04 23:16 UTC (permalink / raw)
To: git, junkio
When called with "--stdout", it still writes to standard output.
Notable differences to git-format-patch:
- since fmt-patch uses the standardized logging machinery, it is
no longer "From nobody", but "From <commit_sha1>",
- the empty lines before and after the "---" just before the
diffstat are no longer there,
- git-format-patch outputs the commit_sha1 just before the first
diff, which fmt-patch does not,
- the file names are no longer output to stdout, but to stderr
(since stdout is freopen()ed all the time), and
- "git fmt-patch HEAD^" does not work as expected: it outputs
*all* commits reachable from HEAD^!
The last one is possibly a showstopper. At least I used to call that
command quite often...
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
I forgot to "git-update-index builtin-log.c"...
builtin-log.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 71 insertions(+), 1 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index a39aed6..576703c 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -69,12 +69,65 @@ int cmd_log(int argc, const char **argv,
return cmd_log_wc(argc, argv, envp, &rev);
}
+static int istitlechar(char c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || c == '.' || c == '_';
+}
+
+static void reopen_stdout(struct commit *commit, int nr)
+{
+ char filename[1024];
+ char *sol;
+ int len;
+
+
+ sprintf(filename, "%04d", nr);
+ len = strlen(filename);
+
+ sol = strstr(commit->buffer, "\n\n");
+ if (sol) {
+ int j, space = 1;
+
+ sol += 2;
+ /* strip [PATCH] or [PATCH blabla] */
+ if (!strncmp(sol, "[PATCH", 6)) {
+ char *eos = strchr(sol + 6, ']');
+ if (eos) {
+ while (isspace(*eos))
+ eos++;
+ sol = eos;
+ }
+ }
+
+ for (j = 0; len < 1024 - 6 && sol[j] && sol[j] != '\n'; j++) {
+ if (istitlechar(sol[j])) {
+ if (space) {
+ filename[len++] = '-';
+ space = 0;
+ }
+ filename[len++] = sol[j];
+ if (sol[j] == '.')
+ while (sol[j + 1] == '.')
+ j++;
+ } else
+ space = 1;
+ }
+ while (filename[len - 1] == '.' || filename[len - 1] == '-')
+ len--;
+ }
+ strcpy(filename + len, ".txt");
+ fprintf(stderr, "%s\n", filename);
+ freopen(filename, "w", stdout);
+}
+
int cmd_format_patch(int argc, const char **argv, char **envp)
{
struct commit *commit;
struct commit **list = NULL;
struct rev_info rev;
- int nr = 0;
+ int nr = 0, total;
+ int use_stdout = 0;
init_revisions(&rev);
rev.commit_format = CMIT_FMT_EMAIL;
@@ -87,20 +140,37 @@ int cmd_format_patch(int argc, const cha
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
argc = setup_revisions(argc, argv, &rev, "HEAD");
+ while (argc > 1) {
+ if (!strcmp(argv[1], "--stdout"))
+ use_stdout = 1;
+ else
+ die ("unrecognized argument: %s", argv[1]);
+ argc--;
+ argv++;
+ }
+
prepare_revision_walk(&rev);
while ((commit = get_revision(&rev)) != NULL) {
+ /* ignore merges */
+ if (commit->parents && commit->parents->next)
+ continue;
nr++;
list = realloc(list, nr * sizeof(list[0]));
list[nr - 1] = commit;
}
+ total = nr;
while (0 <= --nr) {
int shown;
commit = list[nr];
+ if (!use_stdout)
+ reopen_stdout(commit, total - nr);
shown = log_tree_commit(&rev, commit);
free(commit->buffer);
commit->buffer = NULL;
if (shown)
printf("-- \n%s\n\n", git_version_string);
+ if (!use_stdout)
+ fclose(stdout);
}
free(list);
return 0;
--
1.3.1.g42859-dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] Teach fmt-patch to write individual files.
2006-05-04 23:16 [PATCH] Teach fmt-patch to write individual files Johannes Schindelin
@ 2006-05-05 0:09 ` Junio C Hamano
2006-05-05 0:56 ` Johannes Schindelin
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2006-05-05 0:09 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> When called with "--stdout", it still writes to standard output.
>
> Notable differences to git-format-patch:
>
> - since fmt-patch uses the standardized logging machinery, it is
> no longer "From nobody", but "From <commit_sha1>",
Yes, and the date on that UNIX-From line has been updated ;-).
> - the empty lines before and after the "---" just before the
> diffstat are no longer there,
Personally, I find this the most annoying myself. I am not
complaining to you because as you know you inherited this
behaviour from my code.
> - git-format-patch outputs the commit_sha1 just before the first
> diff, which fmt-patch does not,
Which should be fine.
> - the file names are no longer output to stdout, but to stderr
> (since stdout is freopen()ed all the time), and
Which might be a bigger deal; I suspect people capture that while
dumping patches into individual files, and do their
postprocessing using the list of filenames.
> - "git fmt-patch HEAD^" does not work as expected: it outputs
> *all* commits reachable from HEAD^!
If we really wanted to handle this, you could do something like
what builtin-diff does before letting the revision machinery
start walking the revision tree. Look at pending objects, and
if you find only one UNINTERESTING commit, add_object the
current HEAD there as well. Personally I do not think it is
worth it; rather we would probably want to standardize on rev-list
syntax.
Two major differences you forgot to mention.
One is that it does not do the "git cherry" filtering. It is
not a big deal for me personally, but some people may be
depending on it. I dunno.
Another is -o outdir, which should be trivial to add once you
have implemented output switching with freopen().
Anyhow, thanks for starting this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Teach fmt-patch to write individual files.
2006-05-05 0:09 ` Junio C Hamano
@ 2006-05-05 0:56 ` Johannes Schindelin
0 siblings, 0 replies; 5+ messages in thread
From: Johannes Schindelin @ 2006-05-05 0:56 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Hi,
On Thu, 4 May 2006, Junio C Hamano wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > When called with "--stdout", it still writes to standard output.
> >
> > Notable differences to git-format-patch:
> >
> > - since fmt-patch uses the standardized logging machinery, it is
> > no longer "From nobody", but "From <commit_sha1>",
>
> Yes, and the date on that UNIX-From line has been updated ;-).
Right.
> > - the empty lines before and after the "---" just before the
> > diffstat are no longer there,
>
> Personally, I find this the most annoying myself. I am not
> complaining to you because as you know you inherited this
> behaviour from my code.
How about this?
-- snip --
diff --git a/log-tree.c b/log-tree.c
index d92abaf..6379d43 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -86,7 +86,7 @@ int log_tree_diff_flush(struct rev_info
}
if (opt->loginfo && !opt->no_commit_id)
- show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n");
+ show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "\n---\n\n" : "\n");
diff_flush(&opt->diffopt);
return 1;
}
-- snap --
> > - git-format-patch outputs the commit_sha1 just before the first
> > diff, which fmt-patch does not,
>
> Which should be fine.
Yeah, I just wanted to mention it in case people rely on it.
> > - the file names are no longer output to stdout, but to stderr
> > (since stdout is freopen()ed all the time), and
>
> Which might be a bigger deal; I suspect people capture that while
> dumping patches into individual files, and do their
> postprocessing using the list of filenames.
I hoped it is not necessary to "FILE *realstdout = fdopen(dup(1));" but I
can do it if this is wanted.
> > - "git fmt-patch HEAD^" does not work as expected: it outputs
> > *all* commits reachable from HEAD^!
>
> If we really wanted to handle this, you could do something like
> what builtin-diff does before letting the revision machinery
> start walking the revision tree. Look at pending objects, and
> if you find only one UNINTERESTING commit, add_object the
> current HEAD there as well. Personally I do not think it is
> worth it; rather we would probably want to standardize on rev-list
> syntax.
Well, I have to get used to add ".." after HEAD^, but that is probably not
very difficult. I would like fmt-patch to error out without a range,
though.
> Two major differences you forgot to mention.
>
> One is that it does not do the "git cherry" filtering. It is
> not a big deal for me personally, but some people may be
> depending on it. I dunno.
Oops. I really did not think of that.
> Another is -o outdir, which should be trivial to add once you
> have implemented output switching with freopen().
Yes, this becomes easy now. I'll do that next.
Ciao,
Dscho
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] Teach fmt-patch to write individual files.
@ 2006-05-04 23:07 Johannes Schindelin
2006-05-04 23:15 ` Johannes Schindelin
0 siblings, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2006-05-04 23:07 UTC (permalink / raw)
To: git, junkio
When called with "--stdout", it still writes to standard output.
Notable differences to git-format-patch:
- since fmt-patch uses the standardized logging machinery, it is
no longer "From nobody", but "From <commit_sha1>",
- the empty lines before and after the "---" just before the
diffstat are no longer there,
- git-format-patch outputs the commit_sha1 just before the first
diff, which fmt-patch does not,
- the file names are no longer output to stdout, but to stderr
(since stdout is freopen()ed all the time), and
- "git fmt-patch HEAD^" does not work as expected: it outputs
*all* commits reachable from HEAD^!
The last one is possibly a showstopper. At least I used to call that
command quite often...
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
builtin-log.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 60 insertions(+), 1 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index a39aed6..a75a37f 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -69,12 +69,54 @@ int cmd_log(int argc, const char **argv,
return cmd_log_wc(argc, argv, envp, &rev);
}
+static int istitlechar(char c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || c == '.' || c == '_';
+}
+
+static void reopen_stdout(struct commit *commit, int nr)
+{
+ char filename[1024];
+ char *sol;
+ int len;
+
+
+ sprintf(filename, "%04d", nr);
+ len = strlen(filename);
+
+ sol = strstr(commit->buffer, "\n\n");
+ if (sol) {
+ int j, space = 1;
+
+ sol += 2;
+ for (j = 0; len < 1024 - 6 && sol[j] && sol[j] != '\n'; j++) {
+ if (istitlechar(sol[j])) {
+ if (space) {
+ filename[len++] = '-';
+ space = 0;
+ }
+ filename[len++] = sol[j];
+ if (sol[j] == '.')
+ while (sol[++j] == '.');
+ } else
+ space = 1;
+ }
+ while (filename[len - 1] == '.')
+ len--;
+ }
+ strcpy(filename + len, ".txt");
+ fprintf(stderr, "%s\n", filename);
+ freopen(filename, "w", stdout);
+}
+
int cmd_format_patch(int argc, const char **argv, char **envp)
{
struct commit *commit;
struct commit **list = NULL;
struct rev_info rev;
- int nr = 0;
+ int nr = 0, total;
+ int use_stdout = 0;
init_revisions(&rev);
rev.commit_format = CMIT_FMT_EMAIL;
@@ -87,20 +129,37 @@ int cmd_format_patch(int argc, const cha
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
argc = setup_revisions(argc, argv, &rev, "HEAD");
+ while (argc > 1) {
+ if (!strcmp(argv[1], "--stdout"))
+ use_stdout = 1;
+ else
+ die ("unrecognized argument: %s", argv[1]);
+ argc--;
+ argv++;
+ }
+
prepare_revision_walk(&rev);
while ((commit = get_revision(&rev)) != NULL) {
+ /* ignore merges */
+ if (commit->parents && commit->parents->next)
+ continue;
nr++;
list = realloc(list, nr * sizeof(list[0]));
list[nr - 1] = commit;
}
+ total = nr;
while (0 <= --nr) {
int shown;
commit = list[nr];
+ if (!use_stdout)
+ reopen_stdout(commit, total - nr);
shown = log_tree_commit(&rev, commit);
free(commit->buffer);
commit->buffer = NULL;
if (shown)
printf("-- \n%s\n\n", git_version_string);
+ if (!use_stdout)
+ fclose(stdout);
}
free(list);
return 0;
--
1.3.1.g42859-dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-05-05 0:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-04 23:16 [PATCH] Teach fmt-patch to write individual files Johannes Schindelin
2006-05-05 0:09 ` Junio C Hamano
2006-05-05 0:56 ` Johannes Schindelin
-- strict thread matches above, loose matches on Subject: below --
2006-05-04 23:07 Johannes Schindelin
2006-05-04 23:15 ` Johannes Schindelin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox