@@ -2491,27 +2491,23 @@ static void parse_from_existing(struct branch *b)
2491
2491
}
2492
2492
}
2493
2493
2494
- static int parse_from (struct branch * b )
2494
+ static int parse_objectish (struct branch * b , const char * objectish )
2495
2495
{
2496
- const char * from ;
2497
2496
struct branch * s ;
2498
2497
struct object_id oid ;
2499
2498
2500
- if (!skip_prefix (command_buf .buf , "from " , & from ))
2501
- return 0 ;
2502
-
2503
2499
oidcpy (& oid , & b -> branch_tree .versions [1 ].oid );
2504
2500
2505
- s = lookup_branch (from );
2501
+ s = lookup_branch (objectish );
2506
2502
if (b == s )
2507
2503
die ("Can't create a branch from itself: %s" , b -> name );
2508
2504
else if (s ) {
2509
2505
struct object_id * t = & s -> branch_tree .versions [1 ].oid ;
2510
2506
oidcpy (& b -> oid , & s -> oid );
2511
2507
oidcpy (& b -> branch_tree .versions [0 ].oid , t );
2512
2508
oidcpy (& b -> branch_tree .versions [1 ].oid , t );
2513
- } else if (* from == ':' ) {
2514
- uintmax_t idnum = parse_mark_ref_eol (from );
2509
+ } else if (* objectish == ':' ) {
2510
+ uintmax_t idnum = parse_mark_ref_eol (objectish );
2515
2511
struct object_entry * oe = find_mark (idnum );
2516
2512
if (oe -> type != OBJ_COMMIT )
2517
2513
die ("Mark :%" PRIuMAX " not a commit" , idnum );
@@ -2525,13 +2521,13 @@ static int parse_from(struct branch *b)
2525
2521
} else
2526
2522
parse_from_existing (b );
2527
2523
}
2528
- } else if (!get_oid (from , & b -> oid )) {
2524
+ } else if (!get_oid (objectish , & b -> oid )) {
2529
2525
parse_from_existing (b );
2530
2526
if (is_null_oid (& b -> oid ))
2531
2527
b -> delete = 1 ;
2532
2528
}
2533
2529
else
2534
- die ("Invalid ref name or SHA1 expression: %s" , from );
2530
+ die ("Invalid ref name or SHA1 expression: %s" , objectish );
2535
2531
2536
2532
if (b -> branch_tree .tree && !oideq (& oid , & b -> branch_tree .versions [1 ].oid )) {
2537
2533
release_tree_content_recursive (b -> branch_tree .tree );
@@ -2542,6 +2538,26 @@ static int parse_from(struct branch *b)
2542
2538
return 1 ;
2543
2539
}
2544
2540
2541
+ static int parse_from (struct branch * b )
2542
+ {
2543
+ const char * from ;
2544
+
2545
+ if (!skip_prefix (command_buf .buf , "from " , & from ))
2546
+ return 0 ;
2547
+
2548
+ return parse_objectish (b , from );
2549
+ }
2550
+
2551
+ static int parse_objectish_with_prefix (struct branch * b , const char * prefix )
2552
+ {
2553
+ const char * base ;
2554
+
2555
+ if (!skip_prefix (command_buf .buf , prefix , & base ))
2556
+ return 0 ;
2557
+
2558
+ return parse_objectish (b , base );
2559
+ }
2560
+
2545
2561
static struct hash_list * parse_merge (unsigned int * count )
2546
2562
{
2547
2563
struct hash_list * list = NULL , * * tail = & list , * n ;
@@ -3087,6 +3103,28 @@ static void parse_progress(void)
3087
3103
skip_optional_lf ();
3088
3104
}
3089
3105
3106
+ static void parse_alias (void )
3107
+ {
3108
+ struct object_entry * e ;
3109
+ struct branch b ;
3110
+
3111
+ skip_optional_lf ();
3112
+ read_next_command ();
3113
+
3114
+ /* mark ... */
3115
+ parse_mark ();
3116
+ if (!next_mark )
3117
+ die (_ ("Expected 'mark' command, got %s" ), command_buf .buf );
3118
+
3119
+ /* to ... */
3120
+ memset (& b , 0 , sizeof (b ));
3121
+ if (!parse_objectish_with_prefix (& b , "to " ))
3122
+ die (_ ("Expected 'to' command, got %s" ), command_buf .buf );
3123
+ e = find_object (& b .oid );
3124
+ assert (e );
3125
+ insert_mark (next_mark , e );
3126
+ }
3127
+
3090
3128
static char * make_fast_import_path (const char * path )
3091
3129
{
3092
3130
if (!relative_marks_paths || is_absolute_path (path ))
@@ -3214,6 +3252,8 @@ static int parse_one_feature(const char *feature, int from_stream)
3214
3252
option_import_marks (arg , from_stream , 1 );
3215
3253
} else if (skip_prefix (feature , "export-marks=" , & arg )) {
3216
3254
option_export_marks (arg );
3255
+ } else if (!strcmp (feature , "alias" )) {
3256
+ ; /* Don't die - this feature is supported */
3217
3257
} else if (!strcmp (feature , "get-mark" )) {
3218
3258
; /* Don't die - this feature is supported */
3219
3259
} else if (!strcmp (feature , "cat-blob" )) {
@@ -3370,6 +3410,8 @@ int cmd_main(int argc, const char **argv)
3370
3410
parse_checkpoint ();
3371
3411
else if (!strcmp ("done" , command_buf .buf ))
3372
3412
break ;
3413
+ else if (!strcmp ("alias" , command_buf .buf ))
3414
+ parse_alias ();
3373
3415
else if (starts_with (command_buf .buf , "progress " ))
3374
3416
parse_progress ();
3375
3417
else if (skip_prefix (command_buf .buf , "feature " , & v ))
0 commit comments