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

[PATCH v7 2/6] fast-import: put marks reading in it's own function

From
Sverre Rabbelier <srabbelier@gmail.com>
Date
Sep 6, 2009, 14:35 UTC
Message-ID
<1252247748-14507-3-git-send-email-srabbelier@gmail.com>
In-Reply-To
<1252247748-14507-2-git-send-email-srabbelier@gmail.com>

All options do nothing but set settings, with the exception of the --input-marks option. Delay the reading of the marks file till after all options have been parsed.

Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
---
  Unchanged again.
 fast-import.c |   73 ++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 41 insertions(+), 32 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index b904f20..812fcf0 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -315,6 +315,7 @@ static struct object_entry_pool *blocks;
 static struct object_entry *object_table[1 << 16];
 static struct mark_set *marks;
 static const char *mark_file;
+static const char *input_file;
 
 /* Our last blob */
 static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
@@ -1643,6 +1644,42 @@ static void dump_marks(void)
 	}
 }
 
+static void read_marks(void)
+{
+	char line[512];
+	FILE *f = fopen(input_file, "r");
+	if (!f)
+		die_errno("cannot read '%s'", input_file);
+	while (fgets(line, sizeof(line), f)) {
+		uintmax_t mark;
+		char *end;
+		unsigned char sha1[20];
+		struct object_entry *e;
+
+		end = strchr(line, '\n');
+		if (line[0] != ':' || !end)
+			die("corrupt mark line: %s", line);
+		*end = 0;
+		mark = strtoumax(line + 1, &end, 10);
+		if (!mark || end == line + 1
+			|| *end != ' ' || get_sha1(end + 1, sha1))
+			die("corrupt mark line: %s", line);
+		e = find_object(sha1);
+		if (!e) {
+			enum object_type type = sha1_object_info(sha1, NULL);
+			if (type < 0)
+				die("object not found: %s", sha1_to_hex(sha1));
+			e = insert_object(sha1);
+			e->type = type;
+			e->pack_id = MAX_PACK_ID;
+			e->offset = 1; /* just not zero! */
+		}
+		insert_mark(mark, e);
+	}
+	fclose(f);
+}
+
+
 static int read_next_command(void)
 {
 	static int stdin_eof = 0;
@@ -2338,39 +2375,9 @@ static void parse_progress(void)
 	skip_optional_lf();
 }
 
-static void option_import_marks(const char *input_file)
+static void option_import_marks(const char *marks)
 {
-	char line[512];
-	FILE *f = fopen(input_file, "r");
-	if (!f)
-		die_errno("cannot read '%s'", input_file);
-	while (fgets(line, sizeof(line), f)) {
-		uintmax_t mark;
-		char *end;
-		unsigned char sha1[20];
-		struct object_entry *e;
-
-		end = strchr(line, '\n');
-		if (line[0] != ':' || !end)
-			die("corrupt mark line: %s", line);
-		*end = 0;
-		mark = strtoumax(line + 1, &end, 10);
-		if (!mark || end == line + 1
-			|| *end != ' ' || get_sha1(end + 1, sha1))
-			die("corrupt mark line: %s", line);
-		e = find_object(sha1);
-		if (!e) {
-			enum object_type type = sha1_object_info(sha1, NULL);
-			if (type < 0)
-				die("object not found: %s", sha1_to_hex(sha1));
-			e = insert_object(sha1);
-			e->type = type;
-			e->pack_id = MAX_PACK_ID;
-			e->offset = 1; /* just not zero! */
-		}
-		insert_mark(mark, e);
-	}
-	fclose(f);
+	input_file = xstrdup(marks);
 }
 
 static void option_date_format(const char *fmt)
@@ -2495,6 +2502,8 @@ int main(int argc, const char **argv)
 	}
 	if (i != argc)
 		usage(fast_import_usage);
+	if (input_file)
+		read_marks();
 
 	rc_free = pool_alloc(cmd_save * sizeof(*rc_free));
 	for (i = 0; i < (cmd_save - 1); i++)
-- 
1.6.4.16.g72c66.dirty
Previous: Sverre RabbelierNext: Sverre Rabbelier
Message 3 of 15 in “fast-import: add new feature and option command”
  1. 0/6 fast-import: add new feature and option commandSverre Rabbelier, Sep 6, 2009
  2. 1/6 fast-import: put option parsing code in separate functionsSverre Rabbelier, Sep 6, 2009
  3. 2/6 fast-import: put marks reading in it's own functionSverre Rabbelier, Sep 6, 2009
  4. 3/6 fast-import: add feature commandSverre Rabbelier, Sep 6, 2009
  5. 4/6 fast-import: test the new feature commandSverre Rabbelier, Sep 6, 2009
  6. 5/6 fast-import: add option commandSverre Rabbelier, Sep 6, 2009
  7. 6/6 fast-import: test the new option commandSverre Rabbelier, Sep 6, 2009
  8. Shawn O. PearceSep 12, 2009
  9. Sverre RabbelierSep 12, 2009
  10. Shawn O. PearceSep 12, 2009
  11. Sverre RabbelierSep 12, 2009
  12. Miklos VajnaSep 13, 2009
  13. Shawn O. PearceSep 12, 2009
  14. Sverre RabbelierSep 12, 2009
  15. Shawn O. PearceSep 12, 2009

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.