git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] fast-export: output reset command for commandline revs

From
Sverre Rabbelier <srabbelier@gmail.com>
Date
Nov 5, 2011, 23:23 UTC
Message-ID
<1320535407-4933-4-git-send-email-srabbelier@gmail.com>
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
Previous: Johannes SchindelinNext: Jonathan Nieder
Message 35 of 42 in “fast-export fixes”
  1. 0/3 fast-export fixesSverre Rabbelier, Nov 5, 2011
  2. 1/3 t9350: point out that refs are not updated correctlySverre Rabbelier, Nov 5, 2011
  3. Jonathan NiederNov 6, 2011
  4. Sverre RabbelierNov 6, 2011
  5. Jonathan NiederNov 7, 2011
  6. Felipe ContrerasOct 24, 2012
  7. Jonathan NiederOct 24, 2012
  8. Felipe ContrerasOct 24, 2012
  9. Jonathan NiederOct 24, 2012
  10. Felipe ContrerasOct 25, 2012
  11. Jonathan NiederOct 25, 2012
  12. Felipe ContrerasOct 25, 2012
  13. Jonathan NiederOct 25, 2012
  14. Sverre RabbelierOct 25, 2012
  15. Felipe ContrerasOct 25, 2012
  16. Sverre RabbelierOct 25, 2012
  17. Felipe ContrerasOct 25, 2012
  18. Sverre RabbelierOct 25, 2012
  19. Jonathan NiederOct 25, 2012
  20. Sverre RabbelierOct 25, 2012
  21. Jonathan NiederOct 25, 2012
  22. Sverre RabbelierOct 25, 2012
  23. Felipe ContrerasOct 25, 2012
  24. Felipe ContrerasOct 25, 2012
  25. Jonathan NiederOct 25, 2012
  26. Felipe ContrerasOct 25, 2012
  27. Jonathan NiederOct 25, 2012
  28. Felipe ContrerasOct 25, 2012
  29. Johannes SchindelinOct 24, 2012
  30. Felipe ContrerasOct 25, 2012
  31. 2/3 fast-export: do not refer to non-existing marksSverre Rabbelier, Nov 5, 2011
  32. Jonathan NiederNov 6, 2011
  33. Sverre RabbelierNov 6, 2011
  34. Johannes SchindelinJan 29, 2019
  35. 3/3 fast-export: output reset command for commandline revsSverre Rabbelier, Nov 5, 2011
  36. Jonathan NiederNov 6, 2011
  37. Sverre RabbelierNov 6, 2011
  38. Jonathan NiederNov 7, 2011
  39. Junio C HamanoNov 7, 2011
  40. Junio C HamanoNov 7, 2011
  41. Thomas RastNov 30, 2011
  42. Felipe ContrerasOct 24, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.