why git fast-import file modes are hardcoded?

2019-08-13 12:23发布

问题:

I'm trying to convert my CVS repository into GIT and I faced with strange issue: git fast-import has hardcoded file modes 100755 and 100644, otherwise it dies.

source:

p = get_mode(p, &mode);
if (!p)
    die("Corrupt mode: %s", command_buf.buf);
switch (mode) {
    case 0644:
    case 0755:
    mode |= S_IFREG;
    case S_IFREG | 0644:
    case S_IFREG | 0755:
    case S_IFLNK:
    case S_IFDIR:
    case S_IFGITLINK:
        /* ok */
        break;
    default:
        die("Corrupt mode: %s", command_buf.buf);
}

// https://github.com/git/git/blob/master/fast-import.c 2272-2288

could someone please explain me the reason of such solution?

回答1:

Git doesn't store file modes, it only stores the type of file (symlink, directory, executable, not executable) using something that looks suspiciously like unix file modes.

Storing something that is not one of these hardcoded bits, for example, 0777 would not be legal. This would be a corrupt tree object and git fsck would complain about it.

(Note that there is a historical exclusion to this - 0664 is allowed in a tree, and is considered a warning instead of an error.)