fast-import: add new feature and option command
v8 cover fast-import: add new feature and option command
This reroll addressess comments from Shawn and the fast-import mailing list. It also adds a new feature, "relative-marks", which will be very useful for remote helpers.
Apologies for taking so long with the reroll, hopefully this version is good for next and I can finish my git-remote-hg work :).
Sverre Rabbelier (7):
fast-import: put option parsing code in separate functions
fast-import: put marks reading in it's own function
fast-import: add feature command
fast-import: add option command
fast-import: test the new option command
fast-import: allow for multiple --import-marks= arguments
fast-import: add (non-)relative-marks feature
Documentation/git-fast-import.txt | 79 +++++++++ fast-import.c | 317 +++++++++++++++++++++++++++---------- t/t9300-fast-import.sh | 152 ++++++++++++++++++ 3 files changed, 462 insertions(+), 86 deletions(-)
PATCH v8 1/7 fast-import: put option parsing code in separate functions
Putting the options in their own functions increases readability of the option parsing block and makes it easier to reuse the option parsing code later on.
---
Rebased against current master, no other changes.
fast-import.c | 115 +++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 75 insertions(+), 40 deletions(-)
fast-import.c +75 -40
@@ -295,6 +295,7 @@ static unsigned long branch_count;static unsigned long branch_load_count;static int failure;static FILE *pack_edges; +static unsigned int show_stats =1 ;/* Memory pools */ static size_t mem_pool_alloc =2 *1024 *1024 -sizeof (struct mem_pool );
@@ -2420,7 +2421,7 @@ static void parse_progress(void)skip_optional_lf (); } -static void import_marks (const char *input_file) +static void option_import_marks (const char *input_file) {char line[512 ];FILE *f =fopen (input_file,"r" );
@@ -2455,6 +2456,76 @@ static void import_marks(const char *input_file)fclose (f); } +static void option_date_format (const char *fmt) +{ +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); +} + +static void option_max_pack_size (const char *packsize) +{ + max_packsize =strtoumax (packsize,NULL ,0 ) *1024 *1024 ; +} + +static void option_depth (const char *depth) +{ + max_depth =strtoul (depth,NULL ,0 ); +if (max_depth >MAX_DEPTH ) +die ("--depth cannot exceed %u" ,MAX_DEPTH ); +} + +static void option_active_branches (const char *branches) +{ + max_active_branches =strtoul (branches,NULL ,0 ); +} + +static void option_export_marks (const char *marks) +{ + mark_file =xstrdup (marks); +} + +static void option_export_pack_edges (const char *edges) +{ +if (pack_edges) +fclose (pack_edges); + pack_edges =fopen (edges,"a" ); +if (!pack_edges) +die_errno ("Cannot open '%s'" , edges); +} + +static void parse_one_option (const char *option) +{ +if (!prefixcmp (option,"date-format=" )) { +option_date_format (option +12 ); + }else if (!prefixcmp (option,"max-pack-size=" )) { +option_max_pack_size (option +14 ); + }else if (!prefixcmp (option,"depth=" )) { +option_depth (option +6 ); + }else if (!prefixcmp (option,"active-branches=" )) { +option_active_branches (option +16 ); + }else if (!prefixcmp (option,"import-marks=" )) { +option_import_marks (option +13 ); + }else if (!prefixcmp (option,"export-marks=" )) { +option_export_marks (option +13 ); + }else if (!prefixcmp (option,"export-pack-edges=" )) { +option_export_pack_edges (option +18 ); + }else if (!prefixcmp (option,"force" )) { + force_update =1 ; + }else if (!prefixcmp (option,"quiet" )) { + show_stats =0 ; + }else if (!prefixcmp (option,"stats" )) { + show_stats =1 ; + }else { +die ("Unsupported option: %s" , option); + } +} +static int git_pack_config (const char *k,const char *v,void *cb) {if (!strcmp (k,"pack.depth" )) {
@@ -2481,7 +2552,7 @@ static const char fast_import_usage[] =int main (int argc,const char **argv) { -unsigned int i, show_stats =1 ; +unsigned int i;git_extract_argv0_path (argv[0 ]);
@@ -2505,44 +2576,8 @@ int main(int argc, const char **argv)if (*a !='-' || !strcmp (a,"--" ))break ; -else if (!prefixcmp (a,"--date-format=" )) { -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 (!prefixcmp (a,"--max-pack-size=" )) - max_packsize =strtoumax (a +16 ,NULL ,0 ) *1024 *1024 ; -else if (!prefixcmp (a,"--depth=" )) { - max_depth =strtoul (a +8 ,NULL ,0 ); -if (max_depth >MAX_DEPTH ) -die ("--depth cannot exceed %u" ,MAX_DEPTH ); - } -else if (!prefixcmp (a,"--active-branches=" )) - max_active_branches =strtoul (a +18 ,NULL ,0 ); -else if (!prefixcmp (a,"--import-marks=" )) -import_marks (a +15 ); -else if (!prefixcmp (a,"--export-marks=" )) - mark_file = a +15 ; -else if (!prefixcmp (a,"--export-pack-edges=" )) { -if (pack_edges) -fclose (pack_edges); - pack_edges =fopen (a +20 ,"a" ); -if (!pack_edges) -die_errno ("Cannot open '%s'" , a +20 ); - }else if (!strcmp (a,"--force" )) - force_update =1 ; -else if (!strcmp (a,"--quiet" )) - show_stats =0 ; -else if (!strcmp (a,"--stats" )) - show_stats =1 ; -else -die ("unknown option %s" , a); + +parse_one_option (a +2 ); }if (i != argc)usage (fast_import_usage);
Signature · 1 line
1.6.5.3.164.g07b0c
PATCH v8 2/7 fast-import: put marks reading in it's own function
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.
Also, rename mark_file to export_marks_file as it is now ambiguous.
---
Renamed mark_fiel to export_marks_file and added import_marks_file as per Shawn's comments.
fast-import.c | 93 +++++++++++++++++++++++++++++++------------------------- 1 files changed, 51 insertions(+), 42 deletions(-)
fast-import.c +51 -42
@@ -318,7 +318,8 @@ static unsigned int object_entry_alloc = 5000;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 *export_marks_file; +static const char *import_marks_file;/* Our last blob */ static struct last_object last_blob = {STRBUF_INIT ,0 ,0 ,0 };
@@ -455,8 +456,8 @@ static void write_crash_report(const char *err)fputc ('\n' , rpt);fputs ("Marks\n" , rpt);fputs ("-----\n" , rpt); -if (mark_file) -fprintf (rpt," exported to %s\n" , mark_file); +if (export_marks_file) +fprintf (rpt," exported to %s\n" , export_marks_file);else dump_marks_helper (rpt,0 , marks);
@@ -1603,13 +1604,13 @@ static void dump_marks(void)int mark_fd;FILE *f; -if (!mark_file) +if (!export_marks_file)return ; - mark_fd =hold_lock_file_for_update (&mark_lock, mark_file,0 ); + mark_fd =hold_lock_file_for_update (&mark_lock, export_marks_file,0 );if (mark_fd <0 ) { failure |=error ("Unable to write marks file %s: %s" , - mark_file,strerror (errno)); + export_marks_file,strerror (errno));return ; }
@@ -1618,7 +1619,7 @@ static void dump_marks(void)int saved_errno = errno;rollback_lock_file (&mark_lock); failure |=error ("Unable to write marks file %s: %s" , - mark_file,strerror (saved_errno)); + export_marks_file,strerror (saved_errno));return ; }
@@ -1634,7 +1635,7 @@ static void dump_marks(void)int saved_errno = errno;rollback_lock_file (&mark_lock); failure |=error ("Unable to write marks file %s: %s" , - mark_file,strerror (saved_errno)); + export_marks_file,strerror (saved_errno));return ; }
@@ -1642,11 +1643,47 @@ static void dump_marks(void)int saved_errno = errno;rollback_lock_file (&mark_lock); failure |=error ("Unable to commit marks file %s: %s" , - mark_file,strerror (saved_errno)); + export_marks_file,strerror (saved_errno));return ; } } +static void read_marks (void ) +{ +char line[512 ]; +FILE *f =fopen (import_marks_file,"r" ); +if (!f) +die_errno ("cannot read '%s'" , import_marks_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 ;
@@ -2421,39 +2458,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); + import_marks_file =xstrdup (marks); }static void option_date_format (const char *fmt)
@@ -2487,7 +2494,7 @@ static void option_active_branches(const char *branches)static void option_export_marks (const char *marks) { - mark_file =xstrdup (marks); + export_marks_file =xstrdup (marks); }static void option_export_pack_edges (const char *edges)
@@ -2581,6 +2588,8 @@ int main(int argc, const char **argv) }if (i != argc)usage (fast_import_usage); +if (import_marks_file) +read_marks (); rc_free =pool_alloc (cmd_save *sizeof (*rc_free));for (i =0 ; i < (cmd_save -1 ); i++)
Signature · 1 line
1.6.5.3.164.g07b0c
PATCH v8 3/7 fast-import: add feature command
This allows the fronted to require a specific feature to be supported by the frontend, or abort.
Also add support for four initial feature, date-format=, force=, import-marks=, export-marks=.
---
Updated documentation, reject feature commands after a data command, as per Shawn's comments. Also factor out parse_one_feature from parse_feature so that we can re-use it in patch 4/7.
This also has the previous 4/6 squashed in (which added tests)
Documentation/git-fast-import.txt | 25 +++++++++++++ fast-import.c | 38 ++++++++++++++++++++ t/t9300-fast-import.sh | 70 +++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 0 deletions(-)
Documentation/git-fast-import.txt +25 -0
@@ -303,6 +303,10 @@ and control the current import process. More detailed discussion standard output. This command is optional and is not needed to perform an import. +`feature`:: + Require that fast-import supports the specified feature, or + abort if it does not. + `commit` ~~~~~~~~ Create or update a branch with a new commit, recording one logical
@@ -846,6 +850,27 @@ Placing a `progress` command immediately after a `checkpoint` will inform the reader when the `checkpoint` has been completed and it can safely access the refs that fast-import updated. +`feature` +~~~~~~~~~ +Require that fast-import supports the specified feature, or abort if +it does not. + +.... + 'feature' SP <feature> LF +.... + +The <feature> part of the command may be any string matching +^[a-zA-Z][a-zA-Z-]*$ and should be understood by fast-import. + +Feature work identical as their option counterparts. + +The following features are currently supported: + +* date-format +* import-marks +* export-marks +* force + Crash Reports ------------- If fast-import is supplied invalid input it will terminate with a
fast-import.c +38 -0
@@ -353,6 +353,7 @@ static struct recent_command *rc_free;static unsigned int cmd_save =100 ;static uintmax_t next_mark;static struct strbuf new_data =STRBUF_INIT ; +static int seen_data_command;static void write_branch_report (FILE *rpt,struct branch *b) {
@@ -1704,6 +1705,11 @@ static int read_next_command(void)if (stdin_eof)return EOF ; +if (!seen_data_command + &&prefixcmp (command_buf.buf,"feature " )) { + seen_data_command =1 ; + } + rc = rc_free;if (rc) rc_free = rc->next;
@@ -2533,6 +2539,36 @@ static void parse_one_option(const char *option) } } +static int parse_one_feature (const char *feature) +{ +if (!prefixcmp (feature,"date-format=" )) { +option_date_format (feature +12 ); + }else if (!prefixcmp (feature,"import-marks=" )) { +option_import_marks (feature +13 ); + }else if (!prefixcmp (feature,"export-marks=" )) { +option_export_marks (feature +13 ); + }else if (!prefixcmp (feature,"force" )) { + force_update =1 ; + }else { +return 0 ; + } + +return 1 ; +} + +static void parse_feature (void ) +{ +char *feature = command_buf.buf +8 ; + +if (seen_data_command) +die ("Got feature command '%s' after data command" , feature); + +if (parse_one_feature (feature)) +return ; + +die ("This version of fast-import does not support feature %s." , feature); +} +static int git_pack_config (const char *k,const char *v,void *cb) {if (!strcmp (k,"pack.depth" )) {
@@ -2612,6 +2648,8 @@ int main(int argc, const char **argv)parse_checkpoint (); else if (!prefixcmp(command_buf.buf, "progress "))parse_progress (); + else if (!prefixcmp(command_buf.buf, "feature ")) +parse_feature (); else die("Unsupported command: %s", command_buf.buf); }
t/t9300-fast-import.sh +70 -0
74 lines not on this page · raw message
Signature · 1 line
1.6.5.3.164.g07b0c
PATCH v8 4/7 fast-import: add option command
This allows the frontend to specify any of the supported options as long as no non-option command has been given. This way the user does not have to include any frontend-specific options, but instead she can rely on the frontend to tell fast-import what it needs.
Also factor out parsing of argv and have it execute when we reach the first non-option command, or after all commands have been read and no non-option command has been encountered.
Non-git options are ignored, unrecognised options result in an error.
---
Reject unknown options, update documentation, and some style fixes.
Documentation/git-fast-import.txt | 32 +++++++++++++ fast-import.c | 87 ++++++++++++++++++++++++++----------- 2 files changed, 94 insertions(+), 25 deletions(-)
Documentation/git-fast-import.txt +32 -0
@@ -307,6 +307,11 @@ and control the current import process. More detailed discussion Require that fast-import supports the specified feature, or abort if it does not. +`option`:: + Specify any of the options listed under OPTIONS that do not + change stream semantic to suit the frontend's needs. This + command is optional and is not needed to perform an import. + `commit` ~~~~~~~~ Create or update a branch with a new commit, recording one logical
@@ -871,6 +876,33 @@ The following features are currently supported: * export-marks * force +`option` +~~~~~~~~ +Processes the specified option so that git fast-import behaves in a +way that suits the frontend's needs. +Note that options specified by the frontend are overridden by any +options the user may specify to git fast-import itself. + +.... + 'option' SP <option> LF +.... + +The `<option>` part of the command may contain any of the options +listed in the OPTIONS section that do not change import semantics, +without the leading '--' and is treated in the same way. + +Option commands must be the first commands on the input (not counting +feature commands), to give an option command after any non-option +command is an error. + +The following commandline options change import semantics and may therefore +not be passed as option: + +* date-format +* import-marks +* export-marks +* force + Crash Reports ------------- If fast-import is supplied invalid input it will terminate with a
fast-import.c +62 -25
152 lines not on this page · raw message
Signature · 1 line
1.6.5.3.164.g07b0c
PATCH v8 5/7 fast-import: test the new option command
Test the quiet option and verify that the commandline options override it.
Also make sure that an unknown option command is rejected and that non-git options are ignored.
Lastly, show that unknown options are rejected when parsed on the commandline.
---
Tests updated to match the new behavior.
t/t9300-fast-import.sh | 37 ++++++++++++++++++++++++++++++++++++- 1 files changed, 36 insertions(+), 1 deletions(-)
t/t9300-fast-import.sh +36 -1
@@ -1255,7 +1255,7 @@ test_expect_success \ 'git cat-file blob refs/notes/foobar:$commit3 >actual && test_cmp expect actual' ### -### series R (feature) +### series R (feature and option) ### cat >input <<EOF
@@ -1324,4 +1324,39 @@ test_expect_success \ 'cat input | git fast-import --import-marks=marks.out && test_cmp marks.out marks.new' +cat >input << EOF +option git quiet +blob +data 3 +hi + +EOF + +touch empty + +test_expect_success 'R: quiet option results in no stats being output' ' + cat input | git fast-import 2> output && + test_cmp empty output +' + +cat >input <<EOF +option git non-existing-option +EOF + +test_expect_success 'R: die on unknown option' ' + test_must_fail git fast-import <input +' + +test_expect_success 'R: unknown commandline options are rejected' '\ + test_must_fail git fast-import --non-existing-option < /dev/null +' + +cat >input <<EOF +option non-existing-vcs non-existing-option +EOF + +test_expect_success 'R: ignore non-git options' ' + git fast-import <input +' + test_done
Signature · 1 line
1.6.5.3.164.g07b0c
PATCH v8 6/7 fast-import: allow for multiple --import-marks= arguments
The --import-marks= option may be specified multiple times on the commandline and should result in all marks being read in. Only one import-marks feature may be specified in the stream, which is overriden by any --import-marks= commandline options.
If one wishes to specify import-marks files in addition to the one specified in the stream, it is easy to repeat the stream option as a --import-marks= commandline option.
Also verify this behavior with tests.
---
New in this series. Without this it is no longer possible to specify multiple --import-marks= options on the commandline.
Documentation/git-fast-import.txt | 8 +++++++- fast-import.c | 21 ++++++++++++++++----- t/t9300-fast-import.sh | 22 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-)
Documentation/git-fast-import.txt +7 -1
@@ -867,7 +867,8 @@ it does not. The <feature> part of the command may be any string matching ^[a-zA-Z][a-zA-Z-]*$ and should be understood by fast-import. -Feature work identical as their option counterparts. +Feature work identical as their option counterparts with the +exception of the import-marks feature, see below. The following features are currently supported:
@@ -876,6 +877,11 @@ The following features are currently supported: * export-marks * force +The import-marks behaves differently from when it is specified as +commandline option in that only one "feature import-marks" is allowed +per stream. Also, any --import-marks= specified on the commandline +will override those from the stream (if any). + `option` ~~~~~~~~ Processes the specified option so that git fast-import behaves in a
fast-import.c +16 -5
@@ -322,6 +322,7 @@ static struct object_entry *object_table[1 << 16];static struct mark_set *marks;static const char *export_marks_file;static const char *import_marks_file; +static int import_marks_file_from_stream;/* Our last blob */ static struct last_object last_blob = {STRBUF_INIT ,0 ,0 ,0 };
@@ -2469,9 +2470,19 @@ static void parse_progress(void)skip_optional_lf (); } -static void option_import_marks (const char *marks) +static void option_import_marks (const char *marks,int from_stream) { +if (import_marks_file) { +if (from_stream) +die ("Only one import-marks command allowed per stream" ); + +/* read previous mark file */ +if (!import_marks_file_from_stream) +read_marks (); + } + import_marks_file =xstrdup (marks); + import_marks_file_from_stream = from_stream; }static void option_date_format (const char *fmt)
@@ -2538,12 +2549,12 @@ static int parse_one_option(const char *option)return 1 ; } -static int parse_one_feature (const char *feature) +static int parse_one_feature (const char *feature,int from_stream) {if (!prefixcmp (feature,"date-format=" )) {option_date_format (feature +12 ); }else if (!prefixcmp (feature,"import-marks=" )) { -option_import_marks (feature +13 ); +option_import_marks (feature +13 , from_stream); }else if (!prefixcmp (feature,"export-marks=" )) {option_export_marks (feature +13 ); }else if (!prefixcmp (feature,"force" )) {
@@ -2562,7 +2573,7 @@ static void parse_feature(void)if (seen_data_command)die ("Got feature command '%s' after data command" , feature); -if (parse_one_feature (feature)) +if (parse_one_feature (feature,1 ))return ;die ("This version of fast-import does not support feature %s." , feature);
@@ -2618,7 +2629,7 @@ static void parse_argv(void)if (parse_one_option (a +2 ))continue ; -if (parse_one_feature (a +2 )) +if (parse_one_feature (a +2 ,0 ))continue ;die ("unknown option %s" , a);
t/t9300-fast-import.sh +22 -0
@@ -1286,6 +1286,15 @@ test_expect_success 'R: abort on receiving feature after data command' ' ' cat >input << EOF +feature import-marks=git.marks +feature import-marks=git2.marks +EOF + +test_expect_success 'R: only one import-marks feature allowed per stream' ' + test_must_fail git fast-import <input +' + +cat >input << EOF feature export-marks=git.marks blob mark :1
@@ -1324,6 +1333,19 @@ test_expect_success \ 'cat input | git fast-import --import-marks=marks.out && test_cmp marks.out marks.new' + +cat >input <<EOF +feature import-marks=nonexistant.marks +feature export-marks=combined.marks +EOF + +test_expect_success 'R: multiple --import-marks= should be honoured' ' + head -n2 marks.out > one.marks && + tail -n +3 marks.out > two.marks && + git fast-import --import-marks=one.marks --import-marks=two.marks <input && + test_cmp marks.out combined.marks +' + cat >input << EOF option git quiet blob
Signature · 1 line
1.6.5.3.164.g07b0c
PATCH v8 7/7 fast-import: add (non-)relative-marks feature
After specifying 'feature relative-marks' the paths specified with 'feature import-marks' and 'feature export-marks' are relative to an internal directory in the current repository.
In git-fast-import this means that the paths are relative to the '.git/info/fast-import' directory. However, other importers may use a different location.
Add 'feature non-relative-marks' to disable this behavior, this way it is possible to, for example, specify the import-marks location as relative, and the export-marks location as non-relative.
Also add tests to verify this behavior.
---
As requested by Daniel, it is now possible to have the marks be relative to a constant directory. We might want to consider making this the default at some point.
This patch opens the way for remote-helpers to use the marks feature without poluting the work tree, which I think is very important.
Documentation/git-fast-import.txt | 16 ++++++++++++++++ fast-import.c | 19 +++++++++++++++++-- t/t9300-fast-import.sh | 25 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-)
Documentation/git-fast-import.txt +16 -0
@@ -75,6 +75,20 @@ OPTIONS set of marks. If a mark is defined to different values, the last file wins. +--relative-marks:: + After specifying --relative-marks= the paths specified + with --import-marks= and --export-marks= are relative + to an internal directory in the current repository. + In git-fast-import this means that the paths are relative + to the .git/info/fast-import directory. However, other + importers may use a different location. + +--no-relative-marks:: + Negates a previous --relative-marks. Allows for combining + relative and non-relative marks by interweaving + --(no-)-relative-marks= with the --(import|export)-marks= + options. + --export-pack-edges=<file>:: After creating a packfile, print a line of data to <file> listing the filename of the packfile and the last
@@ -875,6 +889,8 @@ The following features are currently supported: * date-format * import-marks * export-marks +* relative-marks +* no-relative-marks * force The import-marks behaves differently from when it is specified as
fast-import.c +17 -2
@@ -323,6 +323,7 @@ static struct mark_set *marks;static const char *export_marks_file;static const char *import_marks_file;static int import_marks_file_from_stream; +static int relative_marks_paths;/* Our last blob */ static struct last_object last_blob = {STRBUF_INIT ,0 ,0 ,0 };
@@ -2470,6 +2471,16 @@ static void parse_progress(void)skip_optional_lf (); } +static char *make_fast_import_path (const char *path) +{ +if (!relative_marks_paths ||is_absolute_path (path)) +return xstrdup (path); + +struct strbuf abs_path =STRBUF_INIT ; +strbuf_addf (&abs_path,"%s/info/fast-import/%s" ,get_git_dir (), path); +return strbuf_detach (&abs_path,NULL ); +} +static void option_import_marks (const char *marks,int from_stream) {if (import_marks_file) {
@@ -2481,7 +2492,7 @@ static void option_import_marks(const char *marks, int from_stream)read_marks (); } - import_marks_file =xstrdup (marks); + import_marks_file =make_fast_import_path (marks); import_marks_file_from_stream = from_stream; }
@@ -2516,7 +2527,7 @@ static void option_active_branches(const char *branches)static void option_export_marks (const char *marks) { - export_marks_file =xstrdup (marks); + export_marks_file =make_fast_import_path (marks); }static void option_export_pack_edges (const char *edges)
@@ -2557,6 +2568,10 @@ static int parse_one_feature(const char *feature, int from_stream)option_import_marks (feature +13 , from_stream); }else if (!prefixcmp (feature,"export-marks=" )) {option_export_marks (feature +13 ); + }else if (!prefixcmp (feature,"relative-marks" )) { + relative_marks_paths =1 ; + }else if (!prefixcmp (feature,"no-relative-marks" )) { + relative_marks_paths =0 ; }else if (!prefixcmp (feature,"force" )) { force_update =1 ; }else {
t/t9300-fast-import.sh +25 -0
@@ -1346,6 +1346,31 @@ test_expect_success 'R: multiple --import-marks= should be honoured' ' test_cmp marks.out combined.marks ' +cat >input <<EOF +feature relative-marks +feature import-marks=relative.in +feature export-marks=relative.out +EOF + +test_expect_success 'R: feature relative-marks should be honoured' ' + mkdir -p .git/info/fast-import/ && + cp marks.new .git/info/fast-import/relative.in && + git fast-import <input && + test_cmp marks.new .git/info/fast-import/relative.out +' + +cat >input <<EOF +feature relative-marks +feature import-marks=relative.in +feature no-relative-marks +feature export-marks=non-relative.out +EOF + +test_expect_success 'R: feature no-relative-marks should be honoured' ' + git fast-import <input && + test_cmp marks.new non-relative.out +' + cat >input << EOF option git quiet blob
Signature · 1 line
1.6.5.3.164.g07b0c
Re: [PATCH v8 7/7] fast-import: add (non-)relative-marks feature
Quoted 16 lines · Sverre Rabbelier
After specifying 'feature relative-marks' the paths specified with 'feature import-marks' and 'feature export-marks' are relative to an internal directory in the current repository.
In git-fast-import this means that the paths are relative to the '.git/info/fast-import' directory. However, other importers may use a different location.
Add 'feature non-relative-marks' to disable this behavior, this way it is possible to, for example, specify the import-marks location as relative, and the export-marks location as non-relative.
Also add tests to verify this behavior.
Cc Daniel Barkalow <[email protected]>Signed-off-by Sverre Rabbelier <[email protected]>
Quoted 8 lines
---
As requested by Daniel, it is now possible to have the marks be relative to a constant directory. We might want to consider making this the default at some point.
This patch opens the way for remote-helpers to use the marks feature without poluting the work tree, which I think is very important.
I think it would be better to make relative paths be the only available method, in part because we don't want to polute the work tree, but more because otherwise scripts aren't transferrable. That is, if you have an absolute path, you can't send the same script to two different importers (because they'd have to write their marks to the same location). And there's no way for the program constructing a script to determine a good absolute location if the script may be run on a different host than it's generated on (think of getting a Linux user getting a script attached to a bug report from a native Windows user; there are no absolute paths that are valid on both of these).
(However, it probably does make sense to permit absolute paths in the command line, since whoever's writing the command line is presumably aware of any local conventions)
-Daniel
*This .sig left intentionally blank*