mirror of
https://github.com/git/git.git
synced 2024-11-17 22:44:49 +01:00
Merge branch 'ar/chmod-series' into next
* ar/chmod-series: make update-index --chmod work with multiple files and --stdin
This commit is contained in:
commit
8b7257514b
1 changed files with 16 additions and 7 deletions
|
@ -329,7 +329,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int chmod_path(int flip, const char *path)
|
static void chmod_path(int flip, const char *path)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
struct cache_entry *ce;
|
struct cache_entry *ce;
|
||||||
|
@ -337,21 +337,24 @@ static int chmod_path(int flip, const char *path)
|
||||||
|
|
||||||
pos = cache_name_pos(path, strlen(path));
|
pos = cache_name_pos(path, strlen(path));
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
return -1;
|
goto fail;
|
||||||
ce = active_cache[pos];
|
ce = active_cache[pos];
|
||||||
mode = ntohl(ce->ce_mode);
|
mode = ntohl(ce->ce_mode);
|
||||||
if (!S_ISREG(mode))
|
if (!S_ISREG(mode))
|
||||||
return -1;
|
goto fail;
|
||||||
switch (flip) {
|
switch (flip) {
|
||||||
case '+':
|
case '+':
|
||||||
ce->ce_mode |= htonl(0111); break;
|
ce->ce_mode |= htonl(0111); break;
|
||||||
case '-':
|
case '-':
|
||||||
ce->ce_mode &= htonl(~0111); break;
|
ce->ce_mode &= htonl(~0111); break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
active_cache_changed = 1;
|
active_cache_changed = 1;
|
||||||
return 0;
|
report("chmod %cx '%s'", flip, path);
|
||||||
|
return;
|
||||||
|
fail:
|
||||||
|
die("git-update-index: cannot chmod %cx '%s'", flip, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cache_file cache_file;
|
static struct cache_file cache_file;
|
||||||
|
@ -597,6 +600,7 @@ int main(int argc, const char **argv)
|
||||||
int read_from_stdin = 0;
|
int read_from_stdin = 0;
|
||||||
const char *prefix = setup_git_directory();
|
const char *prefix = setup_git_directory();
|
||||||
int prefix_length = prefix ? strlen(prefix) : 0;
|
int prefix_length = prefix ? strlen(prefix) : 0;
|
||||||
|
char set_executable_bit = 0;
|
||||||
|
|
||||||
git_config(git_default_config);
|
git_config(git_default_config);
|
||||||
|
|
||||||
|
@ -663,8 +667,7 @@ int main(int argc, const char **argv)
|
||||||
!strcmp(path, "--chmod=+x")) {
|
!strcmp(path, "--chmod=+x")) {
|
||||||
if (argc <= i+1)
|
if (argc <= i+1)
|
||||||
die("git-update-index: %s <path>", path);
|
die("git-update-index: %s <path>", path);
|
||||||
if (chmod_path(path[8], argv[++i]))
|
set_executable_bit = path[8];
|
||||||
die("git-update-index: %s cannot chmod %s", path, argv[i]);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(path, "--assume-unchanged")) {
|
if (!strcmp(path, "--assume-unchanged")) {
|
||||||
|
@ -719,6 +722,8 @@ int main(int argc, const char **argv)
|
||||||
die("unknown option %s", path);
|
die("unknown option %s", path);
|
||||||
}
|
}
|
||||||
update_one(path, prefix, prefix_length);
|
update_one(path, prefix, prefix_length);
|
||||||
|
if (set_executable_bit)
|
||||||
|
chmod_path(set_executable_bit, path);
|
||||||
}
|
}
|
||||||
if (read_from_stdin) {
|
if (read_from_stdin) {
|
||||||
struct strbuf buf;
|
struct strbuf buf;
|
||||||
|
@ -733,6 +738,10 @@ int main(int argc, const char **argv)
|
||||||
else
|
else
|
||||||
path_name = buf.buf;
|
path_name = buf.buf;
|
||||||
update_one(path_name, prefix, prefix_length);
|
update_one(path_name, prefix, prefix_length);
|
||||||
|
if (set_executable_bit) {
|
||||||
|
const char *p = prefix_path(prefix, prefix_length, path_name);
|
||||||
|
chmod_path(set_executable_bit, p);
|
||||||
|
}
|
||||||
if (path_name != buf.buf)
|
if (path_name != buf.buf)
|
||||||
free(path_name);
|
free(path_name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue