diff options
author | Torsten Bögershausen <tboegi@web.de> | 2017-11-16 17:38:28 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-17 10:31:05 +0900 |
commit | 9472935d81eaf9faed771878c9df0216ae0d9045 (patch) | |
tree | 9e8ed5c59d04b47defd123a1110fde0c38305328 /sha1_file.c | |
parent | cb5918aa0d50f50e83787f65c2ddc3dcb10159fe (diff) | |
download | git-9472935d81eaf9faed771878c9df0216ae0d9045.tar.gz |
add: introduce "--renormalize"tb/add-renormalize
Make it safer to normalize the line endings in a repository.
Files that had been commited with CRLF will be commited with LF.
The old way to normalize a repo was like this:
# Make sure that there are not untracked files
$ echo "* text=auto" >.gitattributes
$ git read-tree --empty
$ git add .
$ git commit -m "Introduce end-of-line normalization"
The user must make sure that there are no untracked files,
otherwise they would have been added and tracked from now on.
The new "add --renormalize" does not add untracked files:
$ echo "* text=auto" >.gitattributes
$ git add --renormalize .
$ git commit -m "Introduce end-of-line normalization"
Note that "git add --renormalize <pathspec>" is the short form for
"git add -u --renormalize <pathspec>".
While at it, document that the same renormalization may be needed,
whenever a clean filter is added or changed.
Helped-By: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sha1_file.c b/sha1_file.c index 10c3a0083d..15abb184c2 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -74,6 +74,18 @@ static struct cached_object *find_cached_object(const unsigned char *sha1) return NULL; } + +static enum safe_crlf get_safe_crlf(unsigned flags) +{ + if (flags & HASH_RENORMALIZE) + return SAFE_CRLF_RENORMALIZE; + else if (flags & HASH_WRITE_OBJECT) + return safe_crlf; + else + return SAFE_CRLF_FALSE; +} + + int mkdir_in_gitdir(const char *path) { if (mkdir(path, 0777)) { @@ -1680,7 +1692,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size, if ((type == OBJ_BLOB) && path) { struct strbuf nbuf = STRBUF_INIT; if (convert_to_git(&the_index, path, buf, size, &nbuf, - write_object ? safe_crlf : SAFE_CRLF_FALSE)) { + get_safe_crlf(flags))) { buf = strbuf_detach(&nbuf, &size); re_allocated = 1; } @@ -1714,7 +1726,7 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd, assert(would_convert_to_git_filter_fd(path)); convert_to_git_filter_fd(&the_index, path, fd, &sbuf, - write_object ? safe_crlf : SAFE_CRLF_FALSE); + get_safe_crlf(flags)); if (write_object) ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB), |