git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* xdiff: generate "anti-diffs" aka what is common to two files
@ 2006-06-29  4:57 Linus Torvalds
  2006-06-29  6:04 ` Junio C Hamano
  2006-06-29 18:18 ` Davide Libenzi
  0 siblings, 2 replies; 3+ messages in thread
From: Linus Torvalds @ 2006-06-29  4:57 UTC (permalink / raw)
  To: Davide Libenzi, Junio C Hamano, Git Mailing List


This fairly trivial patch adds a new XDL_EMIT_xxx flag to tell libxdiff 
that we don't want to generate the _diff_ between two files, we want to 
see the lines that are _common_ to two files.

So when you set XDL_EMIT_COMMON, xdl_diff() will do everything exactly 
like it used to do, but the output records it generates just contain the 
lines that aren't part of the diff.

This is for doing things like generating the common base case for a file 
that was added in both branches.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

Davide, I say it's a "fairly trivial patch", but quite frankly, I'm 
winging it. I'm not that comfortable with the libxdiff internal workings, 
so while this seems to work for me and make sense, can you please take a 
quick look.

Junio: the patch that actually _uses_ this comes next. It's based on my 
previous "throw-away" example patches, if you want me to base it on 
something else, please holler.

diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index 2ce10b4..c9f8178 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -39,6 +39,7 @@ #define XDL_PATCH_MODEMASK ((1 << 8) - 1
 #define XDL_PATCH_IGNOREBSPACE (1 << 8)
 
 #define XDL_EMIT_FUNCNAMES (1 << 0)
+#define XDL_EMIT_COMMON (1 << 1)
 
 #define XDL_MMB_READONLY (1 << 0)
 
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index ad5bfb1..3604ca1 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -100,6 +100,21 @@ static void xdl_find_func(xdfile_t *xf, 
 }
 
 
+int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
+		    xdemitconf_t const *xecfg) {
+	xdfile_t *xdf = &xe->xdf1;
+	const char *rchg = xdf->rchg;
+	long ix;
+
+	for (ix = 0; ix < xdf->nrec; ix++) {
+		if (rchg[ix])
+			continue;
+		if (xdl_emit_record(xdf, ix, "", ecb))
+			return -1;
+	}
+	return 0;
+}		
+
 int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
 		  xdemitconf_t const *xecfg) {
 	long s1, s2, e1, e2, lctx;
@@ -107,6 +122,9 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange
 	char funcbuf[40];
 	long funclen = 0;
 
+	if (xecfg->flags & XDL_EMIT_COMMON)
+		return xdl_emit_common(xe, xscr, ecb, xecfg);
+
 	for (xch = xche = xscr; xch; xch = xche->next) {
 		xche = xdl_get_hunk(xch, xecfg);
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: xdiff: generate "anti-diffs" aka what is common to two files
  2006-06-29  4:57 xdiff: generate "anti-diffs" aka what is common to two files Linus Torvalds
@ 2006-06-29  6:04 ` Junio C Hamano
  2006-06-29 18:18 ` Davide Libenzi
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2006-06-29  6:04 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

Linus Torvalds <torvalds@osdl.org> writes:

> Junio: the patch that actually _uses_ this comes next. It's based on my 
> previous "throw-away" example patches, if you want me to base it on 
> something else, please holler.

Nah, I appreciate that you did it this way, because it gave me a
test case to "git-am" your two patches into a temporary branch
and "pull --squash" that into lt/merge-tree branch ;-).

	git am ./+LT.mbox
        ... two patches, applied with --whitespace=strip ...
	git tag -f CG
        git reset --hard HEAD^^
        git pull --squash . tag CG
        git commig -C CG
        git tag -d CG

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: xdiff: generate "anti-diffs" aka what is common to two files
  2006-06-29  4:57 xdiff: generate "anti-diffs" aka what is common to two files Linus Torvalds
  2006-06-29  6:04 ` Junio C Hamano
@ 2006-06-29 18:18 ` Davide Libenzi
  1 sibling, 0 replies; 3+ messages in thread
From: Davide Libenzi @ 2006-06-29 18:18 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Junio C Hamano, Git Mailing List

On Wed, 28 Jun 2006, Linus Torvalds wrote:

> Davide, I say it's a "fairly trivial patch", but quite frankly, I'm
> winging it. I'm not that comfortable with the libxdiff internal workings,
> so while this seems to work for me and make sense, can you please take a
> quick look.

Looks fine to me.



- Davide

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-06-29 18:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-29  4:57 xdiff: generate "anti-diffs" aka what is common to two files Linus Torvalds
2006-06-29  6:04 ` Junio C Hamano
2006-06-29 18:18 ` Davide Libenzi

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).