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

Function diagnose_invalid_index_path

object-name.c:1645–1699  ·  view source on GitHub ↗

Must be called only when :stage:filename doesn't exist. */

Source from the content-addressed store, hash-verified

1643
1644/* Must be called only when :stage:filename doesn't exist. */
1645static void diagnose_invalid_index_path(struct repository *r,
1646 int stage,
1647 const char *prefix,
1648 const char *filename)
1649{
1650 struct index_state *istate = r->index;
1651 const struct cache_entry *ce;
1652 int pos;
1653 unsigned namelen = strlen(filename);
1654 struct strbuf fullname = STRBUF_INIT;
1655
1656 if (!prefix)
1657 prefix = "";
1658
1659 /* Wrong stage number? */
1660 pos = index_name_pos(istate, filename, namelen);
1661 if (pos < 0)
1662 pos = -pos - 1;
1663 if (pos < istate->cache_nr) {
1664 ce = istate->cache[pos];
1665 if (!S_ISSPARSEDIR(ce->ce_mode) &&
1666 ce_namelen(ce) == namelen &&
1667 !memcmp(ce->name, filename, namelen))
1668 die(_("path '%s' is in the index, but not at stage %d\n"
1669 "hint: Did you mean ':%d:%s'?"),
1670 filename, stage,
1671 ce_stage(ce), filename);
1672 }
1673
1674 /* Confusion between relative and absolute filenames? */
1675 strbuf_addstr(&fullname, prefix);
1676 strbuf_addstr(&fullname, filename);
1677 pos = index_name_pos(istate, fullname.buf, fullname.len);
1678 if (pos < 0)
1679 pos = -pos - 1;
1680 if (pos < istate->cache_nr) {
1681 ce = istate->cache[pos];
1682 if (!S_ISSPARSEDIR(ce->ce_mode) &&
1683 ce_namelen(ce) == fullname.len &&
1684 !memcmp(ce->name, fullname.buf, fullname.len))
1685 die(_("path '%s' is in the index, but not '%s'\n"
1686 "hint: Did you mean ':%d:%s' aka ':%d:./%s'?"),
1687 fullname.buf, filename,
1688 ce_stage(ce), fullname.buf,
1689 ce_stage(ce), filename);
1690 }
1691
1692 if (repo_file_exists(r, filename))
1693 die(_("path '%s' exists on disk, but not in the index"), filename);
1694 if (is_missing_file_error(errno))
1695 die(_("path '%s' does not exist (neither on disk nor in the index)"),
1696 filename);
1697
1698 strbuf_release(&fullname);
1699}
1700
1701
1702static char *resolve_relative_path(struct repository *r, const char *rel)

Callers 2

reject_tree_in_indexFunction · 0.85
get_oid_with_context_1Function · 0.85

Calls 6

index_name_posFunction · 0.85
strbuf_addstrFunction · 0.85
repo_file_existsFunction · 0.85
is_missing_file_errorFunction · 0.85
strbuf_releaseFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected