@@ -1371,16 +1371,33 @@ static void dump_marks_helper(FILE *f,
1371
1371
1372
1372
static void dump_marks (void )
1373
1373
{
1374
- if (mark_file )
1375
- {
1376
- FILE * f = fopen (mark_file , "w" );
1377
- if (f ) {
1378
- dump_marks_helper (f , 0 , marks );
1379
- fclose (f );
1380
- } else
1381
- failure |= error ("Unable to write marks file %s: %s" ,
1382
- mark_file , strerror (errno ));
1374
+ static struct lock_file mark_lock ;
1375
+ int mark_fd ;
1376
+ FILE * f ;
1377
+
1378
+ if (!mark_file )
1379
+ return ;
1380
+
1381
+ mark_fd = hold_lock_file_for_update (& mark_lock , mark_file , 0 );
1382
+ if (mark_fd < 0 ) {
1383
+ failure |= error ("Unable to write marks file %s: %s" ,
1384
+ mark_file , strerror (errno ));
1385
+ return ;
1386
+ }
1387
+
1388
+ f = fdopen (mark_fd , "w" );
1389
+ if (!f ) {
1390
+ rollback_lock_file (& mark_lock );
1391
+ failure |= error ("Unable to write marks file %s: %s" ,
1392
+ mark_file , strerror (errno ));
1393
+ return ;
1383
1394
}
1395
+
1396
+ dump_marks_helper (f , 0 , marks );
1397
+ fclose (f );
1398
+ if (commit_lock_file (& mark_lock ))
1399
+ failure |= error ("Unable to write marks file %s: %s" ,
1400
+ mark_file , strerror (errno ));
1384
1401
}
1385
1402
1386
1403
static void read_next_command (void )
@@ -1976,6 +1993,40 @@ static void cmd_checkpoint(void)
1976
1993
read_next_command ();
1977
1994
}
1978
1995
1996
+ static void import_marks (const char * input_file )
1997
+ {
1998
+ char line [512 ];
1999
+ FILE * f = fopen (input_file , "r" );
2000
+ if (!f )
2001
+ die ("cannot read %s: %s" , input_file , strerror (errno ));
2002
+ while (fgets (line , sizeof (line ), f )) {
2003
+ uintmax_t mark ;
2004
+ char * end ;
2005
+ unsigned char sha1 [20 ];
2006
+ struct object_entry * e ;
2007
+
2008
+ end = strchr (line , '\n' );
2009
+ if (line [0 ] != ':' || !end )
2010
+ die ("corrupt mark line: %s" , line );
2011
+ * end = 0 ;
2012
+ mark = strtoumax (line + 1 , & end , 10 );
2013
+ if (!mark || end == line + 1
2014
+ || * end != ' ' || get_sha1 (end + 1 , sha1 ))
2015
+ die ("corrupt mark line: %s" , line );
2016
+ e = find_object (sha1 );
2017
+ if (!e ) {
2018
+ enum object_type type = sha1_object_info (sha1 , NULL );
2019
+ if (type < 0 )
2020
+ die ("object not found: %s" , sha1_to_hex (sha1 ));
2021
+ e = insert_object (sha1 );
2022
+ e -> type = type ;
2023
+ e -> pack_id = MAX_PACK_ID ;
2024
+ }
2025
+ insert_mark (mark , e );
2026
+ }
2027
+ fclose (f );
2028
+ }
2029
+
1979
2030
static const char fast_import_usage [] =
1980
2031
"git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]" ;
1981
2032
@@ -1984,6 +2035,12 @@ int main(int argc, const char **argv)
1984
2035
int i , show_stats = 1 ;
1985
2036
1986
2037
git_config (git_default_config );
2038
+ alloc_objects (object_entry_alloc );
2039
+ strbuf_init (& command_buf );
2040
+ atom_table = xcalloc (atom_table_sz , sizeof (struct atom_str * ));
2041
+ branch_table = xcalloc (branch_table_sz , sizeof (struct branch * ));
2042
+ avail_tree_table = xcalloc (avail_tree_table_sz , sizeof (struct avail_tree_content * ));
2043
+ marks = pool_calloc (1 , sizeof (struct mark_set ));
1987
2044
1988
2045
for (i = 1 ; i < argc ; i ++ ) {
1989
2046
const char * a = argv [i ];
@@ -2007,6 +2064,8 @@ int main(int argc, const char **argv)
2007
2064
max_depth = strtoul (a + 8 , NULL , 0 );
2008
2065
else if (!prefixcmp (a , "--active-branches=" ))
2009
2066
max_active_branches = strtoul (a + 18 , NULL , 0 );
2067
+ else if (!prefixcmp (a , "--import-marks=" ))
2068
+ import_marks (a + 15 );
2010
2069
else if (!prefixcmp (a , "--export-marks=" ))
2011
2070
mark_file = a + 15 ;
2012
2071
else if (!prefixcmp (a , "--export-pack-edges=" )) {
@@ -2027,14 +2086,6 @@ int main(int argc, const char **argv)
2027
2086
if (i != argc )
2028
2087
usage (fast_import_usage );
2029
2088
2030
- alloc_objects (object_entry_alloc );
2031
- strbuf_init (& command_buf );
2032
-
2033
- atom_table = xcalloc (atom_table_sz , sizeof (struct atom_str * ));
2034
- branch_table = xcalloc (branch_table_sz , sizeof (struct branch * ));
2035
- avail_tree_table = xcalloc (avail_tree_table_sz , sizeof (struct avail_tree_content * ));
2036
- marks = pool_calloc (1 , sizeof (struct mark_set ));
2037
-
2038
2089
start_packfile ();
2039
2090
for (;;) {
2040
2091
read_next_command ();
0 commit comments