MCPcopy Create free account
hub / github.com/git/git / update_dir_rename_counts

Function update_dir_rename_counts

diffcore-rename.c:455–572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455static void update_dir_rename_counts(struct dir_rename_info *info,
456 struct strintmap *dirs_removed,
457 const char *oldname,
458 const char *newname)
459{
460 char *old_dir;
461 char *new_dir;
462 const char new_dir_first_char = newname[0];
463 int first_time_in_loop = 1;
464
465 if (!info->setup)
466 /*
467 * info->setup is 0 here in two cases: (1) all auxiliary
468 * vars (like dirs_removed) were NULL so
469 * initialize_dir_rename_info() returned early, or (2)
470 * either break detection or copy detection are active so
471 * that we never called initialize_dir_rename_info(). In
472 * the former case, we don't have enough info to know if
473 * directories were renamed (because dirs_removed lets us
474 * know about a necessary prerequisite, namely if they were
475 * removed), and in the latter, we don't care about
476 * directory renames or find_basename_matches.
477 *
478 * This matters because both basename and inexact matching
479 * will also call update_dir_rename_counts(). In either of
480 * the above two cases info->dir_rename_counts will not
481 * have been properly initialized which prevents us from
482 * updating it, but in these two cases we don't care about
483 * dir_rename_counts anyway, so we can just exit early.
484 */
485 return;
486
487
488 old_dir = xstrdup(oldname);
489 new_dir = xstrdup(newname);
490
491 while (1) {
492 int drd_flag = NOT_RELEVANT;
493
494 /* Get old_dir, skip if its directory isn't relevant. */
495 dirname_munge(old_dir);
496 if (info->relevant_source_dirs &&
497 !strintmap_contains(info->relevant_source_dirs, old_dir))
498 break;
499
500 /* Get new_dir */
501 dirname_munge(new_dir);
502
503 /*
504 * When renaming
505 * "a/b/c/d/e/foo.c" -> "a/b/some/thing/else/e/foo.c"
506 * then this suggests that both
507 * a/b/c/d/e/ => a/b/some/thing/else/e/
508 * a/b/c/d/ => a/b/some/thing/else/
509 * so we want to increment counters for both. We do NOT,
510 * however, also want to suggest that there was the following
511 * rename:
512 * a/b/c/ => a/b/some/thing/

Callers 3

find_basename_matchesFunction · 0.85
find_renamesFunction · 0.85

Calls 5

xstrdupFunction · 0.85
dirname_mungeFunction · 0.85
strintmap_containsFunction · 0.85
strintmap_getFunction · 0.85
increment_countFunction · 0.85

Tested by

no test coverage detected