From 57059091fad25427bce9b3d47e073ce0518d164b Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 9 Apr 2007 01:06:28 -0400 Subject: get rid of num_packed_objects() The coming index format change doesn't allow for the number of objects to be determined from the size of the index file directly. Instead, Let's initialize a field in the packed_git structure with the object count when the index is validated since the count is always known at that point. While at it let's reorder some struct packed_git fields to avoid padding due to needed 64-bit alignment for some of them. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index eb57507b80..5b67f4c989 100644 --- a/cache.h +++ b/cache.h @@ -376,11 +376,12 @@ struct pack_window { extern struct packed_git { struct packed_git *next; struct pack_window *windows; - const void *index_data; - off_t index_size; off_t pack_size; - time_t mtime; + const void *index_data; + size_t index_size; + uint32_t num_objects; int index_version; + time_t mtime; int pack_fd; int pack_local; unsigned char sha1[20]; @@ -431,7 +432,6 @@ extern void pack_report(void); extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *); extern void unuse_pack(struct pack_window **); extern struct packed_git *add_packed_git(const char *, int, int); -extern uint32_t num_packed_objects(const struct packed_git *p); extern const unsigned char *nth_packed_object_sha1(const struct packed_git *, uint32_t); extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); -- cgit v1.2.3 From 9eec4795d44439cd170fb52c73827c728252648d Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 9 Apr 2007 21:14:58 -0700 Subject: Add "S_IFDIRLNK" file mode infrastructure for git links This just adds the basic helper functions to recognize and work with git tree entries that are links to other git repositories ("subprojects"). They still aren't actually connected up to any of the code-paths, but now all the infrastructure is in place. The next commit will start actually adding actual subproject support. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index eb57507b80..1b3d00ee11 100644 --- a/cache.h +++ b/cache.h @@ -24,6 +24,22 @@ #define DTYPE(de) DT_UNKNOWN #endif +/* + * A "directory link" is a link to another git directory. + * + * The value 0160000 is not normally a valid mode, and + * also just happens to be S_IFDIR + S_IFLNK + * + * NOTE! We *really* shouldn't depend on the S_IFxxx macros + * always having the same values everywhere. We should use + * our internal git values for these things, and then we can + * translate that to the OS-specific value. It just so + * happens that everybody shares the same bit representation + * in the UNIX world (and apparently wider too..) + */ +#define S_IFDIRLNK 0160000 +#define S_ISDIRLNK(m) (((m) & S_IFMT) == S_IFDIRLNK) + /* * Intensive research over the course of many years has shown that * port 9418 is totally unused by anything else. Or @@ -104,6 +120,8 @@ static inline unsigned int create_ce_mode(unsigned int mode) { if (S_ISLNK(mode)) return htonl(S_IFLNK); + if (S_ISDIR(mode) || S_ISDIRLNK(mode)) + return htonl(S_IFDIRLNK); return htonl(S_IFREG | ce_permissions(mode)); } static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned int mode) @@ -121,7 +139,7 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in } #define canon_mode(mode) \ (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ - S_ISLNK(mode) ? S_IFLNK : S_IFDIR) + S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFDIRLNK) #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7) -- cgit v1.2.3 From f98157720239f0dd94d03632dc873e3eb3135e2f Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 10 Apr 2007 00:56:33 +0200 Subject: (encode_85, decode_85): Mark source buffer pointer as "const". Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 384b260227..1904131f27 100644 --- a/cache.h +++ b/cache.h @@ -468,8 +468,8 @@ extern int pager_in_use; extern int pager_use_color; /* base85 */ -int decode_85(char *dst, char *line, int linelen); -void encode_85(char *buf, unsigned char *data, int bytes); +int decode_85(char *dst, const char *line, int linelen); +void encode_85(char *buf, const unsigned char *data, int bytes); /* alloc.c */ struct blob; -- cgit v1.2.3 From d0bfd026a8241d544c339944976927b388d61a5e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 12 Apr 2007 01:07:32 -0700 Subject: Add basic infrastructure to assign attributes to paths This adds the basic infrastructure to assign attributes to paths, in a way similar to what the exclusion mechanism does based on $GIT_DIR/info/exclude and .gitignore files. An attribute is just a simple string that does not contain any whitespace. They can be specified in $GIT_DIR/info/attributes file, and .gitattributes file in each directory. Each line in these files defines a pattern matching rule. Similar to the exclusion mechanism, a later match overrides an earlier match in the same file, and entries from .gitattributes file in the same directory takes precedence over the ones from parent directories. Lines in $GIT_DIR/info/attributes file are used as the lowest precedence default rules. A line is either a comment (an empty line, or a line that begins with a '#'), or a rule, which is a whitespace separated list of tokens. The first token on the line is a shell glob pattern. The rest are names of attributes, each of which can optionally be prefixed with '!'. Such a line means "if a path matches this glob, this attribute is set (or unset -- if the attribute name is prefixed with '!'). For glob matching, the same "if the pattern does not have a slash in it, the basename of the path is matched with fnmatch(3) against the pattern, otherwise, the path is matched with the pattern with FNM_PATHNAME" rule as the exclusion mechanism is used. This does not define what an attribute means. Tying an attribute to various effects it has on git operation for paths that have it will be specified separately. Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b1bd9e46c2..63af43fe5c 100644 --- a/cache.h +++ b/cache.h @@ -151,6 +151,8 @@ enum object_type { #define CONFIG_ENVIRONMENT "GIT_CONFIG" #define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL" #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" +#define GITATTRIBUTES_FILE ".gitattributes" +#define INFOATTRIBUTES_FILE "info/attributes" extern int is_bare_repository_cfg; extern int is_bare_repository(void); -- cgit v1.2.3 From f48fd68887a03756658a46486a5dd1301c5a655f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 14 Apr 2007 08:54:37 -0700 Subject: attribute macro support This adds "attribute macros" (for lack of better name). So far, we have low-level attributes such as crlf and diff, which are defined in operational terms --- setting or unsetting them on a particular path directly affects what is done to the path. For example, in order to decline diffs or crlf conversions on a binary blob, no diffs on PostScript files, and treat all other files normally, you would have something like these: * diff crlf *.ps !diff proprietary.o !diff !crlf That is fine as the operation goes, but gets unwieldy rather rapidly, when we start adding more low-level attributes that are defined in operational terms. A near-term example of such an attribute would be 'merge-3way' which would control if git should attempt the usual 3-way file-level merge internally, or leave merging to a specialized external program of user's choice. When it is added, we do _not_ want to force the users to update the above to: * diff crlf merge-3way *.ps !diff proprietary.o !diff !crlf !merge-3way The way this patch solves this issue is to realize that the attributes the user is assigning to paths are not defined in terms of operations but in terms of what they are. All of the three low-level attributes usually make sense for most of the files that sane SCM users have git operate on (these files are typically called "text'). Only a few cases, such as binary blob, need exception to decline the "usual treatment given to text files" -- and people mark them as "binary". So this allows the $GIT_DIR/info/alternates and .gitattributes at the toplevel of the project to also specify attributes that assigns other attributes. The syntax is '[attr]' followed by an attribute name followed by a list of attribute names: [attr] binary !diff !crlf !merge-3way When "binary" attribute is set to a path, if the path has not got diff/crlf/merge-3way attribute set or unset by other rules, this rule unsets the three low-level attributes. It is expected that the user level .gitattributes will be expressed mostly in terms of attributes based on what the files are, and the above sample would become like this: (built-in attribute configuration) [attr] binary !diff !crlf !merge-3way * diff crlf merge-3way (project specific .gitattributes) proprietary.o binary (user preference $GIT_DIR/info/attributes) *.ps !diff There are a few caveats. * As described above, you can define these macros only in $GIT_DIR/info/attributes and toplevel .gitattributes. * There is no attempt to detect circular definition of macro attributes, and definitions are evaluated from bottom to top as usual to fill in other attributes that have not yet got values. The following would work as expected: [attr] text diff crlf [attr] ps text !diff *.ps ps while this would most likely not (I haven't tried): [attr] ps text !diff [attr] text diff crlf *.ps ps * When a macro says "[attr] A B !C", saying that a path does not have attribute A does not let you tell anything about attributes B or C. That is, given this: [attr] text diff crlf [attr] ps text !diff *.txt !ps path hello.txt, which would match "*.txt" pattern, would have "ps" attribute set to zero, but that does not make text attribute of hello.txt set to false (nor diff attribute set to true). Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 63af43fe5c..38ad00661d 100644 --- a/cache.h +++ b/cache.h @@ -153,6 +153,7 @@ enum object_type { #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" #define GITATTRIBUTES_FILE ".gitattributes" #define INFOATTRIBUTES_FILE "info/attributes" +#define ATTRIBUTE_MACRO_PREFIX "[attr]" extern int is_bare_repository_cfg; extern int is_bare_repository(void); -- cgit v1.2.3 From 54dab52ae8518da67e271b5b3a1f91af1fd5e314 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 16 Apr 2007 12:31:56 -0400 Subject: add get_size_from_delta() ... which consists of existing code split out of packed_delta_info() for other callers to use it as well. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 5b67f4c989..63399c7c6b 100644 --- a/cache.h +++ b/cache.h @@ -436,6 +436,7 @@ extern const unsigned char *nth_packed_object_sha1(const struct packed_git *, ui extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); +extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); /* Dumb servers support */ -- cgit v1.2.3 From 2c1cbec1e2f0bd7b15fe5e921d287babfd91c7d3 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 16 Apr 2007 22:10:19 -0700 Subject: Use proper object allocators for unknown object nodes too We used to use a different allocator scheme for when we didn't know the object type. That meant that objects that were created without any up-front knowledge of the type would not go through the same allocation paths as normal object allocations, and would miss out on the statistics. But perhaps more importantly than the statistics (that are useful when looking at memory usage but not much else), if we want to make the object hash tables use a denser object pointer representation, we need to make sure that they all go through the same blocking allocator. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b1bd9e46c2..aa72791947 100644 --- a/cache.h +++ b/cache.h @@ -484,6 +484,7 @@ extern struct blob *alloc_blob_node(void); extern struct tree *alloc_tree_node(void); extern struct commit *alloc_commit_node(void); extern struct tag *alloc_tag_node(void); +extern struct object *alloc_object_node(void); extern void alloc_report(void); /* trace.c */ -- cgit v1.2.3 From 100c5f3b0b27ec6617de1a785c4ff481e92636c1 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 16 Apr 2007 22:11:43 -0700 Subject: Clean up object creation to use more common code This replaces the fairly odd "created_object()" function that did _most_ of the object setup with a more complete "create_object()" function that also has a more natural calling convention. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index aa72791947..4de25cc4b2 100644 --- a/cache.h +++ b/cache.h @@ -476,15 +476,11 @@ int decode_85(char *dst, const char *line, int linelen); void encode_85(char *buf, const unsigned char *data, int bytes); /* alloc.c */ -struct blob; -struct tree; -struct commit; -struct tag; -extern struct blob *alloc_blob_node(void); -extern struct tree *alloc_tree_node(void); -extern struct commit *alloc_commit_node(void); -extern struct tag *alloc_tag_node(void); -extern struct object *alloc_object_node(void); +extern void *alloc_blob_node(void); +extern void *alloc_tree_node(void); +extern void *alloc_commit_node(void); +extern void *alloc_tag_node(void); +extern void *alloc_object_node(void); extern void alloc_report(void); /* trace.c */ -- cgit v1.2.3 From 1401f46bb42d1eb6225a5e08543c06a5b18fd3b7 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Wed, 18 Apr 2007 05:34:34 +0200 Subject: Use const qualifier for 'sha1' parameter in delete_ref function delete_ref function does not change the 'sha1' parameter. Non-const pointer causes a compiler warning if you call to the function using a const argument. Signed-off-by: Carlos Rica Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1904131f27..7cedda684f 100644 --- a/cache.h +++ b/cache.h @@ -213,7 +213,7 @@ struct lock_file { extern int hold_lock_file_for_update(struct lock_file *, const char *path, int); extern int commit_lock_file(struct lock_file *); extern void rollback_lock_file(struct lock_file *); -extern int delete_ref(const char *, unsigned char *sha1); +extern int delete_ref(const char *, const unsigned char *sha1); /* Environment bits from configuration mechanism */ extern int use_legacy_headers; -- cgit v1.2.3 From ac78e548049f4e86b38368d2c4b4dbb546c64ac6 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 19 Apr 2007 02:05:03 +0200 Subject: Simplify calling of CR/LF conversion routines Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 38ad00661d..8c804cb6ee 100644 --- a/cache.h +++ b/cache.h @@ -496,8 +496,8 @@ extern void trace_printf(const char *format, ...); extern void trace_argv_printf(const char **argv, int count, const char *format, ...); /* convert.c */ -extern int convert_to_git(const char *path, char **bufp, unsigned long *sizep); -extern int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep); +extern char *convert_to_git(const char *path, const char *src, unsigned long *sizep); +extern char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep); /* match-trees.c */ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int); -- cgit v1.2.3 From 5e635e396020cc08bc21a3e67c20c5294d6d13fd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Apr 2007 03:11:10 -0700 Subject: lockfile: record the primary process. The usual process flow is the main process opens and holds the lock to the index, does its thing, perhaps spawning children during the course, and then writes the resulting index out by releaseing the lock. However, the lockfile interface uses atexit(3) to clean it up, without regard to who actually created the lock. This typically leads to a confusing behaviour of lock being released too early when the child exits, and then the parent process when it calls commit_lockfile() finds that it cannot unlock it. This fixes the problem by recording who created and holds the lock, and upon atexit(3) handler, child simply ignores the lockfile the parent created. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8c804cb6ee..faddaf6504 100644 --- a/cache.h +++ b/cache.h @@ -209,6 +209,7 @@ extern int refresh_cache(unsigned int flags); struct lock_file { struct lock_file *next; + pid_t owner; char on_list; char filename[PATH_MAX]; }; -- cgit v1.2.3 From 228e94f93570b580da388069900c56b813c91953 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 1 Apr 2007 18:14:06 -0700 Subject: Move index-related variables into a structure. This defines a index_state structure and moves index-related global variables into it. Currently there is one instance of it, the_index, and everybody accesses it, so there is no code change. Signed-off-by: Junio C Hamano --- cache.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 89aaf0022d..4841c9a161 100644 --- a/cache.h +++ b/cache.h @@ -143,9 +143,22 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7) -extern struct cache_entry **active_cache; -extern unsigned int active_nr, active_alloc, active_cache_changed; -extern struct cache_tree *active_cache_tree; +struct index_state { + struct cache_entry **cache; + unsigned int cache_nr, cache_alloc, cache_changed; + struct cache_tree *cache_tree; + time_t timestamp; + void *mmap; + size_t mmap_size; +}; + +extern struct index_state the_index; + +#define active_cache (the_index.cache) +#define active_nr (the_index.cache_nr) +#define active_alloc (the_index.cache_alloc) +#define active_cache_changed (the_index.cache_changed) +#define active_cache_tree (the_index.cache_tree) enum object_type { OBJ_BAD = -1, -- cgit v1.2.3 From 4aab5b46f44a7ba860e07a52be506b7b57b2bd5f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 1 Apr 2007 23:26:07 -0700 Subject: Make read-cache.c "the_index" free. This makes all low-level functions defined in read-cache.c to take an explicit index_state structure as their first parameter, to specify which index to work on. These functions traditionally operated on "the_index" and were named foo_cache(); the counterparts this patch introduces are called foo_index(). The traditional foo_cache() functions are made into macros that give "the_index" to their corresponding foo_index() functions. Signed-off-by: Junio C Hamano --- cache.h | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4841c9a161..74e47dffa2 100644 --- a/cache.h +++ b/cache.h @@ -154,12 +154,27 @@ struct index_state { extern struct index_state the_index; +#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS #define active_cache (the_index.cache) #define active_nr (the_index.cache_nr) #define active_alloc (the_index.cache_alloc) #define active_cache_changed (the_index.cache_changed) #define active_cache_tree (the_index.cache_tree) +#define read_cache() read_index(&the_index) +#define read_cache_from(path) read_index_from(&the_index, (path)) +#define write_cache(newfd, cache, entries) write_index(&the_index, (newfd)) +#define discard_cache() discard_index(&the_index) +#define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) +#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) +#define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) +#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) +#define add_file_to_cache(path, verbose) add_file_to_index(&the_index, (path), (verbose)) +#define refresh_cache(flags) refresh_index(&the_index, flags) +#define ce_match_stat(ce, st, really) ie_match_stat(&the_index, (ce), (st), (really)) +#define ce_modified(ce, st, really) ie_modified(&the_index, (ce), (st), (really)) +#endif + enum object_type { OBJ_BAD = -1, OBJ_NONE = 0, @@ -208,23 +223,23 @@ extern void verify_non_filename(const char *prefix, const char *name); #define alloc_nr(x) (((x)+16)*3/2) /* Initialize and use the cache information */ -extern int read_cache(void); -extern int read_cache_from(const char *path); -extern int write_cache(int newfd, struct cache_entry **cache, int entries); -extern int discard_cache(void); +extern int read_index(struct index_state *); +extern int read_index_from(struct index_state *, const char *path); +extern int write_index(struct index_state *, int newfd); +extern int discard_index(struct index_state *); extern int verify_path(const char *path); -extern int cache_name_pos(const char *name, int namelen); +extern int index_name_pos(struct index_state *, const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ -extern int add_cache_entry(struct cache_entry *ce, int option); +extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option); extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); -extern int remove_cache_entry_at(int pos); -extern int remove_file_from_cache(const char *path); -extern int add_file_to_cache(const char *path, int verbose); +extern int remove_index_entry_at(struct index_state *, int pos); +extern int remove_file_from_index(struct index_state *, const char *path); +extern int add_file_to_index(struct index_state *, const char *path, int verbose); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); -extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int); -extern int ce_modified(struct cache_entry *ce, struct stat *st, int); +extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, int); +extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); extern int read_pipe(int fd, char** return_buf, unsigned long* return_size); @@ -236,7 +251,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); #define REFRESH_UNMERGED 0x0002 /* allow unmerged */ #define REFRESH_QUIET 0x0004 /* be quiet about it */ #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ -extern int refresh_cache(unsigned int flags); +extern int refresh_index(struct index_state *, unsigned int flags); struct lock_file { struct lock_file *next; -- cgit v1.2.3 From 40689ae1ef9a05503c75298ec50b194ca9d15522 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Sun, 22 Apr 2007 18:43:56 +0200 Subject: Add S_IFINVALID mode S_IFINVALID is used to signal, that no mode information is available. Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 89aaf0022d..b1adbe7b6e 100644 --- a/cache.h +++ b/cache.h @@ -24,6 +24,9 @@ #define DTYPE(de) DT_UNKNOWN #endif +/* unknown mode (impossible combination S_IFIFO|S_IFCHR) */ +#define S_IFINVALID 0030000 + /* * A "directory link" is a link to another git directory. * -- cgit v1.2.3 From a0cd87a57044efa8aef39b476fd9240af57a1853 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Mon, 23 Apr 2007 22:55:05 +0200 Subject: add get_sha1_with_mode get_sha1_with_mode basically behaves as get_sha1. It has an additional parameter for storing the mode of the object. If the mode can not be determined, it stores S_IFINVALID. Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b1adbe7b6e..23e8f24d5c 100644 --- a/cache.h +++ b/cache.h @@ -342,6 +342,7 @@ static inline unsigned int hexval(unsigned int c) #define DEFAULT_ABBREV 7 extern int get_sha1(const char *str, unsigned char *sha1); +extern int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode); extern int get_sha1_hex(const char *hex, unsigned char *sha1); extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ extern int read_ref(const char *filename, unsigned char *sha1); -- cgit v1.2.3 From efbc5831264fbe3696e6fc264bba9319265d7344 Mon Sep 17 00:00:00 2001 From: "Luiz Fernando N. Capitulino" Date: Wed, 25 Apr 2007 11:18:08 -0300 Subject: entry.c: Use const qualifier for 'struct checkout' parameters Signed-off-by: Luiz Fernando N. Capitulino Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f05b67ad45..38a0cbd580 100644 --- a/cache.h +++ b/cache.h @@ -409,7 +409,7 @@ struct checkout { refresh_cache:1; }; -extern int checkout_entry(struct cache_entry *ce, struct checkout *state, char *topath); +extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From a7b02ccf9a682fa0c2b28df6ca20f9199cdca4de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 24 Apr 2007 23:36:22 -0700 Subject: Add --date={local,relative,default} This adds --date={local,relative,default} option to log family of commands, to allow displaying timestamps in user's local timezone, relative time, or the default format. Existing --relative-date option is a synonym of --date=relative; we could probably deprecate it in the long run. Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 38a0cbd580..8e76152645 100644 --- a/cache.h +++ b/cache.h @@ -389,7 +389,7 @@ extern void *read_object_with_reference(const unsigned char *sha1, unsigned long *size, unsigned char *sha1_ret); -enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT }; +enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL }; const char *show_date(unsigned long time, int timezone, enum date_mode mode); const char *show_rfc2822_date(unsigned long time, int timezone); int parse_date(const char *date, char *buf, int bufsize); -- cgit v1.2.3 From 726f852b0ed7e03e88c419a9996c3815911c9db1 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 9 May 2007 14:42:42 -0400 Subject: deprecate the new loose object header format Now that we encourage and actively preserve objects in a packed form more agressively than we did at the time the new loose object format and core.legacyheaders were introduced, that extra loose object format doesn't appear to be worth it anymore. Because the packing of loose objects has to go through the delta match loop anyway, and since most of them should end up being deltified in most cases, there is really little advantage to have this parallel loose object format as the CPU savings it might provide is rather lost in the noise in the end. This patch gets rid of core.legacyheaders, preserve the legacy format as the only writable loose object format and deprecate the other one to keep things simpler. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8e76152645..5725bce6f4 100644 --- a/cache.h +++ b/cache.h @@ -273,7 +273,6 @@ extern void rollback_lock_file(struct lock_file *); extern int delete_ref(const char *, const unsigned char *sha1); /* Environment bits from configuration mechanism */ -extern int use_legacy_headers; extern int trust_executable_bit; extern int has_symlinks; extern int assume_unchanged; @@ -354,7 +353,6 @@ extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1, const char **ignore); extern int has_sha1_file(const unsigned char *sha1); extern void *map_sha1_file(const unsigned char *sha1, unsigned long *); -extern int legacy_loose_object(unsigned char *); extern int has_pack_file(const unsigned char *sha1); extern int has_pack_index(const unsigned char *sha1); -- cgit v1.2.3 From 960ccca6803c9fb57429d43572a9545a96107e32 Mon Sep 17 00:00:00 2001 From: Dana How Date: Wed, 9 May 2007 13:56:50 -0700 Subject: Custom compression levels for objects and packs Add config variables pack.compression and core.loosecompression , and switch --compression=level to pack-objects. Loose objects will be compressed using core.loosecompression if set, else core.compression if set, else Z_BEST_SPEED. Packed objects will be compressed using --compression=level if seen, else pack.compression if set, else core.compression if set, else Z_DEFAULT_COMPRESSION. This is the "pack compression level". Loose objects added to a pack undeltified will be recompressed to the pack compression level if it is unequal to the current loose compression level by the preceding rules, or if the loose object was written while core.legacyheaders = true. Newly deltified loose objects are always compressed to the current pack compression level. Previously packed objects added to a pack are recompressed to the current pack compression level exactly when their deltification status changes, since the previous pack data cannot be reused. In either case, the --no-reuse-object switch from the first patch below will always force recompression to the current pack compression level, instead of assuming the pack compression level hasn't changed and pack data can be reused when possible. This applies on top of the following patches from Nicolas Pitre: [PATCH] allow for undeltified objects not to be reused [PATCH] make "repack -f" imply "pack-objects --no-reuse-object" Signed-off-by: Dana L. How Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8e76152645..2b3f359b21 100644 --- a/cache.h +++ b/cache.h @@ -283,6 +283,8 @@ extern int warn_ambiguous_refs; extern int shared_repository; extern const char *apply_default_whitespace; extern int zlib_compression_level; +extern int core_compression_level; +extern int core_compression_seen; extern size_t packed_git_window_size; extern size_t packed_git_limit; extern size_t delta_base_cache_limit; -- cgit v1.2.3 From f859c846e90b385c7ef873df22403529208ade50 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 11 May 2007 22:11:07 -0700 Subject: Add has_symlink_leading_path() function. When we are applying a patch that creates a blob at a path, or when we are switching from a branch that does not have a blob at the path to another branch that has one, we need to make sure that there is nothing at the path in the working tree, as such a file is a local modification made by the user that would be lost by the operation. Normally, lstat() on the path and making sure ENOENT is returned is good enough for that purpose. However there is a twist. We may be creating a regular file arch/x86_64/boot/Makefile, while removing an existing symbolic link at arch/x86_64/boot that points at existing ../i386/boot directory that has Makefile in it. We always first check without touching filesystem and then perform the actual operation, so when we verify the new file, arch/x86_64/boot/Makefile, does not exist, we haven't removed the symbolic link arc/x86_64/boot symbolic link yet. lstat() on the file sees through the symbolic link and reports the file is there, which is not what we want. The function has_symlink_leading_path() function takes a path, and sees if any of the leading directory component is a symbolic link. When files in a new directory are created, we tend to process them together because both index and tree are sorted. The function takes advantage of this and allows the caller to cache and reuse which symbolic link on the filesystem caused the function to return true. The calling sequence would be: char last_symlink[PATH_MAX]; *last_symlink = '\0'; for each index entry { if (!lose) continue; if (lstat(it)) if (errno == ENOENT) ; /* happy */ else error; else if (has_symlink_leading_path(it, last_symlink)) ; /* happy */ else error; /* would lose local changes */ unlink_entry(it, last_symlink); } Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8e76152645..aaeb04a1b9 100644 --- a/cache.h +++ b/cache.h @@ -410,6 +410,7 @@ struct checkout { }; extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); +extern int has_symlink_leading_path(const char *name, char *last_symlink); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From 7841ce79854868eaaa146c1d018b17fc4f3320be Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Wed, 16 May 2007 20:09:41 +0300 Subject: connect: display connection progress Make git notify the user about host resolution/connection attempts. This is useful both as a progress indicator on slow links, and helps reassure the user there are no firewall problems. Signed-off-by: Michael S. Tsirkin Acked-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index aaeb04a1b9..206bbe4fd5 100644 --- a/cache.h +++ b/cache.h @@ -463,7 +463,8 @@ struct ref { #define REF_HEADS (1u << 1) #define REF_TAGS (1u << 2) -extern pid_t git_connect(int fd[2], char *url, const char *prog); +#define CONNECT_VERBOSE (1u << 0) +extern pid_t git_connect(int fd[2], char *url, const char *prog, int flags); extern int finish_connect(pid_t pid); extern int path_match(const char *path, int nr, char **match); extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, -- cgit v1.2.3 From 5e6cfc80e26a4d0ebac38cff74c2cdebbe66cd27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 19 May 2007 00:09:41 +0200 Subject: git-archive: convert archive entries like checkouts do As noted by Johan Herland, git-archive is a kind of checkout and needs to apply any checkout filters that might be configured. This patch adds the convenience function convert_sha1_file which returns a buffer containing the object's contents, after converting, if necessary (i.e. it's a combination of read_sha1_file and convert_to_working_tree). Direct calls to read_sha1_file in git-archive are then replaced by calls to convert_sha1_file. Since convert_sha1_file expects its path argument to be NUL-terminated -- a convention it inherits from convert_to_working_tree -- the patch also changes the path handling in archive-tar.c to always NUL-terminate the string. It used to solely rely on the len field of struct strbuf before. archive-zip.c already NUL-terminates the path and thus needs no such change. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index aaeb04a1b9..4204bc168c 100644 --- a/cache.h +++ b/cache.h @@ -548,6 +548,7 @@ extern void trace_argv_printf(const char **argv, int count, const char *format, /* convert.c */ extern char *convert_to_git(const char *path, const char *src, unsigned long *sizep); extern char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep); +extern void *convert_sha1_file(const char *path, const unsigned char *sha1, unsigned int mode, enum object_type *type, unsigned long *size); /* match-trees.c */ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int); -- cgit v1.2.3 From 6b62816cb12e621c5952f088542bec6dfc7ec5d6 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Sat, 12 May 2007 11:45:59 -0400 Subject: Move refspec parser from connect.c and cache.h to remote.{c,h} Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 65b4685c1f..0e6439b0dd 100644 --- a/cache.h +++ b/cache.h @@ -467,8 +467,6 @@ struct ref { extern pid_t git_connect(int fd[2], char *url, const char *prog, int flags); extern int finish_connect(pid_t pid); extern int path_match(const char *path, int nr, char **match); -extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, - int nr_refspec, char **refspec, int all); extern int get_ack(int fd, unsigned char *result_sha1); extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags); extern int server_supports(const char *feature); -- cgit v1.2.3 From 302b9282c9ddfcc704ca759bdc98c1d5f75eba2f Mon Sep 17 00:00:00 2001 From: Martin Waitz Date: Mon, 21 May 2007 22:08:28 +0200 Subject: rename dirlink to gitlink. Unify naming of plumbing dirlink/gitlink concept: git ls-files -z '*.[ch]' | xargs -0 perl -pi -e 's/dirlink/gitlink/g;' -e 's/DIRLNK/GITLINK/g;' Signed-off-by: Junio C Hamano --- cache.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 65b4685c1f..cd875bc2e9 100644 --- a/cache.h +++ b/cache.h @@ -40,8 +40,8 @@ * happens that everybody shares the same bit representation * in the UNIX world (and apparently wider too..) */ -#define S_IFDIRLNK 0160000 -#define S_ISDIRLNK(m) (((m) & S_IFMT) == S_IFDIRLNK) +#define S_IFGITLINK 0160000 +#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) /* * Intensive research over the course of many years has shown that @@ -123,8 +123,8 @@ static inline unsigned int create_ce_mode(unsigned int mode) { if (S_ISLNK(mode)) return htonl(S_IFLNK); - if (S_ISDIR(mode) || S_ISDIRLNK(mode)) - return htonl(S_IFDIRLNK); + if (S_ISDIR(mode) || S_ISGITLINK(mode)) + return htonl(S_IFGITLINK); return htonl(S_IFREG | ce_permissions(mode)); } static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned int mode) @@ -142,7 +142,7 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in } #define canon_mode(mode) \ (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ - S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFDIRLNK) + S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFGITLINK) #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7) -- cgit v1.2.3 From d079837eeeadc37d266113a1fd2deb0a01aaee91 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 26 May 2007 01:24:19 -0400 Subject: Lazily open pack index files on demand In some repository configurations the user may have many packfiles, but all of the recent commits/trees/tags/blobs are likely to be in the most recent packfile (the one with the newest mtime). It is therefore common to be able to complete an entire operation by accessing only one packfile, even if there are 25 packfiles available to the repository. Rather than opening and mmaping the corresponding .idx file for every pack found, we now only open and map the .idx when we suspect there might be an object of interest in there. Of course we cannot known in advance which packfile contains an object, so we still need to scan the entire packed_git list to locate anything. But odds are users want to access objects in the most recently created packfiles first, and that may be all they ever need for the current operation. Junio observed in b867092f that placing recent packfiles before older ones can slightly improve access times for recent objects, without degrading it for historical object access. This change improves upon Junio's observations by trying even harder to avoid the .idx files that we won't need. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index cd875bc2e9..0f4a05b51e 100644 --- a/cache.h +++ b/cache.h @@ -485,10 +485,11 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1, struct packed_git *packs); extern void pack_report(void); +extern int open_pack_index(struct packed_git *); extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *); extern void unuse_pack(struct pack_window **); extern struct packed_git *add_packed_git(const char *, int, int); -extern const unsigned char *nth_packed_object_sha1(const struct packed_git *, uint32_t); +extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t); extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); -- cgit v1.2.3 From 192a6be2a77ab3bf446237fdf6575b0aca863d9e Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 30 May 2007 10:32:19 -0700 Subject: fix signed range problems with hex conversions Make hexval_table[] "const". Also make sure that the accessor function hexval() does not access the table with out-of-range values by declaring its parameter "unsigned char", instead of "unsigned int". With this, gcc can just generate: movzbl (%rdi), %eax movsbl hexval_table(%rax),%edx movzbl 1(%rdi), %eax movsbl hexval_table(%rax),%eax sall $4, %edx orl %eax, %edx for the code to generate a byte from two hex characters. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7cedda684f..bea8cad5b2 100644 --- a/cache.h +++ b/cache.h @@ -302,8 +302,8 @@ extern int legacy_loose_object(unsigned char *); extern int has_pack_file(const unsigned char *sha1); extern int has_pack_index(const unsigned char *sha1); -extern signed char hexval_table[256]; -static inline unsigned int hexval(unsigned int c) +extern const signed char hexval_table[256]; +static inline unsigned int hexval(unsigned char c) { return hexval_table[c]; } -- cgit v1.2.3 From 892c41b98ae2e6baf3aa13901cb10db9ac67d2f3 Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Wed, 6 Jun 2007 09:10:42 +0200 Subject: introduce GIT_WORK_TREE to specify the work tree setup_gdg is used as abbreviation for setup_git_directory_gently. The work tree can be specified using the environment variable GIT_WORK_TREE and the config option core.worktree (the environment variable has precendence over the config option). Additionally there is a command line option --work-tree which sets the environment variable. setup_gdg does the following now: GIT_DIR unspecified repository in .git directory parent directory of the .git directory is used as work tree, GIT_WORK_TREE is ignored GIT_DIR unspecified repository in cwd GIT_DIR is set to cwd see the cases with GIT_DIR specified what happens next and also see the note below GIT_DIR specified GIT_WORK_TREE/core.worktree unspecified cwd is used as work tree GIT_DIR specified GIT_WORK_TREE/core.worktree specified the specified work tree is used Note on the case where GIT_DIR is unspecified and repository is in cwd: GIT_WORK_TREE is used but is_inside_git_dir is always true. I did it this way because setup_gdg might be called multiple times (e.g. when doing alias expansion) and in successive calls setup_gdg should do the same thing every time. Meaning of is_bare/is_inside_work_tree/is_inside_git_dir: (1) is_bare_repository A repository is bare if core.bare is true or core.bare is unspecified and the name suggests it is bare (directory not named .git). The bare option disables a few protective checks which are useful with a working tree. Currently this changes if a repository is bare: updates of HEAD are allowed git gc packs the refs the reflog is disabled by default (2) is_inside_work_tree True if the cwd is inside the associated working tree (if there is one), false otherwise. (3) is_inside_git_dir True if the cwd is inside the git directory, false otherwise. Before this patch is_inside_git_dir was always true for bare repositories. When setup_gdg finds a repository git_config(git_default_config) is always called. This ensure that is_bare_repository makes use of core.bare and does not guess even though core.bare is specified. inside_work_tree and inside_git_dir are set if setup_gdg finds a repository. The is_inside_work_tree and is_inside_git_dir functions will die if they are called before a successful call to setup_gdg. Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8a9d1f3883..ae1990a54e 100644 --- a/cache.h +++ b/cache.h @@ -192,6 +192,7 @@ enum object_type { }; #define GIT_DIR_ENVIRONMENT "GIT_DIR" +#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" @@ -207,6 +208,7 @@ enum object_type { extern int is_bare_repository_cfg; extern int is_bare_repository(void); extern int is_inside_git_dir(void); +extern int is_inside_work_tree(void); extern const char *get_git_dir(void); extern char *get_object_directory(void); extern char *get_refs_directory(void); -- cgit v1.2.3 From a6080a0a44d5ead84db3dabbbc80e82df838533d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 7 Jun 2007 00:04:01 -0700 Subject: War on whitespace This uses "git-apply --whitespace=strip" to fix whitespace errors that have crept in to our source files over time. There are a few files that need to have trailing whitespaces (most notably, test vectors). The results still passes the test, and build result in Documentation/ area is unchanged. Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8a9d1f3883..5e7381eb1e 100644 --- a/cache.h +++ b/cache.h @@ -479,7 +479,7 @@ extern void prepare_packed_git(void); extern void reprepare_packed_git(void); extern void install_packed_git(struct packed_git *pack); -extern struct packed_git *find_sha1_pack(const unsigned char *sha1, +extern struct packed_git *find_sha1_pack(const unsigned char *sha1, struct packed_git *packs); extern void pack_report(void); -- cgit v1.2.3 From 6815e56933f5bb03d6af1eb2d2b356356cf7bf8e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 11 Jun 2007 09:39:44 -0400 Subject: refactor dir_add_name This is in preparation for keeping two entry lists in the dir object. This patch adds and uses the ALLOC_GROW() macro, which implements the commonly used idiom of growing a dynamic array using the alloc_nr function (not just in dir.c, but everywhere). We also move creation of a dir_entry to dir_entry_new. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 5e7381eb1e..6761554e6c 100644 --- a/cache.h +++ b/cache.h @@ -225,6 +225,21 @@ extern void verify_non_filename(const char *prefix, const char *name); #define alloc_nr(x) (((x)+16)*3/2) +/* + * Realloc the buffer pointed at by variable 'x' so that it can hold + * at least 'nr' entries; the number of entries currently allocated + * is 'alloc', using the standard growing factor alloc_nr() macro. + * + * DO NOT USE any expression with side-effect for 'x' or 'alloc'. + */ +#define ALLOC_GROW(x, nr, alloc) \ + do { \ + if ((nr) >= alloc) { \ + alloc = alloc_nr(alloc); \ + x = xrealloc((x), alloc * sizeof(*(x))); \ + } \ + } while(0) + /* Initialize and use the cache information */ extern int read_index(struct index_state *); extern int read_index_from(struct index_state *, const char *path); -- cgit v1.2.3 From 4234a76167b12a7669dae0e6386c62e712b9dcf5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 11 Jun 2007 22:10:55 -0700 Subject: Extend --pretty=oneline to cover the first paragraph, so that an ugly commit message like this can be handled sanely. Currently, --pretty=oneline and --pretty=email (hence format-patch) take and use only the first line of the commit log message. This changes them to: - Take the first paragraph, where the definition of the first paragraph is "skip all blank lines from the beginning, and then grab everything up to the next empty line". - Replace all line breaks with a whitespace. This change would not affect a well-behaved commit message that adheres to the convention of "single line summary, a blank line, and then body of message", as its first paragraph always consists of a single line. Commit messages from different culture, such as the ones imported from CVS/SVN, can however get chomped with the existing behaviour at the first linebreak in the middle of sentence right now, which would become much easier to see with this change. The Subject: and --pretty=oneline output would become very long and unsightly for non-conforming commits, but their messages are already ugly anyway, and thischange at least avoids the loss of information. The Subject: line from a multi-line paragraph is folded using RFC2822 line folding rules at the places where line breaks were in the original. Signed-off-by: Junio C Hamano --- cache.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6761554e6c..9700ca5018 100644 --- a/cache.h +++ b/cache.h @@ -235,7 +235,10 @@ extern void verify_non_filename(const char *prefix, const char *name); #define ALLOC_GROW(x, nr, alloc) \ do { \ if ((nr) >= alloc) { \ - alloc = alloc_nr(alloc); \ + if (alloc_nr(alloc) < (nr)) \ + alloc = (nr); \ + else \ + alloc = alloc_nr(alloc); \ x = xrealloc((x), alloc * sizeof(*(x))); \ } \ } while(0) -- cgit v1.2.3 From 4175e9e3a8734be1e96e385b0fa2428b86ed5809 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 13 Jun 2007 01:42:05 -0700 Subject: More static There still are quite a few symbols that ought to be static. Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6761554e6c..cec19ba448 100644 --- a/cache.h +++ b/cache.h @@ -369,7 +369,6 @@ extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1, const char **ignore); extern int has_sha1_file(const unsigned char *sha1); -extern void *map_sha1_file(const unsigned char *sha1, unsigned long *); extern int has_pack_file(const unsigned char *sha1); extern int has_pack_index(const unsigned char *sha1); -- cgit v1.2.3 From c927e6c69b50877e116340671ed35aaf6d3a8f49 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 16 Jun 2007 18:37:39 -0400 Subject: Fix ALLOC_GROW off-by-one The ALLOC_GROW macro will never let us fill the array completely, instead allocating an extra chunk if that would be the case. This is because the 'nr' argument was originally treated as "how much we do have now" instead of "how much do we want". The latter makes much more sense because you can grow by more than one item. This off-by-one never resulted in an error because it meant we were overly conservative about when to allocate. Any callers which passed "how much we have now" need to be updated, or they will fail to allocate enough. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9700ca5018..aba7a5ec04 100644 --- a/cache.h +++ b/cache.h @@ -234,7 +234,7 @@ extern void verify_non_filename(const char *prefix, const char *name); */ #define ALLOC_GROW(x, nr, alloc) \ do { \ - if ((nr) >= alloc) { \ + if ((nr) > alloc) { \ if (alloc_nr(alloc) < (nr)) \ alloc = (nr); \ else \ -- cgit v1.2.3 From 9378c16135100fb65ad575cd35074af166de1cab Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 24 Jun 2007 15:11:24 -0700 Subject: Add core.quotepath configuration variable. We always quote "unusual" byte values in a pathname using C-string style, to make it safer for parsing scripts that do not handle NUL separated records well (or just too lazy to bother). The absolute minimum bytes that need to be quoted for this purpose are TAB, LF (and other control characters), double quote and backslash. However, we have also always quoted the bytes in high 8-bit range; this was partly because we were lazy and partly because we were being cautious. This introduces an internal "quote_path_fully" variable, and core.quotepath configuration variable to control it. When set to false, it does not quote bytes in high 8-bit range anymore but passes them intact. The variable defaults to "true" to retain the traditional behaviour for now. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ed83d92c5a..67763571b5 100644 --- a/cache.h +++ b/cache.h @@ -292,6 +292,7 @@ extern int delete_ref(const char *, const unsigned char *sha1); /* Environment bits from configuration mechanism */ extern int trust_executable_bit; +extern int quote_path_fully; extern int has_symlinks; extern int assume_unchanged; extern int prefer_symlink_refs; -- cgit v1.2.3 From 06f59e9f5daa06fc4bd51cf4c508b3edd3ed514a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 29 Jun 2007 13:40:46 -0400 Subject: Don't fflush(stdout) when it's not helpful This patch arose from a discussion started by Jim Meyering's patch whose intention was to provide better diagnostics for failed writes. Linus proposed a better way to do things, which also had the added benefit that adding a fflush() to git-log-* operations and incremental git-blame operations could improve interactive respose time feel, at the cost of making things a bit slower when we aren't piping the output to a downstream program. This patch skips the fflush() calls when stdout is a regular file, or if the environment variable GIT_FLUSH is set to "0". This latter can speed up a command such as: GIT_FLUSH=0 strace -c -f -e write time git-rev-list HEAD | wc -l a tiny amount. Signed-off-by: "Theodore Ts'o" Acked-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ed83d92c5a..0525c4ee55 100644 --- a/cache.h +++ b/cache.h @@ -532,6 +532,8 @@ extern char git_default_name[MAX_GITNAME]; extern const char *git_commit_encoding; extern const char *git_log_output_encoding; +/* IO helper functions */ +extern void maybe_flush_or_die(FILE *, const char *); extern int copy_fd(int ifd, int ofd); extern int read_in_full(int fd, void *buf, size_t count); extern int write_in_full(int fd, const void *buf, size_t count); -- cgit v1.2.3 From 54adf3706c5c799584c1bcdcac96fb3285b97de4 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Tue, 3 Jul 2007 14:18:11 -0400 Subject: Add core.pager config variable. This adds a configuration variable that performs the same function as, but is overridden by, GIT_PAGER. Signed-off-by: Brian Gernhardt Acked-by: Johannes E. Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0d23a25b1f..e64071e2e3 100644 --- a/cache.h +++ b/cache.h @@ -546,6 +546,7 @@ extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char /* pager.c */ extern void setup_pager(void); +extern char *pager_program; extern int pager_in_use; extern int pager_use_color; -- cgit v1.2.3 From 0b87b6e081e75170ffa40e92aebde1e22ad3161e Mon Sep 17 00:00:00 2001 From: Brian Downing Date: Thu, 12 Jul 2007 08:32:26 -0500 Subject: Add functions for parsing integers with size suffixes Split out the nnn{k,m,g} parsing code from git_config_int into git_parse_long, so command-line parameters can enjoy the same functionality. Also add get_parse_ulong for unsigned values. Make git_config_int use git_parse_long, and add get_config_ulong as well. Signed-off-by: Brian Downing Acked-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e64071e2e3..917a7e34f1 100644 --- a/cache.h +++ b/cache.h @@ -521,7 +521,10 @@ typedef int (*config_fn_t)(const char *, const char *); extern int git_default_config(const char *, const char *); extern int git_config_from_file(config_fn_t fn, const char *); extern int git_config(config_fn_t fn); +extern int git_parse_long(const char *, long *); +extern int git_parse_ulong(const char *, unsigned long *); extern int git_config_int(const char *, const char *); +extern unsigned long git_config_ulong(const char *, const char *); extern int git_config_bool(const char *, const char *); extern int git_config_set(const char *, const char *); extern int git_config_set_multivar(const char *, const char *, const char *, int); -- cgit v1.2.3 From ee8f838e0346751b21250f8d107049829b855a98 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 14 Jul 2007 01:00:42 +0200 Subject: Support output ISO 8601 format dates Support output of full ISO 8601 style dates in e.g. git log and other places that use interpolation for formatting. Signed-off-by: Robin Rosenberg Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 917a7e34f1..b39557dd01 100644 --- a/cache.h +++ b/cache.h @@ -409,7 +409,7 @@ extern void *read_object_with_reference(const unsigned char *sha1, unsigned long *size, unsigned char *sha1_ret); -enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL }; +enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL, DATE_ISO8601 }; const char *show_date(unsigned long time, int timezone, enum date_mode mode); const char *show_rfc2822_date(unsigned long time, int timezone); int parse_date(const char *date, char *buf, int bufsize); -- cgit v1.2.3 From 73013afd14c14ba178ab2aaa458168ec1d5506de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 13 Jul 2007 23:14:52 -0700 Subject: Make show_rfc2822_date() just another date output format. These days, show_date() takes a date_mode parameter to specify the output format, and a separate specialized function for dates in E-mails does not make much sense anymore. This retires show_rfc2822_date() function and make it just another date output format. Signed-off-by: Junio C Hamano --- cache.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b39557dd01..328c1ad411 100644 --- a/cache.h +++ b/cache.h @@ -409,9 +409,16 @@ extern void *read_object_with_reference(const unsigned char *sha1, unsigned long *size, unsigned char *sha1_ret); -enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL, DATE_ISO8601 }; +enum date_mode { + DATE_NORMAL = 0, + DATE_RELATIVE, + DATE_SHORT, + DATE_LOCAL, + DATE_ISO8601, + DATE_RFC2822 +}; + const char *show_date(unsigned long time, int timezone, enum date_mode mode); -const char *show_rfc2822_date(unsigned long time, int timezone); int parse_date(const char *date, char *buf, int bufsize); void datestamp(char *buf, int bufsize); unsigned long approxidate(const char *); -- cgit v1.2.3 From c4fba0a358d43fdb2301dd122d68c49dd8471d71 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Wed, 18 Jul 2007 20:31:03 +0200 Subject: Rename read_pipe() with read_fd() and make its buffer nul-terminated. The new name is closer to the purpose of the function. A NUL-terminated buffer makes things easier when callers need that. Since the function returns only the memory written with data, almost always allocating more space than needed because final size is unknown, an extra NUL terminating the buffer is harmless. It is not included in the returned size, so the function remains working as before. Also, now the function allows the buffer passed to be NULL at first, and alloc_nr is now used for growing the buffer, instead size=*2. Signed-off-by: Carlos Rica Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 328c1ad411..53801b8089 100644 --- a/cache.h +++ b/cache.h @@ -265,7 +265,7 @@ extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); -extern int read_pipe(int fd, char** return_buf, unsigned long* return_size); +extern int read_fd(int fd, char **return_buf, unsigned long *return_size); extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object); extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); -- cgit v1.2.3 From 4d87b9c5db2590f7616fedfc0a538fc78f528e14 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 20 Jul 2007 13:06:09 +0100 Subject: launch_editor(): Heed GIT_EDITOR and core.editor settings In the commit 'Add GIT_EDITOR environment and core.editor configuration variables', this was done for the shell scripts. Port it over to builtin-tag's version of launch_editor(), which is just about to be refactored into editor.c. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 53801b8089..67b1af16d9 100644 --- a/cache.h +++ b/cache.h @@ -560,6 +560,8 @@ extern char *pager_program; extern int pager_in_use; extern int pager_use_color; +extern char *editor_program; + /* base85 */ int decode_85(char *dst, const char *line, int linelen); void encode_85(char *buf, const unsigned char *data, int bytes); -- cgit v1.2.3 From e5392c51469c25851f9c6e53165d75fc61901768 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 01:28:59 +0100 Subject: Add is_absolute_path() and make_absolute_path() This patch adds convenience functions to work with absolute paths. The function is_absolute_path() should help the efforts to integrate the MinGW fork. Note that make_absolute_path() returns a pointer to a static buffer. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 53801b8089..98af53040d 100644 --- a/cache.h +++ b/cache.h @@ -358,6 +358,11 @@ int git_config_perm(const char *var, const char *value); int adjust_shared_perm(const char *path); int safe_create_leading_directories(char *path); char *enter_repo(char *path, int strict); +static inline int is_absolute_path(const char *path) +{ + return path[0] == '/'; +} +const char *make_absolute_path(const char *path); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); -- cgit v1.2.3 From d7ac12b25d375d32372b13f74e90425ca21d5dc1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 01:29:38 +0100 Subject: Add set_git_dir() function With the function set_git_dir() you can reset the path that will be used for git_path(), git_dir() and friends. The responsibility to close files and throw away information from the old git_dir lies with the caller. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 98af53040d..e1f94cbade 100644 --- a/cache.h +++ b/cache.h @@ -214,6 +214,7 @@ extern char *get_object_directory(void); extern char *get_refs_directory(void); extern char *get_index_file(void); extern char *get_graft_file(void); +extern int set_git_dir(const char *path); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" -- cgit v1.2.3 From e90fdc39b6903502192b2dd11e5503cea721a1ad Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Aug 2007 01:30:14 +0100 Subject: Clean up work-tree handling The old version of work-tree support was an unholy mess, barely readable, and not to the point. For example, why do you have to provide a worktree, when it is not used? As in "git status". Now it works. Another riddle was: if you can have work trees inside the git dir, why are some programs complaining that they need a work tree? IOW it is allowed to call $ git --git-dir=../ --work-tree=. bla when you really want to. In this case, you are both in the git directory and in the working tree. So, programs have to actually test for the right thing, namely if they are inside a working tree, and not if they are inside a git directory. Also, GIT_DIR=../.git should behave the same as if no GIT_DIR was specified, unless there is a repository in the current working directory. It does now. The logic to determine if a repository is bare, or has a work tree (tertium non datur), is this: --work-tree=bla overrides GIT_WORK_TREE, which overrides core.bare = true, which overrides core.worktree, which overrides GIT_DIR/.. when GIT_DIR ends in /.git, which overrides the directory in which .git/ was found. In related news, a long standing bug was fixed: when in .git/bla/x.git/, which is a bare repository, git formerly assumed ../.. to be the appropriate git dir. This problem was reported by Shawn Pearce to have caused much pain, where a colleague mistakenly ran "git init" in "/" a long time ago, and bare repositories just would not work. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e1f94cbade..e97af18eea 100644 --- a/cache.h +++ b/cache.h @@ -208,6 +208,7 @@ enum object_type { extern int is_bare_repository_cfg; extern int is_bare_repository(void); extern int is_inside_git_dir(void); +extern char *git_work_tree_cfg; extern int is_inside_work_tree(void); extern const char *get_git_dir(void); extern char *get_object_directory(void); @@ -215,6 +216,7 @@ extern char *get_refs_directory(void); extern char *get_index_file(void); extern char *get_graft_file(void); extern int set_git_dir(const char *path); +extern const char *get_git_work_tree(void); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" -- cgit v1.2.3 From af3785dc5a76f4d5ddb8039e33c322e0e8b60e72 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 9 Aug 2007 13:42:50 -0700 Subject: Optimize "diff --cached" performance. The read_tree() function is called only from the call chain to run "git diff --cached" (this includes the internal call made by git-runstatus to run_diff_index()). The function vacates stage without any funky "merge" magic. The caller then goes and compares stage #1 entries from the tree with stage #0 entries from the original index. When adding the cache entries this way, it used the general purpose add_cache_entry(). This function looks for an existing entry to replace or if there is none to find where to insert the new entry, resolves D/F conflict and all the other things. For the purpose of reading entries into an empty stage, none of that processing is needed. We can instead append everything and then sort the result at the end. This commit changes read_tree() to first make sure that there is no existing cache entries at specified stage, and if that is the case, it runs add_cache_entry() with ADD_CACHE_JUST_APPEND flag (new), and then sort the resulting cache using qsort(). This new flag tells add_cache_entry() to omit all the checks such as "Does this path already exist? Does adding this path remove other existing entries because it turns a directory to a file?" and instead append the given cache entry straight at the end of the active cache. The caller of course is expected to sort the resulting cache at the end before using the result. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e97af18eea..e5276e6add 100644 --- a/cache.h +++ b/cache.h @@ -258,6 +258,7 @@ extern int index_name_pos(struct index_state *, const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ +#define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option); extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); extern int remove_index_entry_at(struct index_state *, int pos); -- cgit v1.2.3 From d616813d75b888b7c29bbad19808fe5cffa5380c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 11 Aug 2007 23:59:01 +0200 Subject: git-add: Add support for --refresh option. This allows to refresh only a subset of the project files, based on the specified pathspecs. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4507404240..c7e00e7b05 100644 --- a/cache.h +++ b/cache.h @@ -173,7 +173,7 @@ extern struct index_state the_index; #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) #define add_file_to_cache(path, verbose) add_file_to_index(&the_index, (path), (verbose)) -#define refresh_cache(flags) refresh_index(&the_index, flags) +#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL) #define ce_match_stat(ce, st, really) ie_match_stat(&the_index, (ce), (st), (really)) #define ce_modified(ce, st, really) ie_modified(&the_index, (ce), (st), (really)) #endif @@ -278,7 +278,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); #define REFRESH_UNMERGED 0x0002 /* allow unmerged */ #define REFRESH_QUIET 0x0004 /* be quiet about it */ #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ -extern int refresh_index(struct index_state *, unsigned int flags); +extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen); struct lock_file { struct lock_file *next; -- cgit v1.2.3 From aecbf914c43ab76e055fa8a25b12456ae74d91bc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 31 Aug 2007 13:13:42 -0700 Subject: git-diff: resurrect the traditional empty "diff --git" behaviour The warning message to suggest "Consider running git-status" from "git-diff" that we experimented with during the 1.5.3 cycle turns out to be a bad idea. It robbed cache-dirty information from people who valued it, while still asking users to run "update-index --refresh". It was hoped that the new behaviour would at least have some educational value, but not showing the cache-dirty paths like before meant that the user would not even know easily which paths were cache-dirty, and it made the need to refresh the index look like even more unnecessary chore. This commit reinstates the traditional behaviour, but with a twist. By default, the empty "diff --git" output is totally squelched out from "git diff" output. At the end of the command, it automatically runs "update-index --refresh" as needed, without even bothering the user. In other words, people who do not care about the cache-dirtyness do not even have to see the warning. The traditional behaviour to see the stat-dirty output and to bypassing the overhead of content comparison can be specified by setting the configuration variable diff.autorefreshindex to false. Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index c7e00e7b05..70abbd59bf 100644 --- a/cache.h +++ b/cache.h @@ -594,6 +594,9 @@ extern char *convert_to_git(const char *path, const char *src, unsigned long *si extern char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep); extern void *convert_sha1_file(const char *path, const unsigned char *sha1, unsigned int mode, enum object_type *type, unsigned long *size); +/* diff.c */ +extern int diff_auto_refresh_index; + /* match-trees.c */ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int); -- cgit v1.2.3 From 89b4256cfbb8d878cc4cd1104ac4865ba1f2a58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 3 Sep 2007 20:08:01 +0200 Subject: Remove unused function convert_sha1_file() convert_sha1_file() became unused by the previous patch -- remove it. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 70abbd59bf..493983cbae 100644 --- a/cache.h +++ b/cache.h @@ -592,7 +592,6 @@ extern void trace_argv_printf(const char **argv, int count, const char *format, /* convert.c */ extern char *convert_to_git(const char *path, const char *src, unsigned long *sizep); extern char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep); -extern void *convert_sha1_file(const char *path, const unsigned char *sha1, unsigned int mode, enum object_type *type, unsigned long *size); /* diff.c */ extern int diff_auto_refresh_index; -- cgit v1.2.3 From fd17f5b5f77716bf90098c6e49e3cf7fd9f56306 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 10 Sep 2007 12:35:09 +0200 Subject: Replace all read_fd use with strbuf_read, and get rid of it. This brings builtin-stripspace, builtin-tag and mktag to use strbufs. Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 493983cbae..231f81d8e3 100644 --- a/cache.h +++ b/cache.h @@ -269,7 +269,6 @@ extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); -extern int read_fd(int fd, char **return_buf, unsigned long *return_size); extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object); extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); -- cgit v1.2.3 From 6640f88165f77edcc266a2c0c56fb017dc613198 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Tue, 11 Sep 2007 05:17:28 +0200 Subject: Move make_cache_entry() from merge-recursive.c into read-cache.c The function make_cache_entry() is too useful to be hidden away in merge-recursive. So move it to libgit.a (exposing it via cache.h). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 493983cbae..8246500166 100644 --- a/cache.h +++ b/cache.h @@ -264,6 +264,7 @@ extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall extern int remove_index_entry_at(struct index_state *, int pos); extern int remove_file_from_index(struct index_state *, const char *path); extern int add_file_to_index(struct index_state *, const char *path, int verbose); +extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, int); extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); -- cgit v1.2.3 From 5ecd293d1420bf641a927a015877950f4d79c067 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 16 Sep 2007 15:51:04 +0200 Subject: Rewrite convert_to_{git,working_tree} to use strbuf's. * Now, those functions take an "out" strbuf argument, where they store their result if any. In that case, it also returns 1, else it returns 0. * those functions support "in place" editing, in the sense that it's OK to call them this way: convert_to_git(path, sb->buf, sb->len, sb); When doable, conversions are done in place for real, else the strbuf content is just replaced with the new one, transparentely for the caller. If you want to create a new filter working this way, being the accumulation of filter1, filter2, ... filtern, then your meta_filter would be: int meta_filter(..., const char *src, size_t len, struct strbuf *sb) { int ret = 0; ret |= filter1(...., src, len, sb); if (ret) { src = sb->buf; len = sb->len; } ret |= filter2(...., src, len, sb); if (ret) { src = sb->buf; len = sb->len; } .... return ret | filtern(..., src, len, sb); } That's why subfilters the convert_to_* functions called were also rewritten to work this way. Signed-off-by: Pierre Habouzit Acked-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 231f81d8e3..37eb57eaba 100644 --- a/cache.h +++ b/cache.h @@ -2,6 +2,7 @@ #define CACHE_H #include "git-compat-util.h" +#include "strbuf.h" #include SHA1_HEADER #include @@ -589,8 +590,9 @@ extern void trace_printf(const char *format, ...); extern void trace_argv_printf(const char **argv, int count, const char *format, ...); /* convert.c */ -extern char *convert_to_git(const char *path, const char *src, unsigned long *sizep); -extern char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep); +/* returns 1 if *dst was used */ +extern int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst); +extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); /* diff.c */ extern int diff_auto_refresh_index; -- cgit v1.2.3 From 000dfd3f6e3f61e15ccfd4cecb3a51624adfbf38 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Sep 2007 23:15:19 -0700 Subject: Export matches_pack_name() and fix its return value The function sounds boolean; make it behave as one, not "0 for success, non-zero for failure". Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 70abbd59bf..3fa5b8e6a8 100644 --- a/cache.h +++ b/cache.h @@ -529,6 +529,7 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); +extern int matches_pack_name(struct packed_git *p, const char *name); /* Dumb servers support */ extern int update_server_info(int); -- cgit v1.2.3 From b888d61c8308027433df9c243fa551f42db1c76a Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 10 Sep 2007 23:03:25 -0400 Subject: Make fetch a builtin Thanks to Johannes Schindelin for review and fixes, and Julian Phillips for the original C translation. This changes a few small bits of behavior: branch..merge is parsed as if it were the lhs of a fetch refspec, and does not have to exactly match the actual lhs of a refspec, so long as it is a valid abbreviation for the same ref. branch..merge is no longer ignored if the remote is configured with a branches/* file. Neither behavior is useful, because there can only be one ref that gets fetched, but this is more consistant. Also, fetch prints different information to standard out. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8246500166..16bdbb2591 100644 --- a/cache.h +++ b/cache.h @@ -492,6 +492,7 @@ struct ref { unsigned char old_sha1[20]; unsigned char new_sha1[20]; unsigned char force; + unsigned char merge; struct ref *peer_ref; /* when renaming */ char name[FLEX_ARRAY]; /* more */ }; -- cgit v1.2.3 From 19247e5510279f018f8358a72b38cc5aa62fac8a Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 20 Sep 2007 10:43:11 +0200 Subject: nfv?asprintf are broken without va_copy, workaround them. * drop nfasprintf. * move nfvasprintf into imap-send.c back, and let it work on a 8k buffer, and die() in case of overflow. It should be enough for imap commands, if someone cares about imap-send, he's welcomed to fix it properly. * replace nfvasprintf use in merge-recursive with a copy of the strbuf_addf logic, it's one place, we'll live with it. To ease the change, output_buffer string list is replaced with a strbuf ;) * rework trace.c to call vsnprintf itself. It's used to format strerror()s and git command names, it should never be more than a few octets long, let it work on a 8k static buffer with vsnprintf or die loudly. Signed-off-by: Pierre Habouzit --- cache.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8650d62334..916ee5155b 100644 --- a/cache.h +++ b/cache.h @@ -585,8 +585,6 @@ extern void *alloc_object_node(void); extern void alloc_report(void); /* trace.c */ -extern int nfasprintf(char **str, const char *fmt, ...); -extern int nfvasprintf(char **str, const char *fmt, va_list va); extern void trace_printf(const char *format, ...); extern void trace_argv_printf(const char **argv, int count, const char *format, ...); -- cgit v1.2.3 From 102c2338da0b0954a04742f5cbe307fa6b49f225 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Tue, 11 Sep 2007 05:17:28 +0200 Subject: Move make_cache_entry() from merge-recursive.c into read-cache.c The function make_cache_entry() is too useful to be hidden away in merge-recursive. So move it to libgit.a (exposing it via cache.h). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 70abbd59bf..fc195bc47c 100644 --- a/cache.h +++ b/cache.h @@ -264,6 +264,7 @@ extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall extern int remove_index_entry_at(struct index_state *, int pos); extern int remove_file_from_index(struct index_state *, const char *path); extern int add_file_to_index(struct index_state *, const char *path, int verbose); +extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, int); extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); -- cgit v1.2.3 From 856665f827c31ace3f19e672f8911f7f15f2a0e2 Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Fri, 28 Sep 2007 15:17:31 +0100 Subject: parse_date_format(): convert a format name to an enum date_mode Factor out the code to parse --date= parameter to revision walkers into a separate function, parse_date_format(). This function is passed a string and converts it to an enum date_format: - "relative" => DATE_RELATIVE - "iso8601" or "iso" => DATE_ISO8601 - "rfc2822" => DATE_RFC2822 - "short" => DATE_SHORT - "local" => DATE_LOCAL - "default" => DATE_NORMAL In the event that none of these strings is found, the function die()s. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8246500166..5587f7ebc7 100644 --- a/cache.h +++ b/cache.h @@ -432,6 +432,7 @@ const char *show_date(unsigned long time, int timezone, enum date_mode mode); int parse_date(const char *date, char *buf, int bufsize); void datestamp(char *buf, int bufsize); unsigned long approxidate(const char *); +enum date_mode parse_date_format(const char *format); extern const char *git_author_info(int); extern const char *git_committer_info(int); -- cgit v1.2.3 From 98158e9cfd2808613f305bf587ce697762c884bb Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 19 Oct 2007 21:47:53 +0200 Subject: Change git_connect() to return a struct child_process instead of a pid_t. This prepares the API of git_connect() and finish_connect() to operate on a struct child_process. Currently, we just use that object as a placeholder for the pid that we used to return. A follow-up patch will change the implementation of git_connect() and finish_connect() to make full use of the object. Old code had early-return-on-error checks at the calling sites of git_connect(), but since git_connect() dies on errors anyway, these checks were removed. [sp: Corrected style nit of "conn == NULL" to "!conn"] Signed-off-by: Johannes Sixt Signed-off-by: Shawn O. Pearce --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 27485d36c2..bfffa05dff 100644 --- a/cache.h +++ b/cache.h @@ -503,8 +503,8 @@ struct ref { #define REF_TAGS (1u << 2) #define CONNECT_VERBOSE (1u << 0) -extern pid_t git_connect(int fd[2], char *url, const char *prog, int flags); -extern int finish_connect(pid_t pid); +extern struct child_process *git_connect(int fd[2], char *url, const char *prog, int flags); +extern int finish_connect(struct child_process *conn); extern int path_match(const char *path, int nr, char **match); extern int get_ack(int fd, unsigned char *result_sha1); extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags); -- cgit v1.2.3 From a9cc857ada7c57069ff00eed8d0addcf55849f39 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 2 Nov 2007 00:24:27 -0700 Subject: War on whitespace: first, a bit of retreat. This introduces core.whitespace configuration variable that lets you specify the definition of "whitespace error". Currently there are two kinds of whitespace errors defined: * trailing-space: trailing whitespaces at the end of the line. * space-before-tab: a SP appears immediately before HT in the indent part of the line. You can specify the desired types of errors to be detected by listing their names (unique abbreviations are accepted) separated by comma. By default, these two errors are always detected, as that is the traditional behaviour. You can disable detection of a particular type of error by prefixing a '-' in front of the name of the error, like this: [core] whitespace = -trailing-space This patch teaches the code to output colored diff with DIFF_WHITESPACE color to highlight the detected whitespace errors to honor the new configuration. Signed-off-by: Junio C Hamano --- cache.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index bfffa05dff..a6e5988f07 100644 --- a/cache.h +++ b/cache.h @@ -602,4 +602,13 @@ extern int diff_auto_refresh_index; /* match-trees.c */ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int); +/* + * whitespace rules. + * used by both diff and apply + */ +#define WS_TRAILING_SPACE 01 +#define WS_SPACE_BEFORE_TAB 02 +#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB) +extern unsigned whitespace_rule; + #endif /* CACHE_H */ -- cgit v1.2.3 From 459fa6d0fe6a45b8b120463b56a68e943e3a8101 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 Oct 2007 18:00:27 -0700 Subject: git-diff: complain about >=8 consecutive spaces in initial indent This introduces a new whitespace error type, "indent-with-non-tab". The error is about starting a line with 8 or more SP, instead of indenting it with a HT. This is not enabled by default, as some projects employ an indenting policy to use only SPs and no HTs. The kernel folks and git contributors may want to enable this detection with: [core] whitespace = indent-with-non-tab Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a6e5988f07..3f4282795e 100644 --- a/cache.h +++ b/cache.h @@ -608,6 +608,7 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i */ #define WS_TRAILING_SPACE 01 #define WS_SPACE_BEFORE_TAB 02 +#define WS_INDENT_WITH_NON_TAB 04 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB) extern unsigned whitespace_rule; -- cgit v1.2.3 From 4577370e9bfeca8652880b99b8499f76d18865ba Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 29 Oct 2007 21:05:40 -0400 Subject: Miscellaneous const changes and utilities The list of remote refs in struct transport should be const, because builtin-fetch will get confused if it changes. The url in git_connect should be const (and work on a copy) instead of requiring the caller to copy it. match_refs doesn't modify the refspecs it gets. get_fetch_map and get_remote_ref don't change the list they get. Allow transport get_refs_list methods to modify the struct transport. Add a function to copy a list of refs, when a function needs a mutable copy of a const list. Add a function to check the type of a ref, as per the code in connect.c Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index bfffa05dff..119566bf6f 100644 --- a/cache.h +++ b/cache.h @@ -503,7 +503,7 @@ struct ref { #define REF_TAGS (1u << 2) #define CONNECT_VERBOSE (1u << 0) -extern struct child_process *git_connect(int fd[2], char *url, const char *prog, int flags); +extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags); extern int finish_connect(struct child_process *conn); extern int path_match(const char *path, int nr, char **match); extern int get_ack(int fd, unsigned char *result_sha1); -- cgit v1.2.3 From 59f0f2f33a420e9a14bb8cef20d38f508f0d098e Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sat, 3 Nov 2007 12:23:11 +0100 Subject: Refactor working tree setup Create a setup_work_tree() that can be used from any command requiring a working tree conditionally. Signed-off-by: Mike Hommey Acked-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index bfffa05dff..497b9f962d 100644 --- a/cache.h +++ b/cache.h @@ -222,6 +222,7 @@ extern const char *get_git_work_tree(void); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" extern const char **get_pathspec(const char *prefix, const char **pathspec); +extern void setup_work_tree(void); extern const char *setup_git_directory_gently(int *); extern const char *setup_git_directory(void); extern const char *prefix_path(const char *prefix, int len, const char *path); -- cgit v1.2.3 From 609a2289d76fd9a7dddceabc63d1654fe61e0ffb Mon Sep 17 00:00:00 2001 From: David Symonds Date: Wed, 7 Nov 2007 14:24:28 +1100 Subject: Improve accuracy of check for presence of deflateBound. ZLIB_VERNUM isn't defined in some zlib versions, so this patch does a proper linking test in autoconf to see whether deflateBound exists in zlib. Also, setting NO_DEFLATE_BOUND will also work for folk not using autoconf. Signed-off-by: David Symonds Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index fc195bc47c..ddc011d192 100644 --- a/cache.h +++ b/cache.h @@ -6,7 +6,7 @@ #include SHA1_HEADER #include -#if ZLIB_VERNUM < 0x1200 +#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200 #define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11) #endif -- cgit v1.2.3 From 4bd5b7dacc404e6b733d9ab6744429c5027bb5e1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 10 Nov 2007 00:15:03 -0800 Subject: ce_match_stat, run_diff_files: use symbolic constants for readability ce_match_stat() can be told: (1) to ignore CE_VALID bit (used under "assume unchanged" mode) and perform the stat comparison anyway; (2) not to perform the contents comparison for racily clean entries and report mismatch of cached stat information; using its "option" parameter. Give them symbolic constants. Similarly, run_diff_files() can be told not to report anything on removed paths. Also give it a symbolic constant for that. Signed-off-by: Junio C Hamano --- cache.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index fc195bc47c..31af16a7ee 100644 --- a/cache.h +++ b/cache.h @@ -174,8 +174,8 @@ extern struct index_state the_index; #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) #define add_file_to_cache(path, verbose) add_file_to_index(&the_index, (path), (verbose)) #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL) -#define ce_match_stat(ce, st, really) ie_match_stat(&the_index, (ce), (st), (really)) -#define ce_modified(ce, st, really) ie_modified(&the_index, (ce), (st), (really)) +#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) +#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) #endif enum object_type { @@ -266,8 +266,14 @@ extern int remove_file_from_index(struct index_state *, const char *path); extern int add_file_to_index(struct index_state *, const char *path, int verbose); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); -extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, int); -extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); + +/* do stat comparison even if CE_VALID is true */ +#define CE_MATCH_IGNORE_VALID 01 +/* do not check the contents but report dirty on racily-clean entries */ +#define CE_MATCH_RACY_IS_DIRTY 02 +extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, unsigned int); +extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, unsigned int); + extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); extern int read_fd(int fd, char **return_buf, unsigned long *return_size); -- cgit v1.2.3 From 039bc64e886716593d59910694a6c8ed5b72c515 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 14 Nov 2007 00:05:00 -0800 Subject: core.excludesfile clean-up There are inconsistencies in the way commands currently handle the core.excludesfile configuration variable. The problem is the variable is too new to be noticed by anything other than git-add and git-status. * git-ls-files does not notice any of the "ignore" files by default, as it predates the standardized set of ignore files. The calling scripts established the convention to use .git/info/exclude, .gitignore, and later core.excludesfile. * git-add and git-status know about it because they call add_excludes_from_file() directly with their own notion of which standard set of ignore files to use. This is just a stupid duplication of code that need to be updated every time the definition of the standard set of ignore files is changed. * git-read-tree takes --exclude-per-directory=, not because the flexibility was needed. Again, this was because the option predates the standardization of the ignore files. * git-merge-recursive uses hardcoded per-directory .gitignore and nothing else. git-clean (scripted version) does not honor core.* because its call to underlying ls-files does not know about it. git-clean in C (parked in 'pu') doesn't either. We probably could change git-ls-files to use the standard set when no excludes are specified on the command line and ignore processing was asked, or something like that, but that will be a change in semantics and might break people's scripts in a subtle way. I am somewhat reluctant to make such a change. On the other hand, I think it makes perfect sense to fix git-read-tree, git-merge-recursive and git-clean to follow the same rule as other commands. I do not think of a valid use case to give an exclude-per-directory that is nonstandard to read-tree command, outside a "negative" test in the t1004 test script. This patch is the first step to untangle this mess. The next step would be to teach read-tree, merge-recursive and clean (in C) to use setup_standard_excludes(). Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f4f27cd70d..33ebccf48d 100644 --- a/cache.h +++ b/cache.h @@ -581,6 +581,7 @@ extern int pager_in_use; extern int pager_use_color; extern char *editor_program; +extern char *excludes_file; /* base85 */ int decode_85(char *dst, const char *line, int linelen); -- cgit v1.2.3 From 4723ee992cba052dc735b7d2b6f43aad26d9150a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 13 Nov 2007 21:05:03 +0100 Subject: Close files opened by lock_file() before unlinking. This is needed on Windows since open files cannot be unlinked. Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 33ebccf48d..dc75f9d343 100644 --- a/cache.h +++ b/cache.h @@ -290,6 +290,7 @@ extern int refresh_index(struct index_state *, unsigned int flags, const char ** struct lock_file { struct lock_file *next; + int fd; pid_t owner; char on_list; char filename[PATH_MAX]; -- cgit v1.2.3 From 506b17b136ba8ee29098c2ee26b94f527cea9ebc Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Tue, 13 Nov 2007 21:05:05 +0100 Subject: Introduce git_etc_gitconfig() that encapsulates access of ETC_GITCONFIG. In a subsequent patch the path to the system-wide config file will be computed. This is a preparation for that change. It turns all accesses of ETC_GITCONFIG into function calls. There is no change in behavior. As a consequence, config.c is the only file that needs the definition of ETC_GITCONFIG. Hence, -DETC_GITCONFIG is removed from the CFLAGS and a special build rule for config.c is introduced. As a side-effect, changing the defintion of ETC_GITCONFIG (e.g. in config.mak) does not trigger a complete rebuild anymore. Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index dc75f9d343..a0b93770d4 100644 --- a/cache.h +++ b/cache.h @@ -557,6 +557,7 @@ extern int git_config_bool(const char *, const char *); extern int git_config_set(const char *, const char *); extern int git_config_set_multivar(const char *, const char *, const char *, int); extern int git_config_rename_section(const char *, const char *); +extern const char *git_etc_gitconfig(void); extern int check_repository_format_version(const char *var, const char *value); #define MAX_GITNAME (1000) -- cgit v1.2.3 From 8736a8489080509516f5f4cc1cc74de33150f397 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 17 Nov 2007 07:54:27 -0500 Subject: send-pack: track errors for each ref Instead of keeping the 'ret' variable, we instead have a status flag for each ref that tracks what happened to it. We then print the ref status after all of the refs have been examined. This paves the way for three improvements: - updating tracking refs only for non-error refs - incorporating remote rejection into the printed status - printing errors in a different order than we processed (e.g., consolidating non-ff errors near the end with a special message) Signed-off-by: Jeff King Acked-by: Alex Riesen Acked-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e5ea637c29..6663ec52d1 100644 --- a/cache.h +++ b/cache.h @@ -493,8 +493,17 @@ struct ref { struct ref *next; unsigned char old_sha1[20]; unsigned char new_sha1[20]; - unsigned char force; - unsigned char merge; + unsigned char force : 1; + unsigned char merge : 1; + unsigned char nonfastforward : 1; + unsigned char deletion : 1; + enum { + REF_STATUS_NONE = 0, + REF_STATUS_OK, + REF_STATUS_REJECT_NONFASTFORWARD, + REF_STATUS_REJECT_NODELETE, + REF_STATUS_UPTODATE, + } status; struct ref *peer_ref; /* when renaming */ char name[FLEX_ARRAY]; /* more */ }; -- cgit v1.2.3 From ca74c458a3908314cf29b96f1c43fe2b2597de76 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 17 Nov 2007 07:56:03 -0500 Subject: send-pack: assign remote errors to each ref This lets us show remote errors (e.g., a denied hook) along with the usual push output. There is a slightly clever optimization in receive_status that bears explanation. We need to correlate the returned status and our ref objects, which naively could be an O(m*n) operation. However, since the current implementation of receive-pack returns the errors to us in the same order that we sent them, we optimistically look for the next ref to be looked up to come after the last one we have found. So it should be an O(m+n) merge if the receive-pack behavior holds, but we fall back to a correct but slower behavior if it should change. Signed-off-by: Jeff King Acked-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6663ec52d1..81e8c88e46 100644 --- a/cache.h +++ b/cache.h @@ -503,7 +503,9 @@ struct ref { REF_STATUS_REJECT_NONFASTFORWARD, REF_STATUS_REJECT_NODELETE, REF_STATUS_UPTODATE, + REF_STATUS_REMOTE_REJECT, } status; + char *error; struct ref *peer_ref; /* when renaming */ char name[FLEX_ARRAY]; /* more */ }; -- cgit v1.2.3 From 9f8a15c73437abc634f2c43501105b108c51eae8 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 18 Nov 2007 04:31:37 -0500 Subject: Fix warning about bitfield in struct ref cache.h:503: warning: type of bit-field 'force' is a GCC extension cache.h:504: warning: type of bit-field 'merge' is a GCC extension cache.h:505: warning: type of bit-field 'nonfastforward' is a GCC extension cache.h:506: warning: type of bit-field 'deletion' is a GCC extension So we change it to an 'unsigned int' which is not a GCC extension. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- cache.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 81e8c88e46..6ccb764229 100644 --- a/cache.h +++ b/cache.h @@ -493,10 +493,10 @@ struct ref { struct ref *next; unsigned char old_sha1[20]; unsigned char new_sha1[20]; - unsigned char force : 1; - unsigned char merge : 1; - unsigned char nonfastforward : 1; - unsigned char deletion : 1; + unsigned int force:1, + merge:1, + nonfastforward:1, + deletion:1; enum { REF_STATUS_NONE = 0, REF_STATUS_OK, -- cgit v1.2.3 From cda69f481db510e2a3f0ca8a0f4b54123c799416 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 18 Nov 2007 02:13:10 -0500 Subject: make "find_ref_by_name" a public function This was a static in remote.c, but is generally useful. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6ccb764229..8d601dd6f7 100644 --- a/cache.h +++ b/cache.h @@ -514,6 +514,8 @@ struct ref { #define REF_HEADS (1u << 1) #define REF_TAGS (1u << 2) +extern struct ref *find_ref_by_name(struct ref *list, const char *name); + #define CONNECT_VERBOSE (1u << 0) extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags); extern int finish_connect(struct child_process *conn); -- cgit v1.2.3 From 2a0fe89a976331cb2163d4f299e38e2cb5010632 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 18 Nov 2007 02:16:52 -0500 Subject: send-pack: tighten remote error reporting Previously, we set all ref pushes to 'OK', and then marked them as errors if the remote reported so. This has the problem that if the remote dies or fails to report a ref, we just assume it was OK. Instead, we use a new non-OK state to indicate that we are expecting status (if the remote doesn't support the report-status feature, we fall back on the old behavior). Thus we can flag refs for which we expected a status, but got none (conversely, we now also print a warning for refs for which we get a status, but weren't expecting one). This also allows us to simplify the receive_status exit code, since each ref is individually marked with failure until we get a success response. We can just print the usual status table, so the user still gets a sense of what we were trying to do when the failure happened. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8d601dd6f7..e0c1cc3fe8 100644 --- a/cache.h +++ b/cache.h @@ -504,8 +504,9 @@ struct ref { REF_STATUS_REJECT_NODELETE, REF_STATUS_UPTODATE, REF_STATUS_REMOTE_REJECT, + REF_STATUS_EXPECTING_REPORT, } status; - char *error; + char *remote_status; struct ref *peer_ref; /* when renaming */ char name[FLEX_ARRAY]; /* more */ }; -- cgit v1.2.3 From 79803322c1d8d2f74e1a53d44f363d878180e0f5 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Sun, 11 Nov 2007 15:01:46 +0100 Subject: add refname_match() We use at least two rulesets for matching abbreviated refnames with full refnames (starting with 'refs/'). git-rev-parse and git-fetch use slightly different rules. This commit introduces a new function refname_match (const char *abbrev_name, const char *full_name, const char **rules). abbrev_name is expanded using the rules and matched against full_name. If a match is found the function returns true. rules is a NULL-terminate list of format patterns with "%.*s", for example: const char *ref_rev_parse_rules[] = { "%.*s", "refs/%.*s", "refs/tags/%.*s", "refs/heads/%.*s", "refs/remotes/%.*s", "refs/remotes/%.*s/HEAD", NULL }; Asterisks are included in the format strings because this is the form required in sha1_name.c. Sharing the list with the functions there is a good idea to avoid duplicating the rules. Hopefully this facilitates unified matching rules in the future. This commit makes the rules used by rev-parse for resolving refs to sha1s available for string comparison. Before this change, the rules were buried in get_sha1*() and dwim_ref(). A follow-up commit will refactor the rules used by fetch. refname_match() will be used for matching refspecs in git-send-pack. Thanks to Daniel Barkalow for pointing out that ref_matches_abbrev in remote.c solves a similar problem and care should be taken to avoid confusion. Signed-off-by: Steffen Prohaska Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 33ebccf48d..38d9a285e0 100644 --- a/cache.h +++ b/cache.h @@ -415,6 +415,9 @@ extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int * extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref); extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref); +extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules); +extern const char *ref_rev_parse_rules[]; + extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg); extern int validate_headref(const char *ref); -- cgit v1.2.3 From 605b4978a105e2f40a353513f616be7d20f91c15 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Sun, 11 Nov 2007 15:01:48 +0100 Subject: refactor fetch's ref matching to use refname_match() The old rules used by fetch were coded as a series of ifs. The old rules are: 1) match full refname if it starts with "refs/" or matches "HEAD" 2) verify that full refname starts with "refs/" 3) match abbreviated name in "refs/" if it starts with "heads/", "tags/", or "remotes/". 4) match abbreviated name in "refs/heads/" This is replaced by the new rules a) match full refname b) match abbreviated name prefixed with "refs/" c) match abbreviated name prefixed with "refs/heads/" The details of the new rules are different from the old rules. We no longer verify that the full refname starts with "refs/". The new rule (a) matches any full string. The old rules (1) and (2) were stricter. Now, the caller is responsible for using sensible full refnames. This should be the case for the current code. The new rule (b) is less strict than old rule (3). The new rule accepts abbreviated names that start with a non-standard prefix below "refs/". Despite this modifications the new rules should handle all cases as expected. Two tests are added to verify that fetch does not resolve short tags or HEAD in remotes. We may even think about loosening the rules a bit more and unify them with the rev-parse rules. This would be done by replacing ref_ref_fetch_rules with ref_ref_parse_rules. Note, the two new test would break. Signed-off-by: Steffen Prohaska Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 38d9a285e0..cb8f3cabbb 100644 --- a/cache.h +++ b/cache.h @@ -417,6 +417,7 @@ extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref); extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules); extern const char *ref_rev_parse_rules[]; +extern const char *ref_fetch_rules[]; extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg); extern int validate_headref(const char *ref); -- cgit v1.2.3 From ee425e4643aa2d7be72cb4586d7554cecce44d6e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 18 Nov 2007 01:13:32 -0800 Subject: Export three helper functions from ls-files This exports three helper functions from ls-files. * pathspec_match() checks if a given path matches a set of pathspecs and optionally records which pathspec was used. This function used to be called "match()" but renamed to be a bit less vague. * report_path_error() takes a set of pathspecs and the record pathspec_match() above leaves, and gives error message. This was split out of the main function of ls-files. * overlay_tree_on_cache() takes a tree-ish (typically "HEAD") and overlays it on the current in-core index. By iterating over the resulting index, the caller can find out the paths in either the index or the HEAD. This function used to be called "overlay_tree()" but renamed to be a bit more descriptive. Signed-off-by: Junio C Hamano --- cache.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 33ebccf48d..26eec229eb 100644 --- a/cache.h +++ b/cache.h @@ -610,4 +610,10 @@ extern int diff_auto_refresh_index; /* match-trees.c */ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int); + +/* ls-files */ +int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen); +int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset); +void overlay_tree_on_cache(const char *tree_name, const char *prefix); + #endif /* CACHE_H */ -- cgit v1.2.3 From b6ec1d619fb54642388063a88e2255556cf5de06 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 18 Nov 2007 01:12:04 -0800 Subject: Fix add_files_to_cache() to take pathspec, not user specified list of files This separates the logic to limit the extent of change to the index by where you are (controlled by "prefix") and what you specify from the command line (controlled by "pathspec"). Signed-off-by: Junio C Hamano --- cache.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 26eec229eb..cf0bdc674c 100644 --- a/cache.h +++ b/cache.h @@ -604,13 +604,15 @@ extern void trace_argv_printf(const char **argv, int count, const char *format, extern int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst); extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); +/* add */ +void add_files_to_cache(int verbose, const char *prefix, const char **pathspec); + /* diff.c */ extern int diff_auto_refresh_index; /* match-trees.c */ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int); - /* ls-files */ int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen); int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset); -- cgit v1.2.3 From b45563a229f5150271837cf487a91ddd8224fbd3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 30 Nov 2007 22:22:38 -0800 Subject: rename: Break filepairs with different types. When we consider if a path has been totally rewritten, we did not touch changes from symlinks to files or vice versa. But a change that modifies even the type of a blob surely should count as a complete rewrite. While we are at it, modernise diffcore-break to be aware of gitlinks (we do not want to touch them). Signed-off-by: Junio C Hamano --- cache.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index aaa135bfde..d0e7a71c6e 100644 --- a/cache.h +++ b/cache.h @@ -192,6 +192,13 @@ enum object_type { OBJ_MAX, }; +static inline enum object_type object_type(unsigned int mode) +{ + return S_ISDIR(mode) ? OBJ_TREE : + S_ISGITLINK(mode) ? OBJ_COMMIT : + OBJ_BLOB; +} + #define GIT_DIR_ENVIRONMENT "GIT_DIR" #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" -- cgit v1.2.3 From d9ccfe7711a8bf1ed9d9cd87daa9863e0d564b23 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 2 Dec 2007 13:43:34 -0800 Subject: Fix --signoff in builtin-commit differently. Introduce fmt_name() specifically meant for formatting the name and email pair, to add signed-off-by value. This reverts parts of 13208572fbe8838fd8835548d7502202d1f7b21d (builtin-commit: fix --signoff) so that an empty datestamp string given to fmt_ident() by mistake will error out as before. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index cf0bdc674c..43cfebb0cf 100644 --- a/cache.h +++ b/cache.h @@ -444,6 +444,7 @@ enum date_mode parse_date_format(const char *format); extern const char *git_author_info(int); extern const char *git_committer_info(int); extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int); +extern const char *fmt_name(const char *name, const char *email); struct checkout { const char *base_dir; -- cgit v1.2.3 From b319ce4c14f7fe0ee469a3f9def1098d84177849 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 3 Dec 2007 05:51:50 +0100 Subject: Trace and quote with argv: get rid of unneeded count argument. Now that str_buf takes care of all the allocations, there is no more gain to pass an argument count. So this patch removes the "count" argument from: - "sq_quote_argv" - "trace_argv_printf" and all the callers. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index d0e7a71c6e..ed8be06299 100644 --- a/cache.h +++ b/cache.h @@ -620,7 +620,7 @@ extern void alloc_report(void); /* trace.c */ extern void trace_printf(const char *format, ...); -extern void trace_argv_printf(const char **argv, int count, const char *format, ...); +extern void trace_argv_printf(const char **argv, const char *format, ...); /* convert.c */ /* returns 1 if *dst was used */ -- cgit v1.2.3 From cf1b7869f0c571bbd4f72a4355d9aca558baa0da Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 6 Dec 2007 00:14:14 -0800 Subject: Use gitattributes to define per-path whitespace rule The `core.whitespace` configuration variable allows you to define what `diff` and `apply` should consider whitespace errors for all paths in the project (See gitlink:git-config[1]). This attribute gives you finer control per path. For example, if you have these in the .gitattributes: frotz whitespace nitfol -whitespace xyzzy whitespace=-trailing all types of whitespace problems known to git are noticed in path 'frotz' (i.e. diff shows them in diff.whitespace color, and apply warns about them), no whitespace problem is noticed in path 'nitfol', and the default types of whitespace problems except "trailing whitespace" are noticed for path 'xyzzy'. A project with mixed Python and C might want to have: *.c whitespace *.py whitespace=-indent-with-non-tab in its toplevel .gitattributes file. Signed-off-by: Junio C Hamano --- cache.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3f4282795e..9cc6268d45 100644 --- a/cache.h +++ b/cache.h @@ -610,6 +610,8 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i #define WS_SPACE_BEFORE_TAB 02 #define WS_INDENT_WITH_NON_TAB 04 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB) -extern unsigned whitespace_rule; +extern unsigned whitespace_rule_cfg; +extern unsigned whitespace_rule(const char *); +extern unsigned parse_whitespace_rule(const char *); #endif /* CACHE_H */ -- cgit v1.2.3 From 774751a8bc594a5b56039bbdc43c45e3882dd804 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 8 Dec 2007 17:32:08 -0800 Subject: Re-fix "builtin-commit: fix --signoff" An earlier fix to the said commit was incomplete; it mixed up the meaning of the flag parameter passed to the internal fmt_ident() function, so this corrects it. git_author_info() and git_committer_info() can be told to issue a warning when no usable user information is found, and optionally can be told to error out. Operations that actually use the information to record a new commit or a tag will still error out, but the caller to leave reflog record will just silently use bogus user information. Not warning on misconfigured user information while writing a reflog entry is somewhat debatable, but it is probably nicer to the users to silently let it pass, because the only information you are losing is who checked out the branch. * git_author_info() and git_committer_info() used to take 1 (positive int) to error out with a warning on misconfiguration; this is now signalled with a symbolic constant IDENT_ERROR_ON_NO_NAME. * These functions used to take -1 (negative int) to warn but continue; this is now signalled with a symbolic constant IDENT_WARN_ON_NO_NAME. * fmt_ident() function implements the above error reporting behaviour common to git_author_info() and git_committer_info(). A symbolic constant IDENT_NO_DATE can be or'ed in to the flag parameter to make it return only the "Name ". * fmt_name() is a thin wrapper around fmt_ident() that always passes IDENT_ERROR_ON_NO_NAME and IDENT_NO_DATE. Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 406befb705..c6142e9b7a 100644 --- a/cache.h +++ b/cache.h @@ -453,6 +453,9 @@ void datestamp(char *buf, int bufsize); unsigned long approxidate(const char *); enum date_mode parse_date_format(const char *format); +#define IDENT_WARN_ON_NO_NAME 1 +#define IDENT_ERROR_ON_NO_NAME 2 +#define IDENT_NO_DATE 4 extern const char *git_author_info(int); extern const char *git_committer_info(int); extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int); -- cgit v1.2.3 From 6e9af863ee76423ec8416ad16140ef5f810783bf Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 11 Dec 2007 01:27:33 -0500 Subject: Support GIT_PAGER_IN_USE environment variable When deciding whether or not to turn on automatic color support, git_config_colorbool checks whether stdout is a tty. However, because we run a pager, if stdout is not a tty, we must check whether it is because we started the pager. This used to be done by checking the pager_in_use variable. This variable was set only when the git program being run started the pager; there was no way for an external program running git indicate that it had already started a pager. This patch allows a program to set GIT_PAGER_IN_USE to a true value to indicate that even though stdout is not a tty, it is because a pager is being used. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1bcb3df7a2..27d90fe543 100644 --- a/cache.h +++ b/cache.h @@ -608,7 +608,7 @@ extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char /* pager.c */ extern void setup_pager(void); extern char *pager_program; -extern int pager_in_use; +extern int pager_in_use(void); extern int pager_use_color; extern char *editor_program; -- cgit v1.2.3 From c1795bb08aae9fb7e4dc1a01e292b85e59b1c640 Mon Sep 17 00:00:00 2001 From: Wincent Colaiuta Date: Thu, 13 Dec 2007 14:32:29 +0100 Subject: Unify whitespace checking This commit unifies three separate places where whitespace checking was performed: - the whitespace checking previously done in builtin-apply.c is extracted into a function in ws.c - the equivalent logic in "git diff" is removed - the emit_line_with_ws() function is also removed because that also rechecks the whitespace, and its functionality is rolled into ws.c The new function is called check_and_emit_line() and it does two things: checks a line for whitespace errors and optionally emits it. The checking is based on lines of content rather than patch lines (in other words, the caller must strip the leading "+" or "-"); this was suggested by Junio on the mailing list to allow for a future extension to "git show" to display whitespace errors in blobs. At the same time we teach it to report all classes of whitespace errors found for a given line rather than reporting only the first found error. Signed-off-by: Wincent Colaiuta Signed-off-by: Junio C Hamano --- cache.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 27d90fe543..39331c28be 100644 --- a/cache.h +++ b/cache.h @@ -655,6 +655,10 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i extern unsigned whitespace_rule_cfg; extern unsigned whitespace_rule(const char *); extern unsigned parse_whitespace_rule(const char *); +extern unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, + FILE *stream, const char *set, + const char *reset, const char *ws); +extern char *whitespace_error_string(unsigned ws); /* ls-files */ int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen); -- cgit v1.2.3 From d6cf61bfd4bccffcc8b095f8469dbe749d70abdf Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 16 Jan 2008 11:05:32 -0800 Subject: close_lock_file(): new function in the lockfile API The lockfile API is a handy way to obtain a file that is cleaned up if you die(). But sometimes you would need this sequence to work: 1. hold_lock_file_for_update() to get a file descriptor for writing; 2. write the contents out, without being able to decide if the results should be committed or rolled back; 3. do something else that makes the decision --- and this "something else" needs the lockfile not to have an open file descriptor for writing (e.g. Windows do not want a open file to be renamed); 4. call commit_lock_file() or rollback_lock_file() as appropriately. This adds close_lock_file() you can call between step 2 and 3 in the above sequence. Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 39331c28be..24735bdfee 100644 --- a/cache.h +++ b/cache.h @@ -308,7 +308,7 @@ extern int commit_lock_file(struct lock_file *); extern int hold_locked_index(struct lock_file *, int); extern int commit_locked_index(struct lock_file *); extern void set_alternate_index_output(const char *); - +extern int close_lock_file(struct lock_file *); extern void rollback_lock_file(struct lock_file *); extern int delete_ref(const char *, const unsigned char *sha1); -- cgit v1.2.3 From c9ced051c3afa6f3da7f59b0dcb92787b2b5c702 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 17 Jan 2008 22:57:00 -0500 Subject: Fix random fast-import errors when compiled with NO_MMAP fast-import was relying on the fact that on most systems mmap() and write() are synchronized by the filesystem's buffer cache. We were relying on the ability to mmap() 20 bytes beyond the current end of the file, then later fill in those bytes with a future write() call, then read them through the previously obtained mmap() address. This isn't always true with some implementations of NFS, but it is especially not true with our NO_MMAP=YesPlease build time option used on some platforms. If fast-import was built with NO_MMAP=YesPlease we used the malloc()+pread() emulation and the subsequent write() call does not update the trailing 20 bytes of a previously obtained "mmap()" (aka malloc'd) address. Under NO_MMAP that behavior causes unpack_entry() in sha1_file.c to be unable to read an object header (or data) that has been unlucky enough to be written to the packfile at a location such that it is in the trailing 20 bytes of a window previously opened on that same packfile. This bug has gone unnoticed for a very long time as it is highly data dependent. Not only does the object have to be placed at the right position, but it also needs to be positioned behind some other object that has been accessed due to a branch cache invalidation. In other words the stars had to align just right, and if you did run into this bug you probably should also have purchased a lottery ticket. Fortunately the workaround is a lot easier than the bug explanation. Before we allow unpack_entry() to read data from a pack window that has also (possibly) been modified through write() we force all existing windows on that packfile to be closed. By closing the windows we ensure that any new access via the emulated mmap() will reread the packfile, updating to the current file content. This comes at a slight performance degredation as we cannot reuse previously cached windows when we update the packfile. But it is a fairly minor difference as the window closes happen at only two points: - When the packfile is finalized and its .idx is generated: At this stage we are getting ready to update the refs and any data access into the packfile is going to be random, and is going after only the branch tips (to ensure they are valid). Our existing windows (if any) are not likely to be positioned at useful locations to access those final tip commits so we probably were closing them before anyway. - When the branch cache missed and we need to reload: At this point fast-import is getting change commands for the next commit and it needs to go re-read a tree object it previously had written out to the packfile. What windows we had (if any) are not likely to cover the tree in question so we probably were closing them before anyway. We do try to avoid unnecessarily closing windows in the second case by checking to see if the packfile size has increased since the last time we called unpack_entry() on that packfile. If the size has not changed then we have not written additional data, and any existing window is still vaild. This nicely handles the cases where fast-import is going through a branch cache reload and needs to read many trees at once. During such an event we are not likely to be updating the packfile so we do not cycle the windows between reads. With this change in place t9301-fast-export.sh (which was broken by c3b0dec509fe136c5417422f31898b5a4e2d5e02) finally works again. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 24735bdfee..549f4bbac7 100644 --- a/cache.h +++ b/cache.h @@ -561,6 +561,7 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1, extern void pack_report(void); extern int open_pack_index(struct packed_git *); extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *); +extern void close_pack_windows(struct packed_git *); extern void unuse_pack(struct pack_window **); extern struct packed_git *add_packed_git(const char *, int, int); extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t); -- cgit v1.2.3 From 7a51ed66f653c248993b3c4a61932e47933d835e Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 14 Jan 2008 16:03:17 -0800 Subject: Make on-disk index representation separate from in-core one This converts the index explicitly on read and write to its on-disk format, allowing the in-core format to contain more flags, and be simpler. In particular, the in-core format is now host-endian (as opposed to the on-disk one that is network endian in order to be able to be shared across machines) and as a result we can dispense with all the htonl/ntohl on accesses to the cache_entry fields. This will make it easier to make use of various temporary flags that do not exist in the on-disk format. Signed-off-by: Linus Torvalds --- cache.h | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 549f4bbac7..4a054c5402 100644 --- a/cache.h +++ b/cache.h @@ -94,48 +94,66 @@ struct cache_time { * We save the fields in big-endian order to allow using the * index file over NFS transparently. */ +struct ondisk_cache_entry { + struct cache_time ctime; + struct cache_time mtime; + unsigned int dev; + unsigned int ino; + unsigned int mode; + unsigned int uid; + unsigned int gid; + unsigned int size; + unsigned char sha1[20]; + unsigned short flags; + char name[FLEX_ARRAY]; /* more */ +}; + struct cache_entry { - struct cache_time ce_ctime; - struct cache_time ce_mtime; + unsigned int ce_ctime; + unsigned int ce_mtime; unsigned int ce_dev; unsigned int ce_ino; unsigned int ce_mode; unsigned int ce_uid; unsigned int ce_gid; unsigned int ce_size; + unsigned int ce_flags; unsigned char sha1[20]; - unsigned short ce_flags; char name[FLEX_ARRAY]; /* more */ }; #define CE_NAMEMASK (0x0fff) #define CE_STAGEMASK (0x3000) -#define CE_UPDATE (0x4000) #define CE_VALID (0x8000) #define CE_STAGESHIFT 12 -#define create_ce_flags(len, stage) htons((len) | ((stage) << CE_STAGESHIFT)) -#define ce_namelen(ce) (CE_NAMEMASK & ntohs((ce)->ce_flags)) +/* In-memory only */ +#define CE_UPDATE (0x10000) +#define CE_REMOVE (0x20000) + +#define create_ce_flags(len, stage) ((len) | ((stage) << CE_STAGESHIFT)) +#define ce_namelen(ce) (CE_NAMEMASK & (ce)->ce_flags) #define ce_size(ce) cache_entry_size(ce_namelen(ce)) -#define ce_stage(ce) ((CE_STAGEMASK & ntohs((ce)->ce_flags)) >> CE_STAGESHIFT) +#define ondisk_ce_size(ce) ondisk_cache_entry_size(ce_namelen(ce)) +#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644) static inline unsigned int create_ce_mode(unsigned int mode) { if (S_ISLNK(mode)) - return htonl(S_IFLNK); + return S_IFLNK; if (S_ISDIR(mode) || S_ISGITLINK(mode)) - return htonl(S_IFGITLINK); - return htonl(S_IFREG | ce_permissions(mode)); + return S_IFGITLINK; + return S_IFREG | ce_permissions(mode); } static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned int mode) { extern int trust_executable_bit, has_symlinks; if (!has_symlinks && S_ISREG(mode) && - ce && S_ISLNK(ntohl(ce->ce_mode))) + ce && S_ISLNK(ce->ce_mode)) return ce->ce_mode; if (!trust_executable_bit && S_ISREG(mode)) { - if (ce && S_ISREG(ntohl(ce->ce_mode))) + if (ce && S_ISREG(ce->ce_mode)) return ce->ce_mode; return create_ce_mode(0666); } @@ -146,14 +164,14 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFGITLINK) #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7) +#define ondisk_cache_entry_size(len) ((offsetof(struct ondisk_cache_entry,name) + (len) + 8) & ~7) struct index_state { struct cache_entry **cache; unsigned int cache_nr, cache_alloc, cache_changed; struct cache_tree *cache_tree; time_t timestamp; - void *mmap; - size_t mmap_size; + void *alloc; }; extern struct index_state the_index; -- cgit v1.2.3 From 7fec10b7f41fa32e71aa6377bd04cd7c6fb419e0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 18 Jan 2008 23:42:00 -0800 Subject: index: be careful when handling long names We currently use lower 12-bit (masked with CE_NAMEMASK) in the ce_flags field to store the length of the name in cache_entry, without checking the length parameter given to create_ce_flags(). This can make us store incorrect length. Currently we are mostly protected by the fact that many codepaths first copy the path in a variable of size PATH_MAX, which typically is 4096 that happens to match the limit, but that feels like a bug waiting to happen. Besides, that would not allow us to shorten the width of CE_NAMEMASK to use the bits for new flags. This redefines the meaning of the name length stored in the cache_entry. A name that does not fit is represented by storing CE_NAMEMASK in the field, and the actual length needs to be computed by actually counting the bytes in the name[] field. This way, only the unusually long paths need to suffer. Signed-off-by: Junio C Hamano Signed-off-by: Linus Torvalds --- cache.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4a054c5402..9eaffdefd0 100644 --- a/cache.h +++ b/cache.h @@ -131,8 +131,21 @@ struct cache_entry { #define CE_UPDATE (0x10000) #define CE_REMOVE (0x20000) -#define create_ce_flags(len, stage) ((len) | ((stage) << CE_STAGESHIFT)) -#define ce_namelen(ce) (CE_NAMEMASK & (ce)->ce_flags) +static inline unsigned create_ce_flags(size_t len, unsigned stage) +{ + if (len >= CE_NAMEMASK) + len = CE_NAMEMASK; + return (len | (stage << CE_STAGESHIFT)); +} + +static inline size_t ce_namelen(const struct cache_entry *ce) +{ + size_t len = ce->ce_flags & CE_NAMEMASK; + if (len < CE_NAMEMASK) + return len; + return strlen(ce->name + CE_NAMEMASK) + CE_NAMEMASK; +} + #define ce_size(ce) cache_entry_size(ce_namelen(ce)) #define ondisk_ce_size(ce) ondisk_cache_entry_size(ce_namelen(ce)) #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) -- cgit v1.2.3 From eadb5831342bb2e756fa05c03642c4aa1929d4f5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 18 Jan 2008 23:45:24 -0800 Subject: Avoid running lstat(2) on the same cache entry. Aside from the lstat(2) done for work tree files, there are quite many lstat(2) calls in refname dwimming codepath. This patch is not about reducing them. * It adds a new ce_flag, CE_UPTODATE, that is meant to mark the cache entries that record a regular file blob that is up to date in the work tree. If somebody later walks the index and wants to see if the work tree has changes, they do not have to be checked with lstat(2) again. * fill_stat_cache_info() marks the cache entry it just added with CE_UPTODATE. This has the effect of marking the paths we write out of the index and lstat(2) immediately as "no need to lstat -- we know it is up-to-date", from quite a lot fo callers: - git-apply --index - git-update-index - git-checkout-index - git-add (uses add_file_to_index()) - git-commit (ditto) - git-mv (ditto) * refresh_cache_ent() also marks the cache entry that are clean with CE_UPTODATE. * write_index is changed not to write CE_UPTODATE out to the index file, because CE_UPTODATE is meant to be transient only in core. For the same reason, CE_UPDATE is not written to prevent an accident from happening. Signed-off-by: Junio C Hamano Signed-off-by: Linus Torvalds --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9eaffdefd0..3a47cdc9d2 100644 --- a/cache.h +++ b/cache.h @@ -130,6 +130,7 @@ struct cache_entry { /* In-memory only */ #define CE_UPDATE (0x10000) #define CE_REMOVE (0x20000) +#define CE_UPTODATE (0x40000) static inline unsigned create_ce_flags(size_t len, unsigned stage) { @@ -149,6 +150,8 @@ static inline size_t ce_namelen(const struct cache_entry *ce) #define ce_size(ce) cache_entry_size(ce_namelen(ce)) #define ondisk_ce_size(ce) ondisk_cache_entry_size(ce_namelen(ce)) #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) +#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE) +#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE) #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644) static inline unsigned int create_ce_mode(unsigned int mode) -- cgit v1.2.3 From cf558704fb68514a820e3666968967c900e0fd29 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 22 Jan 2008 18:41:14 -0800 Subject: Create pathname-based hash-table lookup into index This creates a hash index of every single file added to the index. Right now that hash index isn't actually used for much: I implemented a "cache_name_exists()" function that uses it to efficiently look up a filename in the index without having to do the O(logn) binary search, but quite frankly, that's not why this patch is interesting. No, the whole and only reason to create the hash of the filenames in the index is that by modifying the hash function, you can fairly easily do things like making it always hash equivalent names into the same bucket. That, in turn, means that suddenly questions like "does this name exist in the index under an _equivalent_ name?" becomes much much cheaper. Guiding principles behind this patch: - it shouldn't be too costly. In fact, my primary goal here was to actually speed up "git commit" with a fully populated kernel tree, by being faster at checking whether a file already existed in the index. I did succeed, but only barely: Best before: [torvalds@woody linux]$ time git commit > /dev/null real 0m0.255s user 0m0.168s sys 0m0.088s Best after: [torvalds@woody linux]$ time ~/git/git commit > /dev/null real 0m0.233s user 0m0.144s sys 0m0.088s so some things are actually faster (~8%). Caveat: that's really the best case. Other things are invariably going to be slightly slower, since we populate that index cache, and quite frankly, few things really use it to look things up. That said, the cost is really quite small. The worst case is probably doing a "git ls-files", which will do very little except puopulate the index, and never actually looks anything up in it, just lists it. Before: [torvalds@woody linux]$ time git ls-files > /dev/null real 0m0.016s user 0m0.016s sys 0m0.000s After: [torvalds@woody linux]$ time ~/git/git ls-files > /dev/null real 0m0.021s user 0m0.012s sys 0m0.008s and while the thing has really gotten relatively much slower, we're still talking about something almost unmeasurable (eg 5ms). And that really should be pretty much the worst case. So we lose 5ms on one "benchmark", but win 22ms on another. Pick your poison - this patch has the advantage that it will _likely_ speed up the cases that are complex and expensive more than it slows down the cases that are already so fast that nobody cares. But if you look at relative speedups/slowdowns, it doesn't look so good. - It should be simple and clean The code may be a bit subtle (the reasons I do hash removal the way I do etc), but it re-uses the existing hash.c files, so it really is fairly small and straightforward apart from a few odd details. Now, this patch on its own doesn't really do much, but I think it's worth looking at, if only because if done correctly, the name hashing really can make an improvement to the whole issue of "do we have a filename that looks like this in the index already". And at least it gets real testing by being used even by default (ie there is a real use-case for it even without any insane filesystems). NOTE NOTE NOTE! The current hash is a joke. I'm ashamed of it, I'm just not ashamed of it enough to really care. I took all the numbers out of my nether regions - I'm sure it's good enough that it works in practice, but the whole point was that you can make a really much fancier hash that hashes characters not directly, but by their upper-case value or something like that, and thus you get a case-insensitive hash, while still keeping the name and the index itself totally case sensitive. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3a47cdc9d2..409738ca6b 100644 --- a/cache.h +++ b/cache.h @@ -3,6 +3,7 @@ #include "git-compat-util.h" #include "strbuf.h" +#include "hash.h" #include SHA1_HEADER #include @@ -109,6 +110,7 @@ struct ondisk_cache_entry { }; struct cache_entry { + struct cache_entry *next; unsigned int ce_ctime; unsigned int ce_mtime; unsigned int ce_dev; @@ -131,6 +133,7 @@ struct cache_entry { #define CE_UPDATE (0x10000) #define CE_REMOVE (0x20000) #define CE_UPTODATE (0x40000) +#define CE_UNHASHED (0x80000) static inline unsigned create_ce_flags(size_t len, unsigned stage) { @@ -188,6 +191,7 @@ struct index_state { struct cache_tree *cache_tree; time_t timestamp; void *alloc; + struct hash_table name_hash; }; extern struct index_state the_index; @@ -211,6 +215,7 @@ extern struct index_state the_index; #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) +#define cache_name_exists(name, namelen) index_name_exists(&the_index, (name), (namelen)) #endif enum object_type { @@ -297,6 +302,7 @@ extern int read_index_from(struct index_state *, const char *path); extern int write_index(struct index_state *, int newfd); extern int discard_index(struct index_state *); extern int verify_path(const char *path); +extern int index_name_exists(struct index_state *istate, const char *name, int namelen); extern int index_name_pos(struct index_state *, const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ -- cgit v1.2.3 From 9cb76b8cdc8ac62a77080595f6443613fd64bab3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 22 Jan 2008 23:01:13 -0800 Subject: lazy index hashing This delays the hashing of index names until it becomes necessary for the first time. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 409738ca6b..e4aeff07d1 100644 --- a/cache.h +++ b/cache.h @@ -191,6 +191,7 @@ struct index_state { struct cache_tree *cache_tree; time_t timestamp; void *alloc; + unsigned name_hash_initialized : 1; struct hash_table name_hash; }; -- cgit v1.2.3 From b2979ff599a6bcf9dbf5e2ef1e32b81a1b88e115 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 15 Jan 2008 00:59:05 -0800 Subject: core.whitespace: cr-at-eol This new error mode allows a line to have a carriage return at the end of the line when checking and fixing trailing whitespace errors. Some people like to keep CRLF line ending recorded in the repository, and still want to take advantage of the automated trailing whitespace stripping. We still show ^M in the diff output piped to "less" to remind them that they do have the CR at the end, but these carriage return characters at the end are no longer flagged as errors. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 549f4bbac7..ad11c90caf 100644 --- a/cache.h +++ b/cache.h @@ -652,6 +652,7 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i #define WS_TRAILING_SPACE 01 #define WS_SPACE_BEFORE_TAB 02 #define WS_INDENT_WITH_NON_TAB 04 +#define WS_CR_AT_EOL 010 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB) extern unsigned whitespace_rule_cfg; extern unsigned whitespace_rule(const char *); -- cgit v1.2.3 From d6b8fc303b389b026f2bf9918f6f83041488989b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 31 Jan 2008 01:17:48 -0800 Subject: gitignore(5): Allow "foo/" in ignore list to match directory "foo" A pattern "foo/" in the exclude list did not match directory "foo", but a pattern "foo" did. This attempts to extend the exclude mechanism so that it would while not matching a regular file or a symbolic link "foo". In order to differentiate a directory and non directory, this passes down the type of path being checked to excluded() function. A downside is that the recursive directory walk may need to run lstat(2) more often on systems whose "struct dirent" do not give the type of the entry; earlier it did not have to do so for an excluded path, but we now need to figure out if a path is a directory before deciding to exclude it. This is especially bad because an idea similar to the earlier CE_UPTODATE optimization to reduce number of lstat(2) calls would by definition not apply to the codepaths involved, as (1) directories will not be registered in the index, and (2) excluded paths will not be in the index anyway. Signed-off-by: Junio C Hamano --- cache.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 549f4bbac7..5529830110 100644 --- a/cache.h +++ b/cache.h @@ -141,6 +141,18 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in } return create_ce_mode(mode); } +static inline int ce_to_dtype(const struct cache_entry *ce) +{ + unsigned ce_mode = ntohl(ce->ce_mode); + if (S_ISREG(ce_mode)) + return DT_REG; + else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode)) + return DT_DIR; + else if (S_ISLNK(ce_mode)) + return DT_LNK; + else + return DT_UNKNOWN; +} #define canon_mode(mode) \ (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFGITLINK) -- cgit v1.2.3 From 21e5ad50fc5e7277c74cfbb3cf6502468e840f86 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Wed, 6 Feb 2008 12:25:58 +0100 Subject: safecrlf: Add mechanism to warn about irreversible crlf conversions CRLF conversion bears a slight chance of corrupting data. autocrlf=true will convert CRLF to LF during commit and LF to CRLF during checkout. A file that contains a mixture of LF and CRLF before the commit cannot be recreated by git. For text files this is the right thing to do: it corrects line endings such that we have only LF line endings in the repository. But for binary files that are accidentally classified as text the conversion can corrupt data. If you recognize such corruption early you can easily fix it by setting the conversion type explicitly in .gitattributes. Right after committing you still have the original file in your work tree and this file is not yet corrupted. You can explicitly tell git that this file is binary and git will handle the file appropriately. Unfortunately, the desired effect of cleaning up text files with mixed line endings and the undesired effect of corrupting binary files cannot be distinguished. In both cases CRLFs are removed in an irreversible way. For text files this is the right thing to do because CRLFs are line endings, while for binary files converting CRLFs corrupts data. This patch adds a mechanism that can either warn the user about an irreversible conversion or can even refuse to convert. The mechanism is controlled by the variable core.safecrlf, with the following values: - false: disable safecrlf mechanism - warn: warn about irreversible conversions - true: refuse irreversible conversions The default is to warn. Users are only affected by this default if core.autocrlf is set. But the current default of git is to leave core.autocrlf unset, so users will not see warnings unless they deliberately chose to activate the autocrlf mechanism. The safecrlf mechanism's details depend on the git command. The general principles when safecrlf is active (not false) are: - we warn/error out if files in the work tree can modified in an irreversible way without giving the user a chance to backup the original file. - for read-only operations that do not modify files in the work tree we do not not print annoying warnings. There are exceptions. Even though... - "git add" itself does not touch the files in the work tree, the next checkout would, so the safety triggers; - "git apply" to update a text file with a patch does touch the files in the work tree, but the operation is about text files and CRLF conversion is about fixing the line ending inconsistencies, so the safety does not trigger; - "git diff" itself does not touch the files in the work tree, it is often run to inspect the changes you intend to next "git add". To catch potential problems early, safety triggers. The concept of a safety check was originally proposed in a similar way by Linus Torvalds. Thanks to Dimitry Potapov for insisting on getting the naked LF/autocrlf=true case right. Signed-off-by: Steffen Prohaska --- cache.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 549f4bbac7..6003c83b2d 100644 --- a/cache.h +++ b/cache.h @@ -330,6 +330,14 @@ extern size_t packed_git_limit; extern size_t delta_base_cache_limit; extern int auto_crlf; +enum safe_crlf { + SAFE_CRLF_FALSE = 0, + SAFE_CRLF_FAIL = 1, + SAFE_CRLF_WARN = 2, +}; + +extern enum safe_crlf safe_crlf; + #define GIT_REPO_VERSION 0 extern int repository_format_version; extern int check_repository_format(void); @@ -633,7 +641,8 @@ extern void trace_argv_printf(const char **argv, const char *format, ...); /* convert.c */ /* returns 1 if *dst was used */ -extern int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst); +extern int convert_to_git(const char *path, const char *src, size_t len, + struct strbuf *dst, enum safe_crlf checksafe); extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); /* add */ -- cgit v1.2.3 From ab88c36321df647e17d477f19591cf6ca95de7f0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 6 Feb 2008 05:11:18 -0500 Subject: allow suppressing of global and system config The GIT_CONFIG_NOGLOBAL and GIT_CONFIG_NOSYSTEM environment variables are magic undocumented switches that can be used to ensure a totally clean environment. This is necessary for running reliable tests, since those config files may contain settings that change the outcome of tests. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 549f4bbac7..af74e203b7 100644 --- a/cache.h +++ b/cache.h @@ -589,6 +589,9 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int extern int git_config_rename_section(const char *, const char *); extern const char *git_etc_gitconfig(void); extern int check_repository_format_version(const char *var, const char *value); +extern int git_env_bool(const char *, int); +extern int git_config_system(void); +extern int git_config_global(void); #define MAX_GITNAME (1000) extern char git_default_email[MAX_GITNAME]; -- cgit v1.2.3 From 94a5728cfb593d80164620f8fa7e1ef322ad0025 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Thu, 7 Feb 2008 11:40:13 -0500 Subject: Library function to check for unmerged index entries It's small, but it was in three places already, so it should be in the library. Signed-off-by: Daniel Barkalow --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e4aeff07d1..888895a969 100644 --- a/cache.h +++ b/cache.h @@ -208,6 +208,7 @@ extern struct index_state the_index; #define read_cache_from(path) read_index_from(&the_index, (path)) #define write_cache(newfd, cache, entries) write_index(&the_index, (newfd)) #define discard_cache() discard_index(&the_index) +#define unmerged_cache() unmerged_index(&the_index) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) @@ -302,6 +303,7 @@ extern int read_index(struct index_state *); extern int read_index_from(struct index_state *, const char *path); extern int write_index(struct index_state *, int newfd); extern int discard_index(struct index_state *); +extern int unmerged_index(struct index_state *); extern int verify_path(const char *path); extern int index_name_exists(struct index_state *istate, const char *name, int namelen); extern int index_name_pos(struct index_state *, const char *name, int namelen); -- cgit v1.2.3 From 40ea4ed9032a80c9dba706d6030bd11b08c35f4d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 11 Feb 2008 10:41:18 -0800 Subject: Add config_error_nonbool() helper function This is used to report misconfigured configuration file that does not give any value to a non-boolean variable, e.g. [section] var It is perfectly fine to say it if the section.var is a boolean (it means true), but if a variable expects a string value it should be flagged as a configuration error. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 549f4bbac7..6abcee4372 100644 --- a/cache.h +++ b/cache.h @@ -589,6 +589,7 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int extern int git_config_rename_section(const char *, const char *); extern const char *git_etc_gitconfig(void); extern int check_repository_format_version(const char *var, const char *value); +extern int config_error_nonbool(const char *); #define MAX_GITNAME (1000) extern char git_default_email[MAX_GITNAME]; -- cgit v1.2.3 From ea5105a5e3c6629ee64b499ea918c2b80882fc22 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 16 Feb 2008 06:00:24 +0100 Subject: config: add 'git_config_string' to refactor string config variables. In many places we just check if a value from the config file is not NULL, then we duplicate it and return 0. This patch introduces the new 'git_config_string' function to do that. This function is also used to refactor some code in 'config.c'. Refactoring other files is left for other patches. Also not all the code in "config.c" is refactored, because the function takes a "const char **" as its first parameter, but in many places a "char *" is used instead of a "const char *". (And C does not allow using a "char **" instead of a "const char **" without a warning.) Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6abcee4372..c83b123fa5 100644 --- a/cache.h +++ b/cache.h @@ -584,6 +584,7 @@ extern int git_parse_ulong(const char *, unsigned long *); extern int git_config_int(const char *, const char *); extern unsigned long git_config_ulong(const char *, const char *); extern int git_config_bool(const char *, const char *); +extern int git_config_string(const char **, const char *, const char *); extern int git_config_set(const char *, const char *); extern int git_config_set_multivar(const char *, const char *, const char *, int); extern int git_config_rename_section(const char *, const char *); -- cgit v1.2.3 From 872da32d80c004c26a19a5d6cb31eb3e7f034094 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 16 Feb 2008 06:01:11 +0100 Subject: Add "const" qualifier to "char *pager_program". Also use "git_config_string" to simplify "config.c" code where "pager_program" is set. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index c83b123fa5..1ecaef14c3 100644 --- a/cache.h +++ b/cache.h @@ -610,7 +610,7 @@ extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char /* pager.c */ extern void setup_pager(void); -extern char *pager_program; +extern const char *pager_program; extern int pager_in_use(void); extern int pager_use_color; -- cgit v1.2.3 From ee9601e6bef2281e3183e127e1e4e36ed257af7a Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 16 Feb 2008 06:01:41 +0100 Subject: Add "const" qualifier to "char *editor_program". Also use "git_config_string" to simplify "config.c" code where "editor_program" is set. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1ecaef14c3..ce7b386a4d 100644 --- a/cache.h +++ b/cache.h @@ -614,7 +614,7 @@ extern const char *pager_program; extern int pager_in_use(void); extern int pager_use_color; -extern char *editor_program; +extern const char *editor_program; extern char *excludes_file; /* base85 */ -- cgit v1.2.3 From dfb068be8deef2065970b2a7889acc51abf4dd78 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 16 Feb 2008 06:01:59 +0100 Subject: Add "const" qualifier to "char *excludes_file". Also use "git_config_string" to simplify "config.c" code where "excludes_file" is set. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ce7b386a4d..43ba6a3ba5 100644 --- a/cache.h +++ b/cache.h @@ -615,7 +615,7 @@ extern int pager_in_use(void); extern int pager_use_color; extern const char *editor_program; -extern char *excludes_file; +extern const char *excludes_file; /* base85 */ int decode_85(char *dst, const char *line, int linelen); -- cgit v1.2.3 From 8177631547e4d10ae071def07eff83e056092bfa Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 24 Dec 2007 00:51:01 -0800 Subject: expose a helper function peel_to_type(). This helper function is the core of "$object^{type}" parser. Now it is made available to callers outside sha1_name.c --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e1000bccb2..4bfb1ba499 100644 --- a/cache.h +++ b/cache.h @@ -499,6 +499,9 @@ extern void *read_object_with_reference(const unsigned char *sha1, unsigned long *size, unsigned char *sha1_ret); +extern struct object *peel_to_type(const char *name, int namelen, + struct object *o, enum object_type); + enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, -- cgit v1.2.3 From 9ed36cfa35cfbd09c454f12194a91cd50ba284d1 Mon Sep 17 00:00:00 2001 From: Jay Soffian Date: Tue, 19 Feb 2008 11:24:37 -0500 Subject: branch: optionally setup branch.*.merge from upstream local branches "git branch" and "git checkout -b" now honor --track option even when the upstream branch is local. Previously --track was silently ignored when forking from a local branch. Also the command did not error out when --track was explicitly asked for but the forked point specified was not an existing branch (i.e. when there is no way to set up the tracking configuration), but now it correctly does. The configuration setting branch.autosetupmerge can now be set to "always", which is equivalent to using --track from the command line. Setting branch.autosetupmerge to "true" will retain the former behavior of only setting up branch.*.merge for remote upstream branches. Includes test cases for the new functionality. Signed-off-by: Jay Soffian Signed-off-by: Junio C Hamano --- cache.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 888895a969..0cd1368aef 100644 --- a/cache.h +++ b/cache.h @@ -373,6 +373,15 @@ extern size_t packed_git_limit; extern size_t delta_base_cache_limit; extern int auto_crlf; +enum branch_track { + BRANCH_TRACK_NEVER = 0, + BRANCH_TRACK_REMOTE, + BRANCH_TRACK_ALWAYS, + BRANCH_TRACK_EXPLICIT, +}; + +extern enum branch_track git_branch_track; + #define GIT_REPO_VERSION 0 extern int repository_format_version; extern int check_repository_format(void); -- cgit v1.2.3 From a22c637124a2f591382d56546136a8e2bb2c2c66 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 22 Feb 2008 20:37:40 -0800 Subject: Fix name re-hashing semantics We handled the case of removing and re-inserting cache entries badly, which is something that merging commonly needs to do (removing the different stages, and then re-inserting one of them as the merged state). We even had a rather ugly special case for this failure case, where replace_index_entry() basically turned itself into a no-op if the new and the old entries were the same, exactly because the hash routines didn't handle it on their own. So what this patch does is to not just have the UNHASHED bit, but a HASHED bit too, and when you insert an entry into the name hash, that involves: - clear the UNHASHED bit, because now it's valid again for lookup (which is really all that UNHASHED meant) - if we're being lazy, we're done here (but we still want to clear the UNHASHED bit regardless of lazy mode, since we can become unlazy later, and so we need the UNHASHED bit to always be set correctly, even if we never actually insert the entry into the hash list) - if it was already hashed, we just leave it on the list - otherwise mark it HASHED and insert it into the list this all means that unhashing and rehashing a name all just works automatically. Obviously, you cannot change the name of an entry (that would be a serious bug), but nothing can validly do that anyway (you'd have to allocate a new struct cache_entry anyway since the name length could change), so that's not a new limitation. The code actually gets simpler in many ways, although the lazy hashing does mean that there are a few odd cases (ie something can be marked unhashed even though it was never on the hash in the first place, and isn't actually marked hashed!). Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e1000bccb2..0b69c92daa 100644 --- a/cache.h +++ b/cache.h @@ -133,7 +133,9 @@ struct cache_entry { #define CE_UPDATE (0x10000) #define CE_REMOVE (0x20000) #define CE_UPTODATE (0x40000) -#define CE_UNHASHED (0x80000) + +#define CE_HASHED (0x100000) +#define CE_UNHASHED (0x200000) static inline unsigned create_ce_flags(size_t len, unsigned stage) { -- cgit v1.2.3 From d070e3a31bf94de1ef503b155a5e028545f7decc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 22 Feb 2008 20:39:21 -0800 Subject: Name hash fixups: export (and rename) remove_hash_entry This makes the name hash removal function (which really just sets the bit that disables lookups of it) available to external routines, and makes read_cache_unmerged() use it when it drops an unmerged entry from the index. It's renamed to remove_index_entry(), and we drop the (unused) 'istate' argument. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0b69c92daa..88d3b92d2e 100644 --- a/cache.h +++ b/cache.h @@ -137,6 +137,20 @@ struct cache_entry { #define CE_HASHED (0x100000) #define CE_UNHASHED (0x200000) +/* + * We don't actually *remove* it, we can just mark it invalid so that + * we won't find it in lookups. + * + * Not only would we have to search the lists (simple enough), but + * we'd also have to rehash other hash buckets in case this makes the + * hash bucket empty (common). So it's much better to just mark + * it. + */ +static inline void remove_index_entry(struct cache_entry *ce) +{ + ce->ce_flags |= CE_UNHASHED; +} + static inline unsigned create_ce_flags(size_t len, unsigned stage) { if (len >= CE_NAMEMASK) -- cgit v1.2.3 From eb7a2f1d50ca8620b087dd2751d0fe2505e7974f Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 22 Feb 2008 20:41:17 -0800 Subject: Use helper function for copying index entry information We used to just memcpy() the index entry when we copied the stat() and SHA1 hash information, which worked well enough back when the index entry was just an exact bit-for-bit representation of the information on disk. However, these days we actually have various management information in the cache entry too, and we should be careful to not overwrite it when we copy the stat information from another index entry. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 88d3b92d2e..fa5a9e523e 100644 --- a/cache.h +++ b/cache.h @@ -110,7 +110,6 @@ struct ondisk_cache_entry { }; struct cache_entry { - struct cache_entry *next; unsigned int ce_ctime; unsigned int ce_mtime; unsigned int ce_dev; @@ -121,6 +120,7 @@ struct cache_entry { unsigned int ce_size; unsigned int ce_flags; unsigned char sha1[20]; + struct cache_entry *next; char name[FLEX_ARRAY]; /* more */ }; @@ -137,6 +137,22 @@ struct cache_entry { #define CE_HASHED (0x100000) #define CE_UNHASHED (0x200000) +/* + * Copy the sha1 and stat state of a cache entry from one to + * another. But we never change the name, or the hash state! + */ +#define CE_STATE_MASK (CE_HASHED | CE_UNHASHED) +static inline void copy_cache_entry(struct cache_entry *dst, struct cache_entry *src) +{ + unsigned int state = dst->ce_flags & CE_STATE_MASK; + + /* Don't copy hash chain and name */ + memcpy(dst, src, offsetof(struct cache_entry, next)); + + /* Restore the hash state */ + dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state; +} + /* * We don't actually *remove* it, we can just mark it invalid so that * we won't find it in lookups. -- cgit v1.2.3 From fe3403c3205de44faa926a086b4b99f157fc63fe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 23 Feb 2008 16:59:16 -0800 Subject: ws_fix_copy(): move the whitespace fixing function to ws.c This is used by git-apply but we can use it elsewhere by slightly generalizing it. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ad11c90caf..3d4c6b078c 100644 --- a/cache.h +++ b/cache.h @@ -661,6 +661,7 @@ extern unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); extern char *whitespace_error_string(unsigned ws); +extern int ws_fix_copy(char *, const char *, int, unsigned, int *); /* ls-files */ int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen); -- cgit v1.2.3 From 94351118c0a820002b093598e7fac5bdf3c0291f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 24 Feb 2008 17:17:14 -0500 Subject: make alias lookup a public, procedural function This converts git_config_alias to the public alias_lookup function. Because of the nature of our config parser, we still have to rely on setting static data. However, that interface is wrapped so that you can just say value = alias_lookup(key); Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index fa5a9e523e..1e9c937299 100644 --- a/cache.h +++ b/cache.h @@ -765,4 +765,6 @@ int pathspec_match(const char **spec, char *matched, const char *filename, int s int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset); void overlay_tree_on_cache(const char *tree_name, const char *prefix); +char *alias_lookup(const char *alias); + #endif /* CACHE_H */ -- cgit v1.2.3 From 1468bd47833c6ec3c85620d6af1d910e9378f714 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 25 Feb 2008 14:24:48 -0500 Subject: Use a single implementation and API for copy_file() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Originally by Kristian Hï¿œgsberg; I fixed the conversion of rerere, which had a different API. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 43ba6a3ba5..98cfed63ee 100644 --- a/cache.h +++ b/cache.h @@ -602,6 +602,7 @@ extern const char *git_log_output_encoding; /* IO helper functions */ extern void maybe_flush_or_die(FILE *, const char *); extern int copy_fd(int ifd, int ofd); +extern int copy_file(const char *dst, const char *src, int mode); extern int read_in_full(int fd, void *buf, size_t count); extern int write_in_full(int fd, const void *buf, size_t count); extern void write_or_die(int fd, const void *buf, size_t count); -- cgit v1.2.3 From 355885d531568e144ce5c9a2f65792a3aa8b5528 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Mon, 25 Feb 2008 22:46:04 +0100 Subject: add generic, type aware object chain walker The requirements are: * it may not crash on NULL pointers * a callback function is needed, as index-pack/unpack-objects need to do different things * the type information is needed to check the expected <-> real type and print better error messages Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 43ba6a3ba5..d3b898708b 100644 --- a/cache.h +++ b/cache.h @@ -189,6 +189,7 @@ enum object_type { /* 5 for future expansion */ OBJ_OFS_DELTA = 6, OBJ_REF_DELTA = 7, + OBJ_ANY, OBJ_MAX, }; -- cgit v1.2.3 From 0ab9e1e8cdaefdd33bf24bb0be0ec766483f8bbe Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 5 Mar 2008 18:25:10 -0800 Subject: Add 'df_name_compare()' helper function This new helper is identical to base_name_compare(), except it compares conflicting directory/file entries as equal in order to help handling DF conflicts (thus the name). Note that while a directory name compares as equal to a regular file with the new helper, they then individually compare _differently_ to a filename that has a dot after the basename (because '\0' < '.' < '/'). So a directory called "foo/" will compare equal to a file "foo", even though "foo.c" will compare after "foo" and before "foo/" This will be used by routines that want to traverse the git namespace but then handle conflicting entries together when possible. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e230302623..6eb16cb0df 100644 --- a/cache.h +++ b/cache.h @@ -536,6 +536,7 @@ extern int create_symref(const char *ref, const char *refs_heads_master, const c extern int validate_headref(const char *ref); extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); +extern int df_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2); extern void *read_object_with_reference(const unsigned char *sha1, -- cgit v1.2.3 From d1f128b0509dce8b492c233b36131f096fd71274 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 6 Mar 2008 12:46:09 -0800 Subject: Add 'const' where appropriate to index handling functions This is in an effort to make the source index of 'unpack_trees()' as being const, and thus making the compiler help us verify that we only access it for reading. The constification also extended to some of the hashing helpers that get called indirectly. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6eb16cb0df..b519b7a0c3 100644 --- a/cache.h +++ b/cache.h @@ -346,12 +346,12 @@ extern void verify_non_filename(const char *prefix, const char *name); /* Initialize and use the cache information */ extern int read_index(struct index_state *); extern int read_index_from(struct index_state *, const char *path); -extern int write_index(struct index_state *, int newfd); +extern int write_index(const struct index_state *, int newfd); extern int discard_index(struct index_state *); -extern int unmerged_index(struct index_state *); +extern int unmerged_index(const struct index_state *); extern int verify_path(const char *path); extern int index_name_exists(struct index_state *istate, const char *name, int namelen); -extern int index_name_pos(struct index_state *, const char *name, int namelen); +extern int index_name_pos(const struct index_state *, const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ @@ -368,8 +368,8 @@ extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); #define CE_MATCH_IGNORE_VALID 01 /* do not check the contents but report dirty on racily-clean entries */ #define CE_MATCH_RACY_IS_DIRTY 02 -extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, unsigned int); -extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, unsigned int); +extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int); +extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int); extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); -- cgit v1.2.3 From 96872bc200c41407607019c1f0fb005840f576a2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 21 Mar 2008 13:16:24 -0700 Subject: Move name hashing functions into a file of its own It's really totally separate functionality, and if we want to start doing case-insensitive hash lookups, I'd rather do it when it's separated out. It also renames "remove_index_entry()" to "remove_name_hash()", because that really describes the thing better. It doesn't actually remove the index entry, that's done by "remove_index_entry_at()", which is something very different, despite the similarity in names. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2a1e7ec6b2..2afc788f74 100644 --- a/cache.h +++ b/cache.h @@ -153,20 +153,6 @@ static inline void copy_cache_entry(struct cache_entry *dst, struct cache_entry dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state; } -/* - * We don't actually *remove* it, we can just mark it invalid so that - * we won't find it in lookups. - * - * Not only would we have to search the lists (simple enough), but - * we'd also have to rehash other hash buckets in case this makes the - * hash bucket empty (common). So it's much better to just mark - * it. - */ -static inline void remove_index_entry(struct cache_entry *ce) -{ - ce->ce_flags |= CE_UNHASHED; -} - static inline unsigned create_ce_flags(size_t len, unsigned stage) { if (len >= CE_NAMEMASK) @@ -241,6 +227,23 @@ struct index_state { extern struct index_state the_index; +/* Name hashing */ +extern void add_name_hash(struct index_state *istate, struct cache_entry *ce); +/* + * We don't actually *remove* it, we can just mark it invalid so that + * we won't find it in lookups. + * + * Not only would we have to search the lists (simple enough), but + * we'd also have to rehash other hash buckets in case this makes the + * hash bucket empty (common). So it's much better to just mark + * it. + */ +static inline void remove_name_hash(struct cache_entry *ce) +{ + ce->ce_flags |= CE_UNHASHED; +} + + #ifndef NO_THE_INDEX_COMPATIBILITY_MACROS #define active_cache (the_index.cache) #define active_nr (the_index.cache_nr) -- cgit v1.2.3 From df292c791ab790340cc9e3577a073bcb9d1900ea Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 21 Mar 2008 15:53:00 -0700 Subject: Make "index_name_exists()" return the cache_entry it found This allows verify_absent() in unpack_trees() to use the hash chains rather than looking it up using the binary search. Perhaps more importantly, it's also going to be useful for the next phase, where we actually start looking at the cache entry when we do case-insensitive lookups and checking the result. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2afc788f74..76d95d2c81 100644 --- a/cache.h +++ b/cache.h @@ -353,7 +353,7 @@ extern int write_index(const struct index_state *, int newfd); extern int discard_index(struct index_state *); extern int unmerged_index(const struct index_state *); extern int verify_path(const char *path); -extern int index_name_exists(struct index_state *istate, const char *name, int namelen); +extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen); extern int index_name_pos(const struct index_state *, const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ -- cgit v1.2.3 From cd2fef59edf72a1d9792d9cb72aae1e6f6c7b1d4 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 21 Mar 2008 15:55:19 -0700 Subject: Make hash_name_lookup able to do case-independent lookups Right now nobody uses it, but "index_name_exists()" gets a flag so you can enable it on a case-by-case basis. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 76d95d2c81..a9ddaa1240 100644 --- a/cache.h +++ b/cache.h @@ -264,7 +264,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) -#define cache_name_exists(name, namelen) index_name_exists(&the_index, (name), (namelen)) +#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase)) #endif enum object_type { @@ -353,7 +353,7 @@ extern int write_index(const struct index_state *, int newfd); extern int discard_index(struct index_state *); extern int unmerged_index(const struct index_state *); extern int verify_path(const char *path); -extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen); +extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int igncase); extern int index_name_pos(const struct index_state *, const char *name, int namelen); #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ -- cgit v1.2.3 From 0a9b88b7dee70bd36d35b7857640a18ee3adeef1 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 21 Mar 2008 16:52:46 -0700 Subject: Add 'core.ignorecase' option ..and start using it for directory entry traversal (ie "git status" will not consider entries that match an existing entry case-insensitively to be a new file) Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a9ddaa1240..9bce723bb8 100644 --- a/cache.h +++ b/cache.h @@ -407,6 +407,7 @@ extern int delete_ref(const char *, const unsigned char *sha1); extern int trust_executable_bit; extern int quote_path_fully; extern int has_symlinks; +extern int ignore_case; extern int assume_unchanged; extern int prefer_symlink_refs; extern int log_all_ref_updates; -- cgit v1.2.3 From 1102952b45dde09d73445aa2284bcb592362fa23 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 22 Mar 2008 14:22:44 -0700 Subject: Make git-add behave more sensibly in a case-insensitive environment This expands on the previous patch, and allows "git add" to sanely handle a filename that has changed case, keeping the case in the index constant, and avoiding aliases. In particular, if you have an index entry called "File", but the checked-out tree is case-corrupted and has an entry called "file" instead, doing a git add . (or naming "file" explicitly) will automatically notice that we have an alias, and will replace the name "file" with the existing index capitalization (ie "File"). However, if we actually have *both* a file called "File" and one called "file", and they don't have the same lstat() information (ie we're on a case-sensitive filesystem but have the "core.ignorecase" flag set), we will error out if we try to add them both. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9bce723bb8..81727e4afe 100644 --- a/cache.h +++ b/cache.h @@ -133,6 +133,7 @@ struct cache_entry { #define CE_UPDATE (0x10000) #define CE_REMOVE (0x20000) #define CE_UPTODATE (0x40000) +#define CE_ADDED (0x80000) #define CE_HASHED (0x100000) #define CE_UNHASHED (0x200000) -- cgit v1.2.3 From b44ebb19e3234c5dffe9869ceac5408bb44c2e20 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Wed, 20 Feb 2008 23:13:13 +0100 Subject: Add platform-independent .git "symlink" This patch allows .git to be a regular textfile containing the path of the real git directory (prefixed with "gitdir: "), which can be useful on platforms lacking support for real symlinks. Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2a1e7ec6b2..2bda40c616 100644 --- a/cache.h +++ b/cache.h @@ -311,6 +311,7 @@ extern char *get_index_file(void); extern char *get_graft_file(void); extern int set_git_dir(const char *path); extern const char *get_git_work_tree(void); +extern const char *read_gitfile_gently(const char *path); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" -- cgit v1.2.3 From a53f2ec617ba36a67bf8794d28d666d45ce374a6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 12 Apr 2008 18:33:31 -0700 Subject: git_config_bool_or_int() This new function can be used by config parsers to tell if a variable is simply set, set to 1, or set to "true". Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2a1e7ec6b2..50b28fad01 100644 --- a/cache.h +++ b/cache.h @@ -692,6 +692,7 @@ extern int git_parse_long(const char *, long *); extern int git_parse_ulong(const char *, unsigned long *); extern int git_config_int(const char *, const char *); extern unsigned long git_config_ulong(const char *, const char *); +extern int git_config_bool_or_int(const char *, const char *, int *); extern int git_config_bool(const char *, const char *); extern int git_config_string(const char **, const char *, const char *); extern int git_config_set(const char *, const char *); -- cgit v1.2.3 From 06cbe8550324e0fd2290839bf3b9a92aa53b70ab Mon Sep 17 00:00:00 2001 From: Heikki Orsila Date: Wed, 16 Apr 2008 11:34:24 +0300 Subject: Make core.sharedRepository more generic git init --shared=0xxx, where '0xxx' is an octal number, will create a repository with file modes set to '0xxx'. Users with a safe umask value (0077) can use this option to force file modes. For example, '0640' is a group-readable but not group-writable regardless of user's umask value. Values compatible with old Git versions are written as they were before, for compatibility reasons. That is, "1" for "group" and "2" for "everybody". "git config core.sharedRepository 0xxx" is also handled. Signed-off-by: Heikki Orsila Signed-off-by: Junio C Hamano --- cache.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 50b28fad01..3fcc283002 100644 --- a/cache.h +++ b/cache.h @@ -474,10 +474,20 @@ static inline void hashclr(unsigned char *hash) int git_mkstemp(char *path, size_t n, const char *template); +/* + * NOTE NOTE NOTE!! + * + * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must + * not be changed. Old repositories have core.sharedrepository written in + * numeric format, and therefore these values are preserved for compatibility + * reasons. + */ enum sharedrepo { - PERM_UMASK = 0, - PERM_GROUP, - PERM_EVERYBODY + PERM_UMASK = 0, + OLD_PERM_GROUP = 1, + OLD_PERM_EVERYBODY = 2, + PERM_GROUP = 0660, + PERM_EVERYBODY = 0664, }; int git_config_perm(const char *var, const char *value); int adjust_shared_perm(const char *path); -- cgit v1.2.3 From be885d96fe0ebed47e637f3b0dd24fc5902f7081 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Sat, 26 Apr 2008 15:53:12 -0400 Subject: Make ls-remote http://... list HEAD, like for git://... This makes a struct ref able to represent a symref, and makes http.c able to recognize one, and makes transport.c look for "HEAD" as a ref in the list, and makes it dereference symrefs for the resulting ref, if any. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3fcc283002..cfc123747c 100644 --- a/cache.h +++ b/cache.h @@ -634,6 +634,7 @@ struct ref { struct ref *next; unsigned char old_sha1[20]; unsigned char new_sha1[20]; + char *symref; unsigned int force:1, merge:1, nonfastforward:1, -- cgit v1.2.3 From 0104ca09e3abf48ab26fd0599c4b686fcff60ffc Mon Sep 17 00:00:00 2001 From: Heikki Orsila Date: Sun, 27 Apr 2008 21:21:58 +0300 Subject: Make read_in_full() and write_in_full() consistent with xread() and xwrite() xread() and xwrite() return ssize_t values as their native POSIX counterparts read(2) and write(2). To be consistent, read_in_full() and write_in_full() should also return ssize_t values. Signed-off-by: Junio C Hamano --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3fcc283002..5a28dddec9 100644 --- a/cache.h +++ b/cache.h @@ -726,8 +726,8 @@ extern const char *git_log_output_encoding; extern void maybe_flush_or_die(FILE *, const char *); extern int copy_fd(int ifd, int ofd); extern int copy_file(const char *dst, const char *src, int mode); -extern int read_in_full(int fd, void *buf, size_t count); -extern int write_in_full(int fd, const void *buf, size_t count); +extern ssize_t read_in_full(int fd, void *buf, size_t count); +extern ssize_t write_in_full(int fd, const void *buf, size_t count); extern void write_or_die(int fd, const void *buf, size_t count); extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg); -- cgit v1.2.3 From ea3cd5c7c63fadacd66c364ae4b8c6d01e5809b1 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Thu, 17 Apr 2008 19:32:26 -0400 Subject: Add a lockfile function to append to a file This takes care of copying the original contents into the replacement file after the lock is held, so that concurrent additions can't miss each other's changes. [jc: munged to drop mmap in favor of copy_file.] Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 5a28dddec9..396eabf6ed 100644 --- a/cache.h +++ b/cache.h @@ -391,6 +391,7 @@ struct lock_file { char filename[PATH_MAX]; }; extern int hold_lock_file_for_update(struct lock_file *, const char *path, int); +extern int hold_lock_file_for_append(struct lock_file *, const char *path, int); extern int commit_lock_file(struct lock_file *); extern int hold_locked_index(struct lock_file *, int); -- cgit v1.2.3 From bef70b22ba63d71c1ae2e070e64ff9863ea1ad14 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Thu, 17 Apr 2008 19:32:30 -0400 Subject: Add a library function to add an alternate to the alternates file This is in the core so that, if the alternates file has already been read, the addition can be parsed and put into effect for the current process. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 396eabf6ed..9da9179afd 100644 --- a/cache.h +++ b/cache.h @@ -599,6 +599,7 @@ extern struct alternate_object_database { char base[FLEX_ARRAY]; /* more */ } *alt_odb_list; extern void prepare_alt_odb(void); +extern void add_to_alternates_file(const char *reference); struct pack_window { struct pack_window *next; -- cgit v1.2.3 From 19757d80e522e9f04c125ad5977c3a79db99b192 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Sun, 27 Apr 2008 13:39:21 -0400 Subject: Add a function to set a non-default work tree This function may only be used before the work tree is used. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9da9179afd..aba029315c 100644 --- a/cache.h +++ b/cache.h @@ -311,6 +311,7 @@ extern char *get_index_file(void); extern char *get_graft_file(void); extern int set_git_dir(const char *path); extern const char *get_git_work_tree(void); +extern void set_git_work_tree(const char *tree); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" -- cgit v1.2.3 From f225aeb278eb1c8c028cd2ff1fdfe7a45067b8e1 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Sun, 27 Apr 2008 13:39:27 -0400 Subject: Provide API access to init_db() The caller first calls set_git_dir() to specify the GIT_DIR, and then calls init_db() to initialize it. This also cleans up various parts of the code to account for the fact that everything is done with GIT_DIR set, so it's unnecessary to pass the specified directory around. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index aba029315c..f3ad9741cc 100644 --- a/cache.h +++ b/cache.h @@ -324,6 +324,10 @@ extern const char *prefix_filename(const char *prefix, int len, const char *path extern void verify_filename(const char *prefix, const char *name); extern void verify_non_filename(const char *prefix, const char *name); +#define INIT_DB_QUIET 0x0001 + +extern int init_db(const char *template_dir, unsigned int flags); + #define alloc_nr(x) (((x)+16)*3/2) /* -- cgit v1.2.3 From bb1ae3f6fff19b0a1ab1bb6a815d26d39b9f15e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santi=20B=C3=A9jar?= Date: Sun, 4 May 2008 18:04:51 +0200 Subject: commit: Show committer if automatic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To warn the user in case he/she might be using an unintended committer identity. Signed-off-by: Santi Béjar Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index d5d5dad146..327e5eacd3 100644 --- a/cache.h +++ b/cache.h @@ -719,6 +719,7 @@ extern int config_error_nonbool(const char *); #define MAX_GITNAME (1000) extern char git_default_email[MAX_GITNAME]; extern char git_default_name[MAX_GITNAME]; +extern int user_ident_explicitly_given; extern const char *git_commit_encoding; extern const char *git_log_output_encoding; -- cgit v1.2.3 From d177cab0480f9fa172103071203fed1bff95f5c2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 9 May 2008 09:11:43 -0700 Subject: Avoid some unnecessary lstat() calls The commit sequence used to do if (file_exists(p->path)) add_file_to_cache(p->path, 0); where both "file_exists()" and "add_file_to_cache()" needed to do a lstat() on the path to do their work. This cuts down 'lstat()' calls for the partial commit case by two for each path we know about (because we do this twice per path). Just move the lstat() to the caller instead (that's all that "file_exists()" really does), and pass the stat information down to the add_to_cache() function. This essentially makes 'add_to_index()' the core function that adds a path to the index, getting the index pointer, the pathname and the stat information as arguments. There are then shorthand helper functions that use this core function: - 'add_to_cache()' is just 'add_to_index()' with the default index - 'add_file_to_cache/index()' is the same, but does the lstat() call itself, so you can pass just the pathname if you don't already have the stat information available. So old users of the 'add_file_to_xyzzy()' are essentially left unchanged, and this just exposes the more generic helper function that can take existing stat information into account. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 80a8842db4..4803b032ec 100644 --- a/cache.h +++ b/cache.h @@ -261,6 +261,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) +#define add_to_cache(path, st, verbose) add_to_index(&the_index, (path), (st), (verbose)) #define add_file_to_cache(path, verbose) add_file_to_index(&the_index, (path), (verbose)) #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) @@ -365,6 +366,7 @@ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int opt extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); extern int remove_index_entry_at(struct index_state *, int pos); extern int remove_file_from_index(struct index_state *, const char *path); +extern int add_to_index(struct index_state *, const char *path, struct stat *, int verbose); extern int add_file_to_index(struct index_state *, const char *path, int verbose); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); -- cgit v1.2.3 From c40641b77b0274186fd1b327d5dc3246f814aaaf Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 9 May 2008 09:21:07 -0700 Subject: Optimize symlink/directory detection This is the base for making symlink detection in the middle fo a pathname saner and (much) more efficient. Under various loads, we want to verify that the full path leading up to a filename is a real directory tree, and that when we successfully do an 'lstat()' on a filename, we don't get a false positive due to a symlink in the middle of the path that git should have seen as a symlink, not as a normal path component. The 'has_symlink_leading_path()' function already did this, and cached a single level of symlink information, but didn't cache the _lack_ of a symlink, so the normal behaviour was actually the wrong way around, and we ended up doing an 'lstat()' on each path component to check that it was a real directory. This caches the last detected full directory and symlink entries, and speeds up especially deep directory structures a lot by avoiding to lstat() all the directories leading up to each entry in the index. [ This can - and should - probably be extended upon so that we eventually never do a bare 'lstat()' on any path entries at *all* when checking the index, but always check the full path carefully. Right now we do not generally check the whole path for all our normal quick index revalidation. We should also make sure that we're careful about all the invalidation, ie when we remove a link and replace it by a directory we should invalidate the symlink cache if it matches (and vice versa for the directory cache). But regardless, the basic function needs to be sane to do that. The old 'has_symlink_leading_path()' was not capable enough - or indeed the code readable enough - to really do that sanely. So I'm pushing this as not just an optimization, but as a base for further work. ] Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4803b032ec..0d9d9e2577 100644 --- a/cache.h +++ b/cache.h @@ -598,7 +598,7 @@ struct checkout { }; extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); -extern int has_symlink_leading_path(const char *name, char *last_symlink); +extern int has_symlink_leading_path(int len, const char *name); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From c998ae9baa1cc5f507646da9850731de634d2ee7 Mon Sep 17 00:00:00 2001 From: Dustin Sallings Date: Sat, 10 May 2008 15:36:29 -0700 Subject: Allow tracking branches to set up rebase by default. Change cd67e4d4 introduced a new configuration parameter that told pull to automatically perform a rebase instead of a merge. This change provides a configuration option to enable this feature automatically when creating a new branch. If the variable branch.autosetuprebase applies for a branch that's being created, that branch will have branch..rebase set to true. Signed-off-by: Dustin Sallings Signed-off-by: Junio C Hamano --- cache.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7fb8f3359d..3442130a59 100644 --- a/cache.h +++ b/cache.h @@ -434,7 +434,15 @@ enum branch_track { BRANCH_TRACK_EXPLICIT, }; +enum rebase_setup_type { + AUTOREBASE_NEVER = 0, + AUTOREBASE_LOCAL, + AUTOREBASE_REMOTE, + AUTOREBASE_ALWAYS, +}; + extern enum branch_track git_branch_track; +extern enum rebase_setup_type autorebase; #define GIT_REPO_VERSION 0 extern int repository_format_version; -- cgit v1.2.3 From 7ae02a30e817eda16ea362c6304b6ae28c3a7644 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Mon, 12 May 2008 19:58:10 +0200 Subject: Extend interface of add_files_to_cache to allow ignore indexing errors Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- cache.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9cee9a5f3f..4fb629000e 100644 --- a/cache.h +++ b/cache.h @@ -781,7 +781,13 @@ extern int convert_to_git(const char *path, const char *src, size_t len, extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); /* add */ -void add_files_to_cache(int verbose, const char *prefix, const char **pathspec); +#define ADD_FILES_VERBOSE 01 +#define ADD_FILES_IGNORE_ERRORS 02 +/* + * return 0 if success, 1 - if addition of a file failed and + * ADD_FILES_IGNORE_ERRORS was specified in flags + */ +int add_files_to_cache(const char *prefix, const char **pathspec, int flags); /* diff.c */ extern int diff_auto_refresh_index; -- cgit v1.2.3 From bbac73117ebed9f02ccae3df45f4baa0c793dab7 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 14 May 2008 01:32:48 -0400 Subject: add a force_object_loose() function This is meant to force the creation of a loose object even if it already exists packed. Needed for the next commit. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7fb8f3359d..dcc7e98825 100644 --- a/cache.h +++ b/cache.h @@ -506,6 +506,7 @@ extern void * read_sha1_file(const unsigned char *sha1, enum object_type *type, extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1); extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1); extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); +extern int force_object_loose(const unsigned char *sha1, time_t mtime); extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); -- cgit v1.2.3 From ef90d6d4208a5130185b04f06e5f90a5f9959fe3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 May 2008 18:46:53 +0100 Subject: Provide git_config with a callback-data parameter git_config() only had a function parameter, but no callback data parameter. This assumes that all callback functions only modify global variables. With this patch, every callback gets a void * parameter, and it is hoped that this will help the libification effort. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9cee9a5f3f..ebe4031b65 100644 --- a/cache.h +++ b/cache.h @@ -711,10 +711,10 @@ extern int matches_pack_name(struct packed_git *p, const char *name); /* Dumb servers support */ extern int update_server_info(int); -typedef int (*config_fn_t)(const char *, const char *); -extern int git_default_config(const char *, const char *); -extern int git_config_from_file(config_fn_t fn, const char *); -extern int git_config(config_fn_t fn); +typedef int (*config_fn_t)(const char *, const char *, void *); +extern int git_default_config(const char *, const char *, void *); +extern int git_config_from_file(config_fn_t fn, const char *, void *); +extern int git_config(config_fn_t fn, void *); extern int git_parse_long(const char *, long *); extern int git_parse_ulong(const char *, unsigned long *); extern int git_config_int(const char *, const char *); @@ -726,7 +726,7 @@ extern int git_config_set(const char *, const char *); extern int git_config_set_multivar(const char *, const char *, const char *, int); extern int git_config_rename_section(const char *, const char *); extern const char *git_etc_gitconfig(void); -extern int check_repository_format_version(const char *var, const char *value); +extern int check_repository_format_version(const char *var, const char *value, void *cb); extern int git_env_bool(const char *, int); extern int git_config_system(void); extern int git_config_global(void); -- cgit v1.2.3 From 5fdeacb0ca3935923ab988c81414c16080db6a32 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 May 2008 18:03:45 +0100 Subject: Teach update-index about --ignore-submodules Like with the diff machinery, update-index should sometimes just ignore submodules (e.g. to determine a clean state before a rebase). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 093f04cec0..b753b49497 100644 --- a/cache.h +++ b/cache.h @@ -388,6 +388,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); #define REFRESH_UNMERGED 0x0002 /* allow unmerged */ #define REFRESH_QUIET 0x0004 /* be quiet about it */ #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ +#define REFRESH_IGNORE_SUBMODULES 0x0008 /* ignore submodules */ extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen); struct lock_file { -- cgit v1.2.3 From 38ed1d89f759699de56004b08668e1764613f47b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 21 May 2008 12:04:34 -0700 Subject: "git-add -n -u" should not add but just report Signed-off-by: Junio C Hamano --- cache.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 093f04cec0..b1a8427b91 100644 --- a/cache.h +++ b/cache.h @@ -261,8 +261,8 @@ static inline void remove_name_hash(struct cache_entry *ce) #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) -#define add_to_cache(path, st, verbose) add_to_index(&the_index, (path), (st), (verbose)) -#define add_file_to_cache(path, verbose) add_file_to_index(&the_index, (path), (verbose)) +#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags)) +#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags)) #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) @@ -366,8 +366,10 @@ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int opt extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); extern int remove_index_entry_at(struct index_state *, int pos); extern int remove_file_from_index(struct index_state *, const char *path); -extern int add_to_index(struct index_state *, const char *path, struct stat *, int verbose); -extern int add_file_to_index(struct index_state *, const char *path, int verbose); +#define ADD_CACHE_VERBOSE 1 +#define ADD_CACHE_PRETEND 2 +extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags); +extern int add_file_to_index(struct index_state *, const char *path, int flags); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); @@ -782,7 +784,7 @@ extern int convert_to_git(const char *path, const char *src, size_t len, extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); /* add */ -void add_files_to_cache(int verbose, const char *prefix, const char **pathspec); +void add_files_to_cache(const char *prefix, const char **pathspec, int flags); /* diff.c */ extern int diff_auto_refresh_index; -- cgit v1.2.3 From ae299be0e5e610027e6492d48d70c1cbb0e9edd8 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Mon, 19 May 2008 23:48:54 -0700 Subject: Implement normalize_absolute_path normalize_absolute_path removes several oddities form absolute paths, giving nice clean paths like "/dir/sub1/sub2". Also add a test case for this utility, based on a new test program (in the style of test-sha1). Signed-off-by: David Reiss Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 093f04cec0..88c390d9f1 100644 --- a/cache.h +++ b/cache.h @@ -514,6 +514,7 @@ static inline int is_absolute_path(const char *path) return path[0] == '/'; } const char *make_absolute_path(const char *path); +int normalize_absolute_path(char *buf, const char *path); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); -- cgit v1.2.3 From 0454dd93bfb2334355ec62fff670d8c6cb3570a1 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Mon, 19 May 2008 23:49:26 -0700 Subject: Add support for GIT_CEILING_DIRECTORIES Make git recognize a new environment variable that prevents it from chdir'ing up into specified directories when looking for a GIT_DIR. Useful for avoiding slow network directories. For example, I use git in an environment where homedirs are automounted and "ls /home/nonexistent" takes about 9 seconds. Setting GIT_CEILING_DIRS="/home" allows "git help -a" (for bash completion) and "git symbolic-ref" (for my shell prompt) to run in a reasonable time. Signed-off-by: David Reiss Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 88c390d9f1..833f4cd982 100644 --- a/cache.h +++ b/cache.h @@ -300,6 +300,7 @@ static inline enum object_type object_type(unsigned int mode) #define CONFIG_ENVIRONMENT "GIT_CONFIG" #define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL" #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" +#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES" #define GITATTRIBUTES_FILE ".gitattributes" #define INFOATTRIBUTES_FILE "info/attributes" #define ATTRIBUTE_MACRO_PREFIX "[attr]" @@ -515,6 +516,7 @@ static inline int is_absolute_path(const char *path) } const char *make_absolute_path(const char *path); int normalize_absolute_path(char *buf, const char *path); +int longest_ancestor_length(const char *path, const char *prefix_list); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); -- cgit v1.2.3 From 4c81b03e30d13dbc93ea7071438ef2da0acd4189 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 30 May 2008 08:42:16 -0700 Subject: Make pack creation always fsync() the result This means that we can depend on packs always being stable on disk, simplifying a lot of the object serialization worries. And unlike loose objects, serializing pack creation IO isn't going to be a performance killer. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index eab1a172fe..092a997b07 100644 --- a/cache.h +++ b/cache.h @@ -761,6 +761,7 @@ extern ssize_t write_in_full(int fd, const void *buf, size_t count); extern void write_or_die(int fd, const void *buf, size_t count); extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg); +extern void fsync_or_die(int fd, const char *); /* pager.c */ extern void setup_pager(void); -- cgit v1.2.3 From 1b9a9467f8b9a8da2fe58d10ae16779492aa7737 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Thu, 5 Jun 2008 23:15:19 -0400 Subject: Use nonrelative paths instead of absolute paths for cloned repositories Particularly for the "alternates" file, if one will be created, we want a path that doesn't depend on the current directory, but we want to retain any symlinks in the path as given and any in the user's view of the current directory when the path was given. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 092a997b07..0a63c0eae6 100644 --- a/cache.h +++ b/cache.h @@ -524,6 +524,7 @@ static inline int is_absolute_path(const char *path) return path[0] == '/'; } const char *make_absolute_path(const char *path); +const char *make_nonrelative_path(const char *path); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); -- cgit v1.2.3 From 6483925999cde47e5108414ac3f57760394ee2d2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 13 Jun 2008 23:00:51 -0700 Subject: sha1_file.c: dead code removal write_sha1_from_fd() and write_sha1_to_fd() were dead code nobody called, neither the latter's helper repack_object() was. Signed-off-by: Junio C Hamano --- cache.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0a63c0eae6..23f3b92335 100644 --- a/cache.h +++ b/cache.h @@ -536,9 +536,6 @@ extern int force_object_loose(const unsigned char *sha1, time_t mtime); extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); -extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer, - size_t bufsize, size_t *bufposn); -extern int write_sha1_to_fd(int fd, const unsigned char *sha1); extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1, const char **ignore); -- cgit v1.2.3 From 79c6dca413094d2df74e7050f1185963b00e9245 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 16 Jun 2008 22:19:00 -0700 Subject: sha1_file.c: simplify parse_pack_index() It was implemented as a thin wrapper around an otherwise unused helper function parse_pack_index_file(). The code becomes simpler and easier to read by consolidating the two. Signed-off-by: Junio C Hamano --- cache.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 23f3b92335..81b7e17de2 100644 --- a/cache.h +++ b/cache.h @@ -694,8 +694,6 @@ extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, ch extern int server_supports(const char *feature); extern struct packed_git *parse_pack_index(unsigned char *sha1); -extern struct packed_git *parse_pack_index_file(const unsigned char *sha1, - const char *idx_path); extern void prepare_packed_git(void); extern void reprepare_packed_git(void); -- cgit v1.2.3 From aafe9fbaf4f1d1f27a6f6e3eb3e246fff81240ef Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 18 Jun 2008 15:18:44 -0700 Subject: Add config option to enable 'fsync()' of object files As explained in the documentation[*] this is totally useless on filesystems that do ordered/journalled data writes, but it can be a useful safety feature on filesystems like HFS+ that only journal the metadata, not the actual file contents. It defaults to off, although we could presumably in theory some day auto-enable it on a per-filesystem basis. [*] Yes, I updated the docs for the thing. Hell really _has_ frozen over, and the four horsemen are probably just beyond the horizon. EVERYBODY PANIC! Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 81b7e17de2..01c8502afb 100644 --- a/cache.h +++ b/cache.h @@ -435,6 +435,7 @@ extern size_t packed_git_window_size; extern size_t packed_git_limit; extern size_t delta_base_cache_limit; extern int auto_crlf; +extern int fsync_object_files; enum safe_crlf { SAFE_CRLF_FALSE = 0, -- cgit v1.2.3 From 044bbbcb63281dfdb78344ada2c44c96122dc822 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 19 Jun 2008 12:34:06 -0700 Subject: Make git_dir a path relative to work_tree in setup_work_tree() Once we find the absolute paths for git_dir and work_tree, we can make git_dir a relative path since we know pwd will be work_tree. This should save the kernel some time traversing the path to work_tree all the time if git_dir is inside work_tree. Daniel's patch didn't apply for me as-is, so I recreated it with some differences, and here are the numbers from ten runs each. There is some IO for me - probably due to more-or-less random flushing of the journal - so the variation is bigger than I'd like, but whatever: Before: real 0m8.135s real 0m7.933s real 0m8.080s real 0m7.954s real 0m7.949s real 0m8.112s real 0m7.934s real 0m8.059s real 0m7.979s real 0m8.038s After: real 0m7.685s real 0m7.968s real 0m7.703s real 0m7.850s real 0m7.995s real 0m7.817s real 0m7.963s real 0m7.955s real 0m7.848s real 0m7.969s Now, going by "best of ten" (on the assumption that the longer numbers are all due to IO), I'm saying a 7.933s -> 7.685s reduction, and it does seem to be outside of the noise (ie the "after" case never broke 8s, while the "before" case did so half the time). So looks like about 3% to me. Doing it for a slightly smaller test-case (just the "arch" subdirectory) gets more stable numbers probably due to not filling the journal with metadata updates, so we have: Before: real 0m1.633s real 0m1.633s real 0m1.633s real 0m1.632s real 0m1.632s real 0m1.630s real 0m1.634s real 0m1.631s real 0m1.632s real 0m1.632s After: real 0m1.610s real 0m1.609s real 0m1.610s real 0m1.608s real 0m1.607s real 0m1.610s real 0m1.609s real 0m1.611s real 0m1.608s real 0m1.611s where I'ld just take the averages and say 1.632 vs 1.610, which is just over 1% peformance improvement. So it's not in the noise, but it's not as big as I initially thought and measured. (That said, it obviously depends on how deep the working directory path is too, and whether it is behind NFS or something else that might need to cause more work to look up). Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 81b7e17de2..56ac6e7f47 100644 --- a/cache.h +++ b/cache.h @@ -525,6 +525,7 @@ static inline int is_absolute_path(const char *path) } const char *make_absolute_path(const char *path); const char *make_nonrelative_path(const char *path); +const char *make_relative_path(const char *abs, const char *base); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); -- cgit v1.2.3 From 78d0f5d210bc053d961185be6cfb0e248a0bdda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=97=E3=82=89=E3=81=84=E3=81=97=E3=81=AA=E3=81=AA?= =?UTF-8?q?=E3=81=93?= Date: Thu, 19 Jun 2008 08:21:09 +0900 Subject: environment.c: remove unused function get_refs_directory() is not used anywhere. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 81b7e17de2..feb49b788f 100644 --- a/cache.h +++ b/cache.h @@ -311,7 +311,6 @@ extern char *git_work_tree_cfg; extern int is_inside_work_tree(void); extern const char *get_git_dir(void); extern char *get_object_directory(void); -extern char *get_refs_directory(void); extern char *get_index_file(void); extern char *get_graft_file(void); extern int set_git_dir(const char *path); -- cgit v1.2.3 From e4bffb5a1d9ab3c9c0ef0541a395d47516480d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=97=E3=82=89=E3=81=84=E3=81=97=E3=81=AA=E3=81=AA?= =?UTF-8?q?=E3=81=93?= Date: Thu, 19 Jun 2008 08:21:11 +0900 Subject: config.c: make git_env_bool() static This function is not used by any other file. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index feb49b788f..8140763008 100644 --- a/cache.h +++ b/cache.h @@ -734,7 +734,6 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int extern int git_config_rename_section(const char *, const char *); extern const char *git_etc_gitconfig(void); extern int check_repository_format_version(const char *var, const char *value, void *cb); -extern int git_env_bool(const char *, int); extern int git_config_system(void); extern int git_config_global(void); extern int config_error_nonbool(const char *); -- cgit v1.2.3 From 25fe217b86ca40c53e710d776e120dfa0d81f60b Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 5 Mar 2008 21:51:27 +0100 Subject: Windows: Treat Windows style path names. GIT's guts work with a forward slash as a path separators. We do not change that. Rather we make sure that only "normalized" paths enter the depths of the machinery. We have to translate backslashes to forward slashes in the prefix and in command line arguments. Fortunately, all of them are passed through functions in setup.c. A macro has_dos_drive_path() is defined that checks whether a path begins with a drive letter+colon combination. This predicate is always false on Unix. Another macro is_dir_sep() abstracts that a backslash is also a directory separator on Windows. Signed-off-by: Johannes Sixt --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 81b7e17de2..72544de4ce 100644 --- a/cache.h +++ b/cache.h @@ -521,7 +521,7 @@ int safe_create_leading_directories(char *path); char *enter_repo(char *path, int strict); static inline int is_absolute_path(const char *path) { - return path[0] == '/'; + return path[0] == '/' || has_dos_drive_prefix(path); } const char *make_absolute_path(const char *path); const char *make_nonrelative_path(const char *path); -- cgit v1.2.3 From 8eca0b47ff1598a6d163df9358c0e0c9bd92d4c8 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 23 Jun 2008 21:23:39 -0400 Subject: implement some resilience against pack corruptions We should be able to fall back to loose objects or alternative packs when a pack becomes corrupted. This is especially true when an object exists in one pack only as a delta but its base object is corrupted. Currently there is no way to retrieve the former object even if the later is available in another pack or loose. This patch allows for a delta to be resolved (with a performance cost) using a base object from a source other than the pack where that delta is located. Same thing for non-delta objects: rather than failing outright, a search is made in other packs or used loose when the currently active pack has it but corrupted. Of course git will become extremely noisy with error messages when that happens. However, if the operation succeeds nevertheless, a simple 'git repack -a -f -d' will "fix" the corrupted repository given that all corrupted objects have a good duplicate somewhere in the object store, possibly manually copied from another source. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index d12ee7d0f5..a68866c1b4 100644 --- a/cache.h +++ b/cache.h @@ -641,6 +641,8 @@ extern struct packed_git { const void *index_data; size_t index_size; uint32_t num_objects; + uint32_t num_bad_objects; + unsigned char *bad_object_sha1; int index_version; time_t mtime; int pack_fd; -- cgit v1.2.3 From 8e21d63b02f1b26f7695ca515e51e4622a995af2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 25 Jun 2008 01:41:34 -0400 Subject: clone: create intermediate directories of destination repo The shell version used to use "mkdir -p" to create the repo path, but the C version just calls "mkdir". Let's replicate the old behavior. We have to create the git and worktree leading dirs separately; while most of the time, the worktree dir contains the git dir (as .git), the user can override this using GIT_WORK_TREE. We can reuse safe_create_leading_directories, but we need to make a copy of our const buffer to do so. Since merge-recursive uses the same pattern, we can factor this out into a global function. This has two other cleanup advantages for merge-recursive: 1. mkdir_p wasn't a very good name. "mkdir -p foo/bar" actually creates bar, but this function just creates the leading directories. 2. mkdir_p took a mode argument, but it was completely ignored. Acked-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a68866c1b4..a9c14da7a2 100644 --- a/cache.h +++ b/cache.h @@ -517,6 +517,7 @@ enum sharedrepo { int git_config_perm(const char *var, const char *value); int adjust_shared_perm(const char *path); int safe_create_leading_directories(char *path); +int safe_create_leading_directories_const(const char *path); char *enter_repo(char *path, int strict); static inline int is_absolute_path(const char *path) { -- cgit v1.2.3 From 99093238bbf2cd886debf7bdb91478cb405ef66d Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 24 Jun 2008 23:17:12 -0400 Subject: optimize verify-pack a bit Using find_pack_entry_one() to get object offsets is rather suboptimal when nth_packed_object_offset() can be used directly. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a9c14da7a2..c8954ef15f 100644 --- a/cache.h +++ b/cache.h @@ -712,6 +712,7 @@ extern void close_pack_windows(struct packed_git *); extern void unuse_pack(struct pack_window **); extern struct packed_git *add_packed_git(const char *, int, int); extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t); +extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t); extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); -- cgit v1.2.3 From 2beebd22f4af8788eaf19d811de03191ae6f7c42 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 25 Jun 2008 01:41:34 -0400 Subject: clone: create intermediate directories of destination repo The shell version used to use "mkdir -p" to create the repo path, but the C version just calls "mkdir". Let's replicate the old behavior. We have to create the git and worktree leading dirs separately; while most of the time, the worktree dir contains the git dir (as .git), the user can override this using GIT_WORK_TREE. We can reuse safe_create_leading_directories, but we need to make a copy of our const buffer to do so. Since merge-recursive uses the same pattern, we can factor this out into a global function. This has two other cleanup advantages for merge-recursive: 1. mkdir_p wasn't a very good name. "mkdir -p foo/bar" actually creates bar, but this function just creates the leading directories. 2. mkdir_p took a mode argument, but it was completely ignored. Acked-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 56ac6e7f47..ca382d4622 100644 --- a/cache.h +++ b/cache.h @@ -518,6 +518,7 @@ enum sharedrepo { int git_config_perm(const char *var, const char *value); int adjust_shared_perm(const char *path); int safe_create_leading_directories(char *path); +int safe_create_leading_directories_const(const char *path); char *enter_repo(char *path, int strict); static inline int is_absolute_path(const char *path) { -- cgit v1.2.3 From 8f8841e9c8e6a26153b0cf9417c7540cf65ef09f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 26 Jun 2008 15:35:21 -0700 Subject: check_and_emit_line(): rename and refactor The function name was too bland and not explicit enough as to what it is checking. Split it into two, and call the one that checks if there is a whitespace breakage "ws_check()", and call the other one that checks and emits the line after color coding "ws_check_emit()". Signed-off-by: Junio C Hamano --- cache.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 64ef86e129..3dfa53c566 100644 --- a/cache.h +++ b/cache.h @@ -819,9 +819,8 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i extern unsigned whitespace_rule_cfg; extern unsigned whitespace_rule(const char *); extern unsigned parse_whitespace_rule(const char *); -extern unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, - FILE *stream, const char *set, - const char *reset, const char *ws); +extern unsigned ws_check(const char *line, int len, unsigned ws_rule); +extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); extern char *whitespace_error_string(unsigned ws); extern int ws_fix_copy(char *, const char *, int, unsigned, int *); -- cgit v1.2.3 From 877f23ccb88227203f2576abdfb5d1c15925fcb3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 26 Jun 2008 15:36:59 -0700 Subject: Teach "diff --check" about new blank lines at end When a patch adds new blank lines at the end, "git apply --whitespace" warns. This teaches "diff --check" to do the same. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3dfa53c566..188428dd26 100644 --- a/cache.h +++ b/cache.h @@ -823,6 +823,7 @@ extern unsigned ws_check(const char *line, int len, unsigned ws_rule); extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); extern char *whitespace_error_string(unsigned ws); extern int ws_fix_copy(char *, const char *, int, unsigned, int *); +extern int ws_blank_line(const char *line, int len, unsigned ws_rule); /* ls-files */ int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen); -- cgit v1.2.3 From 0989fe9623dc8d98033f6acdcc0c84ec28571b19 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 27 Jun 2008 18:21:54 +0200 Subject: Move split_cmdline() to alias.c split_cmdline() is currently used for aliases only, but later it can be useful for other builtins as well. Move it to alias.c for now, indicating that originally it's for aliases, but we'll have it in libgit this way. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 64ef86e129..6913573d1a 100644 --- a/cache.h +++ b/cache.h @@ -831,5 +831,6 @@ int report_path_error(const char *ps_matched, const char **pathspec, int prefix_ void overlay_tree_on_cache(const char *tree_name, const char *prefix); char *alias_lookup(const char *alias); +int split_cmdline(char *cmdline, const char ***argv); #endif /* CACHE_H */ -- cgit v1.2.3 From e46bbcf6e89e4b1d3d8de1d20d836538ab0f0c85 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 27 Jun 2008 18:21:58 +0200 Subject: Move read_cache_unmerged() to read-cache.c builtin-read-tree has a read_cache_unmerged() which is useful for other builtins, for example builtin-merge uses it as well. Move it to read-cache.c to avoid code duplication. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6913573d1a..d0d74a3ff8 100644 --- a/cache.h +++ b/cache.h @@ -254,6 +254,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define read_cache() read_index(&the_index) #define read_cache_from(path) read_index_from(&the_index, (path)) +#define read_cache_unmerged() read_index_unmerged(&the_index) #define write_cache(newfd, cache, entries) write_index(&the_index, (newfd)) #define discard_cache() discard_index(&the_index) #define unmerged_cache() unmerged_index(&the_index) @@ -356,6 +357,7 @@ extern int init_db(const char *template_dir, unsigned int flags); /* Initialize and use the cache information */ extern int read_index(struct index_state *); extern int read_index_from(struct index_state *, const char *path); +extern int read_index_unmerged(struct index_state *); extern int write_index(const struct index_state *, int newfd); extern int discard_index(struct index_state *); extern int unmerged_index(const struct index_state *); -- cgit v1.2.3 From dc87183189b54441e315d35d48983d80ab085299 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 30 Jun 2008 03:37:47 -0400 Subject: Only use GIT_CONFIG in "git config", not other programs For everything other than using "git config" to read or write a git-style config file that isn't the current repo's config file, GIT_CONFIG was actively detrimental. Rather than argue over which programs are important enough to have work anyway, just fix all of them at the root. Also removes GIT_LOCAL_CONFIG, which would only be useful for programs that do want to use global git-specific config, but not the repo's own git-specific config, and want to use some other, presumably git-specific config. Despite being documented, I can't find any sign that it was ever used. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 64ef86e129..bab0115b6f 100644 --- a/cache.h +++ b/cache.h @@ -298,7 +298,6 @@ static inline enum object_type object_type(unsigned int mode) #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" #define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR" #define CONFIG_ENVIRONMENT "GIT_CONFIG" -#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL" #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" #define GITATTRIBUTES_FILE ".gitattributes" #define INFOATTRIBUTES_FILE "info/attributes" @@ -743,6 +742,7 @@ extern int check_repository_format_version(const char *var, const char *value, v extern int git_config_system(void); extern int git_config_global(void); extern int config_error_nonbool(const char *); +extern const char *config_exclusive_filename; #define MAX_GITNAME (1000) extern char git_default_email[MAX_GITNAME]; -- cgit v1.2.3 From ac9391093f54370ff3f06470e24d78b536a12327 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 14 Jul 2008 21:46:48 -0400 Subject: restore legacy behavior for read_sha1_file() Since commit 8eca0b47ff1598a6d163df9358c0e0c9bd92d4c8, it is possible for read_sha1_file() to return NULL even with existing objects when they are corrupted. Previously a corrupted object would have terminated the program immediately, effectively making read_sha1_file() return NULL only when specified object is not found. Let's restore this behavior for all users of read_sha1_file() and provide a separate function with the ability to not terminate when bad objects are encountered. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0d8eddac77..a8254e2f9e 100644 --- a/cache.h +++ b/cache.h @@ -538,6 +538,9 @@ extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsig extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); extern int force_object_loose(const unsigned char *sha1, time_t mtime); +/* just like read_sha1_file(), but non fatal in presence of bad objects */ +extern void *read_object(const unsigned char *sha1, enum object_type *type, unsigned long *size); + extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); extern int move_temp_to_file(const char *tmpfile, const char *filename); -- cgit v1.2.3 From 3f1b7b607a81cf56254fcc4ed417cc4344cde2a5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 19 Jul 2008 23:25:00 -0700 Subject: refresh-index: fix bitmask assignment 5fdeacb (Teach update-index about --ignore-submodules, 2008-05-14) added a new refresh option flag but did not assign a unique bit for it correctly, and broke "update-index --ignore-missing". This fixes it. Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ca382d4622..9735b66e5e 100644 --- a/cache.h +++ b/cache.h @@ -396,7 +396,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); #define REFRESH_UNMERGED 0x0002 /* allow unmerged */ #define REFRESH_QUIET 0x0004 /* be quiet about it */ #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ -#define REFRESH_IGNORE_SUBMODULES 0x0008 /* ignore submodules */ +#define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */ extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen); struct lock_file { -- cgit v1.2.3 From d14e7407b34b8c11b407358b9677c283c381a71c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 20 Jul 2008 00:21:38 -0700 Subject: "needs update" considered harmful "git update-index --refresh", "git reset" and "git add --refresh" have reported paths that have local modifications as "needs update" since the beginning of git. Although this is logically correct in that you need to update the index at that path before you can commit that change, it is now becoming more and more clear, especially with the continuous push for user friendliness since 1.5.0 series, that the message is suboptimal. After all, the change may be something the user might want to get rid of, and "updating" would be absolutely a wrong thing to do if that is the case. I prepared two alternatives to solve this. Both aim to reword the message to more neutral "locally modified". This patch is a more intrusive variant that changes the message for only Porcelain commands ("add" and "reset") while keeping the plumbing "update-index" intact. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 305e2f701b..38985aa63e 100644 --- a/cache.h +++ b/cache.h @@ -398,6 +398,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); #define REFRESH_QUIET 0x0004 /* be quiet about it */ #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ #define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */ +#define REFRESH_SAY_CHANGED 0x0020 /* say "changed" not "needs update" */ extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen); struct lock_file { -- cgit v1.2.3 From 041aee31be378b3b38e3a0913b29970a7f78873b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 21 Jul 2008 01:24:17 -0700 Subject: builtin-add.c: restructure the code for maintainability A private function add_files_to_cache() in builtin-add.c was borrowed by checkout and commit re-implementors without getting properly refactored to more library-ish place. This does the refactoring. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 38985aa63e..6f374add88 100644 --- a/cache.h +++ b/cache.h @@ -375,6 +375,7 @@ extern int remove_file_from_index(struct index_state *, const char *path); #define ADD_CACHE_VERBOSE 1 #define ADD_CACHE_PRETEND 2 #define ADD_CACHE_IGNORE_ERRORS 4 +#define ADD_CACHE_IGNORE_REMOVAL 8 extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags); extern int add_file_to_index(struct index_state *, const char *path, int flags); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); -- cgit v1.2.3 From 81dc2307d0ad87a4da2e753a9d1b5586d6456eed Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 21 Jul 2008 02:25:56 +0200 Subject: git-mv: Keep moved index entries inact The rewrite of git-mv from a shell script to a builtin was perhaps a little too straightforward: the git add and git rm queues were emulated directly, which resulted in a rather complicated code and caused an inconsistent behaviour when moving dirty index entries; git mv would update the entry based on working tree state, except in case of overwrites, where the new entry would still have sha1 of the old file. This patch introduces rename_index_entry_at() into the index toolkit, which will rename an entry while removing any entries the new entry might render duplicate. This is then used in git mv instead of all the file queues, resulting in a major simplification of the code and an inevitable change in git mv -n output format. Also the code used to refuse renaming overwriting symlink with a regular file and vice versa; there is no need for that. A few new tests have been added to the testsuite to reflect this change. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 38985aa63e..4b6c0a6c59 100644 --- a/cache.h +++ b/cache.h @@ -260,6 +260,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define unmerged_cache() unmerged_index(&the_index) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) +#define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name)) #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) #define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags)) @@ -370,6 +371,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name #define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option); extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); +extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name); extern int remove_index_entry_at(struct index_state *, int pos); extern int remove_file_from_index(struct index_state *, const char *path); #define ADD_CACHE_VERBOSE 1 -- cgit v1.2.3 From 1ce4790bf5eeceb212f003fffcb36069c0ebb45e Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Mon, 28 Jul 2008 08:31:28 +0200 Subject: Make use of stat.ctime configurable A new configuration variable 'core.trustctime' is introduced to allow ignoring st_ctime information when checking if paths in the working tree has changed, because there are situations where it produces too much false positives. Like when file system crawlers keep changing it when scanning and using the ctime for marking scanned files. The default is to notice ctime changes. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4b6c0a6c59..2475de9fa8 100644 --- a/cache.h +++ b/cache.h @@ -423,6 +423,7 @@ extern int delete_ref(const char *, const unsigned char *sha1); /* Environment bits from configuration mechanism */ extern int trust_executable_bit; +extern int trust_ctime; extern int quote_path_fully; extern int has_symlinks; extern int ignore_case; -- cgit v1.2.3 From 43df4f86e035056605ceb757029181d7ddee1e7e Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 08:39:16 +0400 Subject: teach index_fd to work with pipes index_fd can now work with file descriptors that are not normal files but any readable file. If the given file descriptor is a regular file then mmap() is used; for other files, strbuf_read is used. The path parameter, which has been used as hint for filters, can be NULL now to indicate that the file should be hashed literally without any filter. The index_pipe function is removed as redundant. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2475de9fa8..68ce6e686f 100644 --- a/cache.h +++ b/cache.h @@ -391,7 +391,6 @@ extern int ie_modified(const struct index_state *, struct cache_entry *, struct extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); -extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object); extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); -- cgit v1.2.3 From 16ce2e4c8f9664f8ec5ae2bffed34d093d83a4d3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Aug 2008 23:02:08 -0700 Subject: index: future proof for "extended" index entries We do not have any more bits in the on-disk index flags word, but we would need to have more in the future. Use the last remaining bits as a signal to tell us that the index entry we are looking at is an extended one. Since we do not understand the extended format yet, we will just error out when we see it. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2475de9fa8..7b5cc834ab 100644 --- a/cache.h +++ b/cache.h @@ -126,6 +126,7 @@ struct cache_entry { #define CE_NAMEMASK (0x0fff) #define CE_STAGEMASK (0x3000) +#define CE_EXTENDED (0x4000) #define CE_VALID (0x8000) #define CE_STAGESHIFT 12 -- cgit v1.2.3 From 9188ed8962ed47c0f41c24eb1317aa07037da545 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 21 Aug 2008 19:23:20 +0200 Subject: Extend "checkout --track" DWIM to support more cases The code handles additionally "refs/remotes//name", "remotes//name", and "refs//name". Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 928ae9f148..a097a959bd 100644 --- a/cache.h +++ b/cache.h @@ -451,6 +451,7 @@ enum safe_crlf { extern enum safe_crlf safe_crlf; enum branch_track { + BRANCH_TRACK_UNSPECIFIED = -1, BRANCH_TRACK_NEVER = 0, BRANCH_TRACK_REMOTE, BRANCH_TRACK_ALWAYS, -- cgit v1.2.3 From 913e0e99b6a6e63af6a062622a1f94bd78fd8052 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 23 Aug 2008 12:57:30 -0700 Subject: unpack_trees(): protect the handcrafted in-core index from read_cache() unpack_trees() rebuilds the in-core index from scratch by allocating a new structure and finishing it off by copying the built one to the final index. The resulting in-core index is Ok for most use, but read_cache() does not recognize it as such. The function is meant to be no-op if you already have loaded the index, until you call discard_cache(). This change the way read_cache() detects an already initialized in-core index, by introducing an extra bit, and marks the handcrafted in-core index as initialized, to avoid this problem. A better fix in the longer term would be to change the read_cache() API so that it will always discard and re-read from the on-disk index to avoid confusion. But there are higher level API that have relied on the current semantics, and they and their users all need to get converted, which is outside the scope of 'maint' track. An example of such a higher level API is write_cache_as_tree(), which is used by git-write-tree as well as later Porcelains like git-merge, revert and cherry-pick. In the longer term, we should remove read_cache() from there and add one to cmd_write_tree(); other callers expect that the in-core index they prepared is what gets written as a tree so no other change is necessary for this particular codepath. The original version of this patch marked the index by pointing an otherwise wasted malloc'ed memory with o->result.alloc, but this version uses Linus's idea to use a new "initialized" bit, which is conceptually much cleaner. Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2475de9fa8..884fae826c 100644 --- a/cache.h +++ b/cache.h @@ -222,7 +222,8 @@ struct index_state { struct cache_tree *cache_tree; time_t timestamp; void *alloc; - unsigned name_hash_initialized : 1; + unsigned name_hash_initialized : 1, + initialized : 1; struct hash_table name_hash; }; -- cgit v1.2.3 From 394258190c76dd7944688a3a28931071ec02087d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 21 Aug 2008 01:44:53 -0700 Subject: git-add --intent-to-add (-N) This adds "--intent-to-add" option to "git add". This is to let the system know that you will tell it the final contents to be staged later, iow, just be aware of the presense of the path with the type of the blob for now. It is implemented by staging an empty blob as the content. With this sequence: $ git reset --hard $ edit newfile $ git add -N newfile $ edit newfile oldfile $ git diff the diff will show all changes relative to the current commit. Then you can do: $ git commit -a ;# commit everything or $ git commit oldfile ;# only oldfile, newfile not yet added to pretend you are working with an index-free system like CVS. Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index de8c2b6266..f725783b80 100644 --- a/cache.h +++ b/cache.h @@ -371,6 +371,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ #define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */ +#define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option); extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name); @@ -380,6 +381,7 @@ extern int remove_file_from_index(struct index_state *, const char *path); #define ADD_CACHE_PRETEND 2 #define ADD_CACHE_IGNORE_ERRORS 4 #define ADD_CACHE_IGNORE_REMOVAL 8 +#define ADD_CACHE_INTENT 16 extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags); extern int add_file_to_index(struct index_state *, const char *path, int flags); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); -- cgit v1.2.3 From 90b4a71c493bf24f11b5edee8a519110624a6bea Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 9 Sep 2008 01:27:07 -0700 Subject: is_directory(): a generic helper function A simple "grep -e stat --and -e S_ISDIR" revealed there are many open-coded implementations of this function. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index de8c2b6266..ce1f63090d 100644 --- a/cache.h +++ b/cache.h @@ -533,6 +533,7 @@ static inline int is_absolute_path(const char *path) { return path[0] == '/' || has_dos_drive_prefix(path); } +int is_directory(const char *); const char *make_absolute_path(const char *path); const char *make_nonrelative_path(const char *path); const char *make_relative_path(const char *abs, const char *base); -- cgit v1.2.3 From 40c155ff14c8b313d408f2e51a55c881ce082e4e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 9 Sep 2008 01:27:09 -0700 Subject: push: prepare sender to receive extended ref information from the receiver "git push" enhancement allows the receiving end to report not only its own refs but refs in repositories it borrows from via the alternate object store mechanism. By telling the sender that objects reachable from these extra refs are already complete in the receiving end, the number of objects that need to be transfered can be cut down. These entries are sent over the wire with string ".have", instead of the actual names of the refs. This string was chosen so that they are ignored by older programs at the sending end. If we sent some random but valid looking refnames for these entries, "matching refs" rule (triggered when running "git push" without explicit refspecs, where the sender learns what refs the receiver has, and updates only the ones with the names of the refs the sender also has) and "delete missing" rule (triggered when "git push --mirror" is used, where the sender tells the receiver to delete the refs it itself does not have) would try to update/delete them, which is not what we want. This prepares the send-pack (and "push" that runs native protocol) to accept extended existing ref information and make use of it. The ".have" entries are excluded from ref matching rules, and are exempt from deletion rule while pushing with --mirror option, but are still used for pack generation purposes by providing more "bottom" range commits. Signed-off-by: Junio C Hamano --- cache.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ce1f63090d..98a742122d 100644 --- a/cache.h +++ b/cache.h @@ -709,7 +709,11 @@ extern struct child_process *git_connect(int fd[2], const char *url, const char extern int finish_connect(struct child_process *conn); extern int path_match(const char *path, int nr, char **match); extern int get_ack(int fd, unsigned char *result_sha1); -extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags); +struct extra_have_objects { + int nr, alloc; + unsigned char (*array)[20]; +}; +extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags, struct extra_have_objects *); extern int server_supports(const char *feature); extern struct packed_git *parse_pack_index(unsigned char *sha1); -- cgit v1.2.3 From d79796bcf05b89774671a75b3285000c43129823 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 9 Sep 2008 01:27:10 -0700 Subject: push: receiver end advertises refs from alternate repositories Earlier, when pushing into a repository that borrows from alternate object stores, we followed the longstanding design decision not to trust refs in the alternate repository that houses the object store we are borrowing from. If your public repository is borrowing from Linus's public repository, you pushed into it long time ago, and now when you try to push your updated history that is in sync with more recent history from Linus, you will end up sending not just your own development, but also the changes you acquired through Linus's tree, even though the objects needed for the latter already exists at the receiving end. This is because the receiving end does not advertise that the objects only reachable from the borrowed repository (i.e. Linus's) are already available there. This solves the issue by making the receiving end advertise refs from borrowed repositories. They are not sent with their true names but with a phoney name ".have" to make sure that the old senders will safely ignore them (otherwise, the old senders will misbehave, trying to push matching refs, and mirror push that deletes refs that only exist at the receiving end). Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 98a742122d..99af83a047 100644 --- a/cache.h +++ b/cache.h @@ -641,6 +641,8 @@ extern struct alternate_object_database { } *alt_odb_list; extern void prepare_alt_odb(void); extern void add_to_alternates_file(const char *reference); +typedef int alt_odb_fn(struct alternate_object_database *, void *); +extern void foreach_alt_odb(alt_odb_fn, void*); struct pack_window { struct pack_window *next; -- cgit v1.2.3 From d2b0708e1a65953ad93a4adfc27938de0f8df252 Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sat, 27 Sep 2008 12:41:50 +0400 Subject: add have_git_dir() function This function is used to learn whether git_dir is already set up or not. It is necessary, because we want to read configuration in compat/cygwin.c Signed-off-by: Dmitry Potapov Signed-off-by: Shawn O. Pearce --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 99af83a047..818804dad6 100644 --- a/cache.h +++ b/cache.h @@ -313,6 +313,7 @@ extern int is_bare_repository(void); extern int is_inside_git_dir(void); extern char *git_work_tree_cfg; extern int is_inside_work_tree(void); +extern int have_git_dir(void); extern const char *get_git_dir(void); extern char *get_object_directory(void); extern char *get_index_file(void); -- cgit v1.2.3 From 0433bcd9f01b9113a02831c13e364c6a89a0047a Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Thu, 2 Oct 2008 19:14:27 +0900 Subject: config.c: make git_parse_long() static This function is not used in any other file. Signed-off-by: Nanako Shiraishi Signed-off-by: Shawn O. Pearce --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 99af83a047..7027c896bf 100644 --- a/cache.h +++ b/cache.h @@ -749,7 +749,6 @@ typedef int (*config_fn_t)(const char *, const char *, void *); extern int git_default_config(const char *, const char *, void *); extern int git_config_from_file(config_fn_t fn, const char *, void *); extern int git_config(config_fn_t fn, void *); -extern int git_parse_long(const char *, long *); extern int git_parse_ulong(const char *, unsigned long *); extern int git_config_int(const char *, const char *); extern unsigned long git_config_ulong(const char *, const char *); -- cgit v1.2.3 From 9126f0091f271f090cc030a788219574ab0fea97 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 1 Oct 2008 14:05:20 -0400 Subject: fix openssl headers conflicting with custom SHA1 implementations On ARM I have the following compilation errors: CC fast-import.o In file included from cache.h:8, from builtin.h:6, from fast-import.c:142: arm/sha1.h:14: error: conflicting types for 'SHA_CTX' /usr/include/openssl/sha.h:105: error: previous declaration of 'SHA_CTX' was here arm/sha1.h:16: error: conflicting types for 'SHA1_Init' /usr/include/openssl/sha.h:115: error: previous declaration of 'SHA1_Init' was here arm/sha1.h:17: error: conflicting types for 'SHA1_Update' /usr/include/openssl/sha.h:116: error: previous declaration of 'SHA1_Update' was here arm/sha1.h:18: error: conflicting types for 'SHA1_Final' /usr/include/openssl/sha.h:117: error: previous declaration of 'SHA1_Final' was here make: *** [fast-import.o] Error 1 This is because openssl header files are always included in git-compat-util.h since commit 684ec6c63c whenever NO_OPENSSL is not set, which somehow brings in clashing with the custom ARM version. Compilation of git is probably broken on PPC too for the same reason. Turns out that the only file requiring openssl/ssl.h and openssl/err.h is imap-send.c. But only moving those problematic includes there doesn't solve the issue as it also includes cache.h which brings in the conflicting local SHA1 header file. As suggested by Jeff King, the best solution is to rename our references to SHA1 functions and structure to something git specific, and define those according to the implementation used. Signed-off-by: Nicolas Pitre Signed-off-by: Shawn O. Pearce --- cache.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7027c896bf..9f4e5c0d45 100644 --- a/cache.h +++ b/cache.h @@ -6,8 +6,14 @@ #include "hash.h" #include SHA1_HEADER -#include +#ifndef git_SHA_CTX +#define git_SHA_CTX SHA_CTX +#define git_SHA1_Init SHA1_Init +#define git_SHA1_Update SHA1_Update +#define git_SHA1_Final SHA1_Final +#endif +#include #if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200 #define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11) #endif -- cgit v1.2.3 From 06aaaa0bf70fe37d198893f4e25fa73b6516f8a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 1 Oct 2008 11:04:01 +0700 Subject: Extend index to save more flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The on-disk format of index only saves 16 bit flags, nearly all have been used. The last bit (CE_EXTENDED) is used to for future extension. This patch extends index entry format to save more flags in future. The new entry format will be used when CE_EXTENDED bit is 1. Because older implementation may not understand CE_EXTENDED bit and misread the new format, if there is any extended entry in index, index header version will turn 3, which makes it incompatible for older git. If there is none, header version will return to 2 again. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Shawn O. Pearce --- cache.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 991544cf0b..964f7e31cb 100644 --- a/cache.h +++ b/cache.h @@ -115,6 +115,26 @@ struct ondisk_cache_entry { char name[FLEX_ARRAY]; /* more */ }; +/* + * This struct is used when CE_EXTENDED bit is 1 + * The struct must match ondisk_cache_entry exactly from + * ctime till flags + */ +struct ondisk_cache_entry_extended { + struct cache_time ctime; + struct cache_time mtime; + unsigned int dev; + unsigned int ino; + unsigned int mode; + unsigned int uid; + unsigned int gid; + unsigned int size; + unsigned char sha1[20]; + unsigned short flags; + unsigned short flags2; + char name[FLEX_ARRAY]; /* more */ +}; + struct cache_entry { unsigned int ce_ctime; unsigned int ce_mtime; @@ -136,7 +156,15 @@ struct cache_entry { #define CE_VALID (0x8000) #define CE_STAGESHIFT 12 -/* In-memory only */ +/* + * Range 0xFFFF0000 in ce_flags is divided into + * two parts: in-memory flags and on-disk ones. + * Flags in CE_EXTENDED_FLAGS will get saved on-disk + * if you want to save a new flag, add it in + * CE_EXTENDED_FLAGS + * + * In-memory only flags + */ #define CE_UPDATE (0x10000) #define CE_REMOVE (0x20000) #define CE_UPTODATE (0x40000) @@ -145,6 +173,24 @@ struct cache_entry { #define CE_HASHED (0x100000) #define CE_UNHASHED (0x200000) +/* + * Extended on-disk flags + */ +/* CE_EXTENDED2 is for future extension */ +#define CE_EXTENDED2 0x80000000 + +#define CE_EXTENDED_FLAGS (0) + +/* + * Safeguard to avoid saving wrong flags: + * - CE_EXTENDED2 won't get saved until its semantic is known + * - Bits in 0x0000FFFF have been saved in ce_flags already + * - Bits in 0x003F0000 are currently in-memory flags + */ +#if CE_EXTENDED_FLAGS & 0x803FFFFF +#error "CE_EXTENDED_FLAGS out of range" +#endif + /* * Copy the sha1 and stat state of a cache entry from one to * another. But we never change the name, or the hash state! @@ -177,7 +223,9 @@ static inline size_t ce_namelen(const struct cache_entry *ce) } #define ce_size(ce) cache_entry_size(ce_namelen(ce)) -#define ondisk_ce_size(ce) ondisk_cache_entry_size(ce_namelen(ce)) +#define ondisk_ce_size(ce) (((ce)->ce_flags & CE_EXTENDED) ? \ + ondisk_cache_entry_extended_size(ce_namelen(ce)) : \ + ondisk_cache_entry_size(ce_namelen(ce))) #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE) #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE) @@ -220,8 +268,10 @@ static inline int ce_to_dtype(const struct cache_entry *ce) (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFGITLINK) -#define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7) -#define ondisk_cache_entry_size(len) ((offsetof(struct ondisk_cache_entry,name) + (len) + 8) & ~7) +#define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7) +#define cache_entry_size(len) flexible_size(cache_entry,len) +#define ondisk_cache_entry_size(len) flexible_size(ondisk_cache_entry,len) +#define ondisk_cache_entry_extended_size(len) flexible_size(ondisk_cache_entry_extended,len) struct index_state { struct cache_entry **cache; -- cgit v1.2.3 From 98fa473887d0bebd38d568bb07232a336a642dcf Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 16 Oct 2008 11:07:26 -0400 Subject: refactor handling of "other" files in ls-files and status When the "git status" display code was originally converted to C, we copied the code from ls-files to discover whether a pathname returned by read_directory was an "other", or untracked, file. Much later, 5698454e updated the code in ls-files to handle some new cases caused by gitlinks. This left the code in wt-status.c broken: it would display submodule directories as untracked directories. Nobody noticed until now, however, because unless status.showUntrackedFiles was set to "all", submodule directories were not actually reported by read_directory. So the bug was only triggered in the presence of a submodule _and_ this config option. This patch pulls the ls-files code into a new function, cache_name_is_other, and uses it in both places. This should leave the ls-files functionality the same and fix the bug in status. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 884fae826c..76730cee61 100644 --- a/cache.h +++ b/cache.h @@ -270,6 +270,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) #define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase)) +#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) #endif enum object_type { @@ -382,6 +383,7 @@ extern int add_to_index(struct index_state *, const char *path, struct stat *, i extern int add_file_to_index(struct index_state *, const char *path, int flags); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); +extern int index_name_is_other(const struct index_state *, const char *, int); /* do stat comparison even if CE_VALID is true */ #define CE_MATCH_IGNORE_VALID 01 -- cgit v1.2.3 From acd3b9eca82e38950f94e4708b528b7dae09a7c8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 17 Oct 2008 15:44:39 -0700 Subject: Enhance hold_lock_file_for_{update,append}() API This changes the "die_on_error" boolean parameter to a mere "flags", and changes the existing callers of hold_lock_file_for_update/append() functions to pass LOCK_DIE_ON_ERROR. Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 884fae826c..8ab2fd8fd0 100644 --- a/cache.h +++ b/cache.h @@ -411,6 +411,8 @@ struct lock_file { char on_list; char filename[PATH_MAX]; }; +#define LOCK_DIE_ON_ERROR 1 +#define LOCK_NODEREF 2 extern int hold_lock_file_for_update(struct lock_file *, const char *path, int); extern int hold_lock_file_for_append(struct lock_file *, const char *path, int); extern int commit_lock_file(struct lock_file *); -- cgit v1.2.3 From f55527f80223178d1837bae08addc57bed76d236 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 21 Oct 2008 09:54:19 -0400 Subject: rm: loosen safety valve for empty files If a file is different between the working tree copy, the index, and the HEAD, then we do not allow it to be deleted without --force. However, this is overly tight in the face of "git add --intent-to-add": $ git add --intent-to-add file $ : oops, I don't actually want to stage that yet $ git rm --cached file error: 'empty' has staged content different from both the file and the HEAD (use -f to force removal) $ git rm -f --cached file Unfortunately, there is currently no way to distinguish between an empty file that has been added and an "intent to add" file. The ideal behavior would be to disallow the former while allowing the latter. This patch loosens the safety valve to allow the deletion only if we are deleting the cached entry and the cached content is empty. This covers the intent-to-add situation, and assumes there is little harm in not protecting users who have legitimately added an empty file. In many cases, the file will still be empty, in which case the safety valve does not trigger anyway (since the content remains untouched in the working tree). Otherwise, we do remove the fact that no content was staged, but given that the content is by definition empty, it is not terribly difficult for a user to recreate it. However, we still document the desired behavior in the form of two tests. One checks the correct removal of an intent-to-add file. The other checks that we still disallow removal of empty files, but is marked as expect_failure to indicate this compromise. If the intent-to-add feature is ever extended to differentiate between normal empty files and intent-to-add files, then the safety valve can be re-tightened. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index cdbeb48c65..b0edbf9b9f 100644 --- a/cache.h +++ b/cache.h @@ -519,6 +519,7 @@ static inline void hashclr(unsigned char *hash) { memset(hash, 0, 20); } +extern int is_empty_blob_sha1(const unsigned char *sha1); int git_mkstemp(char *path, size_t n, const char *template); -- cgit v1.2.3 From eca35a25a92a1ad725af2a549fc9158488c4cc43 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 26 Oct 2008 03:33:56 +0100 Subject: Fix git branch -m for symrefs. This had two problems with symrefs. First, it copied the actual sha1 instead of the "pointer", second it failed to remove the old ref after a successful rename. Given that till now delete_ref() always dereferenced symrefs, a new parameters has been introduced to delete_ref() to allow deleting refs without a dereference. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 884fae826c..715348a066 100644 --- a/cache.h +++ b/cache.h @@ -420,7 +420,7 @@ extern int commit_locked_index(struct lock_file *); extern void set_alternate_index_output(const char *); extern int close_lock_file(struct lock_file *); extern void rollback_lock_file(struct lock_file *); -extern int delete_ref(const char *, const unsigned char *sha1); +extern int delete_ref(const char *, const unsigned char *sha1, int delopt); /* Environment bits from configuration mechanism */ extern int trust_executable_bit; -- cgit v1.2.3 From 108bebeab31881654b7b0f1b5b393a6655d74d3f Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Sun, 26 Oct 2008 22:59:13 +0100 Subject: Add mksnpath which allows you to specify the output buffer This is just vsnprintf's but additionally calls cleanup_path() on the result. To be used as alternatives to mkpath() where the buffer for the created path may not be reused by subsequent calls of the same formatting function. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 884fae826c..aea13b0822 100644 --- a/cache.h +++ b/cache.h @@ -480,6 +480,9 @@ extern int check_repository_format(void); #define DATA_CHANGED 0x0020 #define TYPE_CHANGED 0x0040 +extern char *mksnpath(char *buf, size_t n, const char *fmt, ...) + __attribute__((format (printf, 3, 4))); + /* Return a statically allocated filename matching the sha1 signature */ extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); -- cgit v1.2.3 From fe2d7776d5191896e361973f478ca078fa95b324 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Mon, 27 Oct 2008 10:22:21 +0100 Subject: Add git_snpath: a .git path formatting routine with output buffer The function's purpose is to replace git_path where the buffer of formatted path may not be reused by subsequent calls of the function or will be copied anyway. Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index aea13b0822..3d5a08ea81 100644 --- a/cache.h +++ b/cache.h @@ -482,6 +482,8 @@ extern int check_repository_format(void); extern char *mksnpath(char *buf, size_t n, const char *fmt, ...) __attribute__((format (printf, 3, 4))); +extern char *git_snpath(char *buf, size_t n, const char *fmt, ...) + __attribute__((format (printf, 3, 4))); /* Return a statically allocated filename matching the sha1 signature */ extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); -- cgit v1.2.3 From aba13e7c0566f578f866504bfcb388a72f7e5079 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Mon, 27 Oct 2008 11:17:51 +0100 Subject: git_pathdup: returns xstrdup-ed copy of the formatted path Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3d5a08ea81..eaacd6dd9f 100644 --- a/cache.h +++ b/cache.h @@ -484,6 +484,8 @@ extern char *mksnpath(char *buf, size_t n, const char *fmt, ...) __attribute__((format (printf, 3, 4))); extern char *git_snpath(char *buf, size_t n, const char *fmt, ...) __attribute__((format (printf, 3, 4))); +extern char *git_pathdup(const char *fmt, ...) + __attribute__((format (printf, 1, 2))); /* Return a statically allocated filename matching the sha1 signature */ extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); -- cgit v1.2.3 From 0e8189e2708bc1da08c77c7e1d960f420b6890a5 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Fri, 31 Oct 2008 11:31:08 -0400 Subject: close another possibility for propagating pack corruption Abstract -------- With index v2 we have a per object CRC to allow quick and safe reuse of pack data when repacking. This, however, doesn't currently prevent a stealth corruption from being propagated into a new pack when _not_ reusing pack data as demonstrated by the modification to t5302 included here. The Context ----------- The Git database is all checksummed with SHA1 hashes. Any kind of corruption can be confirmed by verifying this per object hash against corresponding data. However this can be costly to perform systematically and therefore this check is often not performed at run time when accessing the object database. First, the loose object format is entirely compressed with zlib which already provide a CRC verification of its own when inflating data. Any disk corruption would be caught already in this case. Then, packed objects are also compressed with zlib but only for their actual payload. The object headers and delta base references are not deflated for obvious performance reasons, however this leave them vulnerable to potentially undetected disk corruptions. Object types are often validated against the expected type when they're requested, and deflated size must always match the size recorded in the object header, so those cases are pretty much covered as well. Where corruptions could go unnoticed is in the delta base reference. Of course, in the OBJ_REF_DELTA case, the odds for a SHA1 reference to get corrupted so it actually matches the SHA1 of another object with the same size (the delta header stores the expected size of the base object to apply against) are virtually zero. In the OBJ_OFS_DELTA case, the reference is a pack offset which would have to match the start boundary of a different base object but still with the same size, and although this is relatively much more "probable" than in the OBJ_REF_DELTA case, the probability is also about zero in absolute terms. Still, the possibility exists as demonstrated in t5302 and is certainly greater than a SHA1 collision, especially in the OBJ_OFS_DELTA case which is now the default when repacking. Again, repacking by reusing existing pack data is OK since the per object CRC provided by index v2 guards against any such corruptions. What t5302 failed to test is a full repack in such case. The Solution ------------ As unlikely as this kind of stealth corruption can be in practice, it certainly isn't acceptable to propagate it into a freshly created pack. But, because this is so unlikely, we don't want to pay the run time cost associated with extra validation checks all the time either. Furthermore, consequences of such corruption in anything but repacking should be rather visible, and even if it could be quite unpleasant, it still has far less severe consequences than actively creating bad packs. So the best compromize is to check packed object CRC when unpacking objects, and only during the compression/writing phase of a repack, and only when not streaming the result. The cost of this is minimal (less than 1% CPU time), and visible only with a full repack. Someone with a stats background could provide an objective evaluation of this, but I suspect that it's bad RAM that has more potential for data corruptions at this point, even in those cases where this extra check is not performed. Still, it is best to prevent a known hole for corruption when recreating object data into a new pack. What about the streamed pack case? Well, any client receiving a pack must always consider that pack as untrusty and perform full validation anyway, hence no such stealth corruption could be propagated to remote repositoryes already. It is therefore worthless doing local validation in that case. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b0edbf9b9f..6b18fab3c1 100644 --- a/cache.h +++ b/cache.h @@ -565,6 +565,9 @@ extern int force_object_loose(const unsigned char *sha1, time_t mtime); /* just like read_sha1_file(), but non fatal in presence of bad objects */ extern void *read_object(const unsigned char *sha1, enum object_type *type, unsigned long *size); +/* global flag to enable extra checks when accessing packed objects */ +extern int do_check_packed_object_crc; + extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); extern int move_temp_to_file(const char *tmpfile, const char *filename); -- cgit v1.2.3 From 09ded04b7e1f0096bb2fe356b2f5a298296151dd Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:46 -0400 Subject: make unpack_object_header() non fatal It is possible to have pack corruption in the object header. Currently unpack_object_header() simply die() on them instead of letting the caller deal with that gracefully. So let's have unpack_object_header() return an error instead, and find a better name for unpack_object_header_gently() in that context. All callers of unpack_object_header() are ready for it. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 6b18fab3c1..c440598e27 100644 --- a/cache.h +++ b/cache.h @@ -754,7 +754,7 @@ extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t); extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); -extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); +extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); extern int matches_pack_name(struct packed_git *p, const char *name); -- cgit v1.2.3 From 8d25931d6ff47a7fb06512d767d1d416d9bc7733 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 11:59:03 -0600 Subject: packed_git: convert pack_local flag into a bitfield and add pack_keep pack_keep will be set when a pack file has an associated .keep file. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a1e4982cd4..1a5740f589 100644 --- a/cache.h +++ b/cache.h @@ -671,7 +671,8 @@ extern struct packed_git { int index_version; time_t mtime; int pack_fd; - int pack_local; + unsigned pack_local:1, + pack_keep:1; unsigned char sha1[20]; /* something like ".git/objects/pack/xxxxx.pack" */ char pack_name[FLEX_ARRAY]; /* more */ -- cgit v1.2.3 From 0f4dc14ac4945448f7309964afeb879d20408e07 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sun, 9 Nov 2008 23:59:57 -0600 Subject: sha1_file.c: split has_loose_object() into local and non-local counterparts Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1a5740f589..7595c149ea 100644 --- a/cache.h +++ b/cache.h @@ -565,6 +565,7 @@ extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1, const char **ignore); extern int has_sha1_file(const unsigned char *sha1); +extern int has_loose_object_nonlocal(const unsigned char *sha1); extern int has_pack_file(const unsigned char *sha1); extern int has_pack_index(const unsigned char *sha1); -- cgit v1.2.3 From 14d9c578961ab834bfb0e26481d0212bc0670883 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:17:52 -0500 Subject: define empty tree sha1 as a macro This can potentially be used in a few places, so let's make it available to all parts of the code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index eda7028992..07795d9a81 100644 --- a/cache.h +++ b/cache.h @@ -528,6 +528,12 @@ static inline void hashclr(unsigned char *hash) } extern int is_empty_blob_sha1(const unsigned char *sha1); +#define EMPTY_TREE_SHA1_HEX \ + "4b825dc642cb6eb9a060e54bf8d69288fbee4904" +#define EMPTY_TREE_SHA1_BIN \ + "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \ + "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04" + int git_mkstemp(char *path, size_t n, const char *template); /* -- cgit v1.2.3 From fa7b3c2f752a10a5dca9989d4a1c4b93ffa7f943 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Nov 2008 11:52:35 -0800 Subject: checkout: Fix "initial checkout" detection Earlier commit 5521883 (checkout: do not lose staged removal, 2008-09-07) tightened the rule to prevent switching branches from losing local changes, so that staged removal of paths can be protected, while attempting to keep a loophole to still allow a special case of switching out of an un-checked-out state. However, the loophole was made a bit too tight, and did not allow switching from one branch (in an un-checked-out state) to check out another branch. The change to builtin-checkout.c in this commit loosens it to allow this, by not insisting the original commit and the new commit to be the same. It also introduces a new function, is_index_unborn (and an associated macro, is_cache_unborn), to check if the repository is truly in an un-checked-out state more reliably, by making sure that $GIT_INDEX_FILE did not exist when populating the in-core index structure. A few places the earlier commit 5521883 added the check for the initial checkout condition are updated to use this function. Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a1e4982cd4..3960931a95 100644 --- a/cache.h +++ b/cache.h @@ -255,6 +255,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define read_cache() read_index(&the_index) #define read_cache_from(path) read_index_from(&the_index, (path)) +#define is_cache_unborn() is_index_unborn(&the_index) #define read_cache_unmerged() read_index_unmerged(&the_index) #define write_cache(newfd, cache, entries) write_index(&the_index, (newfd)) #define discard_cache() discard_index(&the_index) @@ -360,6 +361,7 @@ extern int init_db(const char *template_dir, unsigned int flags); /* Initialize and use the cache information */ extern int read_index(struct index_state *); extern int read_index_from(struct index_state *, const char *path); +extern int is_index_unborn(struct index_state *); extern int read_index_unmerged(struct index_state *); extern int write_index(const struct index_state *, int newfd); extern int discard_index(struct index_state *); -- cgit v1.2.3 From 671c9b7e315db89081cc69f83a8f405e4aca37bc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 13 Nov 2008 16:36:30 -0800 Subject: Add cache preload facility This can do the lstat() storm in parallel, giving potentially much improved performance for cold-cache cases or things like NFS that have weak metadata caching. Just use "read_cache_preload()" instead of "read_cache()" to force an optimistic preload of the index stat data. The function takes a pathspec as its argument, allowing us to preload only the relevant portion of the index. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3b5f0c4c00..685a8666b6 100644 --- a/cache.h +++ b/cache.h @@ -262,6 +262,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define read_cache() read_index(&the_index) #define read_cache_from(path) read_index_from(&the_index, (path)) +#define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec)) #define is_cache_unborn() is_index_unborn(&the_index) #define read_cache_unmerged() read_index_unmerged(&the_index) #define write_cache(newfd, cache, entries) write_index(&the_index, (newfd)) @@ -368,6 +369,7 @@ extern int init_db(const char *template_dir, unsigned int flags); /* Initialize and use the cache information */ extern int read_index(struct index_state *); +extern int read_index_preload(struct index_state *, const char **pathspec); extern int read_index_from(struct index_state *, const char *path); extern int is_index_unborn(struct index_state *); extern int read_index_unmerged(struct index_state *); @@ -458,6 +460,7 @@ extern size_t packed_git_limit; extern size_t delta_base_cache_limit; extern int auto_crlf; extern int fsync_object_files; +extern int core_preload_index; enum safe_crlf { SAFE_CRLF_FALSE = 0, -- cgit v1.2.3 From 388b2acd6e649145d4368a10cf4df5f5bbbac2c2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 28 Nov 2008 19:55:25 -0800 Subject: git add --intent-to-add: fix removal of cached emptiness This uses the extended index flag mechanism introduced earlier to mark the entries added to the index via "git add -N" with CE_INTENT_TO_ADD. The logic to detect an "intent to add" entry for the purpose of allowing "git rm --cached $path" is tightened to check not just for a staged empty blob, but with the CE_INTENT_TO_ADD bit. This protects an empty blob that was explicitly added and then modified in the work tree from being dropped with this sequence: $ >empty $ git add empty $ echo "non empty" >empty $ git rm --cached empty Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ef2e7f93f7..f15b3fc906 100644 --- a/cache.h +++ b/cache.h @@ -176,10 +176,11 @@ struct cache_entry { /* * Extended on-disk flags */ +#define CE_INTENT_TO_ADD 0x20000000 /* CE_EXTENDED2 is for future extension */ #define CE_EXTENDED2 0x80000000 -#define CE_EXTENDED_FLAGS (0) +#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD) /* * Safeguard to avoid saving wrong flags: -- cgit v1.2.3 From c74faea19e39ca933492f697596310397175c329 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 9 Dec 2008 14:26:52 -0500 Subject: make sure packs to be replaced are closed beforehand Especially on Windows where an opened file cannot be replaced, make sure pack-objects always close packs it is about to replace. Even on non Windows systems, this could save potential bad results if ever objects were to be read from the new pack file using offset from the old index. This should fix t5303 on Windows. Signed-off-by: Nicolas Pitre Tested-by: Johannes Sixt (MinGW) Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index d1cd6aaf73..42f2f2754b 100644 --- a/cache.h +++ b/cache.h @@ -738,6 +738,7 @@ extern int open_pack_index(struct packed_git *); extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *); extern void close_pack_windows(struct packed_git *); extern void unuse_pack(struct pack_window **); +extern void free_pack_by_name(const char *); extern struct packed_git *add_packed_git(const char *, int, int); extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t); extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t); -- cgit v1.2.3 From 879ef2485d6ced20845ca626ecb45a9b65aa3a70 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 20 Dec 2008 13:05:14 +0100 Subject: Introduce commit notes Commit notes are blobs which are shown together with the commit message. These blobs are taken from the notes ref, which you can configure by the config variable core.notesRef, which in turn can be overridden by the environment variable GIT_NOTES_REF. The notes ref is a branch which contains "files" whose names are the names of the corresponding commits (i.e. the SHA-1). The rationale for putting this information into a ref is this: we want to be able to fetch and possibly union-merge the notes, maybe even look at the date when a note was introduced, and we want to store them efficiently together with the other objects. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 231c06d772..6158d5546b 100644 --- a/cache.h +++ b/cache.h @@ -367,6 +367,8 @@ static inline enum object_type object_type(unsigned int mode) #define GITATTRIBUTES_FILE ".gitattributes" #define INFOATTRIBUTES_FILE "info/attributes" #define ATTRIBUTE_MACRO_PREFIX "[attr]" +#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" +#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" extern int is_bare_repository_cfg; extern int is_bare_repository(void); @@ -538,6 +540,7 @@ enum rebase_setup_type { extern enum branch_track git_branch_track; extern enum rebase_setup_type autorebase; +extern char *notes_ref_name; #define GIT_REPO_VERSION 0 extern int repository_format_version; -- cgit v1.2.3 From 39c68542fc8d8477f2080c99efedb9dce975abc6 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 7 Jan 2009 19:54:47 -0800 Subject: Wrap inflate and other zlib routines for better error reporting R. Tyler Ballance reported a mysterious transient repository corruption; after much digging, it turns out that we were not catching and reporting memory allocation errors from some calls we make to zlib. This one _just_ wraps things; it doesn't do the "retry on low memory error" part, at least not yet. It is an independent issue from the reporting. Some of the errors are expected and passed back to the caller, but we die when zlib reports it failed to allocate memory for now. Signed-off-by: Junio C Hamano --- cache.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 42f2f2754b..17ce4441b6 100644 --- a/cache.h +++ b/cache.h @@ -12,6 +12,10 @@ #define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11) #endif +void git_inflate_init(z_streamp strm); +void git_inflate_end(z_streamp strm); +int git_inflate(z_streamp strm, int flush); + #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) #define DTYPE(de) ((de)->d_type) #else -- cgit v1.2.3 From c2c5b27051babdc2a7503d5b9d695b4c7b45c14b Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 12 Jan 2009 18:42:24 +0100 Subject: sha1_file: make "read_object" static This function is only used from "sha1_file.c". And as we want to add a "replace_object" hook in "read_sha1_file", we must not let people bypass the hook using something other than "read_sha1_file". Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- cache.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 231c06d772..8e1af2669b 100644 --- a/cache.h +++ b/cache.h @@ -631,9 +631,6 @@ extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsig extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); extern int force_object_loose(const unsigned char *sha1, time_t mtime); -/* just like read_sha1_file(), but non fatal in presence of bad objects */ -extern void *read_object(const unsigned char *sha1, enum object_type *type, unsigned long *size); - /* global flag to enable extra checks when accessing packed objects */ extern int do_check_packed_object_crc; -- cgit v1.2.3 From 0b50922abffb82c473182b03eb5bb47a978cceac Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Wed, 14 Jan 2009 15:54:35 +0100 Subject: remove pathspec_match, use match_pathspec instead Both versions have the same functionality. This removes any redundancy. This also adds makes two extensions to match_pathspec: - If pathspec is NULL, return 1. This reflects the behavior of git commands, for which no paths usually means "match all paths". - If seen is NULL, do not use it. Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 231c06d772..c60259d492 100644 --- a/cache.h +++ b/cache.h @@ -936,7 +936,6 @@ extern int ws_fix_copy(char *, const char *, int, unsigned, int *); extern int ws_blank_line(const char *line, int len, unsigned ws_rule); /* ls-files */ -int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen); int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset); void overlay_tree_on_cache(const char *tree_name, const char *prefix); -- cgit v1.2.3 From ae5a6c3684c378bc32c1f6ecc0e6dc45300c14c1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 17 Jan 2009 17:09:53 +0100 Subject: checkout: implement "@{-N}" shortcut name for N-th last branch Implement a shortcut @{-N} for the N-th last branch checked out, that works by parsing the reflog for the message added by previous git-checkout invocations. We expand the @{-N} to the branch name, so that you end up on an attached HEAD on that branch. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8e1af2669b..0dd9168be5 100644 --- a/cache.h +++ b/cache.h @@ -663,6 +663,7 @@ extern int read_ref(const char *filename, unsigned char *sha1); extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *); extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref); extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref); +extern int interpret_nth_last_branch(const char *str, struct strbuf *); extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules); extern const char *ref_rev_parse_rules[]; -- cgit v1.2.3 From 09c9306658f793f2cad1ed7856b55a7c4e758703 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:51 +0100 Subject: lstat_cache(): introduce has_symlink_or_noent_leading_path() function In some cases, especially inside the unpack-trees.c file, and inside the verify_absent() function, we can avoid some unnecessary calls to lstat(), if the lstat_cache() function can also be told to keep track of non-existing directories. So we update the lstat_cache() function to handle this new fact, introduce a new wrapper function, and the result is that we save lots of lstat() calls for a removed directory which previously contained lots of files, when we call this new wrapper of lstat_cache() instead of the old one. We do similar changes inside the unlink_entry() function, since if we can already say that the leading directory component of a pathname does not exist, it is not necessary to try to remove a pathname below it! Thanks to Junio C Hamano, Linus Torvalds and Rene Scharfe for valuable comments to this patch! Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 231c06d772..11181aa007 100644 --- a/cache.h +++ b/cache.h @@ -720,6 +720,7 @@ struct checkout { extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); extern int has_symlink_leading_path(int len, const char *name); +extern int has_symlink_or_noent_leading_path(int len, const char *name); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From bad4a54fa6fe8a9bbdfb5c3e413268eefde69b75 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:52 +0100 Subject: lstat_cache(): introduce has_dirs_only_path() function The create_directories() function in entry.c currently calls stat() or lstat() for each path component of the pathname 'path' each and every time. For the 'git checkout' command, this function is called on each file for which we must do an update (ce->ce_flags & CE_UPDATE), so we get lots and lots of calls. To fix this, we make a new wrapper to the lstat_cache() function, and call the wrapper function instead of the calls to the stat() or the lstat() functions. Since the paths given to the create_directories() function, is sorted alphabetically, the new wrapper would be very cache effective in this situation. To support it we must update the lstat_cache() function to be able to say that "please test the complete length of 'name'", and also to give it the length of a prefix, where the cache should use the stat() function instead of the lstat() function to test each path component. Thanks to Junio C Hamano, Linus Torvalds and Rene Scharfe for valuable comments to this patch! Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 11181aa007..7c8c8e4842 100644 --- a/cache.h +++ b/cache.h @@ -721,6 +721,7 @@ struct checkout { extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); extern int has_symlink_leading_path(int len, const char *name); extern int has_symlink_or_noent_leading_path(int len, const char *name); +extern int has_dirs_only_path(int len, const char *name, int prefix_len); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From aeabab5c712d5acae4a2836272d641acbb87b893 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:53 +0100 Subject: lstat_cache(): introduce invalidate_lstat_cache() function In some cases it could maybe be necessary to say to the cache that "Hey, I deleted/changed the type of this pathname and if you currently have it inside your cache, you should deleted it". This patch introduce a function which support this. Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7c8c8e4842..f4452a89a7 100644 --- a/cache.h +++ b/cache.h @@ -722,6 +722,7 @@ extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, extern int has_symlink_leading_path(int len, const char *name); extern int has_symlink_or_noent_leading_path(int len, const char *name); extern int has_dirs_only_path(int len, const char *name, int prefix_len); +extern void invalidate_lstat_cache(int len, const char *name); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From bda6eb0da9b4e4e763b531c83cab9fd9f85934ff Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:54 +0100 Subject: lstat_cache(): introduce clear_lstat_cache() function If you want to completely clear the contents of the lstat_cache(), then call this new function. Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f4452a89a7..468daf6a43 100644 --- a/cache.h +++ b/cache.h @@ -723,6 +723,7 @@ extern int has_symlink_leading_path(int len, const char *name); extern int has_symlink_or_noent_leading_path(int len, const char *name); extern int has_dirs_only_path(int len, const char *name, int prefix_len); extern void invalidate_lstat_cache(int len, const char *name); +extern void clear_lstat_cache(void); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From f3cad0ad82e24966bf7bcc8a47670c54c30e4b18 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 7 Feb 2009 16:08:28 +0100 Subject: Move sanitary_path_copy() to path.c and rename it to normalize_path_copy() This function and normalize_absolute_path() do almost the same thing. The former already works on Windows, but the latter crashes. In subsequent changes we will remove normalize_absolute_path(). Here we make the replacement function reusable. On the way we rename it to reflect that it does some path normalization. Apart from that this is only moving around code. Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 42f2f2754b..65897e7b2c 100644 --- a/cache.h +++ b/cache.h @@ -548,6 +548,7 @@ const char *make_absolute_path(const char *path); const char *make_nonrelative_path(const char *path); const char *make_relative_path(const char *abs, const char *base); int normalize_absolute_path(char *buf, const char *path); +int normalize_path_copy(char *dst, const char *src); int longest_ancestor_length(const char *path, const char *prefix_list); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ -- cgit v1.2.3 From f2a782b8ba189b5ed51d18aa3eb93a670c220018 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 7 Feb 2009 16:08:31 +0100 Subject: Remove unused normalize_absolute_path() This function is now superseded by normalize_path_copy(). Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 65897e7b2c..39f0d6fea4 100644 --- a/cache.h +++ b/cache.h @@ -547,7 +547,6 @@ static inline int is_absolute_path(const char *path) const char *make_absolute_path(const char *path); const char *make_nonrelative_path(const char *path); const char *make_relative_path(const char *abs, const char *base); -int normalize_absolute_path(char *buf, const char *path); int normalize_path_copy(char *dst, const char *src); int longest_ancestor_length(const char *path, const char *prefix_list); -- cgit v1.2.3 From d551a488169aeb2ac09dba781f2ffbecf3425996 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Sun, 8 Feb 2009 15:34:27 +0100 Subject: Add mailmap.file as configurational option for mailmap location This allows us to augment the repo mailmap file, and to use mailmap files elsewhere than the repository root. Meaning that the entries in mailmap.file will override the entries in "./.mailmap", should they match. Signed-off-by: Marius Storm-Olsen Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 45e713e928..e88bcca96d 100644 --- a/cache.h +++ b/cache.h @@ -867,6 +867,7 @@ extern int user_ident_explicitly_given; extern const char *git_commit_encoding; extern const char *git_log_output_encoding; +extern const char *git_mailmap_file; /* IO helper functions */ extern void maybe_flush_or_die(FILE *, const char *); -- cgit v1.2.3 From 571998921d8fd4ee674545406aabb86987921252 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Mon, 9 Feb 2009 21:54:06 +0100 Subject: lstat_cache(): swap func(length, string) into func(string, length) Swap function argument pair (length, string) into (string, length) to conform with the commonly used order inside the GIT source code. Also, add a note about this fact into the coding guidelines. Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2d889deb26..80eeeb7db8 100644 --- a/cache.h +++ b/cache.h @@ -724,10 +724,10 @@ struct checkout { }; extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); -extern int has_symlink_leading_path(int len, const char *name); -extern int has_symlink_or_noent_leading_path(int len, const char *name); -extern int has_dirs_only_path(int len, const char *name, int prefix_len); -extern void invalidate_lstat_cache(int len, const char *name); +extern int has_symlink_leading_path(const char *name, int len); +extern int has_symlink_or_noent_leading_path(const char *name, int len); +extern int has_dirs_only_path(const char *name, int len, int prefix_len); +extern void invalidate_lstat_cache(const char *name, int len); extern void clear_lstat_cache(void); extern struct alternate_object_database { -- cgit v1.2.3 From 7847892716a3c9a7b8facc076fc056ac425bcfe6 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Mon, 9 Feb 2009 21:54:07 +0100 Subject: unlink_entry(): introduce schedule_dir_for_removal() Currently inside unlink_entry() if we get a successful removal of one file with unlink(), we try to remove the leading directories each and every time. So if one directory containing 200 files is moved to an other location we get 199 failed calls to rmdir() and 1 successful call. To fix this and avoid some unnecessary calls to rmdir(), we schedule each directory for removal and wait much longer before we do the real call to rmdir(). Since the unlink_entry() function is called with alphabetically sorted names, this new function end up being very effective to avoid unnecessary calls to rmdir(). In some cases over 95% of all calls to rmdir() is removed with this patch. Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 80eeeb7db8..1bf2d4bde6 100644 --- a/cache.h +++ b/cache.h @@ -729,6 +729,8 @@ extern int has_symlink_or_noent_leading_path(const char *name, int len); extern int has_dirs_only_path(const char *name, int len, int prefix_len); extern void invalidate_lstat_cache(const char *name, int len); extern void clear_lstat_cache(void); +extern void schedule_dir_for_removal(const char *name, int len); +extern void remove_scheduled_dirs(void); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.3 From 3d20c636af05c44a6ff4df9309c2bca108ee149b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 10 Feb 2009 13:36:12 -0800 Subject: Clear the delta base cache during fast-import checkpoint Otherwise we may reuse the same memory address for a totally different "struct packed_git", and a previously cached object from the prior occupant might be returned when trying to unpack an object from the new pack. Found-by: Daniel Barkalow Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 42f2f2754b..099a32e5fc 100644 --- a/cache.h +++ b/cache.h @@ -739,6 +739,7 @@ extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t extern void close_pack_windows(struct packed_git *); extern void unuse_pack(struct pack_window **); extern void free_pack_by_name(const char *); +extern void clear_delta_base_cache(void); extern struct packed_git *add_packed_git(const char *, int, int); extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t); extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t); -- cgit v1.2.3 From 954cfb5cfd17d57b9b31b19b73efe73199407e07 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 10 Feb 2009 21:31:33 -0800 Subject: Revert "Merge branch 'js/notes'" This reverts commit 7b75b331f6744fbf953fe8913703378ef86a2189, reversing changes made to 5d680a67d7909c89af96eba4a2d77abed606292b. --- cache.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7f1a6e8bd0..a7f435ddef 100644 --- a/cache.h +++ b/cache.h @@ -371,8 +371,6 @@ static inline enum object_type object_type(unsigned int mode) #define GITATTRIBUTES_FILE ".gitattributes" #define INFOATTRIBUTES_FILE "info/attributes" #define ATTRIBUTE_MACRO_PREFIX "[attr]" -#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" -#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" extern int is_bare_repository_cfg; extern int is_bare_repository(void); @@ -544,7 +542,6 @@ enum rebase_setup_type { extern enum branch_track git_branch_track; extern enum rebase_setup_type autorebase; -extern char *notes_ref_name; #define GIT_REPO_VERSION 0 extern int repository_format_version; -- cgit v1.2.3 From 36419c8ee41cecadf67dfeab2808ff2e5025ca52 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Wed, 18 Feb 2009 23:18:03 +0100 Subject: check_updates(): effective removal of cache entries marked CE_REMOVE Below is oprofile output from GIT command 'git chekcout -q my-v2.6.25' (move from tag v2.6.27 to tag v2.6.25 of the Linux kernel): CPU: Core 2, speed 1999.95 MHz (estimated) Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (Unhalted core cycles) count 20000 Counted INST_RETIRED_ANY_P events (number of instructions retired) with a unit mask of 0x00 (No unit mask) count 20000 CPU_CLK_UNHALT...|INST_RETIRED:2...| samples| %| samples| %| ------------------------------------ 409247 100.000 342878 100.000 git CPU_CLK_UNHALT...|INST_RETIRED:2...| samples| %| samples| %| ------------------------------------ 260476 63.6476 257843 75.1996 libz.so.1.2.3 100876 24.6492 64378 18.7758 kernel-2.6.28.4_2.vmlinux 30850 7.5382 7874 2.2964 libc-2.9.so 14775 3.6103 8390 2.4469 git 2020 0.4936 4325 1.2614 libcrypto.so.0.9.8 191 0.0467 32 0.0093 libpthread-2.9.so 58 0.0142 36 0.0105 ld-2.9.so 1 2.4e-04 0 0 libldap-2.3.so.0.2.31 Detail list of the top 20 function entries (libz counted in one blob): CPU_CLK_UNHALTED INST_RETIRED_ANY_P samples % samples % image name symbol name 260476 63.6862 257843 75.2725 libz.so.1.2.3 /lib/libz.so.1.2.3 16587 4.0555 3636 1.0615 libc-2.9.so memcpy 7710 1.8851 277 0.0809 libc-2.9.so memmove 3679 0.8995 1108 0.3235 kernel-2.6.28.4_2.vmlinux d_validate 3546 0.8670 2607 0.7611 kernel-2.6.28.4_2.vmlinux __getblk 3174 0.7760 1813 0.5293 libc-2.9.so _int_malloc 2396 0.5858 3681 1.0746 kernel-2.6.28.4_2.vmlinux copy_to_user 2270 0.5550 2528 0.7380 kernel-2.6.28.4_2.vmlinux __link_path_walk 2205 0.5391 1797 0.5246 kernel-2.6.28.4_2.vmlinux ext4_mark_iloc_dirty 2103 0.5142 1203 0.3512 kernel-2.6.28.4_2.vmlinux find_first_zero_bit 2077 0.5078 997 0.2911 kernel-2.6.28.4_2.vmlinux do_get_write_access 2070 0.5061 514 0.1501 git cache_name_compare 2043 0.4995 1501 0.4382 kernel-2.6.28.4_2.vmlinux rcu_irq_exit 2022 0.4944 1732 0.5056 kernel-2.6.28.4_2.vmlinux __ext4_get_inode_loc 2020 0.4939 4325 1.2626 libcrypto.so.0.9.8 /usr/lib/libcrypto.so.0.9.8 1965 0.4804 1384 0.4040 git patch_delta 1708 0.4176 984 0.2873 kernel-2.6.28.4_2.vmlinux rcu_sched_grace_period 1682 0.4112 727 0.2122 kernel-2.6.28.4_2.vmlinux sysfs_slab_alias 1659 0.4056 290 0.0847 git find_pack_entry_one 1480 0.3619 1307 0.3816 kernel-2.6.28.4_2.vmlinux ext4_writepage_trans_blocks Notice the memmove line, where the CPU did 7710 / 277 = 27.8 cycles per instruction, and compared to the total cycles spent inside the source code of GIT for this command, all the memmove() calls translates to (7710 * 100) / 14775 = 52.2% of this. Retesting with a GIT program compiled for gcov usage, I found out that the memmove() calls came from remove_index_entry_at() in read-cache.c, where we have: memmove(istate->cache + pos, istate->cache + pos + 1, (istate->cache_nr - pos) * sizeof(struct cache_entry *)); remove_index_entry_at() is called 4902 times from check_updates() in unpack-trees.c, and each time called we move each cache_entry pointers (from the removed one) one step to the left. Since we have 28828 entries in the cache this time, and if we on average move half of them each time, we in total move approximately 4902 * 0.5 * 28828 * 4 = 282 629 712 bytes, or twice this amount if each pointer is 8 bytes (64 bit). OK, is seems that the function check_updates() is called 28 times, so the estimated guess above had been more correct if check_updates() had been called only once, but the point is: we get lots of bytes moved. To fix this, and use an O(N) algorithm instead, where N is the number of cache_entries, we delete/remove all entries in one loop through all entries. From a retest, the new remove_marked_cache_entries() from the patch below, ended up with the following output line from oprofile: 46 0.0105 15 0.0041 git remove_marked_cache_entries If we can trust the numbers from oprofile in this case, we saved approximately ((7710 - 46) * 20000) / (2 * 1000 * 1000 * 1000) = 0.077 seconds CPU time with this fix for this particular test. And notice that now the CPU did only 46 / 15 = 3.1 cycles/instruction. Signed-off-by: Kjetil Barvik Acked-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1bf2d4bde6..770d8bc950 100644 --- a/cache.h +++ b/cache.h @@ -445,6 +445,7 @@ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int opt extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name); extern int remove_index_entry_at(struct index_state *, int pos); +extern void remove_marked_cache_entries(struct index_state *istate); extern int remove_file_from_index(struct index_state *, const char *path); #define ADD_CACHE_VERBOSE 1 #define ADD_CACHE_PRETEND 2 -- cgit v1.2.3 From fba2f38a2c2cda458e490c18e0afbb12cbd37969 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Thu, 19 Feb 2009 21:08:29 +0100 Subject: make USE_NSEC work as expected Since the filesystem ext4 is now defined as stable in Linux v2.6.28, and ext4 supports nanonsecond resolution timestamps natively, it is time to make USE_NSEC work as expected. This will make racy git situations less likely to happen. For 'git checkout' this means it will be less likely that we have to open, read the contents of the file into RAM, and check if file is really modified or not. The result sould be a litle less used CPU time, less pagefaults and a litle faster program, at least for 'git checkout'. Since the number of possible racy git situations would increase when disks gets faster, this patch would be more and more helpfull as times go by. For a fast Solid State Disk, this patch should be helpfull. Note that, when file operations starts to take less than 1 nanosecond, one would again start to get more racy git situations. For more info on racy git, see Documentation/technical/racy-git.txt For more info on ext4, see http://kernelnewbies.org/Ext4 Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 770d8bc950..2badbfedc4 100644 --- a/cache.h +++ b/cache.h @@ -140,8 +140,8 @@ struct ondisk_cache_entry_extended { }; struct cache_entry { - unsigned int ce_ctime; - unsigned int ce_mtime; + struct cache_time ce_ctime; + struct cache_time ce_mtime; unsigned int ce_dev; unsigned int ce_ino; unsigned int ce_mode; @@ -282,7 +282,7 @@ struct index_state { struct cache_entry **cache; unsigned int cache_nr, cache_alloc, cache_changed; struct cache_tree *cache_tree; - time_t timestamp; + struct cache_time timestamp; void *alloc; unsigned name_hash_initialized : 1, initialized : 1; -- cgit v1.2.3 From 4fcc86b07db26da17f17af0fd777cab78fcaaf4c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 19 Feb 2009 20:10:49 +0100 Subject: Introduce the function strip_path_suffix() The function strip_path_suffix() will try to strip a given suffix from a given path. The suffix must start at a directory boundary (i.e. "core" is not a path suffix of "libexec/git-core", but "git-core" is). Arbitrary runs of directory separators ("slashes") are assumed identical. Example: strip_path_suffix("C:\\msysgit/\\libexec\\git-core", "libexec///git-core", &prefix) will set prefix to "C:\\msysgit" and return 0. Signed-off-by: Johannes Schindelin Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 37dfb1c18f..21bbf9b119 100644 --- a/cache.h +++ b/cache.h @@ -626,6 +626,7 @@ const char *make_nonrelative_path(const char *path); const char *make_relative_path(const char *abs, const char *base); int normalize_path_copy(char *dst, const char *src); int longest_ancestor_length(const char *path, const char *prefix_list); +char *strip_path_suffix(const char *path, const char *suffix); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); -- cgit v1.2.3 From e43a6fd3e94888d76779ad79fb568ed180e5fcdf Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Thu, 19 Feb 2009 13:54:18 +0100 Subject: More friendly message when locking the index fails. Just saying that index.lock exists doesn't tell the user _what_ to do to fix the problem. We should give an indication that it's normally safe to delete index.lock after making sure git isn't running here. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3a33b1e82b..0e2f219b2b 100644 --- a/cache.h +++ b/cache.h @@ -484,6 +484,7 @@ struct lock_file { }; #define LOCK_DIE_ON_ERROR 1 #define LOCK_NODEREF 2 +extern NORETURN void unable_to_lock_index_die(const char *path, int err); extern int hold_lock_file_for_update(struct lock_file *, const char *path, int); extern int hold_lock_file_for_append(struct lock_file *, const char *path, int); extern int commit_lock_file(struct lock_file *); -- cgit v1.2.3 From 7dff9b30ea0603fe265f9f7da055fc34f5d57d2f Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 20 Feb 2009 14:15:22 -0800 Subject: Support 'raw' date format Talking about --date, one thing I wanted for the 1234567890 date was to get things in the raw format. Sure, you get them with --pretty=raw, but it felt a bit sad that you couldn't just ask for the date in raw format. So here's a throw-away patch (meaning: I won't be re-sending it, because I really don't think it's a big deal) to add "--date=raw". It just prints out the internal raw git format - seconds since epoch plus timezone (put another way: 'date +"%s %z"' format) Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 21a63103d5..189151de25 100644 --- a/cache.h +++ b/cache.h @@ -696,7 +696,8 @@ enum date_mode { DATE_SHORT, DATE_LOCAL, DATE_ISO8601, - DATE_RFC2822 + DATE_RFC2822, + DATE_RAW }; const char *show_date(unsigned long time, int timezone, enum date_mode mode); -- cgit v1.2.3 From e1afca4fd3e7cb4000874e991277f10119de4ad2 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Mon, 23 Feb 2009 19:02:57 +0100 Subject: write_index(): update index_state->timestamp after flushing to disk Since this timestamp is used to check for racy-clean files, it is important to keep it uptodate. For the 'git checkout' command without the '-q' option, this make a huge difference. Before, each and every file which was updated, was racy-clean after the call to unpack_trees() and write_index() but before the GIT process ended. And because of the call to show_local_changes() in builtin-checkout.c, we ended up reading those files back into memory, doing a SHA1 to check if the files was really different from the index. And, of course, no file was different. With this fix, 'git checkout' without the '-q' option should now be almost as fast as with the '-q' option, but not quite, as we still do some few lstat(2) calls more without the '-q' option. Below is some average numbers for 10 checkout's to v2.6.27 and 10 to v2.6.25 of the Linux kernel, to show the difference: before (git version 1.6.2.rc1.256.g58a87): 7.860 user 2.427 sys 19.465 real 52.8% CPU faults: 0 major 95331 minor after: 6.184 user 2.160 sys 17.619 real 47.4% CPU faults: 0 major 38994 minor Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2badbfedc4..2f4f0549f9 100644 --- a/cache.h +++ b/cache.h @@ -430,7 +430,7 @@ extern int read_index_preload(struct index_state *, const char **pathspec); extern int read_index_from(struct index_state *, const char *path); extern int is_index_unborn(struct index_state *); extern int read_index_unmerged(struct index_state *); -extern int write_index(const struct index_state *, int newfd); +extern int write_index(struct index_state *, int newfd); extern int discard_index(struct index_state *); extern int unmerged_index(const struct index_state *); extern int verify_path(const char *path); -- cgit v1.2.3 From 5483f79998c5a9705d453a713d11fb7591329ed4 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 25 Feb 2009 03:32:10 -0500 Subject: refactor find_ref_by_name() to accept const list Since it doesn't actually touch its argument, this makes sense. However, we still want to return a non-const version (which requires a cast) so that this: struct ref *a, *b; a = find_ref_by_name(b); works. Unfortunately, you can also silently strip the const from a variable: struct ref *a; const struct ref *b; a = find_ref_by_name(b); This is a classic C const problem because there is no way to say "return the type with the same constness that was passed to us"; we provide the same semantics as standard library functions like strchr. Signed-off-by: Jeff King Signed-off-by: Jay Soffian Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 189151de25..609380d935 100644 --- a/cache.h +++ b/cache.h @@ -801,7 +801,7 @@ struct ref { #define REF_HEADS (1u << 1) #define REF_TAGS (1u << 2) -extern struct ref *find_ref_by_name(struct ref *list, const char *name); +extern struct ref *find_ref_by_name(const struct ref *list, const char *name); #define CONNECT_VERBOSE (1u << 0) extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags); -- cgit v1.2.3 From cd673c1f17228d272c4b7f81fbb28bc31cf0cac6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Feb 2009 23:15:53 -0800 Subject: has_sha1_pack(): refactor "pretend these packs do not exist" interface Most of the callers of this function except only one pass NULL to its last parameter, ignore_packed. Introduce has_sha1_kept_pack() function that has the function signature and the semantics of this function, and convert the sole caller that does not pass NULL to call this new function. All other callers and has_sha1_pack() lose the ignore_packed parameter. Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 42f2f2754b..c1539bf89a 100644 --- a/cache.h +++ b/cache.h @@ -565,7 +565,8 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l extern int move_temp_to_file(const char *tmpfile, const char *filename); -extern int has_sha1_pack(const unsigned char *sha1, const char **ignore); +extern int has_sha1_pack(const unsigned char *sha1); +extern int has_sha1_kept_pack(const unsigned char *sha1, const char **ignore); extern int has_sha1_file(const unsigned char *sha1); extern int has_loose_object_nonlocal(const unsigned char *sha1); -- cgit v1.2.3 From b8431b033f9e60f87a75b864612873307a3e5966 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Feb 2009 23:30:38 -0800 Subject: has_sha1_kept_pack(): take "struct rev_info" Its "ignore_packed" parameter always comes from struct rev_info. This patch makes the function take a pointer to the surrounding structure, so that the refactoring in the next patch becomes easier to review. There is an unfortunate header file dependency and the easiest workaround is to temporarily move the function declaration from cache.h to revision.h; this will be moved back to cache.h once the function loses this "ignore_packed" parameter altogether in the later part of the series. Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index c1539bf89a..8e43f382e8 100644 --- a/cache.h +++ b/cache.h @@ -566,7 +566,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1); -extern int has_sha1_kept_pack(const unsigned char *sha1, const char **ignore); extern int has_sha1_file(const unsigned char *sha1); extern int has_loose_object_nonlocal(const unsigned char *sha1); -- cgit v1.2.3 From 386cb77210cdb09cd808698d21d0e796cd77f26f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Feb 2009 23:43:37 -0800 Subject: Consolidate ignore_packed logic more This refactors three loops that check if a given packfile is on the ignore_packed list into a function is_kept_pack(). The function returns false for a pack on the list, and true for a pack not on the list, because this list is solely used by "git repack" to pass list of packfiles that do not have corresponding .keep files, i.e. a packfile not on the list is "kept". Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 8e43f382e8..23c16d0d99 100644 --- a/cache.h +++ b/cache.h @@ -747,7 +747,6 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); -extern int matches_pack_name(struct packed_git *p, const char *name); /* Dumb servers support */ extern int update_server_info(int); -- cgit v1.2.3 From 69e020ae00ebd3f7ae3c2f35acb139361417ef64 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 28 Feb 2009 00:37:19 -0800 Subject: is_kept_pack(): final clean-up Now is_kept_pack() is just a member lookup into a structure, we can write it as such. Also rewrite the sole caller of has_sha1_kept_pack() to switch on the criteria the callee uses (namely, revs->kept_pack_only) between calling has_sha1_kept_pack() and has_sha1_pack(), so that these two callees do not have to take a pointer to struct rev_info as an argument. This removes the header file dependency issue temporarily introduced by the earlier commit, so we revert changes associated to that as well. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 23c16d0d99..0a3d523d26 100644 --- a/cache.h +++ b/cache.h @@ -566,6 +566,7 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1); +extern int has_sha1_kept_pack(const unsigned char *sha1); extern int has_sha1_file(const unsigned char *sha1); extern int has_loose_object_nonlocal(const unsigned char *sha1); -- cgit v1.2.3 From 521537476fe99b97bfcdf1b8f0c579061af5fd3e Mon Sep 17 00:00:00 2001 From: Finn Arne Gangstad Date: Mon, 16 Mar 2009 16:42:51 +0100 Subject: New config push.default to decide default behavior for push When "git push" is not told what refspecs to push, it pushes all matching branches to the current remote. For some workflows this default is not useful, and surprises new users. Some have even found that this default behaviour is too easy to trigger by accident with unwanted consequences. Introduce a new configuration variable "push.default" that decides what action git push should take if no refspecs are given or implied by the command line arguments or the current remote configuration. Possible values are: 'nothing' : Push nothing; 'matching' : Current default behaviour, push all branches that already exist in the current remote; 'tracking' : Push the current branch to whatever it is tracking; 'current' : Push the current branch to a branch of the same name, i.e. HEAD. Signed-off-by: Finn Arne Gangstad Signed-off-by: Junio C Hamano --- cache.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 189151de25..df4f117ac6 100644 --- a/cache.h +++ b/cache.h @@ -541,8 +541,17 @@ enum rebase_setup_type { AUTOREBASE_ALWAYS, }; +enum push_default_type { + PUSH_DEFAULT_UNSPECIFIED = -1, + PUSH_DEFAULT_NOTHING = 0, + PUSH_DEFAULT_MATCHING, + PUSH_DEFAULT_TRACKING, + PUSH_DEFAULT_CURRENT, +}; + extern enum branch_track git_branch_track; extern enum rebase_setup_type autorebase; +extern enum push_default_type push_default; #define GIT_REPO_VERSION 0 extern int repository_format_version; -- cgit v1.2.3 From 4d6acb70411cd4fe69610cf1b22f186fa01614f7 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 19 Mar 2009 22:47:54 -0500 Subject: Remove --kept-pack-only option and associated infrastructure This option to pack-objects/rev-list was created to improve the -A and -a options of repack. It was found to be lacking in that it did not provide the ability to differentiate between local and non-local kept packs, and found to be unnecessary since objects residing in local kept packs can be filtered out by the --honor-pack-keep option. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0a3d523d26..23c16d0d99 100644 --- a/cache.h +++ b/cache.h @@ -566,7 +566,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1); -extern int has_sha1_kept_pack(const unsigned char *sha1); extern int has_sha1_file(const unsigned char *sha1); extern int has_loose_object_nonlocal(const unsigned char *sha1); -- cgit v1.2.3 From 431b1969fcde69959a23355fba6894fb69c8fa0c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Mar 2009 12:51:34 -0700 Subject: Rename interpret/substitute nth_last_branch functions These allow you to say "git checkout @{-2}" to switch to the branch two "branch switching" ago by pretending as if you typed the name of that branch. As it is likely that we will be introducing more short-hands to write the name of a branch without writing it explicitly, rename the functions from "nth_last_branch" to more generic "branch_name", to prepare for different semantics. Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 39789ee94a..d28fd74880 100644 --- a/cache.h +++ b/cache.h @@ -671,7 +671,7 @@ extern int read_ref(const char *filename, unsigned char *sha1); extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *); extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref); extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref); -extern int interpret_nth_last_branch(const char *str, struct strbuf *); +extern int interpret_branch_name(const char *str, struct strbuf *); extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules); extern const char *ref_rev_parse_rules[]; -- cgit v1.2.3 From 17e61b82887fb71800b0fcd39ffe89ddf4d2492e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Mar 2009 23:21:00 -0700 Subject: set_shared_perm(): sometimes we know what the final mode bits should look like adjust_shared_perm() first obtains the mode bits from lstat(2), expecting to find what the result of applying user's umask is, and then tweaks it as necessary. When the file to be adjusted is created with mkstemp(3), however, the mode thusly obtained does not have anything to do with user's umask, and we would need to start from 0444 in such a case and there is no point running lstat(2) for such a path. This introduces a new API set_shared_perm() to bypass the lstat(2) and instead force setting the mode bits to the desired value directly. adjust_shared_perm() becomes a thin wrapper to the function. Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 189151de25..e283bbe173 100644 --- a/cache.h +++ b/cache.h @@ -613,7 +613,8 @@ enum sharedrepo { PERM_EVERYBODY = 0664, }; int git_config_perm(const char *var, const char *value); -int adjust_shared_perm(const char *path); +int set_shared_perm(const char *path, int mode); +#define adjust_shared_perm(path) set_shared_perm((path), 0) int safe_create_leading_directories(char *path); int safe_create_leading_directories_const(const char *path); char *enter_repo(char *path, int strict); -- cgit v1.2.3 From be66a6c43dcba42c56f66a8706721a76098f8e25 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 25 Apr 2009 11:57:14 +0200 Subject: Add an option not to use link(src, dest) && unlink(src) when that is unreliable It seems that accessing NTFS partitions with ufsd (at least on my EeePC) has an unnerving bug: if you link() a file and unlink() it right away, the target of the link() will have the correct size, but consist of NULs. It seems as if the calls are simply not serialized correctly, as single-stepping through the function move_temp_to_file() works flawlessly. As ufsd is "Commertial software" (sic!), I cannot fix it, and have to work around it in Git. At the same time, it seems that this fixes msysGit issues 222 and 229 to assume that Windows cannot handle link() && unlink(). Signed-off-by: Johannes Schindelin Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ab1294d6fb..ff9e145be0 100644 --- a/cache.h +++ b/cache.h @@ -554,6 +554,8 @@ extern enum branch_track git_branch_track; extern enum rebase_setup_type autorebase; extern enum push_default_type push_default; +extern int unreliable_hardlinks; + #define GIT_REPO_VERSION 0 extern int repository_format_version; extern int check_repository_format(void); -- cgit v1.2.3 From 348df16679cf35b7bba7afea99638e7d81dc3d33 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 28 Apr 2009 00:32:25 +0200 Subject: Rename core.unreliableHardlinks to core.createObject "Unreliable hardlinks" is a misleading description for what is happening. So rename it to something less misleading. Suggested by Linus Torvalds. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ff9e145be0..d0d48b4c88 100644 --- a/cache.h +++ b/cache.h @@ -554,7 +554,12 @@ extern enum branch_track git_branch_track; extern enum rebase_setup_type autorebase; extern enum push_default_type push_default; -extern int unreliable_hardlinks; +enum object_creation_mode { + OBJECT_CREATION_USES_HARDLINKS = 0, + OBJECT_CREATION_USES_RENAMES = 1, +}; + +extern enum object_creation_mode object_creation_mode; #define GIT_REPO_VERSION 0 extern int repository_format_version; -- cgit v1.2.3 From 4b25d091ba53c758fae0096b8c0662371857b9d9 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Fri, 1 May 2009 12:06:36 +0300 Subject: Fix a bunch of pointer declarations (codestyle) Essentially; s/type* /type */ as per the coding guidelines. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index d0d48b4c88..b8503ad91c 100644 --- a/cache.h +++ b/cache.h @@ -846,7 +846,7 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1, extern void pack_report(void); extern int open_pack_index(struct packed_git *); -extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *); +extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *); extern void close_pack_windows(struct packed_git *); extern void unuse_pack(struct pack_window **); extern void free_pack_by_name(const char *); -- cgit v1.2.3 From 003b33a8ad686ee4a0d0b36635bfd6aba940b24a Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 31 May 2009 01:35:52 -0700 Subject: diff: generate pretty filenames in prep_temp_blob() Naturally, prep_temp_blob() did not care about filenames. As a result, GIT_EXTERNAL_DIFF and textconv generated filenames such as ".diff_XXXXXX". This modifies prep_temp_blob() to generate user-friendly filenames when creating temporary files. Diffing "name.ext" now generates "XXXXXX_name.ext". Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b8503ad91c..871c9844e8 100644 --- a/cache.h +++ b/cache.h @@ -614,6 +614,8 @@ extern int is_empty_blob_sha1(const unsigned char *sha1); int git_mkstemp(char *path, size_t n, const char *template); +int git_mkstemps(char *path, size_t n, const char *template, int suffix_len); + /* * NOTE NOTE NOTE!! * -- cgit v1.2.3 From b9fd284657de3ec30922fb17c0baf243ae947fdd Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 9 Jul 2009 13:35:31 -0700 Subject: Export thread-safe version of 'has_symlink_leading_path()' The threaded index preloading will want it, so that it can avoid locking by simply using a per-thread symlink/directory cache. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 871c9844e8..f1e5ede021 100644 --- a/cache.h +++ b/cache.h @@ -744,7 +744,17 @@ struct checkout { }; extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); + +struct cache_def { + char path[PATH_MAX + 1]; + int len; + int flags; + int track_flags; + int prefix_len_stat_func; +}; + extern int has_symlink_leading_path(const char *name, int len); +extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); extern int has_symlink_or_noent_leading_path(const char *name, int len); extern int has_dirs_only_path(const char *name, int len, int prefix_len); extern void invalidate_lstat_cache(const char *name, int len); -- cgit v1.2.3 From bba0fd22ad654460a81c4b35462b600d9432a869 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 18 Jul 2009 17:19:47 -0700 Subject: push: do not give big warning when no preference is configured If the message said "we will be changing the default in the future, so this is to warn people who want to keep the current default what to do", it would have made some sense, but as it stands, the message is merely an unsolicited advertisement for a new feature, which it is not helpful at all. Squelch it. Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f1e5ede021..c72f125bd4 100644 --- a/cache.h +++ b/cache.h @@ -543,7 +543,6 @@ enum rebase_setup_type { }; enum push_default_type { - PUSH_DEFAULT_UNSPECIFIED = -1, PUSH_DEFAULT_NOTHING = 0, PUSH_DEFAULT_MATCHING, PUSH_DEFAULT_TRACKING, -- cgit v1.2.3 From 7f3140cd23f126e578ccaaea8c2cebe36824a7ac Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 23 Jul 2009 17:33:49 +0200 Subject: git repack: keep commits hidden by a graft When you have grafts that pretend that a given commit has different parents than the ones recorded in the commit object, it is dangerous to let 'git repack' remove those hidden parents, as you can easily remove the graft and end up with a broken repository. So let's play it safe and keep those parent objects and everything that is reachable by them, in addition to the grafted parents. As this behavior can only be triggered by git pack-objects, and as that command handles duplicate parents gracefully, we do not bother to cull duplicated parents that may result by using both true and grafted parents. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b8503ad91c..e902008297 100644 --- a/cache.h +++ b/cache.h @@ -561,6 +561,8 @@ enum object_creation_mode { extern enum object_creation_mode object_creation_mode; +extern int grafts_replace_parents; + #define GIT_REPO_VERSION 0 extern int repository_format_version; extern int check_repository_format(void); -- cgit v1.2.3