git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Sverre Rabbelier <srabbelier@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Jonathan Nieder <jrnieder@gmail.com>, Jeff King <peff@peff.net>,
	Git List <git@vger.kernel.org>,
	Daniel Barkalow <barkalow@iabervon.org>,
	Ramkumar
Cc: Sverre Rabbelier <srabbelier@gmail.com>
Subject: [PATCH 3/3] fast-export: output reset command for commandline revs
Date: Sun,  6 Nov 2011 00:23:27 +0100	[thread overview]
Message-ID: <1320535407-4933-4-git-send-email-srabbelier@gmail.com> (raw)
In-Reply-To: <1320535407-4933-1-git-send-email-srabbelier@gmail.com>

When a revision is specified on the commandline we explicitly output
a 'reset' command for it if it was not handled already. This allows
for example the remote-helper protocol to use fast-export to create
branches that point to a commit that has already been exported.

Initial-patch-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
---

  Most of the hard work for this patch was done by Dscho. The rest of
  it was basically me applying the technique used by jch in c3502fa
  (25-08-2011 do not include sibling history in --ancestry-path).

  The if statement dealing with tag_of_filtered_mode is not as
  elegant as either me or Dscho would have liked, but we couldn't
  find a better way to determine if a ref is a tag at this point
  in the code.

  Additionally, the elem->whence != REV_CMD_RIGHT case should really
  check if REV_CMD_RIGHT_REF, but as this is not provided by the
  ref_info structure this is left as is. A result of this is that
  incorrect input will result in incorrect output, rather than an
  error message. That is: `git fast-export a..<sha1>` will
  incorrectly generate a `reset <sha1>` statement in the fast-export
  stream.

  The dwim_ref bit is a double work (it has already been done by the
  caller of this function), but I decided it would be more work to
  pass this information along than to recompute it for the few
  commandline refs that were relevant.

 builtin/fast-export.c  |   31 +++++++++++++++++++++++++++++--
 t/t9350-fast-export.sh |    2 +-
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index c4c4391..bcfec38 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -18,6 +18,8 @@
 #include "parse-options.h"
 #include "quote.h"
 
+#define REF_HANDLED (ALL_REV_FLAGS + 1)
+
 static const char *fast_export_usage[] = {
 	"git fast-export [rev-list-opts]",
 	NULL
@@ -541,10 +543,34 @@ static void handle_reset(const char *name, struct object *object)
 		       sha1_to_hex(object->sha1));
 }
 
-static void handle_tags_and_duplicates(struct string_list *extra_refs)
+static void handle_tags_and_duplicates(struct rev_info *revs, struct string_list *extra_refs)
 {
 	int i;
 
+	/* even if no commits were exported, we need to export the ref */
+	for (i = 0; i < revs->cmdline.nr; i++) {
+		struct rev_cmdline_entry *elem = &revs->cmdline.rev[i];
+
+		if (elem->flags & UNINTERESTING)
+			continue;
+
+		if (elem->whence != REV_CMD_REV && elem->whence != REV_CMD_RIGHT)
+			continue;
+
+		char *full_name;
+		dwim_ref(elem->name, strlen(elem->name), elem->item->sha1, &full_name);
+
+		if (!prefixcmp(full_name, "refs/tags/") &&
+			(tag_of_filtered_mode != REWRITE ||
+			!get_object_mark(elem->item)))
+			continue;
+
+		if (!(elem->flags & REF_HANDLED)) {
+			handle_reset(full_name, elem->item);
+			elem->flags |= REF_HANDLED;
+		}
+	}
+
 	for (i = extra_refs->nr - 1; i >= 0; i--) {
 		const char *name = extra_refs->items[i].string;
 		struct object *object = extra_refs->items[i].util;
@@ -698,11 +724,12 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 		}
 		else {
 			handle_commit(commit, &revs);
+			commit->object.flags |= REF_HANDLED;
 			handle_tail(&commits, &revs);
 		}
 	}
 
-	handle_tags_and_duplicates(&extra_refs);
+	handle_tags_and_duplicates(&revs, &extra_refs);
 
 	if (export_filename)
 		export_marks(export_filename);
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index 74914dc..ea7dc21 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -446,7 +446,7 @@ from $(git rev-parse master)
 
 EOF
 
-test_expect_failure 'refs are updated even if no commits need to be exported' '
+test_expect_success 'refs are updated even if no commits need to be exported' '
 	git fast-export master..master > actual &&
 	test_cmp expected actual
 '
-- 
1.7.8.rc0.36.g67522.dirty

  parent reply	other threads:[~2011-11-05 23:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-05 23:23 [PATCH 0/3] fast-export fixes Sverre Rabbelier
2011-11-05 23:23 ` [PATCH 1/3] t9350: point out that refs are not updated correctly Sverre Rabbelier
2011-11-06  4:31   ` Jonathan Nieder
2011-11-06 19:38     ` Sverre Rabbelier
2011-11-07  9:32       ` Jonathan Nieder
2012-10-24 17:52   ` Felipe Contreras
2012-10-24 18:08     ` Jonathan Nieder
2012-10-24 19:09       ` Felipe Contreras
2012-10-24 19:11         ` Jonathan Nieder
2012-10-25  4:19           ` Felipe Contreras
2012-10-25  4:27             ` Jonathan Nieder
2012-10-25  5:18               ` Felipe Contreras
2012-10-25  5:28                 ` Jonathan Nieder
2012-10-25  5:39                   ` Sverre Rabbelier
2012-10-25  5:50                     ` Felipe Contreras
2012-10-25  6:07                       ` Sverre Rabbelier
2012-10-25  6:19                         ` Felipe Contreras
2012-10-25  7:06                           ` Sverre Rabbelier
2012-10-25  7:34                             ` Jonathan Nieder
2012-10-25  7:43                               ` Sverre Rabbelier
2012-10-25  7:48                                 ` Jonathan Nieder
2012-10-25  7:50                                   ` Sverre Rabbelier
2012-10-25 13:33                                     ` Felipe Contreras
2012-10-25  5:40                   ` Felipe Contreras
2012-10-25  5:53                     ` Jonathan Nieder
2012-10-25  6:39                       ` Felipe Contreras
2012-10-25  7:18                         ` Jonathan Nieder
2012-10-25 16:43                           ` Felipe Contreras
2012-10-24 21:41     ` Johannes Schindelin
2012-10-25  5:13       ` Felipe Contreras
2011-11-05 23:23 ` [PATCH 2/3] fast-export: do not refer to non-existing marks Sverre Rabbelier
2011-11-06  4:45   ` Jonathan Nieder
2011-11-06 19:40     ` Sverre Rabbelier
2019-01-29 19:41       ` Johannes Schindelin
2011-11-05 23:23 ` Sverre Rabbelier [this message]
2011-11-06  5:01   ` [PATCH 3/3] fast-export: output reset command for commandline revs Jonathan Nieder
2011-11-06 19:48     ` Sverre Rabbelier
2011-11-07  8:58       ` Jonathan Nieder
2011-11-07  5:52   ` Junio C Hamano
2011-11-07  5:53   ` Junio C Hamano
2011-11-30 16:56   ` Thomas Rast
2012-10-24 18:02   ` Felipe Contreras

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1320535407-4933-4-git-send-email-srabbelier@gmail.com \
    --to=srabbelier@gmail.com \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).