Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 1 | #ifndef CACHE_H |
| 2 | #define CACHE_H |
| 3 | |
Junio C Hamano | 4050c0d | 2005-12-05 11:54:29 -0800 | [diff] [blame] | 4 | #include "git-compat-util.h" |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 5 | |
Linus Torvalds | cef661f | 2005-04-21 12:33:22 -0700 | [diff] [blame] | 6 | #include SHA1_HEADER |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 7 | #include <zlib.h> |
| 8 | |
Edgar Toernig | 9da3acf | 2005-04-30 09:51:03 -0700 | [diff] [blame] | 9 | #if ZLIB_VERNUM < 0x1200 |
| 10 | #define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11) |
| 11 | #endif |
| 12 | |
Timo Hirvonen | 962554c | 2006-02-26 17:13:46 +0200 | [diff] [blame] | 13 | #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) |
Edgar Toernig | b682969 | 2005-04-30 09:51:03 -0700 | [diff] [blame] | 14 | #define DTYPE(de) ((de)->d_type) |
| 15 | #else |
Junio C Hamano | 0bdd79a | 2006-01-20 13:33:20 -0800 | [diff] [blame] | 16 | #undef DT_UNKNOWN |
| 17 | #undef DT_DIR |
| 18 | #undef DT_REG |
| 19 | #undef DT_LNK |
Edgar Toernig | b682969 | 2005-04-30 09:51:03 -0700 | [diff] [blame] | 20 | #define DT_UNKNOWN 0 |
| 21 | #define DT_DIR 1 |
| 22 | #define DT_REG 2 |
Junio C Hamano | a15c1c6 | 2005-05-12 17:16:04 -0700 | [diff] [blame] | 23 | #define DT_LNK 3 |
Edgar Toernig | b682969 | 2005-04-30 09:51:03 -0700 | [diff] [blame] | 24 | #define DTYPE(de) DT_UNKNOWN |
| 25 | #endif |
| 26 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 27 | /* |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 28 | * Intensive research over the course of many years has shown that |
| 29 | * port 9418 is totally unused by anything else. Or |
| 30 | * |
| 31 | * Your search - "port 9418" - did not match any documents. |
| 32 | * |
| 33 | * as www.google.com puts it. |
Linus Torvalds | ba8a497 | 2005-09-12 11:23:00 -0700 | [diff] [blame] | 34 | * |
| 35 | * This port has been properly assigned for git use by IANA: |
| 36 | * git (Assigned-9418) [I06-050728-0001]. |
| 37 | * |
| 38 | * git 9418/tcp git pack transfer service |
| 39 | * git 9418/udp git pack transfer service |
| 40 | * |
| 41 | * with Linus Torvalds <torvalds@osdl.org> as the point of |
| 42 | * contact. September 2005. |
| 43 | * |
| 44 | * See http://www.iana.org/assignments/port-numbers |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 45 | */ |
| 46 | #define DEFAULT_GIT_PORT 9418 |
| 47 | |
| 48 | /* |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 49 | * Basic data structures for the directory cache |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 50 | */ |
| 51 | |
| 52 | #define CACHE_SIGNATURE 0x44495243 /* "DIRC" */ |
| 53 | struct cache_header { |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 54 | unsigned int hdr_signature; |
| 55 | unsigned int hdr_version; |
| 56 | unsigned int hdr_entries; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | /* |
| 60 | * The "cache_time" is just the low 32 bits of the |
| 61 | * time. It doesn't matter if it overflows - we only |
| 62 | * check it for equality in the 32 bits we save. |
| 63 | */ |
| 64 | struct cache_time { |
| 65 | unsigned int sec; |
| 66 | unsigned int nsec; |
| 67 | }; |
| 68 | |
| 69 | /* |
| 70 | * dev/ino/uid/gid/size are also just tracked to the low 32 bits |
| 71 | * Again - this is just a (very strong in practice) heuristic that |
| 72 | * the inode hasn't changed. |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 73 | * |
| 74 | * We save the fields in big-endian order to allow using the |
| 75 | * index file over NFS transparently. |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 76 | */ |
| 77 | struct cache_entry { |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 78 | struct cache_time ce_ctime; |
| 79 | struct cache_time ce_mtime; |
| 80 | unsigned int ce_dev; |
| 81 | unsigned int ce_ino; |
| 82 | unsigned int ce_mode; |
| 83 | unsigned int ce_uid; |
| 84 | unsigned int ce_gid; |
| 85 | unsigned int ce_size; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 86 | unsigned char sha1[20]; |
Linus Torvalds | f5cabd1 | 2005-04-15 21:45:38 -0700 | [diff] [blame] | 87 | unsigned short ce_flags; |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 88 | char name[FLEX_ARRAY]; /* more */ |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Linus Torvalds | 95fd5bf | 2005-04-15 22:51:44 -0700 | [diff] [blame] | 91 | #define CE_NAMEMASK (0x0fff) |
| 92 | #define CE_STAGEMASK (0x3000) |
Linus Torvalds | 220a0b5 | 2005-06-05 22:07:31 -0700 | [diff] [blame] | 93 | #define CE_UPDATE (0x4000) |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 94 | #define CE_VALID (0x8000) |
Junio C Hamano | aee4619 | 2005-04-16 08:33:23 -0700 | [diff] [blame] | 95 | #define CE_STAGESHIFT 12 |
Linus Torvalds | 95fd5bf | 2005-04-15 22:51:44 -0700 | [diff] [blame] | 96 | |
Junio C Hamano | aee4619 | 2005-04-16 08:33:23 -0700 | [diff] [blame] | 97 | #define create_ce_flags(len, stage) htons((len) | ((stage) << CE_STAGESHIFT)) |
| 98 | #define ce_namelen(ce) (CE_NAMEMASK & ntohs((ce)->ce_flags)) |
| 99 | #define ce_size(ce) cache_entry_size(ce_namelen(ce)) |
| 100 | #define ce_stage(ce) ((CE_STAGEMASK & ntohs((ce)->ce_flags)) >> CE_STAGESHIFT) |
| 101 | |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 102 | #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644) |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 103 | static inline unsigned int create_ce_mode(unsigned int mode) |
| 104 | { |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 105 | if (S_ISLNK(mode)) |
| 106 | return htonl(S_IFLNK); |
Linus Torvalds | db823d4 | 2005-05-05 16:01:46 -0700 | [diff] [blame] | 107 | return htonl(S_IFREG | ce_permissions(mode)); |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 108 | } |
Junio C Hamano | 1b0c717 | 2006-03-29 22:55:43 -0800 | [diff] [blame] | 109 | #define canon_mode(mode) \ |
| 110 | (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ |
| 111 | S_ISLNK(mode) ? S_IFLNK : S_IFDIR) |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 112 | |
Junio C Hamano | aee4619 | 2005-04-16 08:33:23 -0700 | [diff] [blame] | 113 | #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7) |
Linus Torvalds | f5cabd1 | 2005-04-15 21:45:38 -0700 | [diff] [blame] | 114 | |
Petr Baudis | 8835504 | 2005-05-11 00:58:16 +0200 | [diff] [blame] | 115 | extern struct cache_entry **active_cache; |
| 116 | extern unsigned int active_nr, active_alloc, active_cache_changed; |
Junio C Hamano | bad68ec | 2006-04-24 21:18:58 -0700 | [diff] [blame] | 117 | extern struct cache_tree *active_cache_tree; |
Johannes Schindelin | 8fd2cb4 | 2006-07-25 21:32:18 -0700 | [diff] [blame] | 118 | extern int cache_errno; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 119 | |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 120 | #define GIT_DIR_ENVIRONMENT "GIT_DIR" |
| 121 | #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" |
Junio C Hamano | d19938a | 2005-05-09 17:57:56 -0700 | [diff] [blame] | 122 | #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 123 | #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" |
Junio C Hamano | 5da5c8f | 2005-07-30 00:58:28 -0700 | [diff] [blame] | 124 | #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 125 | |
Pierre Habouzit | c5fba16 | 2006-08-23 12:39:11 +0200 | [diff] [blame] | 126 | extern const char *get_git_dir(void); |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 127 | extern char *get_object_directory(void); |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 128 | extern char *get_refs_directory(void); |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 129 | extern char *get_index_file(void); |
Junio C Hamano | 5da5c8f | 2005-07-30 00:58:28 -0700 | [diff] [blame] | 130 | extern char *get_graft_file(void); |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 131 | |
| 132 | #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 133 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 134 | extern const char **get_pathspec(const char *prefix, const char **pathspec); |
Junio C Hamano | 4ca0660 | 2005-11-25 23:14:15 -0800 | [diff] [blame] | 135 | extern const char *setup_git_directory_gently(int *); |
Linus Torvalds | d288a70 | 2005-08-16 18:06:34 -0700 | [diff] [blame] | 136 | extern const char *setup_git_directory(void); |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 137 | extern const char *prefix_path(const char *prefix, int len, const char *path); |
Junio C Hamano | 4ca0660 | 2005-11-25 23:14:15 -0800 | [diff] [blame] | 138 | extern const char *prefix_filename(const char *prefix, int len, const char *path); |
Linus Torvalds | e23d0b4 | 2006-04-26 10:15:54 -0700 | [diff] [blame] | 139 | extern void verify_filename(const char *prefix, const char *name); |
Junio C Hamano | ea92f41 | 2006-04-26 15:09:27 -0700 | [diff] [blame] | 140 | extern void verify_non_filename(const char *prefix, const char *name); |
Linus Torvalds | d288a70 | 2005-08-16 18:06:34 -0700 | [diff] [blame] | 141 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 142 | #define alloc_nr(x) (((x)+16)*3/2) |
| 143 | |
Linus Torvalds | 734aab7 | 2005-04-09 09:48:20 -0700 | [diff] [blame] | 144 | /* Initialize and use the cache information */ |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 145 | extern int read_cache(void); |
Johannes Schindelin | 8fd2cb4 | 2006-07-25 21:32:18 -0700 | [diff] [blame] | 146 | extern int read_cache_from(const char *path); |
Linus Torvalds | 197ee8c | 2005-04-09 12:09:27 -0700 | [diff] [blame] | 147 | extern int write_cache(int newfd, struct cache_entry **cache, int entries); |
Johannes Schindelin | 6d297f8 | 2006-07-08 18:42:41 +0200 | [diff] [blame] | 148 | extern int discard_cache(void); |
Linus Torvalds | 8dcf39c | 2006-05-18 12:07:31 -0700 | [diff] [blame] | 149 | extern int verify_path(const char *path); |
Linus Torvalds | eb38c22 | 2005-04-09 09:26:55 -0700 | [diff] [blame] | 150 | extern int cache_name_pos(const char *name, int namelen); |
Junio C Hamano | 192268c | 2005-05-07 21:55:21 -0700 | [diff] [blame] | 151 | #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ |
| 152 | #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ |
Junio C Hamano | b155725 | 2005-06-25 02:25:29 -0700 | [diff] [blame] | 153 | #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ |
Junio C Hamano | 192268c | 2005-05-07 21:55:21 -0700 | [diff] [blame] | 154 | extern int add_cache_entry(struct cache_entry *ce, int option); |
Johannes Schindelin | 8fd2cb4 | 2006-07-25 21:32:18 -0700 | [diff] [blame] | 155 | extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); |
Brad Roberts | dbbce55 | 2005-05-14 19:04:25 -0700 | [diff] [blame] | 156 | extern int remove_cache_entry_at(int pos); |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 157 | extern int remove_file_from_cache(const char *path); |
Johannes Schindelin | 11be42a | 2006-07-26 03:52:35 +0200 | [diff] [blame] | 158 | extern int add_file_to_index(const char *path, int verbose); |
Brad Roberts | dbbce55 | 2005-05-14 19:04:25 -0700 | [diff] [blame] | 159 | extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 160 | extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int); |
| 161 | extern int ce_modified(struct cache_entry *ce, struct stat *st, int); |
Linus Torvalds | c0fd1f5 | 2005-07-14 16:55:06 -0700 | [diff] [blame] | 162 | extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); |
Bryan Larsen | 7672db2 | 2005-07-08 16:51:55 -0700 | [diff] [blame] | 163 | extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type); |
Björn Engelmann | e7332f9 | 2006-05-23 20:19:04 +0200 | [diff] [blame] | 164 | extern int read_pipe(int fd, char** return_buf, unsigned long* return_size); |
Daniel Barkalow | 024510c | 2005-12-10 17:25:24 -0500 | [diff] [blame] | 165 | extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object); |
Junio C Hamano | ec1fcc1 | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 166 | extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); |
Junio C Hamano | 415e96c | 2005-05-15 14:23:12 -0700 | [diff] [blame] | 167 | extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); |
| 168 | |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 169 | #define REFRESH_REALLY 0x0001 /* ignore_valid */ |
| 170 | #define REFRESH_UNMERGED 0x0002 /* allow unmerged */ |
| 171 | #define REFRESH_QUIET 0x0004 /* be quiet about it */ |
| 172 | #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ |
| 173 | extern int refresh_cache(unsigned int flags); |
| 174 | |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 175 | struct lock_file { |
| 176 | struct lock_file *next; |
| 177 | char filename[PATH_MAX]; |
Junio C Hamano | 415e96c | 2005-05-15 14:23:12 -0700 | [diff] [blame] | 178 | }; |
Junio C Hamano | 40aaae8 | 2006-08-12 01:03:47 -0700 | [diff] [blame] | 179 | extern int hold_lock_file_for_update(struct lock_file *, const char *path, int); |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 180 | extern int commit_lock_file(struct lock_file *); |
| 181 | extern void rollback_lock_file(struct lock_file *); |
Linus Torvalds | 734aab7 | 2005-04-09 09:48:20 -0700 | [diff] [blame] | 182 | |
Junio C Hamano | 2ae1c53 | 2006-02-27 14:47:45 -0800 | [diff] [blame] | 183 | /* Environment bits from configuration mechanism */ |
Linus Torvalds | 93821bd | 2006-07-11 12:48:08 -0700 | [diff] [blame] | 184 | extern int use_legacy_headers; |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 185 | extern int trust_executable_bit; |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 186 | extern int assume_unchanged; |
Junio C Hamano | 9f0bb90 | 2006-05-02 00:40:24 -0700 | [diff] [blame] | 187 | extern int prefer_symlink_refs; |
Shawn Pearce | 6de08ae | 2006-05-17 05:55:40 -0400 | [diff] [blame] | 188 | extern int log_all_ref_updates; |
Junio C Hamano | 2f8acdb | 2006-03-20 18:45:47 -0800 | [diff] [blame] | 189 | extern int warn_ambiguous_refs; |
Johannes Schindelin | 457f06d | 2005-12-22 23:13:56 +0100 | [diff] [blame] | 190 | extern int shared_repository; |
Junio C Hamano | 2ae1c53 | 2006-02-27 14:47:45 -0800 | [diff] [blame] | 191 | extern const char *apply_default_whitespace; |
Joachim B Haga | 12f6c30 | 2006-07-03 22:11:47 +0200 | [diff] [blame] | 192 | extern int zlib_compression_level; |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 193 | |
Junio C Hamano | ab9cb76 | 2005-11-25 15:59:09 -0800 | [diff] [blame] | 194 | #define GIT_REPO_VERSION 0 |
| 195 | extern int repository_format_version; |
| 196 | extern int check_repository_format(void); |
| 197 | |
Linus Torvalds | 734aab7 | 2005-04-09 09:48:20 -0700 | [diff] [blame] | 198 | #define MTIME_CHANGED 0x0001 |
| 199 | #define CTIME_CHANGED 0x0002 |
| 200 | #define OWNER_CHANGED 0x0004 |
| 201 | #define MODE_CHANGED 0x0008 |
| 202 | #define INODE_CHANGED 0x0010 |
| 203 | #define DATA_CHANGED 0x0020 |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 204 | #define TYPE_CHANGED 0x0040 |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 205 | |
| 206 | /* Return a statically allocated filename matching the sha1 signature */ |
Timo Sirainen | 4ec99bf | 2005-08-09 18:30:22 +0300 | [diff] [blame] | 207 | extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
| 208 | extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
Linus Torvalds | 73134b6 | 2005-04-10 14:03:58 -0700 | [diff] [blame] | 209 | extern char *sha1_file_name(const unsigned char *sha1); |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 210 | extern char *sha1_pack_name(const unsigned char *sha1); |
| 211 | extern char *sha1_pack_index_name(const unsigned char *sha1); |
Junio C Hamano | 013f276 | 2005-10-11 15:22:48 -0700 | [diff] [blame] | 212 | extern const char *find_unique_abbrev(const unsigned char *sha1, int); |
Junio C Hamano | 88cd621 | 2005-09-30 14:02:47 -0700 | [diff] [blame] | 213 | extern const unsigned char null_sha1[20]; |
David Rientjes | 0bef57e | 2006-08-15 13:37:19 -0700 | [diff] [blame] | 214 | static inline int is_null_sha1(const unsigned char *sha1) |
| 215 | { |
| 216 | return !memcmp(sha1, null_sha1, 20); |
| 217 | } |
David Rientjes | a89fccd | 2006-08-17 11:54:57 -0700 | [diff] [blame] | 218 | static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) |
| 219 | { |
| 220 | return memcmp(sha1, sha2, 20); |
| 221 | } |
Shawn Pearce | e702496 | 2006-08-23 02:49:00 -0400 | [diff] [blame] | 222 | static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) |
| 223 | { |
| 224 | memcpy(sha_dst, sha_src, 20); |
| 225 | } |
Junio C Hamano | a8e0d16 | 2006-08-23 13:57:23 -0700 | [diff] [blame] | 226 | static inline void hashclr(unsigned char *hash) |
| 227 | { |
| 228 | memset(hash, 0, 20); |
| 229 | } |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 230 | |
Holger Eitzenberger | f2db68e | 2005-08-04 22:43:03 +0200 | [diff] [blame] | 231 | int git_mkstemp(char *path, size_t n, const char *template); |
| 232 | |
Junio C Hamano | 94df250 | 2006-06-09 23:09:49 -0700 | [diff] [blame] | 233 | enum sharedrepo { |
| 234 | PERM_UMASK = 0, |
| 235 | PERM_GROUP, |
| 236 | PERM_EVERYBODY |
| 237 | }; |
| 238 | int git_config_perm(const char *var, const char *value); |
Johannes Schindelin | 457f06d | 2005-12-22 23:13:56 +0100 | [diff] [blame] | 239 | int adjust_shared_perm(const char *path); |
Junio C Hamano | b2cb942 | 2005-07-06 01:11:52 -0700 | [diff] [blame] | 240 | int safe_create_leading_directories(char *path); |
Timo Hirvonen | bd22c90 | 2005-11-21 02:52:52 +0200 | [diff] [blame] | 241 | char *enter_repo(char *path, int strict); |
Junio C Hamano | b2cb942 | 2005-07-06 01:11:52 -0700 | [diff] [blame] | 242 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 243 | /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ |
Junio C Hamano | 36e4d74 | 2005-06-27 03:34:06 -0700 | [diff] [blame] | 244 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); |
Linus Torvalds | 2ade934 | 2005-04-08 15:01:15 -0700 | [diff] [blame] | 245 | extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size); |
Linus Torvalds | 73134b6 | 2005-04-10 14:03:58 -0700 | [diff] [blame] | 246 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); |
Brian Gerst | bf0f910 | 2005-05-18 08:14:09 -0400 | [diff] [blame] | 247 | extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1); |
Bryan Larsen | 7672db2 | 2005-07-08 16:51:55 -0700 | [diff] [blame] | 248 | extern char *write_sha1_file_prepare(void *buf, |
| 249 | unsigned long len, |
| 250 | const char *type, |
| 251 | unsigned char *sha1, |
| 252 | unsigned char *hdr, |
| 253 | int *hdrlen); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 254 | |
Jason McMullan | 5d6ccf5 | 2005-06-03 11:05:39 -0400 | [diff] [blame] | 255 | extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 256 | |
barkalow@iabervon.org | 70b9829 | 2005-08-02 19:46:29 -0400 | [diff] [blame] | 257 | extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer, |
| 258 | size_t bufsize, size_t *bufposn); |
Daniel Barkalow | a5eda52 | 2005-07-10 18:25:38 -0400 | [diff] [blame] | 259 | extern int write_sha1_to_fd(int fd, const unsigned char *sha1); |
Junio C Hamano | 839837b | 2006-09-01 00:17:47 -0700 | [diff] [blame] | 260 | extern int move_temp_to_file(const char *tmpfile, const char *filename); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 261 | |
Linus Torvalds | dade09c | 2005-07-03 13:06:36 -0700 | [diff] [blame] | 262 | extern int has_sha1_pack(const unsigned char *sha1); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 263 | extern int has_sha1_file(const unsigned char *sha1); |
Junio C Hamano | bb6b8e4 | 2006-07-17 15:04:47 -0700 | [diff] [blame] | 264 | extern void *map_sha1_file(const unsigned char *sha1, unsigned long *); |
| 265 | extern int legacy_loose_object(unsigned char *); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 266 | |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 267 | extern int has_pack_file(const unsigned char *sha1); |
| 268 | extern int has_pack_index(const unsigned char *sha1); |
| 269 | |
Junio C Hamano | 72518e9 | 2006-09-03 21:09:18 -0700 | [diff] [blame] | 270 | enum object_type { |
| 271 | OBJ_NONE = 0, |
| 272 | OBJ_COMMIT = 1, |
| 273 | OBJ_TREE = 2, |
| 274 | OBJ_BLOB = 3, |
| 275 | OBJ_TAG = 4, |
| 276 | /* 5/6 for future expansion */ |
| 277 | OBJ_DELTA = 7, |
| 278 | OBJ_BAD, |
| 279 | }; |
| 280 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 281 | /* Convert to/from hex/sha1 representation */ |
Junio C Hamano | 46a6c26 | 2006-01-25 01:03:18 -0800 | [diff] [blame] | 282 | #define MINIMUM_ABBREV 4 |
| 283 | #define DEFAULT_ABBREV 7 |
| 284 | |
Linus Torvalds | 3c249c9 | 2005-05-01 16:36:56 -0700 | [diff] [blame] | 285 | extern int get_sha1(const char *str, unsigned char *sha1); |
Linus Torvalds | 197ee8c | 2005-04-09 12:09:27 -0700 | [diff] [blame] | 286 | extern int get_sha1_hex(const char *hex, unsigned char *sha1); |
| 287 | extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ |
Linus Torvalds | ca8db14 | 2005-09-25 09:59:37 -0700 | [diff] [blame] | 288 | extern int read_ref(const char *filename, unsigned char *sha1); |
Junio C Hamano | a876ed8 | 2005-09-30 14:08:25 -0700 | [diff] [blame] | 289 | extern const char *resolve_ref(const char *path, unsigned char *sha1, int); |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 290 | extern int create_symref(const char *git_HEAD, const char *refs_heads_master); |
| 291 | extern int validate_symref(const char *git_HEAD); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 292 | |
Linus Torvalds | 958ba6c | 2005-05-20 09:09:18 -0700 | [diff] [blame] | 293 | extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); |
Linus Torvalds | 79517a0 | 2005-04-09 12:59:11 -0700 | [diff] [blame] | 294 | extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 295 | |
Junio C Hamano | 40469ee | 2005-04-28 16:42:27 -0700 | [diff] [blame] | 296 | extern void *read_object_with_reference(const unsigned char *sha1, |
Brian Gerst | bf0f910 | 2005-05-18 08:14:09 -0400 | [diff] [blame] | 297 | const char *required_type, |
Junio C Hamano | 40469ee | 2005-04-28 16:42:27 -0700 | [diff] [blame] | 298 | unsigned long *size, |
| 299 | unsigned char *sha1_ret); |
Junio C Hamano | f4913f9 | 2005-04-20 18:06:49 -0700 | [diff] [blame] | 300 | |
Linus Torvalds | 9a8e35e | 2006-08-26 15:45:26 -0700 | [diff] [blame] | 301 | const char *show_date(unsigned long time, int timezone, int relative); |
Junio C Hamano | 2a38704 | 2006-05-01 01:44:33 -0700 | [diff] [blame] | 302 | const char *show_rfc2822_date(unsigned long time, int timezone); |
Linus Torvalds | 2a39064 | 2005-09-19 15:53:50 -0700 | [diff] [blame] | 303 | int parse_date(const char *date, char *buf, int bufsize); |
Edgar Toernig | ecee9d9 | 2005-04-30 09:46:49 -0700 | [diff] [blame] | 304 | void datestamp(char *buf, int bufsize); |
Linus Torvalds | 3c07b1d | 2005-11-14 19:29:06 -0800 | [diff] [blame] | 305 | unsigned long approxidate(const char *); |
Edgar Toernig | ecee9d9 | 2005-04-30 09:46:49 -0700 | [diff] [blame] | 306 | |
Linus Torvalds | 6aa33f4 | 2005-07-12 11:49:27 -0700 | [diff] [blame] | 307 | extern int setup_ident(void); |
Junio C Hamano | 749be72 | 2006-02-18 20:31:05 -0800 | [diff] [blame] | 308 | extern const char *git_author_info(int); |
| 309 | extern const char *git_committer_info(int); |
Linus Torvalds | 6aa33f4 | 2005-07-12 11:49:27 -0700 | [diff] [blame] | 310 | |
Linus Torvalds | 12dccc1 | 2005-06-05 21:59:54 -0700 | [diff] [blame] | 311 | struct checkout { |
| 312 | const char *base_dir; |
| 313 | int base_dir_len; |
| 314 | unsigned force:1, |
| 315 | quiet:1, |
| 316 | not_new:1, |
| 317 | refresh_cache:1; |
| 318 | }; |
| 319 | |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 320 | extern int checkout_entry(struct cache_entry *ce, struct checkout *state, char *topath); |
Linus Torvalds | 12dccc1 | 2005-06-05 21:59:54 -0700 | [diff] [blame] | 321 | |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 322 | extern struct alternate_object_database { |
Junio C Hamano | d5a63b9 | 2005-08-14 17:25:57 -0700 | [diff] [blame] | 323 | struct alternate_object_database *next; |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 324 | char *name; |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 325 | char base[FLEX_ARRAY]; /* more */ |
Junio C Hamano | d5a63b9 | 2005-08-14 17:25:57 -0700 | [diff] [blame] | 326 | } *alt_odb_list; |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 327 | extern void prepare_alt_odb(void); |
| 328 | |
| 329 | extern struct packed_git { |
| 330 | struct packed_git *next; |
| 331 | unsigned long index_size; |
| 332 | unsigned long pack_size; |
| 333 | unsigned int *index_base; |
| 334 | void *pack_base; |
| 335 | unsigned int pack_last_used; |
Junio C Hamano | f925339 | 2005-06-29 02:51:27 -0700 | [diff] [blame] | 336 | unsigned int pack_use_cnt; |
Linus Torvalds | 9d835df | 2005-10-13 15:38:28 -0700 | [diff] [blame] | 337 | int pack_local; |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 338 | unsigned char sha1[20]; |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 339 | /* something like ".git/objects/pack/xxxxx.pack" */ |
| 340 | char pack_name[FLEX_ARRAY]; /* more */ |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 341 | } *packed_git; |
Junio C Hamano | f3bf922 | 2005-06-30 17:15:39 -0700 | [diff] [blame] | 342 | |
| 343 | struct pack_entry { |
| 344 | unsigned int offset; |
| 345 | unsigned char sha1[20]; |
| 346 | struct packed_git *p; |
| 347 | }; |
| 348 | |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 349 | struct ref { |
| 350 | struct ref *next; |
| 351 | unsigned char old_sha1[20]; |
| 352 | unsigned char new_sha1[20]; |
Junio C Hamano | ff27adf | 2005-08-24 00:40:14 -0700 | [diff] [blame] | 353 | unsigned char force; |
Junio C Hamano | f88395a | 2005-08-03 16:35:29 -0700 | [diff] [blame] | 354 | struct ref *peer_ref; /* when renaming */ |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 355 | char name[FLEX_ARRAY]; /* more */ |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 356 | }; |
| 357 | |
Linus Torvalds | 2718ff0 | 2006-07-04 12:29:10 -0700 | [diff] [blame] | 358 | #define REF_NORMAL (1u << 0) |
| 359 | #define REF_HEADS (1u << 1) |
| 360 | #define REF_TAGS (1u << 2) |
| 361 | |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 362 | extern int git_connect(int fd[2], char *url, const char *prog); |
| 363 | extern int finish_connect(pid_t pid); |
Linus Torvalds | 013e7c7 | 2005-07-04 13:24:30 -0700 | [diff] [blame] | 364 | extern int path_match(const char *path, int nr, char **match); |
Junio C Hamano | f88395a | 2005-08-03 16:35:29 -0700 | [diff] [blame] | 365 | extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, |
| 366 | int nr_refspec, char **refspec, int all); |
Linus Torvalds | 41cb748 | 2005-07-05 15:44:09 -0700 | [diff] [blame] | 367 | extern int get_ack(int fd, unsigned char *result_sha1); |
Linus Torvalds | 2718ff0 | 2006-07-04 12:29:10 -0700 | [diff] [blame] | 368 | extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags); |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 369 | extern int server_supports(const char *feature); |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 370 | |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 371 | extern struct packed_git *parse_pack_index(unsigned char *sha1); |
Peter Hagervall | 2ab141a | 2005-09-02 14:17:10 +0200 | [diff] [blame] | 372 | extern struct packed_git *parse_pack_index_file(const unsigned char *sha1, |
Daniel Barkalow | c508df5 | 2005-08-16 00:10:03 -0400 | [diff] [blame] | 373 | char *idx_path); |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 374 | |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 375 | extern void prepare_packed_git(void); |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 376 | extern void install_packed_git(struct packed_git *pack); |
| 377 | |
| 378 | extern struct packed_git *find_sha1_pack(const unsigned char *sha1, |
| 379 | struct packed_git *packs); |
| 380 | |
Junio C Hamano | f925339 | 2005-06-29 02:51:27 -0700 | [diff] [blame] | 381 | extern int use_packed_git(struct packed_git *); |
| 382 | extern void unuse_packed_git(struct packed_git *); |
Linus Torvalds | 9d835df | 2005-10-13 15:38:28 -0700 | [diff] [blame] | 383 | extern struct packed_git *add_packed_git(char *, int, int); |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 384 | extern int num_packed_objects(const struct packed_git *p); |
| 385 | extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*); |
Junio C Hamano | f3bf922 | 2005-06-30 17:15:39 -0700 | [diff] [blame] | 386 | extern int find_pack_entry_one(const unsigned char *, struct pack_entry *, struct packed_git *); |
| 387 | extern void *unpack_entry_gently(struct pack_entry *, char *, unsigned long *); |
Junio C Hamano | 72518e9 | 2006-09-03 21:09:18 -0700 | [diff] [blame] | 388 | extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); |
Junio C Hamano | f8f135c | 2006-02-15 12:47:43 -0800 | [diff] [blame] | 389 | extern void packed_object_info_detail(struct pack_entry *, char *, unsigned long *, unsigned long *, unsigned int *, unsigned char *); |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 390 | |
Junio C Hamano | 8f3f9b0 | 2005-07-23 17:54:41 -0700 | [diff] [blame] | 391 | /* Dumb servers support */ |
| 392 | extern int update_server_info(int); |
| 393 | |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 394 | typedef int (*config_fn_t)(const char *, const char *); |
| 395 | extern int git_default_config(const char *, const char *); |
Junio C Hamano | 4f62953 | 2005-11-25 16:03:56 -0800 | [diff] [blame] | 396 | extern int git_config_from_file(config_fn_t fn, const char *); |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 397 | extern int git_config(config_fn_t fn); |
| 398 | extern int git_config_int(const char *, const char *); |
| 399 | extern int git_config_bool(const char *, const char *); |
Johannes Schindelin | 10bea15 | 2005-11-17 22:32:36 +0100 | [diff] [blame] | 400 | extern int git_config_set(const char *, const char *); |
Johannes Schindelin | 4ddba79 | 2005-11-20 06:52:22 +0100 | [diff] [blame] | 401 | extern int git_config_set_multivar(const char *, const char *, const char *, int); |
Junio C Hamano | ab9cb76 | 2005-11-25 15:59:09 -0800 | [diff] [blame] | 402 | extern int check_repository_format_version(const char *var, const char *value); |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 403 | |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 404 | #define MAX_GITNAME (1000) |
| 405 | extern char git_default_email[MAX_GITNAME]; |
| 406 | extern char git_default_name[MAX_GITNAME]; |
| 407 | |
Junio C Hamano | 4e72dce | 2005-11-27 16:09:40 -0800 | [diff] [blame] | 408 | #define MAX_ENCODING_LENGTH 64 |
| 409 | extern char git_commit_encoding[MAX_ENCODING_LENGTH]; |
| 410 | |
Junio C Hamano | f3123c4 | 2005-10-22 01:28:13 -0700 | [diff] [blame] | 411 | extern int copy_fd(int ifd, int ofd); |
Rene Scharfe | 7230e6d | 2006-08-21 20:43:43 +0200 | [diff] [blame] | 412 | extern void write_or_die(int fd, const void *buf, size_t count); |
Christian Couder | 6ce4e61 | 2006-09-02 18:23:48 +0200 | [diff] [blame] | 413 | extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); |
Junio C Hamano | ad89721 | 2005-12-14 22:17:38 -0800 | [diff] [blame] | 414 | |
| 415 | /* Finish off pack transfer receiving end */ |
Junio C Hamano | 583b7ea | 2006-06-21 00:30:21 -0700 | [diff] [blame] | 416 | extern int receive_unpack_pack(int fd[2], const char *me, int quiet, int); |
| 417 | extern int receive_keep_pack(int fd[2], const char *me, int quiet, int); |
Junio C Hamano | ad89721 | 2005-12-14 22:17:38 -0800 | [diff] [blame] | 418 | |
Linus Torvalds | f67b45f | 2006-02-28 11:26:21 -0800 | [diff] [blame] | 419 | /* pager.c */ |
| 420 | extern void setup_pager(void); |
Junio C Hamano | 85fb65e | 2006-06-06 16:58:40 -0700 | [diff] [blame] | 421 | extern int pager_in_use; |
Matthias Lederhofer | aa086eb | 2006-07-30 00:27:43 +0200 | [diff] [blame] | 422 | extern int pager_use_color; |
Linus Torvalds | f67b45f | 2006-02-28 11:26:21 -0800 | [diff] [blame] | 423 | |
Junio C Hamano | 051308f | 2006-05-04 16:51:44 -0700 | [diff] [blame] | 424 | /* base85 */ |
| 425 | int decode_85(char *dst, char *line, int linelen); |
Junio C Hamano | 0660626 | 2006-05-05 02:41:53 -0700 | [diff] [blame] | 426 | void encode_85(char *buf, unsigned char *data, int bytes); |
Junio C Hamano | 051308f | 2006-05-04 16:51:44 -0700 | [diff] [blame] | 427 | |
Linus Torvalds | 855419f | 2006-06-19 10:44:15 -0700 | [diff] [blame] | 428 | /* alloc.c */ |
| 429 | struct blob; |
| 430 | struct tree; |
| 431 | struct commit; |
| 432 | struct tag; |
| 433 | extern struct blob *alloc_blob_node(void); |
| 434 | extern struct tree *alloc_tree_node(void); |
| 435 | extern struct commit *alloc_commit_node(void); |
| 436 | extern struct tag *alloc_tag_node(void); |
| 437 | extern void alloc_report(void); |
| 438 | |
Christian Couder | 6ce4e61 | 2006-09-02 18:23:48 +0200 | [diff] [blame] | 439 | /* trace.c */ |
| 440 | extern int nfvasprintf(char **str, const char *fmt, va_list va); |
| 441 | extern void trace_printf(const char *format, ...); |
| 442 | extern void trace_argv_printf(const char **argv, int count, const char *format, ...); |
| 443 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 444 | #endif /* CACHE_H */ |