From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: Re: [PATCH 1/2] add --simplify-combined-diff option
Date: Tue, 29 Jul 2014 09:00:27 -0400 [thread overview]
Message-ID: <20140729130026.GA29912@peff.net> (raw)
In-Reply-To: <20140729120056.GA9175@peff.net>
On Tue, Jul 29, 2014 at 08:00:56AM -0400, Jeff King wrote:
> The implementation just cuts the number of parents down to 1, but
> otherwise runs through the same combined-diff code. The resulting
> pairwise combined-diff differs from a normal diff in a few ways:
>
> 1. The header line is still "diff --combined" (or "--cc") instead of
> "diff --git", and it mentions the filename only once.
>
> 2. The index lines do not contain the file mode; for combined diffs,
> we generate a separate mode line (but only when it has something
> interesting to show).
>
> 3. The hunk header for a single-line change says "-1" in the regular
> code path, but "-1,1" in the combined code path.
>
> Is there any value in keeping this as a pseudo-combined diff (i.e., with
> the combined header, but only a single parent)? It should not be too
> hard to just punt to the regular builtin_diff code path when
> "num_parents == 1".
It's not too hard; mostly we just have to massage the data into a
diff_filepair. Patch is below (I'd squash it, and the further commits
will need fixups to their tests, too).
---
combine-diff.c | 32 +++++++++++++++++++++++++++++---
diff.c | 2 +-
diff.h | 2 ++
t/t4038-diff-combined.sh | 18 +++++++++---------
4 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/combine-diff.c b/combine-diff.c
index 60e54a7..0588c86 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -965,6 +965,28 @@ static int simplify_parents(struct combine_diff_path *p, int nr)
return 1;
}
+static void show_single_parent_patch(struct combine_diff_path *elem,
+ int working_tree_file,
+ struct rev_info *rev)
+{
+ struct diff_filepair pair;
+
+ memset(&pair, 0, sizeof(pair));
+ pair.one = alloc_filespec(elem->path);
+ pair.two = alloc_filespec(elem->path);
+ pair.status = elem->parent[0].status;
+
+ fill_filespec(pair.one, elem->parent[0].sha1, 1, elem->parent[0].mode);
+ if (working_tree_file)
+ fill_filespec(pair.two, null_sha1, 0, elem->mode);
+ else
+ fill_filespec(pair.two, elem->sha1, 1, elem->mode);
+
+ run_diff(&pair, &rev->diffopt);
+ free_filespec(pair.one);
+ free_filespec(pair.two);
+}
+
static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
int dense, int working_tree_file,
struct rev_info *rev)
@@ -982,6 +1004,13 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
int is_binary;
const char *line_prefix = diff_line_prefix(opt);
+ if (rev->simplify_combined_diff)
+ num_parent = simplify_parents(elem, num_parent);
+ if (num_parent == 1) {
+ show_single_parent_patch(elem, working_tree_file, rev);
+ return;
+ }
+
context = opt->context;
userdiff = userdiff_find_by_path(elem->path);
if (!userdiff)
@@ -989,9 +1018,6 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV))
textconv = userdiff_get_textconv(userdiff);
- if (rev->simplify_combined_diff)
- num_parent = simplify_parents(elem, num_parent);
-
/* Read the result of merge first */
if (!working_tree_file)
result = grab_blob(elem->sha1, elem->mode, &result_size,
diff --git a/diff.c b/diff.c
index 867f034..558a520 100644
--- a/diff.c
+++ b/diff.c
@@ -3089,7 +3089,7 @@ static void strip_prefix(int prefix_length, const char **namep, const char **oth
}
}
-static void run_diff(struct diff_filepair *p, struct diff_options *o)
+void run_diff(struct diff_filepair *p, struct diff_options *o)
{
const char *pgm = external_diff();
struct strbuf msg;
diff --git a/diff.h b/diff.h
index b4a624d..a669be0 100644
--- a/diff.h
+++ b/diff.h
@@ -356,4 +356,6 @@ extern int print_stat_summary(FILE *fp, int files,
int insertions, int deletions);
extern void setup_diff_pager(struct diff_options *);
+extern void run_diff(struct diff_filepair *p, struct diff_options *o);
+
#endif /* DIFF_H */
diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
index d522474..29cdb45 100755
--- a/t/t4038-diff-combined.sh
+++ b/t/t4038-diff-combined.sh
@@ -455,11 +455,11 @@ test_expect_success 'simplify combined --patch' '
merge=$(mkcommit new new $side1 $side2) &&
cat >expect <<-\EOF &&
- diff --combined one
- index df967b9..3e75765
+ diff --git a/one b/one
+ index df967b9..3e75765 100644
--- a/one
+++ b/one
- @@ -1,1 +1,1 @@
+ @@ -1 +1 @@
-base
+new
diff --combined two
@@ -485,11 +485,11 @@ test_expect_success 'do not simplify unless all parents are identical' '
merge=$(mkcommit new new $side1 $side2 $side3) &&
cat >expect <<-\EOF &&
- diff --combined one
- index df967b9..3e75765
+ diff --git a/one b/one
+ index df967b9..3e75765 100644
--- a/one
+++ b/one
- @@ -1,1 +1,1 @@
+ @@ -1 +1 @@
-base
+new
diff --combined two
@@ -513,11 +513,11 @@ test_expect_success 'do not simplify away mode changes' '
merge=$(mkcommit new new $side1 $side2) &&
cat >expect <<-\EOF &&
- diff --combined one
- index df967b9..3e75765
+ diff --git a/one b/one
+ index df967b9..3e75765 100644
--- a/one
+++ b/one
- @@ -1,1 +1,1 @@
+ @@ -1 +1 @@
-base
+new
diff --combined two
--
2.1.0.rc0.286.g5c67d74
next prev parent reply other threads:[~2014-07-29 13:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 11:53 [PATCH 0/2] improving "git stash list -p" Jeff King
2014-07-29 12:00 ` [PATCH 1/2] add --simplify-combined-diff option Jeff King
2014-07-29 13:00 ` Jeff King [this message]
2014-07-29 12:03 ` [PATCH 2/2] stash: default listing to "--cc --simplify-combined-diff" Jeff King
2014-07-29 12:07 ` [RFC/PATCH 3/2] stash: show combined diff with "stash show" Jeff King
2014-07-29 18:13 ` Junio C Hamano
2014-07-31 0:17 ` Jeff King
2014-07-31 0:28 ` Junio C Hamano
2014-07-29 17:53 ` [PATCH v2 0/6] improving "git stash list -p" Jeff King
2014-07-29 17:53 ` [PATCH v2 1/6] revision: drop useless string offset when parsing "--pretty" Jeff King
2014-07-29 17:54 ` [PATCH v2 2/6] pretty: treat "--format=" as an empty userformat Jeff King
2014-07-29 17:56 ` [PATCH v2 3/6] pretty: make empty userformats truly empty Jeff King
2014-07-29 17:57 ` [PATCH v2 4/6] add --simplify-combined-diff option Jeff King
2014-07-29 20:02 ` Junio C Hamano
2014-07-29 17:57 ` [PATCH v2 5/6] stash: default listing to "--cc --simplify-combined-diff" Jeff King
2014-07-29 18:58 ` Junio C Hamano
2014-07-30 19:43 ` Junio C Hamano
2014-07-31 0:09 ` Jeff King
2014-08-12 23:30 ` Keller, Jacob E
2014-07-29 17:58 ` [PATCH v2 6/6] stash: show combined diff with "stash show" Jeff King
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=20140729130026.GA29912@peff.net \
--to=peff@peff.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.