MCPcopy Index your code
hub / github.com/git/git / stack_uptodate

Function stack_uptodate

reftable/stack.c:556–619  ·  view source on GitHub ↗

* Check whether the given stack is up-to-date with what we have in memory. * Returns 0 if so, 1 if the stack is out-of-date or a negative error code * otherwise. */

Source from the content-addressed store, hash-verified

554 * otherwise.
555 */
556static int stack_uptodate(struct reftable_stack *st)
557{
558 char **names = NULL;
559 int err;
560
561 /*
562 * When we have cached stat information available then we use it to
563 * verify whether the file has been rewritten.
564 *
565 * Note that we explicitly do not want to use `stat_validity_check()`
566 * and friends here because they may end up not comparing the `st_dev`
567 * and `st_ino` fields. These functions thus cannot guarantee that we
568 * indeed still have the same file.
569 */
570 if (st->list_fd >= 0) {
571 struct stat list_st;
572
573 if (stat(st->list_file, &list_st) < 0) {
574 /*
575 * It's fine for "tables.list" to not exist. In that
576 * case, we have to refresh when the loaded stack has
577 * any tables.
578 */
579 if (errno == ENOENT)
580 return !!st->tables_len;
581 return REFTABLE_IO_ERROR;
582 }
583
584 /*
585 * When "tables.list" refers to the same file we can assume
586 * that it didn't change. This is because we always use
587 * rename(3P) to update the file and never write to it
588 * directly.
589 */
590 if (st->list_st.st_dev == list_st.st_dev &&
591 st->list_st.st_ino == list_st.st_ino)
592 return 0;
593 }
594
595 err = read_lines(st->list_file, &names);
596 if (err < 0)
597 return err;
598
599 for (size_t i = 0; i < st->tables_len; i++) {
600 if (!names[i]) {
601 err = 1;
602 goto done;
603 }
604
605 if (strcmp(st->tables[i]->name, names[i])) {
606 err = 1;
607 goto done;
608 }
609 }
610
611 if (names[st->merged->tables_len]) {
612 err = 1;
613 goto done;

Callers 3

reftable_stack_reloadFunction · 0.85
stack_compact_rangeFunction · 0.85

Calls 3

read_linesFunction · 0.85
free_namesFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected