git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Subject: Re: A note on merging conflicts..
Date: Sat, 1 Jul 2006 20:13:09 +0200	[thread overview]
Message-ID: <20060701181309.GA29199@lsrfire.ath.cx> (raw)
In-Reply-To: <Pine.LNX.4.64.0607010921450.12404@g5.osdl.org>

On Sat, Jul 01, 2006 at 09:25:43AM -0700, Linus Torvalds wrote:
> 
> 
> On Sat, 1 Jul 2006, Rene Scharfe wrote:
> > 
> > You mean something like the following patch on top of the 'next' branch?
> > It also documents the --not switch because I needed it for the example.
> 
> Yes. 
> 
> However, I think that 90% of the code for the ".." and "..." case are the 
> same, as is largely the finding of it.
> 
> So why not just do this all inside the already existing
> 
> 	dotdot = strstr(arg, "..");
> 	if (dotdot) {
> 		unsigned char other_sha1[20];
> 		const char *one = arg;
> 		const char *two = arg + 2;
> 		int symmetric = *two == '.';
> 
> 		*dotdot = '\0';
> 		two += symmetric;
> 
> 		if (one == arg)
> 			one = "HEAD";
> 		if (!*two)
> 			two = "HEAD";
> 		...
> 
> because the only difference is really at the very end.

Hrm, I'm not sure this is really cleaner.  The two operators consist
of all dots only coincidentally, this is not functionally inherent.
So I think it's better to keep them apart.

Let's see..  [Time passes.  A patch materializes at six o'clock.]

With a little helper factored out this doesn't look as bad as I
imagined.  Maybe we can take it.  What do you think?

> Did you test that it looks correct too?

Sort of; I checked that the two forms (with ... and $(git-merge-base))
gave the same results for 7b8cf0cf and 51d1e83f, that's all.  For a
proper test script we'd need to create a repo for which git-merge-base
can report multiple results.  I wasn't able to come up with the needed
commands without thinking and gave up for now.  Am working on it..

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>

diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index ad6d14c..6c370e1 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -15,6 +15,7 @@ SYNOPSIS
 	     [ \--sparse ]
 	     [ \--no-merges ]
 	     [ \--remove-empty ]
+	     [ \--not ]
 	     [ \--all ]
 	     [ \--topo-order ]
 	     [ \--parents ]
@@ -37,6 +38,14 @@ not in 'baz'".
 A special notation <commit1>..<commit2> can be used as a
 short-hand for {caret}<commit1> <commit2>.
 
+Another special notation is <commit1>...<commit2> which is useful for
+merges.  The resulting set of commits is the symmetric difference
+between the two operands.  The following two commands are equivalent:
+
+------------
+$ git-rev-list A B --not $(git-merge-base --all A B)
+$ git-rev-list A...B
+------------
 
 OPTIONS
 -------
@@ -93,6 +102,11 @@ OPTIONS
 --remove-empty::
 	Stop when a given path disappears from the tree.
 
+--not::
+	Reverses the meaning of the '{caret}' prefix (or lack
+	thereof) for all following revision specifiers, up to
+	the next `--not`.
+
 --all::
 	Pretend as if all the refs in `$GIT_DIR/refs/` are
 	listed on the command line as <commit>.
diff --git a/revision.c b/revision.c
index ae4ca82..bcedf66 100644
--- a/revision.c
+++ b/revision.c
@@ -536,6 +536,18 @@ void init_revisions(struct rev_info *rev
 	diff_setup(&revs->diffopt);
 }
 
