OPTIONS
-------
+--date-format=<fmt>::
+ Specify the type of dates the frontend will supply to
+ gfi within `author`, `committer` and `tagger` commands.
+ See ``Date Formats'' below for details about which formats
+ are supported, and their syntax.
+
--max-pack-size=<n>::
Maximum size of each output packfile, expressed in MiB.
The default is 4096 (4 GiB) as that is the maximum allowed
Frontends can use this file to validate imports after they
have been completed.
-
Performance
-----------
The design of gfi allows it to import large projects in a minimum
spaces in their name, or early termination of gfi when it encounters
unexpected input.
+Date Formats
+~~~~~~~~~~~~
+The following date formats are supported. A frontend should select
+the format it will use for this import by passing the format name
+in the `--date-format=<fmt>` command line option.
+
+`raw`::
+ This is the Git native format and is `<time> SP <tz>`.
+ It is also gfi's default format, if `--date-format` was
+ not specified.
++
+The time of the event is specified by `<time>` as the number of
+seconds since the UNIX epoch (midnight, Jan 1, 1970, UTC) and is
+written as an ASCII decimal integer.
++
+The timezone is specified by `<tz>` as a positive or negative offset
+from UTC. For example EST (which is typically 5 hours behind GMT)
+would be expressed in `<tz>` by ``-0500'' while GMT is ``+0000''.
++
+If the timezone is not available in the source material, use
+``+0000'', or the most common local timezone. For example many
+organizations have a CVS repository which has only ever been accessed
+by users who are located in the same location and timezone. In this
+case the user's timezone can be easily assumed.
++
+Unlike the `rfc2822` format, this format is very strict. Any
+variation in formatting will cause gfi to reject the value.
+
+`rfc2822`::
+ This is the standard email format as described by RFC 2822.
++
+An example value is ``Tue Feb 6 11:22:18 2007 -0500''. The Git
+parser is accurate, but a little on the lenient side. Its the
+same parser used by gitlink:git-am[1] when applying patches
+received from email.
++
+Some malformed strings may be accepted as valid dates. In some of
+these cases Git will still be able to obtain the correct date from
+the malformed string. There are also some types of malformed
+strings which Git will parse wrong, and yet consider valid.
+Seriously malformed strings will be rejected.
++
+If the source material is formatted in RFC 2822 style dates,
+the frontend should let gfi handle the parsing and conversion
+(rather than attempting to do it itself) as the Git parser has
+been well tested in the wild.
++
+Frontends should prefer the `raw` format if the source material
+is already in UNIX-epoch format, or is easily convertible to
+that format, as there is no ambiguity in parsing.
+
+`now`::
+ Always use the current time and timezone. The literal
+ `now` must always be supplied for `<when>`.
++
+This is a toy format. The current time and timezone of this system
+is always copied into the identity string at the time it is being
+created by gfi. There is no way to specify a different time or
+timezone.
++
+This particular format is supplied as its short to implement and
+may be useful to a process that wants to create a new commit
+right now, without needing to use a working directory or
+gitlink:git-update-index[1].
++
+If separate `author` and `committer` commands are used in a `commit`
+the timestamps may not match, as the system clock will be polled
+twice (once for each command). The only way to ensure that both
+author and committer identity information has the same timestamp
+is to omit `author` (thus copying from `committer`) or to use a
+date format other than `now`.
+
Commands
~~~~~~~~
gfi accepts several commands to update the current repository
....
'commit' SP <ref> LF
mark?
- ('author' SP <name> SP LT <email> GT SP <time> SP <tz> LF)?
- 'committer' SP <name> SP LT <email> GT SP <time> SP <tz> LF
+ ('author' SP <name> SP LT <email> GT SP <when> LF)?
+ 'committer' SP <name> SP LT <email> GT SP <when> LF
data
('from' SP <committish> LF)?
('merge' SP <committish> LF)?
`<name>` is free-form and may contain any sequence of bytes, except
`LT` and `LF`. It is typically UTF-8 encoded.
-The time of the change is specified by `<time>` as the number of
-seconds since the UNIX epoc (midnight, Jan 1, 1970, UTC) and is
-written as an ASCII decimal integer. The committer's
-timezone is specified by `<tz>` as a positive or negative offset
-from UTC. For example EST (which is typically 5 hours behind GMT)
-would be expressed in `<tz>` by ``-0500'' while GMT is ``+0000''.
+The time of the change is specified by `<when>` using the date format
+that was selected by the `--date-format=<fmt>` command line option.
+See ``Date Formats'' above for the set of supported formats, and
+their syntax.
`from`
^^^^^^
....
'tag' SP <name> LF
'from' SP <committish> LF
- 'tagger' SP <name> SP LT <email> GT SP <time> SP <tz> LF
+ 'tagger' SP <name> SP LT <email> GT SP <when> LF
data
LF
....
new_commit ::= 'commit' sp ref_str lf
mark?
- ('author' sp name '<' email '>' ts tz lf)?
- 'committer' sp name '<' email '>' ts tz lf
+ ('author' sp name '<' email '>' when lf)?
+ 'committer' sp name '<' email '>' when lf
commit_msg
('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
new_tag ::= 'tag' sp tag_str lf
'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
- 'tagger' sp name '<' email '>' ts tz lf
+ 'tagger' sp name '<' email '>' when lf
tag_msg;
tag_msg ::= data;
bigint ::= # unsigned integer value, ascii base10 notation;
binary_data ::= # file content, not interpreted;
+ when ::= raw_when | rfc2822_when;
+ raw_when ::= ts sp tz;
+ rfc2822_when ::= # Valid RFC 2822 date and time;
+
sp ::= # ASCII space character;
lf ::= # ASCII newline (LF) character;
unsigned char sha1[20];
};
+typedef enum {
+ WHENSPEC_RAW = 1,
+ WHENSPEC_RFC2822,
+ WHENSPEC_NOW,
+} whenspec_type;
+
/* Configured limits on output */
static unsigned long max_depth = 10;
static unsigned long max_packsize = (1LL << 32) - 1;
static struct tag *last_tag;
/* Input stream parsing */
+static whenspec_type whenspec = WHENSPEC_RAW;
static struct strbuf command_buf;
static uintmax_t next_mark;
static struct dbuf new_data;
return buffer;
}
+static int validate_raw_date(const char *src, char *result, int maxlen)
+{
+ const char *orig_src = src;
+ char *endp, sign;
+
+ strtoul(src, &endp, 10);
+ if (endp == src || *endp != ' ')
+ return -1;
+
+ src = endp + 1;
+ if (*src != '-' && *src != '+')
+ return -1;
+ sign = *src;
+
+ strtoul(src + 1, &endp, 10);
+ if (endp == src || *endp || (endp - orig_src) >= maxlen)
+ return -1;
+
+ strcpy(result, orig_src);
+ return 0;
+}
+
+static char *parse_ident(const char *buf)
+{
+ const char *gt;
+ size_t name_len;
+ char *ident;
+
+ gt = strrchr(buf, '>');
+ if (!gt)
+ die("Missing > in ident string: %s", buf);
+ gt++;
+ if (*gt != ' ')
+ die("Missing space after > in ident string: %s", buf);
+ gt++;
+ name_len = gt - buf;
+ ident = xmalloc(name_len + 24);
+ strncpy(ident, buf, name_len);
+
+ switch (whenspec) {
+ case WHENSPEC_RAW:
+ if (validate_raw_date(gt, ident + name_len, 24) < 0)
+ die("Invalid raw date \"%s\" in ident: %s", gt, buf);
+ break;
+ case WHENSPEC_RFC2822:
+ if (parse_date(gt, ident + name_len, 24) < 0)
+ die("Invalid rfc2822 date \"%s\" in ident: %s", gt, buf);
+ break;
+ case WHENSPEC_NOW:
+ if (strcmp("now", gt))
+ die("Date in ident must be 'now': %s", buf);
+ datestamp(ident + name_len, 24);
+ break;
+ }
+
+ return ident;
+}
+
static void cmd_new_blob(void)
{
size_t l;
read_next_command();
cmd_mark();
if (!strncmp("author ", command_buf.buf, 7)) {
- author = strdup(command_buf.buf);
+ author = parse_ident(command_buf.buf + 7);
read_next_command();
}
if (!strncmp("committer ", command_buf.buf, 10)) {
- committer = strdup(command_buf.buf);
+ committer = parse_ident(command_buf.buf + 10);
read_next_command();
}
if (!committer)
store_tree(&b->branch_tree);
hashcpy(b->branch_tree.versions[0].sha1,
b->branch_tree.versions[1].sha1);
- size_dbuf(&new_data, 97 + msglen
+ size_dbuf(&new_data, 114 + msglen
+ merge_count * 49
+ (author
? strlen(author) + strlen(committer)
free(merge_list);
merge_list = next;
}
- if (author)
- sp += sprintf(sp, "%s\n", author);
- else
- sp += sprintf(sp, "author %s\n", committer + 10);
- sp += sprintf(sp, "%s\n\n", committer);
+ sp += sprintf(sp, "author %s\n", author ? author : committer);
+ sp += sprintf(sp, "committer %s\n", committer);
+ *sp++ = '\n';
memcpy(sp, msg, msglen);
sp += msglen;
free(author);
/* tagger ... */
if (strncmp("tagger ", command_buf.buf, 7))
die("Expected tagger command, got %s", command_buf.buf);
- tagger = strdup(command_buf.buf);
+ tagger = parse_ident(command_buf.buf + 7);
/* tag payload/message */
read_next_command();
sp += sprintf(sp, "object %s\n", sha1_to_hex(sha1));
sp += sprintf(sp, "type %s\n", type_names[OBJ_COMMIT]);
sp += sprintf(sp, "tag %s\n", t->name);
- sp += sprintf(sp, "%s\n\n", tagger);
+ sp += sprintf(sp, "tagger %s\n", tagger);
+ *sp++ = '\n';
memcpy(sp, msg, msglen);
sp += msglen;
free(tagger);
}
static const char fast_import_usage[] =
-"git-fast-import [--depth=n] [--active-branches=n] [--export-marks=marks.file] [--branch-log=log]";
+"git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
int main(int argc, const char **argv)
{
if (*a != '-' || !strcmp(a, "--"))
break;
+ else if (!strncmp(a, "--date-format=", 14)) {
+ const char *fmt = a + 14;
+ if (!strcmp(fmt, "raw"))
+ whenspec = WHENSPEC_RAW;
+ else if (!strcmp(fmt, "rfc2822"))
+ whenspec = WHENSPEC_RFC2822;
+ else if (!strcmp(fmt, "now"))
+ whenspec = WHENSPEC_NOW;
+ else
+ die("unknown --date-format argument %s", fmt);
+ }
else if (!strncmp(a, "--max-pack-size=", 16))
max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;
else if (!strncmp(a, "--depth=", 8))