From: Henrik Grubbström (Grubba) <grubba@xxxxxxxxxx> When having $Id$ tags in other versioning systems, it is customary to recalculate the tags in the source on commit or equvivalent. This commit adds a configuration option to git that causes source files to pass through a conversion roundtrip when added to the index. Signed-off-by: Henrik Grubbström <grubba@xxxxxxxxxx> --- Documentation/config.txt | 6 +++++ cache.h | 1 + config.c | 5 ++++ environment.c | 1 + sha1_file.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 0 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 664de6b..900b095 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -533,6 +533,12 @@ core.sparseCheckout:: Enable "sparse checkout" feature. See section "Sparse checkout" in linkgit:git-read-tree[1] for more information. +core.refilterOnAdd:: + Enable "refilter on add" feature. This causes source files to be + behave as if they were checked out after a linkgit:git-add[1]. + This is typically usefull if eg the `ident` attribute is active, + in which case the $Id$ tags will be updated. + add.ignore-errors:: Tells 'git add' to continue adding files when some files cannot be added due to indexing errors. Equivalent to the '--ignore-errors' diff --git a/cache.h b/cache.h index 1c9f491..beb60f9 100644 --- a/cache.h +++ b/cache.h @@ -540,6 +540,7 @@ extern int read_replace_refs; extern int fsync_object_files; extern int core_preload_index; extern int core_apply_sparse_checkout; +extern int core_refilter_on_add; enum safe_crlf { SAFE_CRLF_FALSE = 0, diff --git a/config.c b/config.c index 6963fbe..b1db505 100644 --- a/config.c +++ b/config.c @@ -523,6 +523,11 @@ static int git_default_core_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.refilteronadd")) { + core_refilter_on_add = git_config_bool(var, value); + return 0; + } + /* Add other config variables here and to Documentation/config.txt. */ return 0; } diff --git a/environment.c b/environment.c index 739ec27..eed7ef1 100644 --- a/environment.c +++ b/environment.c @@ -52,6 +52,7 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; char *notes_ref_name; int grafts_replace_parents = 1; int core_apply_sparse_checkout; +int core_refilter_on_add; /* Parallel index stat data preload? */ int core_preload_index = 0; diff --git a/sha1_file.c b/sha1_file.c index fd8c5df..f2659cb 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2459,6 +2459,54 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, return ret; } +static int refilter_fd(int fd, struct stat *st, const char *path) +{ + int ret = -1; + size_t size = xsize_t(st->st_size); + struct strbuf gbuf = STRBUF_INIT; + + if (!S_ISREG(st->st_mode)) { + struct strbuf sbuf = STRBUF_INIT; + if (strbuf_read(&sbuf, fd, 4096) >= 0) + ret = convert_to_git(path, sbuf.buf, sbuf.len, &gbuf, safe_crlf, 0); + else + ret = -1; + strbuf_release(&sbuf); + } else if (size) { + void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + ret = convert_to_git(path, buf, size, &gbuf, safe_crlf, 0); + munmap(buf, size); + } else + ret = -1; + + if (ret > 0) { + /* Something happened during conversion to git. + * Now convert it back, and save the result. + */ + struct strbuf obuf = STRBUF_INIT; + + lseek(fd, 0, SEEK_SET); + + if (convert_to_working_tree(path, gbuf.buf, gbuf.len, &obuf)) { + if (write_or_whine(fd, obuf.buf, obuf.len, path)) + ftruncate(fd, obuf.len); + else + ret = -1; + } else { + if (write_or_whine(fd, gbuf.buf, gbuf.len, path)) + ftruncate(fd, gbuf.len); + else + ret = -1; + } + + strbuf_release(&obuf); + } + strbuf_release(&gbuf); + + close(fd); + return ret; +} + int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object) { int fd; @@ -2473,6 +2521,15 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write if (index_fd(sha1, fd, st, write_object, OBJ_BLOB, path) < 0) return error("%s: failed to insert into database", path); + if (write_object && core_refilter_on_add) { + fd = open(path, O_RDWR); + if (fd < 0) + return error("open(\"%s\"): %s", path, + strerror(errno)); + if (refilter_fd(fd, st, path) < 0) + return error("%s: failed to refilter file", + path); + } break; case S_IFLNK: if (strbuf_readlink(&sb, path, st->st_size)) { -- 1.6.4.122.g6ffd7 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html