git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: Re: [PATCH] diff-* --with-raw
Date: Mon, 10 Apr 2006 17:06:07 -0700	[thread overview]
Message-ID: <7v3bgl7z80.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7v7j5x7zh3.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Mon, 10 Apr 2006 17:00:40 -0700")

Junio C Hamano <junkio@cox.net> writes:

> Pasky wanted to have an option to get both diff-raw output and
> diff-patch output.  This implements "git-diff-* --with-raw"
> (which obviously implies -p as well) to do so.
>
> Because all the necessary information is already on extended
> header lines such as "index xxxxxx..yyyyyy" and "rename from"
> lines, this is not strictly necessary, but if it helps
> Porcelains...

And this alternative gives raw upfront followed by patch.  It
was unclear which one Pasky wanted, so...

--
diff --git a/diff.c b/diff.c
index 2fa285a..12924f2 100644
--- a/diff.c
+++ b/diff.c
@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *
 	const char *arg = av[0];
 	if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
 		options->output_format = DIFF_FORMAT_PATCH;
+	else if (!strcmp(arg, "--with-raw")) {
+		options->output_format = DIFF_FORMAT_PATCH;
+		options->with_raw = 1;
+	}
 	else if (!strcmp(arg, "-z"))
 		options->line_termination = 0;
 	else if (!strncmp(arg, "-l", 2))
@@ -1270,46 +1274,58 @@ static void diff_resolve_rename_copy(voi
 	diff_debug_queue("resolve-rename-copy done", q);
 }
 
-void diff_flush(struct diff_options *options)
+static void flush_one_pair(struct diff_filepair *p,
+			   int diff_output_format,
+			   struct diff_options *options)
 {
-	struct diff_queue_struct *q = &diff_queued_diff;
-	int i;
 	int inter_name_termination = '\t';
-	int diff_output_format = options->output_format;
 	int line_termination = options->line_termination;
-
 	if (!line_termination)
 		inter_name_termination = 0;
 
-	for (i = 0; i < q->nr; i++) {
-		struct diff_filepair *p = q->queue[i];
-
-		switch (p->status) {
-		case DIFF_STATUS_UNKNOWN:
+	switch (p->status) {
+	case DIFF_STATUS_UNKNOWN:
+		break;
+	case 0:
+		die("internal error in diff-resolve-rename-copy");
+		break;
+	default:
+		switch (diff_output_format) {
+		case DIFF_FORMAT_PATCH:
+			diff_flush_patch(p, options);
 			break;
-		case 0:
-			die("internal error in diff-resolve-rename-copy");
+		case DIFF_FORMAT_RAW:
+		case DIFF_FORMAT_NAME_STATUS:
+			diff_flush_raw(p, line_termination,
+				       inter_name_termination,
+				       options);
 			break;
-		default:
-			switch (diff_output_format) {
-			case DIFF_FORMAT_PATCH:
-				diff_flush_patch(p, options);
-				break;
-			case DIFF_FORMAT_RAW:
-			case DIFF_FORMAT_NAME_STATUS:
-				diff_flush_raw(p, line_termination,
-					       inter_name_termination,
-					       options);
-				break;
-			case DIFF_FORMAT_NAME:
-				diff_flush_name(p,
-						inter_name_termination,
-						line_termination);
-				break;
-			case DIFF_FORMAT_NO_OUTPUT:
-				break;
-			}
+		case DIFF_FORMAT_NAME:
+			diff_flush_name(p,
+					inter_name_termination,
+					line_termination);
+			break;
+		case DIFF_FORMAT_NO_OUTPUT:
+			break;
 		}
+	}
+}
+
+void diff_flush(struct diff_options *options)
+{
+	struct diff_queue_struct *q = &diff_queued_diff;
+	int i;
+	int diff_output_format = options->output_format;
+
+	if (options->with_raw) {
+		for (i = 0; i < q->nr; i++) {
+			struct diff_filepair *p = q->queue[i];
+			flush_one_pair(p, DIFF_FORMAT_RAW, options);
+		}
+	}
+	for (i = 0; i < q->nr; i++) {
+		struct diff_filepair *p = q->queue[i];
+		flush_one_pair(p, diff_output_format, options);
 		diff_free_filepair(p);
 	}
 	free(q->queue);
diff --git a/diff.h b/diff.h
index a02ef28..07b153b 100644
--- a/diff.h
+++ b/diff.h
@@ -24,6 +24,7 @@ struct diff_options {
 	const char *orderfile;
 	const char *pickaxe;
 	unsigned recursive:1,
+		 with_raw:1,
 		 tree_in_recursive:1,
 		 full_index:1;
 	int break_opt;

  reply	other threads:[~2006-04-11  0:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-11  0:00 [PATCH] diff-* --with-raw Junio C Hamano
2006-04-11  0:06 ` Junio C Hamano [this message]
2006-04-11  0:23   ` Petr Baudis
2006-04-11  0:35     ` Junio C Hamano
2006-04-11 11:22       ` [PATCH] Rename --with-raw to --patch-with-raw and document it Petr Baudis
2006-04-11 11:30       ` [PATCH] Separate the raw diff and patch with a newline Petr Baudis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v3bgl7z80.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).