|
4 | 4 | #include "refs.h"
|
5 | 5 | #include "remote.h"
|
6 | 6 | #include "commit.h"
|
| 7 | +#include "worktree.h" |
7 | 8 |
|
8 | 9 | struct tracking {
|
9 | 10 | struct refspec spec;
|
@@ -311,84 +312,6 @@ void remove_branch_state(void)
|
311 | 312 | unlink(git_path_squash_msg());
|
312 | 313 | }
|
313 | 314 |
|
314 |
| -static char *find_linked_symref(const char *symref, const char *branch, |
315 |
| - const char *id) |
316 |
| -{ |
317 |
| - struct strbuf sb = STRBUF_INIT; |
318 |
| - struct strbuf path = STRBUF_INIT; |
319 |
| - struct strbuf gitdir = STRBUF_INIT; |
320 |
| - char *existing = NULL; |
321 |
| - |
322 |
| - /* |
323 |
| - * $GIT_COMMON_DIR/$symref (e.g. HEAD) is practically outside |
324 |
| - * $GIT_DIR so resolve_ref_unsafe() won't work (it uses |
325 |
| - * git_path). Parse the ref ourselves. |
326 |
| - */ |
327 |
| - if (id) |
328 |
| - strbuf_addf(&path, "%s/worktrees/%s/%s", get_git_common_dir(), id, symref); |
329 |
| - else |
330 |
| - strbuf_addf(&path, "%s/%s", get_git_common_dir(), symref); |
331 |
| - |
332 |
| - if (!strbuf_readlink(&sb, path.buf, 0)) { |
333 |
| - if (!starts_with(sb.buf, "refs/") || |
334 |
| - check_refname_format(sb.buf, 0)) |
335 |
| - goto done; |
336 |
| - } else if (strbuf_read_file(&sb, path.buf, 0) >= 0 && |
337 |
| - starts_with(sb.buf, "ref:")) { |
338 |
| - strbuf_remove(&sb, 0, strlen("ref:")); |
339 |
| - strbuf_trim(&sb); |
340 |
| - } else |
341 |
| - goto done; |
342 |
| - if (strcmp(sb.buf, branch)) |
343 |
| - goto done; |
344 |
| - if (id) { |
345 |
| - strbuf_reset(&path); |
346 |
| - strbuf_addf(&path, "%s/worktrees/%s/gitdir", get_git_common_dir(), id); |
347 |
| - if (strbuf_read_file(&gitdir, path.buf, 0) <= 0) |
348 |
| - goto done; |
349 |
| - strbuf_rtrim(&gitdir); |
350 |
| - } else |
351 |
| - strbuf_addstr(&gitdir, get_git_common_dir()); |
352 |
| - strbuf_strip_suffix(&gitdir, ".git"); |
353 |
| - |
354 |
| - existing = strbuf_detach(&gitdir, NULL); |
355 |
| -done: |
356 |
| - strbuf_release(&path); |
357 |
| - strbuf_release(&sb); |
358 |
| - strbuf_release(&gitdir); |
359 |
| - |
360 |
| - return existing; |
361 |
| -} |
362 |
| - |
363 |
| -char *find_shared_symref(const char *symref, const char *target) |
364 |
| -{ |
365 |
| - struct strbuf path = STRBUF_INIT; |
366 |
| - DIR *dir; |
367 |
| - struct dirent *d; |
368 |
| - char *existing; |
369 |
| - |
370 |
| - if ((existing = find_linked_symref(symref, target, NULL))) |
371 |
| - return existing; |
372 |
| - |
373 |
| - strbuf_addf(&path, "%s/worktrees", get_git_common_dir()); |
374 |
| - dir = opendir(path.buf); |
375 |
| - strbuf_release(&path); |
376 |
| - if (!dir) |
377 |
| - return NULL; |
378 |
| - |
379 |
| - while ((d = readdir(dir)) != NULL) { |
380 |
| - if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) |
381 |
| - continue; |
382 |
| - existing = find_linked_symref(symref, target, d->d_name); |
383 |
| - if (existing) |
384 |
| - goto done; |
385 |
| - } |
386 |
| -done: |
387 |
| - closedir(dir); |
388 |
| - |
389 |
| - return existing; |
390 |
| -} |
391 |
| - |
392 | 315 | void die_if_checked_out(const char *branch)
|
393 | 316 | {
|
394 | 317 | char *existing;
|
|
0 commit comments