From: Junio C Hamano Date: Sun, 22 Apr 2007 00:41:40 +0000 (-0700) Subject: Merge branch 'lt/objalloc' X-Git-Tag: v1.5.2-rc0~16 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/42c4b58059fa9af65e90f2c418bb551e30d1d32f?ds=inline;hp=-c Merge branch 'lt/objalloc' * 'lt/objalloc': Clean up object creation to use more common code Use proper object allocators for unknown object nodes too --- 42c4b58059fa9af65e90f2c418bb551e30d1d32f diff --combined cache.h index 05f188558b,4de25cc4b2..89aaf0022d --- a/cache.h +++ b/cache.h @@@ -24,22 -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 @@@ -120,8 -104,6 +120,8 @@@ static inline unsigned int create_ce_mo { 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) @@@ -139,7 -121,7 +139,7 @@@ } #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) @@@ -169,9 -151,6 +169,9 @@@ 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" +#define ATTRIBUTE_MACRO_PREFIX "[attr]" extern int is_bare_repository_cfg; extern int is_bare_repository(void); @@@ -227,7 -206,6 +227,7 @@@ extern int refresh_cache(unsigned int f struct lock_file { struct lock_file *next; + pid_t owner; char on_list; char filename[PATH_MAX]; }; @@@ -239,7 -217,7 +239,7 @@@ extern int commit_locked_index(struct l extern void set_alternate_index_output(const char *); 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; @@@ -398,12 -376,11 +398,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]; @@@ -454,11 -431,11 +454,11 @@@ 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 *); 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 */ @@@ -499,14 -476,11 +499,11 @@@ int decode_85(char *dst, const char *li 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 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 */ @@@ -516,8 -490,8 +513,8 @@@ extern void trace_printf(const char *fo 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); diff --combined tree.c index dbb63fc525,e5bfbceb22..e4a39aa3c3 --- a/tree.c +++ b/tree.c @@@ -127,12 -127,8 +127,8 @@@ int read_tree(struct tree *tree, int st struct tree *lookup_tree(const unsigned char *sha1) { struct object *obj = lookup_object(sha1); - if (!obj) { - struct tree *ret = alloc_tree_node(); - created_object(sha1, &ret->object); - ret->object.type = OBJ_TREE; - return ret; - } + if (!obj) + return create_object(sha1, OBJ_TREE, alloc_tree_node()); if (!obj->type) obj->type = OBJ_TREE; if (obj->type != OBJ_TREE) { @@@ -143,14 -139,6 +139,14 @@@ return (struct tree *) obj; } +/* + * NOTE! Tree refs to external git repositories + * (ie gitlinks) do not count as real references. + * + * You don't have to have those repositories + * available at all, much less have the objects + * accessible from the current repository. + */ static void track_tree_refs(struct tree *item) { int n_refs = 0, i; @@@ -160,11 -148,8 +156,11 @@@ /* Count how many entries there are.. */ init_tree_desc(&desc, item->buffer, item->size); - while (tree_entry(&desc, &entry)) + while (tree_entry(&desc, &entry)) { + if (S_ISDIRLNK(entry.mode)) + continue; n_refs++; + } /* Allocate object refs and walk it again.. */ i = 0; @@@ -173,8 -158,6 +169,8 @@@ while (tree_entry(&desc, &entry)) { struct object *obj; + if (S_ISDIRLNK(entry.mode)) + continue; if (S_ISDIR(entry.mode)) obj = &lookup_tree(entry.sha1)->object; else