[PATCH 10/24] untracked cache: save to an index extension
Helped-by: Stefan Beller Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- Documentation/technical/index-format.txt | 58 + cache.h | 3 + dir.c| 139 +++ dir.h| 1 + read-cache.c | 12 +++ 5 files changed, 213 insertions(+) diff --git a/Documentation/technical/index-format.txt b/Documentation/technical/index-format.txt index fe6f316..899dd3d 100644 --- a/Documentation/technical/index-format.txt +++ b/Documentation/technical/index-format.txt @@ -233,3 +233,61 @@ Git index format The remaining index entries after replaced ones will be added to the final index. These added entries are also sorted by entry namme then stage. + +== Untracked cache + + Untracked cache saves the untracked file list and necessary data to + verify the cache. The signature for this extension is { 'U', 'N', + 'T', 'R' }. + + The extension starts with + + - Stat data of $GIT_DIR/info/exclude. See "Index entry" section from +ctime field until "file size". + + - Stat data of core.excludesfile + + - 32-bit dir_flags (see struct dir_struct) + + - 160-bit SHA-1 of $GIT_DIR/info/exclude. Null SHA-1 means the file +does not exist. + + - 160-bit SHA-1 of core.excludesfile. Null SHA-1 means the file does +not exist. + + - NUL-terminated string of per-dir exclude file name. This usually +is ".gitignore". + + - The number of following directory blocks, variable width +encoding. If this number is zero, the extension ends here with a +following NUL. + + - A number of directory blocks in depth-first-search order, each +consists of + +- The number of untracked entries, variable width encoding. + +- The number of sub-directory blocks, variable width encoding. + +- The directory name terminated by NUL. + +- A number of untrached file/dir names terminated by NUL. + +The remaining data of each directory block is grouped by type: + + - An ewah bitmap, the n-th bit marks whether the n-th directory has +valid untracked cache entries. + + - An ewah bitmap, the n-th bit records "check-only" bit of +read_directory_recursive() for the n-th directory. + + - An ewah bitmap, the n-th bit indicates whether SHA-1 and stat data +is valid for the n-th directory and exists in the next data. + + - An array of stat data. The n-th data corresponds with the n-th +"one" bit in the previous ewah bitmap. + + - An array of SHA-1. The n-th SHA-1 corresponds with the n-th "one" bit +in the previous ewah bitmap. + + - One NUL. diff --git a/cache.h b/cache.h index dcf3a2a..b14d6e2 100644 --- a/cache.h +++ b/cache.h @@ -297,6 +297,8 @@ static inline unsigned int canon_mode(unsigned int mode) #define SPLIT_INDEX_ORDERED(1 << 6) struct split_index; +struct untracked_cache; + struct index_state { struct cache_entry **cache; unsigned int version; @@ -310,6 +312,7 @@ struct index_state { struct hashmap name_hash; struct hashmap dir_hash; unsigned char sha1[20]; + struct untracked_cache *untracked; }; extern struct index_state the_index; diff --git a/dir.c b/dir.c index b2128a0..8f0deb1 100644 --- a/dir.c +++ b/dir.c @@ -12,6 +12,8 @@ #include "refs.h" #include "wildmatch.h" #include "pathspec.h" +#include "varint.h" +#include "ewah/ewok.h" struct path_simplify { int len; @@ -2140,3 +2142,140 @@ void clear_directory(struct dir_struct *dir) } strbuf_release(&dir->basebuf); } + +struct ondisk_untracked_cache { + struct stat_data info_exclude_stat; + struct stat_data excludes_file_stat; + uint32_t dir_flags; + unsigned char info_exclude_sha1[20]; + unsigned char excludes_file_sha1[20]; + char exclude_per_dir[FLEX_ARRAY]; +}; + +#define ouc_size(len) (offsetof(struct ondisk_untracked_cache, exclude_per_dir) + len + 1) + +struct write_data { + int index; /* number of written untracked_cache_dir */ + struct ewah_bitmap *check_only; /* from untracked_cache_dir */ + struct ewah_bitmap *valid; /* from untracked_cache_dir */ + struct ewah_bitmap *sha1_valid; /* set if exclude_sha1 is not null */ + struct strbuf out; + struct strbuf sb_stat; + struct strbuf sb_sha1; +}; + +static void stat_data_to_disk(struct stat_data *to, const struct stat_data *from) +{ + to->sd_ctime.sec = htonl(from->sd_ctime.sec); + to->sd_ctime.nsec = htonl(from->sd_ctime.nsec); + to->sd_mtime.sec = htonl(from->sd_mtime.sec); + to->sd_mtime.nsec = htonl(from->sd_mtime.nsec); + to->sd_dev= htonl(from->sd_dev); + to->sd_ino= htonl(from->sd_ino); + to->sd_uid= htonl(from->sd_uid); + to->sd_gid= htonl(from->sd_gid); + to->sd_size = htonl(from->sd_size); +} + +static
Re: [PATCH 10/24] untracked cache: save to an index extension
On Sun, Feb 8, 2015 at 12:55 AM, Nguyễn Thái Ngọc Duy wrote: > + ouc = xmalloc(sizeof(*ouc) + len + 1); Do we need to free `ouc` at the end of the function as well? -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 10/24] untracked cache: save to an index extension
Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/technical/index-format.txt | 58 + cache.h | 3 + dir.c| 136 +++ dir.h| 1 + read-cache.c | 12 +++ 5 files changed, 210 insertions(+) diff --git a/Documentation/technical/index-format.txt b/Documentation/technical/index-format.txt index fe6f316..899dd3d 100644 --- a/Documentation/technical/index-format.txt +++ b/Documentation/technical/index-format.txt @@ -233,3 +233,61 @@ Git index format The remaining index entries after replaced ones will be added to the final index. These added entries are also sorted by entry namme then stage. + +== Untracked cache + + Untracked cache saves the untracked file list and necessary data to + verify the cache. The signature for this extension is { 'U', 'N', + 'T', 'R' }. + + The extension starts with + + - Stat data of $GIT_DIR/info/exclude. See "Index entry" section from +ctime field until "file size". + + - Stat data of core.excludesfile + + - 32-bit dir_flags (see struct dir_struct) + + - 160-bit SHA-1 of $GIT_DIR/info/exclude. Null SHA-1 means the file +does not exist. + + - 160-bit SHA-1 of core.excludesfile. Null SHA-1 means the file does +not exist. + + - NUL-terminated string of per-dir exclude file name. This usually +is ".gitignore". + + - The number of following directory blocks, variable width +encoding. If this number is zero, the extension ends here with a +following NUL. + + - A number of directory blocks in depth-first-search order, each +consists of + +- The number of untracked entries, variable width encoding. + +- The number of sub-directory blocks, variable width encoding. + +- The directory name terminated by NUL. + +- A number of untrached file/dir names terminated by NUL. + +The remaining data of each directory block is grouped by type: + + - An ewah bitmap, the n-th bit marks whether the n-th directory has +valid untracked cache entries. + + - An ewah bitmap, the n-th bit records "check-only" bit of +read_directory_recursive() for the n-th directory. + + - An ewah bitmap, the n-th bit indicates whether SHA-1 and stat data +is valid for the n-th directory and exists in the next data. + + - An array of stat data. The n-th data corresponds with the n-th +"one" bit in the previous ewah bitmap. + + - An array of SHA-1. The n-th SHA-1 corresponds with the n-th "one" bit +in the previous ewah bitmap. + + - One NUL. diff --git a/cache.h b/cache.h index dcf3a2a..b14d6e2 100644 --- a/cache.h +++ b/cache.h @@ -297,6 +297,8 @@ static inline unsigned int canon_mode(unsigned int mode) #define SPLIT_INDEX_ORDERED(1 << 6) struct split_index; +struct untracked_cache; + struct index_state { struct cache_entry **cache; unsigned int version; @@ -310,6 +312,7 @@ struct index_state { struct hashmap name_hash; struct hashmap dir_hash; unsigned char sha1[20]; + struct untracked_cache *untracked; }; extern struct index_state the_index; diff --git a/dir.c b/dir.c index 95a0f0a..1f2d701 100644 --- a/dir.c +++ b/dir.c @@ -12,6 +12,8 @@ #include "refs.h" #include "wildmatch.h" #include "pathspec.h" +#include "varint.h" +#include "ewah/ewok.h" struct path_simplify { int len; @@ -2139,3 +2141,137 @@ void clear_directory(struct dir_struct *dir) } strbuf_release(&dir->basebuf); } + +struct ondisk_untracked_cache { + struct stat_data info_exclude_stat; + struct stat_data excludes_file_stat; + uint32_t dir_flags; + unsigned char info_exclude_sha1[20]; + unsigned char excludes_file_sha1[20]; + char exclude_per_dir[FLEX_ARRAY]; +}; + +#define ouc_size(len) (offsetof(struct ondisk_untracked_cache, exclude_per_dir) + len + 1) + +struct write_data { + int index; /* number of written untracked_cache_dir */ + struct ewah_bitmap *check_only; /* from untracked_cache_dir */ + struct ewah_bitmap *valid; /* from untracked_cache_dir */ + struct ewah_bitmap *sha1_valid; /* set if exclude_sha1 is not null */ + struct strbuf out; + struct strbuf sb_stat; + struct strbuf sb_sha1; +}; + +static void stat_data_to_disk(struct stat_data *to, const struct stat_data *from) +{ + to->sd_ctime.sec = htonl(from->sd_ctime.sec); + to->sd_ctime.nsec = htonl(from->sd_ctime.nsec); + to->sd_mtime.sec = htonl(from->sd_mtime.sec); + to->sd_mtime.nsec = htonl(from->sd_mtime.nsec); + to->sd_dev= htonl(from->sd_dev); + to->sd_ino= htonl(from->sd_ino); + to->sd_uid= htonl(from->sd_uid); + to->sd_gid= htonl(from->sd_gid); + to->sd_size = htonl(from->sd_size); +} + +static void write_one_dir(struct untracked_cache_dir *untracked
[PATCH 10/24] untracked cache: save to an index extension
Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/technical/index-format.txt | 58 + cache.h | 3 + dir.c| 136 +++ dir.h| 1 + read-cache.c | 12 +++ 5 files changed, 210 insertions(+) diff --git a/Documentation/technical/index-format.txt b/Documentation/technical/index-format.txt index fe6f316..b97ac8d 100644 --- a/Documentation/technical/index-format.txt +++ b/Documentation/technical/index-format.txt @@ -233,3 +233,61 @@ Git index format The remaining index entries after replaced ones will be added to the final index. These added entries are also sorted by entry namme then stage. + +== Untracked cache + + Untracked cache saves the untracked file list and necessary data to + verify the cache. The signature for this extension is { 'U', 'N', + 'T', 'R' }. + + The extension starts with + + - Stat data of $GIT_DIR/info/exclude. See "Index entry" section from +ctime field until "file size". + + - Stat data of core.excludesfile + + - 32-bit dir_flags (see struct dir_struct) + + - 160-bit SHA-1 of $GIT_DIR/info/exclude. Null SHA-1 means the file +does not exist. + + - 160-bit SHA-1 of core.excludesfile. Null SHA-1 means the file does +not exist. + + - NUL-terminated string of per-dir exclude file name. This usually +is ".gitignore". + + - The number of following directory blocks, variable width +encoding. If this number is zero, the extension ends here with a +following NUL. + + - A number of directory blocks in depth-first-search order, each +consists of + +- The number of untracked entries, variable witdh encoding. + +- The number of sub-directory blocks, variable with encoding. + +- The directory name terminated by NUL. + +- A number of untrached file/dir names terminated by NUL. + +The remaining data of each directory block is grouped by type: + + - An ewah bitmap, the n-th bit marks whether the n-th directory has +valid untracked cache entries. + + - An ewah bitmap, the n-th bit records "check-only" bit of +read_directory_recursive() for the n-th directory. + + - An ewah bitmap, the n-th bit indicates whether SHA-1 and stat data +is valid for the n-th directory and exists in the next data. + + - An array of stat data. The n-th data corresponds with the n-th +"one" bit in the previous ewah bitmap. + + - An array of SHA-1. The n-th SHA-1 corresponds with the n-th "one" bit +in the previous ewah bitmap. + + - One NUL. diff --git a/cache.h b/cache.h index dcf3a2a..b14d6e2 100644 --- a/cache.h +++ b/cache.h @@ -297,6 +297,8 @@ static inline unsigned int canon_mode(unsigned int mode) #define SPLIT_INDEX_ORDERED(1 << 6) struct split_index; +struct untracked_cache; + struct index_state { struct cache_entry **cache; unsigned int version; @@ -310,6 +312,7 @@ struct index_state { struct hashmap name_hash; struct hashmap dir_hash; unsigned char sha1[20]; + struct untracked_cache *untracked; }; extern struct index_state the_index; diff --git a/dir.c b/dir.c index 95a0f0a..1f2d701 100644 --- a/dir.c +++ b/dir.c @@ -12,6 +12,8 @@ #include "refs.h" #include "wildmatch.h" #include "pathspec.h" +#include "varint.h" +#include "ewah/ewok.h" struct path_simplify { int len; @@ -2139,3 +2141,137 @@ void clear_directory(struct dir_struct *dir) } strbuf_release(&dir->basebuf); } + +struct ondisk_untracked_cache { + struct stat_data info_exclude_stat; + struct stat_data excludes_file_stat; + uint32_t dir_flags; + unsigned char info_exclude_sha1[20]; + unsigned char excludes_file_sha1[20]; + char exclude_per_dir[FLEX_ARRAY]; +}; + +#define ouc_size(len) (offsetof(struct ondisk_untracked_cache, exclude_per_dir) + len + 1) + +struct write_data { + int index; /* number of written untracked_cache_dir */ + struct ewah_bitmap *check_only; /* from untracked_cache_dir */ + struct ewah_bitmap *valid; /* from untracked_cache_dir */ + struct ewah_bitmap *sha1_valid; /* set if exclude_sha1 is not null */ + struct strbuf out; + struct strbuf sb_stat; + struct strbuf sb_sha1; +}; + +static void stat_data_to_disk(struct stat_data *to, const struct stat_data *from) +{ + to->sd_ctime.sec = htonl(from->sd_ctime.sec); + to->sd_ctime.nsec = htonl(from->sd_ctime.nsec); + to->sd_mtime.sec = htonl(from->sd_mtime.sec); + to->sd_mtime.nsec = htonl(from->sd_mtime.nsec); + to->sd_dev= htonl(from->sd_dev); + to->sd_ino= htonl(from->sd_ino); + to->sd_uid= htonl(from->sd_uid); + to->sd_gid= htonl(from->sd_gid); + to->sd_size = htonl(from->sd_size); +} + +static void write_one_dir(struct untracked_cache_dir *untracked,