+static void add_pending_commit_list(struct rev_info *revs,
+                                    struct commit_list *commit_list,
+                                    unsigned int flags)
+{
+	while (commit_list) {
+		struct object *object = &commit_list->item->object;
+		object->flags |= flags;
+		add_pending_object(revs, object, sha1_to_hex(object->sha1));
+		commit_list = commit_list->next;
+	}
+}
+
 /*
  * Parse revision information, filling in the "rev_info" structure,
  * and removing the used arguments from the argument list.
@@ -771,27 +783,45 @@ int setup_revisions(int argc, const char
 			unsigned char from_sha1[20];
 			const char *next = dotdot + 2;
 			const char *this = arg;
+			int symmetric = *next == '.';
+			unsigned int flags_exclude = flags ^ UNINTERESTING;
+
 			*dotdot = 0;
+			next += symmetric;
+
 			if (!*next)
 				next = "HEAD";
 			if (dotdot == arg)
 				this = "HEAD";
 			if (!get_sha1(this, from_sha1) &&
 			    !get_sha1(next, sha1)) {
-				struct object *exclude;
-				struct object *include;
-
-				exclude = get_reference(revs, this, from_sha1, flags ^ UNINTERESTING);
-				include = get_reference(revs, next, sha1, flags);
-				if (!exclude || !include)
-					die("Invalid revision range %s..%s", arg, next);
+				struct commit *a, *b;
+				struct commit_list *exclude;
+
+				a = lookup_commit_reference(from_sha1);
+				b = lookup_commit_reference(sha1);
+				if (!a || !b) {
+					die(symmetric ?
+					    "Invalid symmetric difference expression %s...%s" :
+					    "Invalid revision range %s..%s",
+					    arg, next);
+				}
 
 				if (!seen_dashdash) {
 					*dotdot = '.';
 					verify_non_filename(revs->prefix, arg);
 				}
-				add_pending_object(revs, exclude, this);
-				add_pending_object(revs, include, next);
+
+				if (symmetric) {
+					exclude = get_merge_bases(a, b);
+					add_pending_commit_list(revs, exclude,
+					                        flags_exclude);
+					a->object.flags |= flags;
+				} else
+					a->object.flags |= flags_exclude;
+				b->object.flags |= flags;
+				add_pending_object(revs, &a->object, this);
+				add_pending_object(revs, &b->object, next);
 				continue;
 			}
 			*dotdot = '.';

  reply	other threads:[~2006-07-01 18:13 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-01  2:44 A note on merging conflicts Linus Torvalds
2006-07-01  3:08 ` Junio C Hamano
2006-07-01  3:54   ` Linus Torvalds
2006-07-01  3:59     ` Linus Torvalds
2006-07-01 15:09     ` Rene Scharfe
2006-07-01 15:23       ` Johannes Schindelin
2006-07-01 16:25       ` Linus Torvalds
2006-07-01 18:13         ` Rene Scharfe [this message]
2006-07-01 18:01       ` J. Bruce Fields
2006-07-01 18:20         ` Linus Torvalds
2006-07-01 22:24           ` Daniel Barkalow
2006-07-01 22:57             ` Linus Torvalds
2006-07-01 23:25               ` Daniel Barkalow
2006-07-01 23:45                 ` Daniel Barkalow
2006-07-02 11:31                   ` Rene Scharfe
2006-07-02 21:42                     ` Daniel Barkalow
2006-07-02  0:08                 ` Linus Torvalds
2006-07-01 18:22         ` Jakub Narebski
2006-07-01 18:52           ` Linus Torvalds
2006-07-01 18:37       ` Junio C Hamano
2006-07-01 19:29         ` Rene Scharfe
2006-07-01 19:56           ` Junio C Hamano
2006-07-01 23:01             ` Johannes Schindelin
2006-07-01 20:04           ` Linus Torvalds
2006-07-01 20:07             ` Junio C Hamano
2006-07-01 20:14               ` Junio C Hamano
2006-07-01 23:29                 ` [PATCH 1/3] Add get_merge_bases_clean() Rene Scharfe
2006-07-01 23:43                   ` Johannes Schindelin
2006-07-01 23:29                 ` [PATCH 2/3] Add '...' operator for revisions Rene Scharfe
2006-07-01 23:29                 ` [PATCH 3/3] Make clear_commit_marks() clean harder Rene Scharfe
2006-07-03  9:32                   ` Junio C Hamano
2006-07-03 13:56                     ` Johannes Schindelin
2006-07-03 17:05                       ` Linus Torvalds
2006-07-03 21:08                         ` Johannes Schindelin
2006-07-03 19:47                       ` Junio C Hamano
2006-07-03 21:12                         ` Johannes Schindelin
2006-07-03 22:55                           ` Linus Torvalds
2006-07-04  7:53                             ` Johannes Schindelin
2006-07-04  8:20                               ` Junio C Hamano
2006-07-02  9:49                 ` [PATCH 4/3] Fold get_merge_bases_clean() into get_merge_bases() Rene Scharfe
2006-07-02  9:56                   ` Johannes Schindelin
2006-07-02 16:43                   ` Linus Torvalds
2006-07-02 17:40                     ` Rene Scharfe
2006-07-02 18:28                       ` Junio C Hamano
2006-07-02 20:59                         ` Rene Scharfe
2006-07-02 21:15                           ` Rene Scharfe
2006-07-02 21:17                           ` Linus Torvalds
2006-07-02 20:44                       ` Linus Torvalds
2006-07-07  8:26 ` A note on merging conflicts Junio C Hamano

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=20060701181309.GA29199@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=torvalds@osdl.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).