@@ -183,7 +183,7 @@ char *get_worktree_git_dir(const struct worktree *wt)
183
183
else if (!wt -> id )
184
184
return xstrdup (repo_get_common_dir (the_repository ));
185
185
else
186
- return xstrdup ( git_common_path ( "worktrees/%s" , wt -> id ) );
186
+ return repo_common_path ( the_repository , "worktrees/%s" , wt -> id );
187
187
}
188
188
189
189
static struct worktree * find_worktree_by_suffix (struct worktree * * list ,
@@ -314,6 +314,7 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
314
314
{
315
315
struct strbuf wt_path = STRBUF_INIT ;
316
316
struct strbuf realpath = STRBUF_INIT ;
317
+ struct strbuf buf = STRBUF_INIT ;
317
318
char * path = NULL ;
318
319
int err , ret = -1 ;
319
320
@@ -343,7 +344,7 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
343
344
if (!is_absolute_path (wt -> path )) {
344
345
strbuf_addf_gently (errmsg ,
345
346
_ ("'%s' file does not contain absolute path to the working tree location" ),
346
- git_common_path ( "worktrees/%s/gitdir" , wt -> id ));
347
+ repo_common_path_replace ( the_repository , & buf , "worktrees/%s/gitdir" , wt -> id ));
347
348
goto done ;
348
349
}
349
350
@@ -365,14 +366,16 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
365
366
goto done ;
366
367
}
367
368
368
- strbuf_realpath (& realpath , git_common_path ( "worktrees/%s" , wt -> id ), 1 );
369
+ strbuf_realpath (& realpath , repo_common_path_replace ( the_repository , & buf , "worktrees/%s" , wt -> id ), 1 );
369
370
ret = fspathcmp (path , realpath .buf );
370
371
371
372
if (ret )
372
373
strbuf_addf_gently (errmsg , _ ("'%s' does not point back to '%s'" ),
373
- wt -> path , git_common_path ("worktrees/%s" , wt -> id ));
374
+ wt -> path , repo_common_path_replace (the_repository , & buf ,
375
+ "worktrees/%s" , wt -> id ));
374
376
done :
375
377
free (path );
378
+ strbuf_release (& buf );
376
379
strbuf_release (& wt_path );
377
380
strbuf_release (& realpath );
378
381
return ret ;
@@ -384,11 +387,13 @@ void update_worktree_location(struct worktree *wt, const char *path_,
384
387
struct strbuf path = STRBUF_INIT ;
385
388
struct strbuf dotgit = STRBUF_INIT ;
386
389
struct strbuf gitdir = STRBUF_INIT ;
390
+ char * wt_gitdir ;
387
391
388
392
if (is_main_worktree (wt ))
389
393
BUG ("can't relocate main worktree" );
390
394
391
- strbuf_realpath (& gitdir , git_common_path ("worktrees/%s/gitdir" , wt -> id ), 1 );
395
+ wt_gitdir = repo_common_path (the_repository , "worktrees/%s/gitdir" , wt -> id );
396
+ strbuf_realpath (& gitdir , wt_gitdir , 1 );
392
397
strbuf_realpath (& path , path_ , 1 );
393
398
strbuf_addf (& dotgit , "%s/.git" , path .buf );
394
399
if (fspathcmp (wt -> path , path .buf )) {
@@ -400,6 +405,7 @@ void update_worktree_location(struct worktree *wt, const char *path_,
400
405
strbuf_release (& path );
401
406
strbuf_release (& dotgit );
402
407
strbuf_release (& gitdir );
408
+ free (wt_gitdir );
403
409
}
404
410
405
411
int is_worktree_being_rebased (const struct worktree * wt ,
@@ -585,6 +591,7 @@ static void repair_gitfile(struct worktree *wt,
585
591
struct strbuf backlink = STRBUF_INIT ;
586
592
char * dotgit_contents = NULL ;
587
593
const char * repair = NULL ;
594
+ char * path = NULL ;
588
595
int err ;
589
596
590
597
/* missing worktree can't be repaired */
@@ -596,7 +603,8 @@ static void repair_gitfile(struct worktree *wt,
596
603
goto done ;
597
604
}
598
605
599
- strbuf_realpath (& repo , git_common_path ("worktrees/%s" , wt -> id ), 1 );
606
+ path = repo_common_path (the_repository , "worktrees/%s" , wt -> id );
607
+ strbuf_realpath (& repo , path , 1 );
600
608
strbuf_addf (& dotgit , "%s/.git" , wt -> path );
601
609
strbuf_addf (& gitdir , "%s/gitdir" , repo .buf );
602
610
dotgit_contents = xstrdup_or_null (read_gitfile_gently (dotgit .buf , & err ));
@@ -626,6 +634,7 @@ static void repair_gitfile(struct worktree *wt,
626
634
627
635
done :
628
636
free (dotgit_contents );
637
+ free (path );
629
638
strbuf_release (& repo );
630
639
strbuf_release (& dotgit );
631
640
strbuf_release (& gitdir );
@@ -657,11 +666,13 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path
657
666
struct strbuf gitdir = STRBUF_INIT ;
658
667
struct strbuf dotgit = STRBUF_INIT ;
659
668
int is_relative_path ;
669
+ char * path = NULL ;
660
670
661
671
if (is_main_worktree (wt ))
662
672
goto done ;
663
673
664
- strbuf_realpath (& gitdir , git_common_path ("worktrees/%s/gitdir" , wt -> id ), 1 );
674
+ path = repo_common_path (the_repository , "worktrees/%s/gitdir" , wt -> id );
675
+ strbuf_realpath (& gitdir , path , 1 );
665
676
666
677
if (strbuf_read_file (& dotgit , gitdir .buf , 0 ) < 0 )
667
678
goto done ;
@@ -680,6 +691,7 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path
680
691
done :
681
692
strbuf_release (& gitdir );
682
693
strbuf_release (& dotgit );
694
+ free (path );
683
695
}
684
696
685
697
void repair_worktrees_after_gitdir_move (const char * old_path )
@@ -871,7 +883,11 @@ int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath,
871
883
ssize_t read_result ;
872
884
873
885
* wtpath = NULL ;
874
- strbuf_realpath (& repo , git_common_path ("worktrees/%s" , id ), 1 );
886
+
887
+ path = repo_common_path (the_repository , "worktrees/%s" , id );
888
+ strbuf_realpath (& repo , path , 1 );
889
+ FREE_AND_NULL (path );
890
+
875
891
strbuf_addf (& gitdir , "%s/gitdir" , repo .buf );
876
892
if (!is_directory (repo .buf )) {
877
893
strbuf_addstr (reason , _ ("not a valid directory" ));
0 commit comments