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" |
Pierre Habouzit | 5ecd293 | 2007-09-16 15:51:04 +0200 | [diff] [blame] | 5 | #include "strbuf.h" |
Linus Torvalds | cf55870 | 2008-01-22 18:41:14 -0800 | [diff] [blame] | 6 | #include "hash.h" |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 7 | #include "advice.h" |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 8 | #include "gettext.h" |
Junio C Hamano | d1bf0e0 | 2011-05-20 12:59:01 -0700 | [diff] [blame] | 9 | #include "convert.h" |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | cef661f | 2005-04-21 12:33:22 -0700 | [diff] [blame] | 11 | #include SHA1_HEADER |
Nicolas Pitre | 9126f00 | 2008-10-01 14:05:20 -0400 | [diff] [blame] | 12 | #ifndef git_SHA_CTX |
| 13 | #define git_SHA_CTX SHA_CTX |
| 14 | #define git_SHA1_Init SHA1_Init |
| 15 | #define git_SHA1_Update SHA1_Update |
| 16 | #define git_SHA1_Final SHA1_Final |
| 17 | #endif |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 18 | |
Nicolas Pitre | 9126f00 | 2008-10-01 14:05:20 -0400 | [diff] [blame] | 19 | #include <zlib.h> |
Junio C Hamano | ef49a7a | 2011-06-10 11:52:15 -0700 | [diff] [blame] | 20 | typedef struct git_zstream { |
| 21 | z_stream z; |
| 22 | unsigned long avail_in; |
| 23 | unsigned long avail_out; |
| 24 | unsigned long total_in; |
| 25 | unsigned long total_out; |
| 26 | unsigned char *next_in; |
| 27 | unsigned char *next_out; |
| 28 | } git_zstream; |
Edgar Toernig | 9da3acf | 2005-04-30 09:51:03 -0700 | [diff] [blame] | 29 | |
Junio C Hamano | ef49a7a | 2011-06-10 11:52:15 -0700 | [diff] [blame] | 30 | void git_inflate_init(git_zstream *); |
| 31 | void git_inflate_init_gzip_only(git_zstream *); |
| 32 | void git_inflate_end(git_zstream *); |
| 33 | int git_inflate(git_zstream *, int flush); |
Linus Torvalds | 39c6854 | 2009-01-07 19:54:47 -0800 | [diff] [blame] | 34 | |
Junio C Hamano | ef49a7a | 2011-06-10 11:52:15 -0700 | [diff] [blame] | 35 | void git_deflate_init(git_zstream *, int level); |
| 36 | void git_deflate_init_gzip(git_zstream *, int level); |
| 37 | void git_deflate_end(git_zstream *); |
Junio C Hamano | 568508e | 2011-10-28 14:48:40 -0700 | [diff] [blame] | 38 | int git_deflate_abort(git_zstream *); |
Junio C Hamano | ef49a7a | 2011-06-10 11:52:15 -0700 | [diff] [blame] | 39 | int git_deflate_end_gently(git_zstream *); |
| 40 | int git_deflate(git_zstream *, int flush); |
| 41 | unsigned long git_deflate_bound(git_zstream *, unsigned long); |
Junio C Hamano | 0bdd79a | 2006-01-20 13:33:20 -0800 | [diff] [blame] | 42 | |
| 43 | #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) |
| 44 | #define DTYPE(de) ((de)->d_type) |
| 45 | #else |
Edgar Toernig | b682969 | 2005-04-30 09:51:03 -0700 | [diff] [blame] | 46 | #undef DT_UNKNOWN |
| 47 | #undef DT_DIR |
| 48 | #undef DT_REG |
Junio C Hamano | a15c1c6 | 2005-05-12 17:16:04 -0700 | [diff] [blame] | 49 | #undef DT_LNK |
Edgar Toernig | b682969 | 2005-04-30 09:51:03 -0700 | [diff] [blame] | 50 | #define DT_UNKNOWN 0 |
| 51 | #define DT_DIR 1 |
| 52 | #define DT_REG 2 |
Martin Koegler | 40689ae | 2007-04-22 18:43:56 +0200 | [diff] [blame] | 53 | #define DT_LNK 3 |
| 54 | #define DTYPE(de) DT_UNKNOWN |
| 55 | #endif |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 56 | |
Linus Torvalds | 9eec479 | 2007-04-09 21:14:58 -0700 | [diff] [blame] | 57 | /* unknown mode (impossible combination S_IFIFO|S_IFCHR) */ |
| 58 | #define S_IFINVALID 0030000 |
| 59 | |
| 60 | /* |
| 61 | * A "directory link" is a link to another git directory. |
| 62 | * |
| 63 | * The value 0160000 is not normally a valid mode, and |
| 64 | * also just happens to be S_IFDIR + S_IFLNK |
| 65 | * |
| 66 | * NOTE! We *really* shouldn't depend on the S_IFxxx macros |
| 67 | * always having the same values everywhere. We should use |
| 68 | * our internal git values for these things, and then we can |
Martin Waitz | 302b928 | 2007-05-21 22:08:28 +0200 | [diff] [blame] | 69 | * translate that to the OS-specific value. It just so |
| 70 | * happens that everybody shares the same bit representation |
Linus Torvalds | 9eec479 | 2007-04-09 21:14:58 -0700 | [diff] [blame] | 71 | * in the UNIX world (and apparently wider too..) |
| 72 | */ |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 73 | #define S_IFGITLINK 0160000 |
| 74 | #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) |
| 75 | |
| 76 | /* |
| 77 | * Intensive research over the course of many years has shown that |
| 78 | * port 9418 is totally unused by anything else. Or |
Linus Torvalds | ba8a497 | 2005-09-12 11:23:00 -0700 | [diff] [blame] | 79 | * |
| 80 | * Your search - "port 9418" - did not match any documents. |
| 81 | * |
| 82 | * as www.google.com puts it. |
| 83 | * |
| 84 | * This port has been properly assigned for git use by IANA: |
| 85 | * git (Assigned-9418) [I06-050728-0001]. |
| 86 | * |
| 87 | * git 9418/tcp git pack transfer service |
| 88 | * git 9418/udp git pack transfer service |
| 89 | * |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 90 | * with Linus Torvalds <torvalds@osdl.org> as the point of |
| 91 | * contact. September 2005. |
| 92 | * |
| 93 | * See http://www.iana.org/assignments/port-numbers |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 94 | */ |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 95 | #define DEFAULT_GIT_PORT 9418 |
| 96 | |
| 97 | /* |
| 98 | * Basic data structures for the directory cache |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 99 | */ |
| 100 | |
| 101 | #define CACHE_SIGNATURE 0x44495243 /* "DIRC" */ |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 102 | struct cache_header { |
| 103 | unsigned int hdr_signature; |
| 104 | unsigned int hdr_version; |
| 105 | unsigned int hdr_entries; |
| 106 | }; |
| 107 | |
| 108 | /* |
| 109 | * The "cache_time" is just the low 32 bits of the |
| 110 | * time. It doesn't matter if it overflows - we only |
| 111 | * check it for equality in the 32 bits we save. |
| 112 | */ |
| 113 | struct cache_time { |
| 114 | unsigned int sec; |
| 115 | unsigned int nsec; |
| 116 | }; |
| 117 | |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 118 | /* |
| 119 | * dev/ino/uid/gid/size are also just tracked to the low 32 bits |
| 120 | * Again - this is just a (very strong in practice) heuristic that |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 121 | * the inode hasn't changed. |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 122 | * |
| 123 | * We save the fields in big-endian order to allow using the |
| 124 | * index file over NFS transparently. |
| 125 | */ |
| 126 | struct ondisk_cache_entry { |
| 127 | struct cache_time ctime; |
| 128 | struct cache_time mtime; |
| 129 | unsigned int dev; |
| 130 | unsigned int ino; |
| 131 | unsigned int mode; |
| 132 | unsigned int uid; |
| 133 | unsigned int gid; |
| 134 | unsigned int size; |
| 135 | unsigned char sha1[20]; |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 136 | unsigned short flags; |
| 137 | char name[FLEX_ARRAY]; /* more */ |
| 138 | }; |
| 139 | |
| 140 | /* |
| 141 | * This struct is used when CE_EXTENDED bit is 1 |
| 142 | * The struct must match ondisk_cache_entry exactly from |
| 143 | * ctime till flags |
| 144 | */ |
| 145 | struct ondisk_cache_entry_extended { |
| 146 | struct cache_time ctime; |
| 147 | struct cache_time mtime; |
| 148 | unsigned int dev; |
| 149 | unsigned int ino; |
| 150 | unsigned int mode; |
| 151 | unsigned int uid; |
| 152 | unsigned int gid; |
| 153 | unsigned int size; |
| 154 | unsigned char sha1[20]; |
| 155 | unsigned short flags; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 156 | unsigned short flags2; |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 157 | char name[FLEX_ARRAY]; /* more */ |
| 158 | }; |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 159 | |
| 160 | struct cache_entry { |
Kjetil Barvik | fba2f38 | 2009-02-19 21:08:29 +0100 | [diff] [blame] | 161 | struct cache_time ce_ctime; |
| 162 | struct cache_time ce_mtime; |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 163 | unsigned int ce_dev; |
| 164 | unsigned int ce_ino; |
| 165 | unsigned int ce_mode; |
| 166 | unsigned int ce_uid; |
| 167 | unsigned int ce_gid; |
| 168 | unsigned int ce_size; |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 169 | unsigned int ce_flags; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 170 | unsigned char sha1[20]; |
Linus Torvalds | eb7a2f1 | 2008-02-22 20:41:17 -0800 | [diff] [blame] | 171 | struct cache_entry *next; |
Jeff King | 2548183 | 2011-10-06 12:06:09 -0400 | [diff] [blame] | 172 | struct cache_entry *dir_next; |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 173 | char name[FLEX_ARRAY]; /* more */ |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Linus Torvalds | 95fd5bf | 2005-04-15 22:51:44 -0700 | [diff] [blame] | 176 | #define CE_NAMEMASK (0x0fff) |
| 177 | #define CE_STAGEMASK (0x3000) |
Junio C Hamano | 16ce2e4 | 2008-08-16 23:02:08 -0700 | [diff] [blame] | 178 | #define CE_EXTENDED (0x4000) |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 179 | #define CE_VALID (0x8000) |
Junio C Hamano | aee4619 | 2005-04-16 08:33:23 -0700 | [diff] [blame] | 180 | #define CE_STAGESHIFT 12 |
Linus Torvalds | 95fd5bf | 2005-04-15 22:51:44 -0700 | [diff] [blame] | 181 | |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 182 | /* |
| 183 | * Range 0xFFFF0000 in ce_flags is divided into |
| 184 | * two parts: in-memory flags and on-disk ones. |
| 185 | * Flags in CE_EXTENDED_FLAGS will get saved on-disk |
| 186 | * if you want to save a new flag, add it in |
| 187 | * CE_EXTENDED_FLAGS |
| 188 | * |
| 189 | * In-memory only flags |
| 190 | */ |
Nguyễn Thái Ngọc Duy | 2977ffb | 2010-11-27 13:22:16 +0700 | [diff] [blame] | 191 | #define CE_UPDATE (1 << 16) |
| 192 | #define CE_REMOVE (1 << 17) |
| 193 | #define CE_UPTODATE (1 << 18) |
| 194 | #define CE_ADDED (1 << 19) |
Linus Torvalds | a22c637 | 2008-02-22 20:37:40 -0800 | [diff] [blame] | 195 | |
Nguyễn Thái Ngọc Duy | 2977ffb | 2010-11-27 13:22:16 +0700 | [diff] [blame] | 196 | #define CE_HASHED (1 << 20) |
| 197 | #define CE_UNHASHED (1 << 21) |
| 198 | #define CE_WT_REMOVE (1 << 22) /* remove in work directory */ |
| 199 | #define CE_CONFLICTED (1 << 23) |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 200 | |
Nguyễn Thái Ngọc Duy | 2977ffb | 2010-11-27 13:22:16 +0700 | [diff] [blame] | 201 | #define CE_UNPACKED (1 << 24) |
Nguyễn Thái Ngọc Duy | 2431afb | 2010-11-27 13:24:04 +0700 | [diff] [blame] | 202 | #define CE_NEW_SKIP_WORKTREE (1 << 25) |
Junio C Hamano | da165f4 | 2010-01-07 14:59:54 -0800 | [diff] [blame] | 203 | |
Linus Torvalds | d070e3a | 2008-02-22 20:39:21 -0800 | [diff] [blame] | 204 | /* |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 205 | * Extended on-disk flags |
| 206 | */ |
Nguyễn Thái Ngọc Duy | 2977ffb | 2010-11-27 13:22:16 +0700 | [diff] [blame] | 207 | #define CE_INTENT_TO_ADD (1 << 29) |
| 208 | #define CE_SKIP_WORKTREE (1 << 30) |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 209 | /* CE_EXTENDED2 is for future extension */ |
Nguyễn Thái Ngọc Duy | 2977ffb | 2010-11-27 13:22:16 +0700 | [diff] [blame] | 210 | #define CE_EXTENDED2 (1 << 31) |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 211 | |
Nguyễn Thái Ngọc Duy | 44a3691 | 2009-08-20 20:46:57 +0700 | [diff] [blame] | 212 | #define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE) |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Safeguard to avoid saving wrong flags: |
| 216 | * - CE_EXTENDED2 won't get saved until its semantic is known |
| 217 | * - Bits in 0x0000FFFF have been saved in ce_flags already |
| 218 | * - Bits in 0x003F0000 are currently in-memory flags |
| 219 | */ |
| 220 | #if CE_EXTENDED_FLAGS & 0x803FFFFF |
| 221 | #error "CE_EXTENDED_FLAGS out of range" |
| 222 | #endif |
| 223 | |
| 224 | /* |
Linus Torvalds | eb7a2f1 | 2008-02-22 20:41:17 -0800 | [diff] [blame] | 225 | * Copy the sha1 and stat state of a cache entry from one to |
| 226 | * another. But we never change the name, or the hash state! |
| 227 | */ |
| 228 | #define CE_STATE_MASK (CE_HASHED | CE_UNHASHED) |
| 229 | static inline void copy_cache_entry(struct cache_entry *dst, struct cache_entry *src) |
| 230 | { |
| 231 | unsigned int state = dst->ce_flags & CE_STATE_MASK; |
| 232 | |
| 233 | /* Don't copy hash chain and name */ |
| 234 | memcpy(dst, src, offsetof(struct cache_entry, next)); |
| 235 | |
| 236 | /* Restore the hash state */ |
| 237 | dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state; |
| 238 | } |
| 239 | |
Junio C Hamano | 7fec10b | 2008-01-18 23:42:00 -0800 | [diff] [blame] | 240 | static inline unsigned create_ce_flags(size_t len, unsigned stage) |
| 241 | { |
| 242 | if (len >= CE_NAMEMASK) |
| 243 | len = CE_NAMEMASK; |
| 244 | return (len | (stage << CE_STAGESHIFT)); |
| 245 | } |
| 246 | |
| 247 | static inline size_t ce_namelen(const struct cache_entry *ce) |
| 248 | { |
| 249 | size_t len = ce->ce_flags & CE_NAMEMASK; |
| 250 | if (len < CE_NAMEMASK) |
| 251 | return len; |
| 252 | return strlen(ce->name + CE_NAMEMASK) + CE_NAMEMASK; |
| 253 | } |
| 254 | |
Junio C Hamano | aee4619 | 2005-04-16 08:33:23 -0700 | [diff] [blame] | 255 | #define ce_size(ce) cache_entry_size(ce_namelen(ce)) |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 256 | #define ondisk_ce_size(ce) (((ce)->ce_flags & CE_EXTENDED) ? \ |
| 257 | ondisk_cache_entry_extended_size(ce_namelen(ce)) : \ |
| 258 | ondisk_cache_entry_size(ce_namelen(ce))) |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 259 | #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) |
Junio C Hamano | eadb583 | 2008-01-18 23:45:24 -0800 | [diff] [blame] | 260 | #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE) |
Nguyễn Thái Ngọc Duy | 44a3691 | 2009-08-20 20:46:57 +0700 | [diff] [blame] | 261 | #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE) |
Junio C Hamano | eadb583 | 2008-01-18 23:45:24 -0800 | [diff] [blame] | 262 | #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE) |
Junio C Hamano | aee4619 | 2005-04-16 08:33:23 -0700 | [diff] [blame] | 263 | |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 264 | #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644) |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 265 | static inline unsigned int create_ce_mode(unsigned int mode) |
| 266 | { |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 267 | if (S_ISLNK(mode)) |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 268 | return S_IFLNK; |
Martin Waitz | 302b928 | 2007-05-21 22:08:28 +0200 | [diff] [blame] | 269 | if (S_ISDIR(mode) || S_ISGITLINK(mode)) |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 270 | return S_IFGITLINK; |
| 271 | return S_IFREG | ce_permissions(mode); |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 272 | } |
Junio C Hamano | 185c975 | 2007-02-16 22:43:48 -0800 | [diff] [blame] | 273 | static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned int mode) |
| 274 | { |
Johannes Sixt | 78a8d64 | 2007-03-02 22:11:30 +0100 | [diff] [blame] | 275 | extern int trust_executable_bit, has_symlinks; |
| 276 | if (!has_symlinks && S_ISREG(mode) && |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 277 | ce && S_ISLNK(ce->ce_mode)) |
Johannes Sixt | 78a8d64 | 2007-03-02 22:11:30 +0100 | [diff] [blame] | 278 | return ce->ce_mode; |
Junio C Hamano | 185c975 | 2007-02-16 22:43:48 -0800 | [diff] [blame] | 279 | if (!trust_executable_bit && S_ISREG(mode)) { |
Linus Torvalds | 7a51ed6 | 2008-01-14 16:03:17 -0800 | [diff] [blame] | 280 | if (ce && S_ISREG(ce->ce_mode)) |
Junio C Hamano | 185c975 | 2007-02-16 22:43:48 -0800 | [diff] [blame] | 281 | return ce->ce_mode; |
| 282 | return create_ce_mode(0666); |
| 283 | } |
| 284 | return create_ce_mode(mode); |
| 285 | } |
Junio C Hamano | d6b8fc3 | 2008-01-31 01:17:48 -0800 | [diff] [blame] | 286 | static inline int ce_to_dtype(const struct cache_entry *ce) |
| 287 | { |
| 288 | unsigned ce_mode = ntohl(ce->ce_mode); |
| 289 | if (S_ISREG(ce_mode)) |
| 290 | return DT_REG; |
| 291 | else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode)) |
| 292 | return DT_DIR; |
| 293 | else if (S_ISLNK(ce_mode)) |
| 294 | return DT_LNK; |
| 295 | else |
| 296 | return DT_UNKNOWN; |
| 297 | } |
René Scharfe | b90d9b8 | 2010-10-04 12:53:11 +0200 | [diff] [blame] | 298 | static inline unsigned int canon_mode(unsigned int mode) |
| 299 | { |
| 300 | if (S_ISREG(mode)) |
| 301 | return S_IFREG | ce_permissions(mode); |
| 302 | if (S_ISLNK(mode)) |
| 303 | return S_IFLNK; |
| 304 | if (S_ISDIR(mode)) |
| 305 | return S_IFDIR; |
| 306 | return S_IFGITLINK; |
| 307 | } |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 308 | |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 309 | #define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7) |
René Scharfe | ee7825b | 2011-10-25 20:00:04 +0200 | [diff] [blame] | 310 | #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) |
Nguyễn Thái Ngọc Duy | 06aaaa0 | 2008-10-01 11:04:01 +0700 | [diff] [blame] | 311 | #define ondisk_cache_entry_size(len) flexible_size(ondisk_cache_entry,len) |
| 312 | #define ondisk_cache_entry_extended_size(len) flexible_size(ondisk_cache_entry_extended,len) |
Linus Torvalds | f5cabd1 | 2005-04-15 21:45:38 -0700 | [diff] [blame] | 313 | |
Junio C Hamano | 228e94f | 2007-04-01 18:14:06 -0700 | [diff] [blame] | 314 | struct index_state { |
| 315 | struct cache_entry **cache; |
| 316 | unsigned int cache_nr, cache_alloc, cache_changed; |
Junio C Hamano | cfc5789 | 2009-12-25 00:30:51 -0800 | [diff] [blame] | 317 | struct string_list *resolve_undo; |
Junio C Hamano | 228e94f | 2007-04-01 18:14:06 -0700 | [diff] [blame] | 318 | struct cache_tree *cache_tree; |
Kjetil Barvik | fba2f38 | 2009-02-19 21:08:29 +0100 | [diff] [blame] | 319 | struct cache_time timestamp; |
Junio C Hamano | 913e0e9 | 2008-08-23 12:57:30 -0700 | [diff] [blame] | 320 | unsigned name_hash_initialized : 1, |
| 321 | initialized : 1; |
Linus Torvalds | cf55870 | 2008-01-22 18:41:14 -0800 | [diff] [blame] | 322 | struct hash_table name_hash; |
Junio C Hamano | 228e94f | 2007-04-01 18:14:06 -0700 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | extern struct index_state the_index; |
| 326 | |
Linus Torvalds | 96872bc | 2008-03-21 13:16:24 -0700 | [diff] [blame] | 327 | /* Name hashing */ |
| 328 | extern void add_name_hash(struct index_state *istate, struct cache_entry *ce); |
| 329 | /* |
| 330 | * We don't actually *remove* it, we can just mark it invalid so that |
| 331 | * we won't find it in lookups. |
| 332 | * |
| 333 | * Not only would we have to search the lists (simple enough), but |
| 334 | * we'd also have to rehash other hash buckets in case this makes the |
| 335 | * hash bucket empty (common). So it's much better to just mark |
| 336 | * it. |
| 337 | */ |
| 338 | static inline void remove_name_hash(struct cache_entry *ce) |
| 339 | { |
| 340 | ce->ce_flags |= CE_UNHASHED; |
| 341 | } |
| 342 | |
| 343 | |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 344 | #ifndef NO_THE_INDEX_COMPATIBILITY_MACROS |
Junio C Hamano | 228e94f | 2007-04-01 18:14:06 -0700 | [diff] [blame] | 345 | #define active_cache (the_index.cache) |
| 346 | #define active_nr (the_index.cache_nr) |
| 347 | #define active_alloc (the_index.cache_alloc) |
| 348 | #define active_cache_changed (the_index.cache_changed) |
| 349 | #define active_cache_tree (the_index.cache_tree) |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 350 | |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 351 | #define read_cache() read_index(&the_index) |
| 352 | #define read_cache_from(path) read_index_from(&the_index, (path)) |
Linus Torvalds | 671c9b7 | 2008-11-13 16:36:30 -0800 | [diff] [blame] | 353 | #define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec)) |
Junio C Hamano | fa7b3c2 | 2008-11-12 11:52:35 -0800 | [diff] [blame] | 354 | #define is_cache_unborn() is_index_unborn(&the_index) |
Miklos Vajna | e46bbcf | 2008-06-27 18:21:58 +0200 | [diff] [blame] | 355 | #define read_cache_unmerged() read_index_unmerged(&the_index) |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 356 | #define write_cache(newfd, cache, entries) write_index(&the_index, (newfd)) |
| 357 | #define discard_cache() discard_index(&the_index) |
Daniel Barkalow | 94a5728 | 2008-02-07 11:40:13 -0500 | [diff] [blame] | 358 | #define unmerged_cache() unmerged_index(&the_index) |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 359 | #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) |
| 360 | #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 361 | #define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name)) |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 362 | #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) |
| 363 | #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) |
Junio C Hamano | 38ed1d8 | 2008-05-21 12:04:34 -0700 | [diff] [blame] | 364 | #define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags)) |
| 365 | #define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags)) |
Matthieu Moy | 3deffc5 | 2009-08-21 10:57:59 +0200 | [diff] [blame] | 366 | #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL) |
Junio C Hamano | 4bd5b7d | 2007-11-10 00:15:03 -0800 | [diff] [blame] | 367 | #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) |
| 368 | #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) |
Linus Torvalds | cd2fef5 | 2008-03-21 15:55:19 -0700 | [diff] [blame] | 369 | #define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase)) |
Jeff King | 98fa473 | 2008-10-16 11:07:26 -0400 | [diff] [blame] | 370 | #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) |
Junio C Hamano | cfc5789 | 2009-12-25 00:30:51 -0800 | [diff] [blame] | 371 | #define resolve_undo_clear() resolve_undo_clear_index(&the_index) |
Junio C Hamano | 8aa3856 | 2009-12-25 13:40:02 -0800 | [diff] [blame] | 372 | #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at) |
Junio C Hamano | 4421a82 | 2009-12-25 11:57:11 -0800 | [diff] [blame] | 373 | #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec) |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 374 | #endif |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 375 | |
Junio C Hamano | edaec3f | 2007-02-28 11:45:56 -0800 | [diff] [blame] | 376 | enum object_type { |
| 377 | OBJ_BAD = -1, |
| 378 | OBJ_NONE = 0, |
| 379 | OBJ_COMMIT = 1, |
| 380 | OBJ_TREE = 2, |
| 381 | OBJ_BLOB = 3, |
| 382 | OBJ_TAG = 4, |
| 383 | /* 5 for future expansion */ |
| 384 | OBJ_OFS_DELTA = 6, |
| 385 | OBJ_REF_DELTA = 7, |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 386 | OBJ_ANY, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 387 | OBJ_MAX |
Junio C Hamano | edaec3f | 2007-02-28 11:45:56 -0800 | [diff] [blame] | 388 | }; |
| 389 | |
Junio C Hamano | b45563a | 2007-11-30 22:22:38 -0800 | [diff] [blame] | 390 | static inline enum object_type object_type(unsigned int mode) |
| 391 | { |
| 392 | return S_ISDIR(mode) ? OBJ_TREE : |
| 393 | S_ISGITLINK(mode) ? OBJ_COMMIT : |
| 394 | OBJ_BLOB; |
| 395 | } |
| 396 | |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 397 | #define GIT_DIR_ENVIRONMENT "GIT_DIR" |
Josh Triplett | a1bea2c | 2011-07-05 10:54:44 -0700 | [diff] [blame] | 398 | #define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE" |
Matthias Lederhofer | 892c41b | 2007-06-06 09:10:42 +0200 | [diff] [blame] | 399 | #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 400 | #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" |
Junio C Hamano | d19938a | 2005-05-09 17:57:56 -0700 | [diff] [blame] | 401 | #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 402 | #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" |
Junio C Hamano | 5da5c8f | 2005-07-30 00:58:28 -0700 | [diff] [blame] | 403 | #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" |
Junio C Hamano | d4ebc36 | 2006-12-19 01:28:15 -0800 | [diff] [blame] | 404 | #define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR" |
| 405 | #define CONFIG_ENVIRONMENT "GIT_CONFIG" |
Jeff King | 2b64fc8 | 2010-08-23 15:16:00 -0400 | [diff] [blame] | 406 | #define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS" |
Junio C Hamano | d4ebc36 | 2006-12-19 01:28:15 -0800 | [diff] [blame] | 407 | #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" |
David Reiss | 0454dd9 | 2008-05-19 23:49:26 -0700 | [diff] [blame] | 408 | #define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES" |
Christian Couder | 6476b38 | 2009-11-18 07:50:58 +0100 | [diff] [blame] | 409 | #define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS" |
Junio C Hamano | d0bfd02 | 2007-04-12 01:07:32 -0700 | [diff] [blame] | 410 | #define GITATTRIBUTES_FILE ".gitattributes" |
| 411 | #define INFOATTRIBUTES_FILE "info/attributes" |
Junio C Hamano | f48fd68 | 2007-04-14 08:54:37 -0700 | [diff] [blame] | 412 | #define ATTRIBUTE_MACRO_PREFIX "[attr]" |
Johannes Schindelin | a97a746 | 2009-10-09 12:21:57 +0200 | [diff] [blame] | 413 | #define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" |
| 414 | #define GIT_NOTES_DEFAULT_REF "refs/notes/commits" |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 415 | #define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 416 | #define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" |
| 417 | #define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE" |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 418 | |
Giuseppe Bilotta | 48a7c1c | 2010-02-25 00:34:14 +0100 | [diff] [blame] | 419 | /* |
| 420 | * Repository-local GIT_* environment variables |
| 421 | * The array is NULL-terminated to simplify its usage in contexts such |
| 422 | * environment creation or simple walk of the list. |
| 423 | * The number of non-NULL entries is available as a macro. |
| 424 | */ |
Jonathan Nieder | 655e8d9 | 2010-08-24 01:41:14 -0500 | [diff] [blame] | 425 | #define LOCAL_REPO_ENV_SIZE 9 |
Giuseppe Bilotta | 48a7c1c | 2010-02-25 00:34:14 +0100 | [diff] [blame] | 426 | extern const char *const local_repo_env[LOCAL_REPO_ENV_SIZE + 1]; |
| 427 | |
Junio C Hamano | 7d1864c | 2007-01-07 02:00:28 -0800 | [diff] [blame] | 428 | extern int is_bare_repository_cfg; |
| 429 | extern int is_bare_repository(void); |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 430 | extern int is_inside_git_dir(void); |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 431 | extern char *git_work_tree_cfg; |
Matthias Lederhofer | 892c41b | 2007-06-06 09:10:42 +0200 | [diff] [blame] | 432 | extern int is_inside_work_tree(void); |
Dmitry Potapov | d2b0708 | 2008-09-27 12:41:50 +0400 | [diff] [blame] | 433 | extern int have_git_dir(void); |
Pierre Habouzit | c5fba16 | 2006-08-23 12:39:11 +0200 | [diff] [blame] | 434 | extern const char *get_git_dir(void); |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 435 | extern char *get_object_directory(void); |
| 436 | extern char *get_index_file(void); |
Junio C Hamano | 5da5c8f | 2005-07-30 00:58:28 -0700 | [diff] [blame] | 437 | extern char *get_graft_file(void); |
Johannes Schindelin | d7ac12b | 2007-08-01 01:29:38 +0100 | [diff] [blame] | 438 | extern int set_git_dir(const char *path); |
Josh Triplett | a1bea2c | 2011-07-05 10:54:44 -0700 | [diff] [blame] | 439 | extern const char *get_git_namespace(void); |
| 440 | extern const char *strip_namespace(const char *namespaced_ref); |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 441 | extern const char *get_git_work_tree(void); |
Junio C Hamano | 13d6ec9 | 2011-08-22 14:04:56 -0700 | [diff] [blame] | 442 | extern const char *read_gitfile(const char *path); |
Fredrik Gustafsson | abc0682 | 2011-08-15 23:17:46 +0200 | [diff] [blame] | 443 | extern const char *resolve_gitdir(const char *suspect); |
Daniel Barkalow | 19757d8 | 2008-04-27 13:39:21 -0400 | [diff] [blame] | 444 | extern void set_git_work_tree(const char *tree); |
Junio C Hamano | 8ac069a | 2005-05-09 22:57:58 -0700 | [diff] [blame] | 445 | |
| 446 | #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 447 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 448 | extern const char **get_pathspec(const char *prefix, const char **pathspec); |
Mike Hommey | 59f0f2f | 2007-11-03 12:23:11 +0100 | [diff] [blame] | 449 | extern void setup_work_tree(void); |
Junio C Hamano | 4ca0660 | 2005-11-25 23:14:15 -0800 | [diff] [blame] | 450 | extern const char *setup_git_directory_gently(int *); |
Linus Torvalds | d288a70 | 2005-08-16 18:06:34 -0700 | [diff] [blame] | 451 | extern const char *setup_git_directory(void); |
Nguyễn Thái Ngọc Duy | edc54fb | 2010-11-11 21:08:03 +0700 | [diff] [blame] | 452 | extern char *prefix_path(const char *prefix, int len, const char *path); |
Junio C Hamano | 4ca0660 | 2005-11-25 23:14:15 -0800 | [diff] [blame] | 453 | extern const char *prefix_filename(const char *prefix, int len, const char *path); |
Junio C Hamano | c6e8c80 | 2009-10-18 00:27:24 -0700 | [diff] [blame] | 454 | extern int check_filename(const char *prefix, const char *name); |
Linus Torvalds | e23d0b4 | 2006-04-26 10:15:54 -0700 | [diff] [blame] | 455 | extern void verify_filename(const char *prefix, const char *name); |
Junio C Hamano | ea92f41 | 2006-04-26 15:09:27 -0700 | [diff] [blame] | 456 | extern void verify_non_filename(const char *prefix, const char *name); |
Linus Torvalds | d288a70 | 2005-08-16 18:06:34 -0700 | [diff] [blame] | 457 | |
Daniel Barkalow | f225aeb | 2008-04-27 13:39:27 -0400 | [diff] [blame] | 458 | #define INIT_DB_QUIET 0x0001 |
| 459 | |
Nguyễn Thái Ngọc Duy | b57fb80 | 2011-03-19 22:16:56 +0700 | [diff] [blame] | 460 | extern int set_git_dir_init(const char *git_dir, const char *real_git_dir, int); |
Daniel Barkalow | f225aeb | 2008-04-27 13:39:27 -0400 | [diff] [blame] | 461 | extern int init_db(const char *template_dir, unsigned int flags); |
| 462 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 463 | #define alloc_nr(x) (((x)+16)*3/2) |
| 464 | |
Jeff King | 6815e56 | 2007-06-11 09:39:44 -0400 | [diff] [blame] | 465 | /* |
| 466 | * Realloc the buffer pointed at by variable 'x' so that it can hold |
| 467 | * at least 'nr' entries; the number of entries currently allocated |
| 468 | * is 'alloc', using the standard growing factor alloc_nr() macro. |
| 469 | * |
Jonathan Nieder | 01f6fd4 | 2010-10-08 11:46:59 -0500 | [diff] [blame] | 470 | * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'. |
Jeff King | 6815e56 | 2007-06-11 09:39:44 -0400 | [diff] [blame] | 471 | */ |
| 472 | #define ALLOC_GROW(x, nr, alloc) \ |
| 473 | do { \ |
Jeff King | c927e6c | 2007-06-16 18:37:39 -0400 | [diff] [blame] | 474 | if ((nr) > alloc) { \ |
Junio C Hamano | 4234a76 | 2007-06-11 22:10:55 -0700 | [diff] [blame] | 475 | if (alloc_nr(alloc) < (nr)) \ |
| 476 | alloc = (nr); \ |
| 477 | else \ |
| 478 | alloc = alloc_nr(alloc); \ |
Jeff King | 6815e56 | 2007-06-11 09:39:44 -0400 | [diff] [blame] | 479 | x = xrealloc((x), alloc * sizeof(*(x))); \ |
| 480 | } \ |
Jonathan Nieder | 9874606 | 2010-08-12 17:11:15 -0500 | [diff] [blame] | 481 | } while (0) |
Jeff King | 6815e56 | 2007-06-11 09:39:44 -0400 | [diff] [blame] | 482 | |
Linus Torvalds | 734aab7 | 2005-04-09 09:48:20 -0700 | [diff] [blame] | 483 | /* Initialize and use the cache information */ |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 484 | extern int read_index(struct index_state *); |
Linus Torvalds | 671c9b7 | 2008-11-13 16:36:30 -0800 | [diff] [blame] | 485 | extern int read_index_preload(struct index_state *, const char **pathspec); |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 486 | extern int read_index_from(struct index_state *, const char *path); |
Junio C Hamano | fa7b3c2 | 2008-11-12 11:52:35 -0800 | [diff] [blame] | 487 | extern int is_index_unborn(struct index_state *); |
Miklos Vajna | e46bbcf | 2008-06-27 18:21:58 +0200 | [diff] [blame] | 488 | extern int read_index_unmerged(struct index_state *); |
Kjetil Barvik | e1afca4 | 2009-02-23 19:02:57 +0100 | [diff] [blame] | 489 | extern int write_index(struct index_state *, int newfd); |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 490 | extern int discard_index(struct index_state *); |
Linus Torvalds | d1f128b | 2008-03-06 12:46:09 -0800 | [diff] [blame] | 491 | extern int unmerged_index(const struct index_state *); |
Linus Torvalds | 8dcf39c | 2006-05-18 12:07:31 -0700 | [diff] [blame] | 492 | extern int verify_path(const char *path); |
Linus Torvalds | cd2fef5 | 2008-03-21 15:55:19 -0700 | [diff] [blame] | 493 | extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int igncase); |
Linus Torvalds | d1f128b | 2008-03-06 12:46:09 -0800 | [diff] [blame] | 494 | extern int index_name_pos(const struct index_state *, const char *name, int namelen); |
Junio C Hamano | 192268c | 2005-05-07 21:55:21 -0700 | [diff] [blame] | 495 | #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ |
| 496 | #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] | 497 | #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ |
Junio C Hamano | af3785d | 2007-08-09 13:42:50 -0700 | [diff] [blame] | 498 | #define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */ |
Junio C Hamano | 3942581 | 2008-08-21 01:44:53 -0700 | [diff] [blame] | 499 | #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */ |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 500 | extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option); |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 501 | extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name); |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 502 | extern int remove_index_entry_at(struct index_state *, int pos); |
Kjetil Barvik | 36419c8 | 2009-02-18 23:18:03 +0100 | [diff] [blame] | 503 | extern void remove_marked_cache_entries(struct index_state *istate); |
Junio C Hamano | 4aab5b4 | 2007-04-01 23:26:07 -0700 | [diff] [blame] | 504 | extern int remove_file_from_index(struct index_state *, const char *path); |
Junio C Hamano | 38ed1d8 | 2008-05-21 12:04:34 -0700 | [diff] [blame] | 505 | #define ADD_CACHE_VERBOSE 1 |
| 506 | #define ADD_CACHE_PRETEND 2 |
Junio C Hamano | 0166592 | 2008-05-25 14:03:50 -0700 | [diff] [blame] | 507 | #define ADD_CACHE_IGNORE_ERRORS 4 |
Junio C Hamano | 041aee3 | 2008-07-21 01:24:17 -0700 | [diff] [blame] | 508 | #define ADD_CACHE_IGNORE_REMOVAL 8 |
Junio C Hamano | 3942581 | 2008-08-21 01:44:53 -0700 | [diff] [blame] | 509 | #define ADD_CACHE_INTENT 16 |
Junio C Hamano | 38ed1d8 | 2008-05-21 12:04:34 -0700 | [diff] [blame] | 510 | extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags); |
| 511 | extern int add_file_to_index(struct index_state *, const char *path, int flags); |
Carlos Rica | 6640f88 | 2007-09-11 05:17:28 +0200 | [diff] [blame] | 512 | extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); |
Brad Roberts | dbbce55 | 2005-05-14 19:04:25 -0700 | [diff] [blame] | 513 | extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); |
Jeff King | 98fa473 | 2008-10-16 11:07:26 -0400 | [diff] [blame] | 514 | extern int index_name_is_other(const struct index_state *, const char *, int); |
Junio C Hamano | 4bd5b7d | 2007-11-10 00:15:03 -0800 | [diff] [blame] | 515 | |
| 516 | /* do stat comparison even if CE_VALID is true */ |
| 517 | #define CE_MATCH_IGNORE_VALID 01 |
| 518 | /* do not check the contents but report dirty on racily-clean entries */ |
Nguyễn Thái Ngọc Duy | 56cac48 | 2009-12-14 18:43:58 +0700 | [diff] [blame] | 519 | #define CE_MATCH_RACY_IS_DIRTY 02 |
| 520 | /* do stat comparison even if CE_SKIP_WORKTREE is true */ |
| 521 | #define CE_MATCH_IGNORE_SKIP_WORKTREE 04 |
Linus Torvalds | d1f128b | 2008-03-06 12:46:09 -0800 | [diff] [blame] | 522 | extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int); |
| 523 | extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int); |
Junio C Hamano | 4bd5b7d | 2007-11-10 00:15:03 -0800 | [diff] [blame] | 524 | |
Nguyễn Thái Ngọc Duy | 0602f3e | 2010-12-15 22:02:36 +0700 | [diff] [blame] | 525 | struct pathspec { |
| 526 | const char **raw; /* get_pathspec() result, not freed by free_pathspec() */ |
| 527 | int nr; |
Jonathan Nieder | 9ddf172 | 2011-03-15 22:42:32 -0500 | [diff] [blame] | 528 | unsigned int has_wildcard:1; |
| 529 | unsigned int recursive:1; |
Nguyễn Thái Ngọc Duy | bc96cc8 | 2010-12-15 22:02:44 +0700 | [diff] [blame] | 530 | int max_depth; |
Nguyễn Thái Ngọc Duy | 0602f3e | 2010-12-15 22:02:36 +0700 | [diff] [blame] | 531 | struct pathspec_item { |
| 532 | const char *match; |
| 533 | int len; |
Junio C Hamano | 33e0f62 | 2011-04-05 09:30:36 -0700 | [diff] [blame] | 534 | unsigned int use_wildcard:1; |
Nguyễn Thái Ngọc Duy | 0602f3e | 2010-12-15 22:02:36 +0700 | [diff] [blame] | 535 | } *items; |
| 536 | }; |
| 537 | |
| 538 | extern int init_pathspec(struct pathspec *, const char **); |
| 539 | extern void free_pathspec(struct pathspec *); |
Nguyễn Thái Ngọc Duy | eb9cb55 | 2010-12-17 19:43:07 +0700 | [diff] [blame] | 540 | extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec); |
Junio C Hamano | c4ce46f | 2011-05-08 01:47:33 -0700 | [diff] [blame] | 541 | |
| 542 | #define HASH_WRITE_OBJECT 1 |
| 543 | #define HASH_FORMAT_CHECK 2 |
| 544 | extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); |
| 545 | extern int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags); |
Junio C Hamano | 415e96c | 2005-05-15 14:23:12 -0700 | [diff] [blame] | 546 | extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); |
| 547 | |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 548 | #define REFRESH_REALLY 0x0001 /* ignore_valid */ |
| 549 | #define REFRESH_UNMERGED 0x0002 /* allow unmerged */ |
| 550 | #define REFRESH_QUIET 0x0004 /* be quiet about it */ |
| 551 | #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ |
Junio C Hamano | 3f1b7b6 | 2008-07-19 23:25:00 -0700 | [diff] [blame] | 552 | #define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */ |
Matthieu Moy | 43673fd | 2009-08-21 10:57:58 +0200 | [diff] [blame] | 553 | #define REFRESH_IN_PORCELAIN 0x0020 /* user friendly output, not "needs update" */ |
Jonathan Nieder | 046613c | 2011-02-22 22:43:23 +0000 | [diff] [blame] | 554 | extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen, const char *header_msg); |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 555 | |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 556 | struct lock_file { |
| 557 | struct lock_file *next; |
Johannes Schindelin | 4723ee9 | 2007-11-13 21:05:03 +0100 | [diff] [blame] | 558 | int fd; |
Junio C Hamano | 5e635e3 | 2007-04-21 03:11:10 -0700 | [diff] [blame] | 559 | pid_t owner; |
Junio C Hamano | 1084b84 | 2007-01-02 11:19:05 -0800 | [diff] [blame] | 560 | char on_list; |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 561 | char filename[PATH_MAX]; |
Junio C Hamano | 415e96c | 2005-05-15 14:23:12 -0700 | [diff] [blame] | 562 | }; |
Junio C Hamano | acd3b9e | 2008-10-17 15:44:39 -0700 | [diff] [blame] | 563 | #define LOCK_DIE_ON_ERROR 1 |
| 564 | #define LOCK_NODEREF 2 |
Miklos Vajna | 1b018fd | 2009-09-27 01:15:09 +0200 | [diff] [blame] | 565 | extern int unable_to_lock_error(const char *path, int err); |
Matthieu Moy | e43a6fd | 2009-02-19 13:54:18 +0100 | [diff] [blame] | 566 | extern NORETURN void unable_to_lock_index_die(const char *path, int err); |
Junio C Hamano | 40aaae8 | 2006-08-12 01:03:47 -0700 | [diff] [blame] | 567 | extern int hold_lock_file_for_update(struct lock_file *, const char *path, int); |
Daniel Barkalow | ea3cd5c | 2008-04-17 19:32:26 -0400 | [diff] [blame] | 568 | extern int hold_lock_file_for_append(struct lock_file *, const char *path, int); |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 569 | extern int commit_lock_file(struct lock_file *); |
Junio C Hamano | ccdc4ec | 2011-03-21 10:16:10 -0700 | [diff] [blame] | 570 | extern void update_index_if_able(struct index_state *, struct lock_file *); |
Junio C Hamano | 30ca07a | 2007-03-31 23:09:02 -0700 | [diff] [blame] | 571 | |
| 572 | extern int hold_locked_index(struct lock_file *, int); |
| 573 | extern int commit_locked_index(struct lock_file *); |
Junio C Hamano | 5e7f56a | 2007-03-31 23:27:41 -0700 | [diff] [blame] | 574 | extern void set_alternate_index_output(const char *); |
Brandon Casey | d6cf61b | 2008-01-16 11:05:32 -0800 | [diff] [blame] | 575 | extern int close_lock_file(struct lock_file *); |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 576 | extern void rollback_lock_file(struct lock_file *); |
Miklos Vajna | eca35a2 | 2008-10-26 03:33:56 +0100 | [diff] [blame] | 577 | extern int delete_ref(const char *, const unsigned char *sha1, int delopt); |
Linus Torvalds | 734aab7 | 2005-04-09 09:48:20 -0700 | [diff] [blame] | 578 | |
Junio C Hamano | 2ae1c53 | 2006-02-27 14:47:45 -0800 | [diff] [blame] | 579 | /* Environment bits from configuration mechanism */ |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 580 | extern int trust_executable_bit; |
Alex Riesen | 1ce4790 | 2008-07-28 08:31:28 +0200 | [diff] [blame] | 581 | extern int trust_ctime; |
Junio C Hamano | 9378c16 | 2007-06-24 15:11:24 -0700 | [diff] [blame] | 582 | extern int quote_path_fully; |
Johannes Sixt | 78a8d64 | 2007-03-02 22:11:30 +0100 | [diff] [blame] | 583 | extern int has_symlinks; |
Linus Torvalds | dce9648 | 2010-10-28 11:28:04 -0700 | [diff] [blame] | 584 | extern int minimum_abbrev, default_abbrev; |
Linus Torvalds | 0a9b88b | 2008-03-21 16:52:46 -0700 | [diff] [blame] | 585 | extern int ignore_case; |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 586 | extern int assume_unchanged; |
Junio C Hamano | 9f0bb90 | 2006-05-02 00:40:24 -0700 | [diff] [blame] | 587 | extern int prefer_symlink_refs; |
Shawn Pearce | 6de08ae | 2006-05-17 05:55:40 -0400 | [diff] [blame] | 588 | extern int log_all_ref_updates; |
Junio C Hamano | 2f8acdb | 2006-03-20 18:45:47 -0800 | [diff] [blame] | 589 | extern int warn_ambiguous_refs; |
Johannes Schindelin | 457f06d | 2005-12-22 23:13:56 +0100 | [diff] [blame] | 590 | extern int shared_repository; |
Junio C Hamano | 2ae1c53 | 2006-02-27 14:47:45 -0800 | [diff] [blame] | 591 | extern const char *apply_default_whitespace; |
Giuseppe Bilotta | 86c91f9 | 2009-08-04 13:16:49 +0200 | [diff] [blame] | 592 | extern const char *apply_default_ignorewhitespace; |
Junio C Hamano | 64589a0 | 2011-10-06 13:22:24 -0500 | [diff] [blame] | 593 | extern const char *git_attributes_file; |
Joachim B Haga | 12f6c30 | 2006-07-03 22:11:47 +0200 | [diff] [blame] | 594 | extern int zlib_compression_level; |
Dana How | 960ccca | 2007-05-09 13:56:50 -0700 | [diff] [blame] | 595 | extern int core_compression_level; |
| 596 | extern int core_compression_seen; |
Shawn O. Pearce | 60bb8b1 | 2006-12-23 02:34:28 -0500 | [diff] [blame] | 597 | extern size_t packed_git_window_size; |
Shawn O. Pearce | 77ccc5b | 2006-12-23 02:33:35 -0500 | [diff] [blame] | 598 | extern size_t packed_git_limit; |
Shawn O. Pearce | 18bdec1 | 2007-03-19 01:14:37 -0400 | [diff] [blame] | 599 | extern size_t delta_base_cache_limit; |
Junio C Hamano | 1536628 | 2011-04-05 10:44:11 -0700 | [diff] [blame] | 600 | extern unsigned long big_file_threshold; |
Junio C Hamano | 568508e | 2011-10-28 14:48:40 -0700 | [diff] [blame] | 601 | extern unsigned long pack_size_limit_cfg; |
Christian Couder | dae556b | 2009-01-23 10:07:46 +0100 | [diff] [blame] | 602 | extern int read_replace_refs; |
Linus Torvalds | aafe9fb | 2008-06-18 15:18:44 -0700 | [diff] [blame] | 603 | extern int fsync_object_files; |
Linus Torvalds | 671c9b7 | 2008-11-13 16:36:30 -0800 | [diff] [blame] | 604 | extern int core_preload_index; |
Nguyễn Thái Ngọc Duy | 08aefc9 | 2009-08-20 20:47:08 +0700 | [diff] [blame] | 605 | extern int core_apply_sparse_checkout; |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 606 | |
Jay Soffian | 9ed36cf | 2008-02-19 11:24:37 -0500 | [diff] [blame] | 607 | enum branch_track { |
Alex Riesen | 9188ed8 | 2008-08-21 19:23:20 +0200 | [diff] [blame] | 608 | BRANCH_TRACK_UNSPECIFIED = -1, |
Jay Soffian | 9ed36cf | 2008-02-19 11:24:37 -0500 | [diff] [blame] | 609 | BRANCH_TRACK_NEVER = 0, |
| 610 | BRANCH_TRACK_REMOTE, |
| 611 | BRANCH_TRACK_ALWAYS, |
| 612 | BRANCH_TRACK_EXPLICIT, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 613 | BRANCH_TRACK_OVERRIDE |
Jay Soffian | 9ed36cf | 2008-02-19 11:24:37 -0500 | [diff] [blame] | 614 | }; |
| 615 | |
Dustin Sallings | c998ae9 | 2008-05-10 15:36:29 -0700 | [diff] [blame] | 616 | enum rebase_setup_type { |
| 617 | AUTOREBASE_NEVER = 0, |
| 618 | AUTOREBASE_LOCAL, |
| 619 | AUTOREBASE_REMOTE, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 620 | AUTOREBASE_ALWAYS |
Dustin Sallings | c998ae9 | 2008-05-10 15:36:29 -0700 | [diff] [blame] | 621 | }; |
| 622 | |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 623 | enum push_default_type { |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 624 | PUSH_DEFAULT_NOTHING = 0, |
| 625 | PUSH_DEFAULT_MATCHING, |
Johan Herland | 53c4031 | 2011-02-16 01:54:24 +0100 | [diff] [blame] | 626 | PUSH_DEFAULT_UPSTREAM, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 627 | PUSH_DEFAULT_CURRENT |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 628 | }; |
| 629 | |
Jay Soffian | 9ed36cf | 2008-02-19 11:24:37 -0500 | [diff] [blame] | 630 | extern enum branch_track git_branch_track; |
Dustin Sallings | c998ae9 | 2008-05-10 15:36:29 -0700 | [diff] [blame] | 631 | extern enum rebase_setup_type autorebase; |
Finn Arne Gangstad | 5215374 | 2009-03-16 16:42:51 +0100 | [diff] [blame] | 632 | extern enum push_default_type push_default; |
Jay Soffian | 9ed36cf | 2008-02-19 11:24:37 -0500 | [diff] [blame] | 633 | |
Johannes Schindelin | 348df16 | 2009-04-28 00:32:25 +0200 | [diff] [blame] | 634 | enum object_creation_mode { |
| 635 | OBJECT_CREATION_USES_HARDLINKS = 0, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 636 | OBJECT_CREATION_USES_RENAMES = 1 |
Johannes Schindelin | 348df16 | 2009-04-28 00:32:25 +0200 | [diff] [blame] | 637 | }; |
| 638 | |
| 639 | extern enum object_creation_mode object_creation_mode; |
Johannes Schindelin | be66a6c | 2009-04-25 11:57:14 +0200 | [diff] [blame] | 640 | |
Johannes Schindelin | a97a746 | 2009-10-09 12:21:57 +0200 | [diff] [blame] | 641 | extern char *notes_ref_name; |
| 642 | |
Johannes Schindelin | 7f3140c | 2009-07-23 17:33:49 +0200 | [diff] [blame] | 643 | extern int grafts_replace_parents; |
| 644 | |
Junio C Hamano | ab9cb76 | 2005-11-25 15:59:09 -0800 | [diff] [blame] | 645 | #define GIT_REPO_VERSION 0 |
| 646 | extern int repository_format_version; |
| 647 | extern int check_repository_format(void); |
| 648 | |
Linus Torvalds | 734aab7 | 2005-04-09 09:48:20 -0700 | [diff] [blame] | 649 | #define MTIME_CHANGED 0x0001 |
| 650 | #define CTIME_CHANGED 0x0002 |
| 651 | #define OWNER_CHANGED 0x0004 |
| 652 | #define MODE_CHANGED 0x0008 |
| 653 | #define INODE_CHANGED 0x0010 |
| 654 | #define DATA_CHANGED 0x0020 |
Kay Sievers | 8ae0a8c | 2005-05-05 14:38:25 +0200 | [diff] [blame] | 655 | #define TYPE_CHANGED 0x0040 |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 656 | |
Alex Riesen | 108bebe | 2008-10-26 22:59:13 +0100 | [diff] [blame] | 657 | extern char *mksnpath(char *buf, size_t n, const char *fmt, ...) |
| 658 | __attribute__((format (printf, 3, 4))); |
Alex Riesen | fe2d777 | 2008-10-27 10:22:21 +0100 | [diff] [blame] | 659 | extern char *git_snpath(char *buf, size_t n, const char *fmt, ...) |
| 660 | __attribute__((format (printf, 3, 4))); |
Alex Riesen | aba13e7 | 2008-10-27 11:17:51 +0100 | [diff] [blame] | 661 | extern char *git_pathdup(const char *fmt, ...) |
| 662 | __attribute__((format (printf, 1, 2))); |
Alex Riesen | 108bebe | 2008-10-26 22:59:13 +0100 | [diff] [blame] | 663 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 664 | /* Return a statically allocated filename matching the sha1 signature */ |
Timo Sirainen | 4ec99bf | 2005-08-09 18:30:22 +0300 | [diff] [blame] | 665 | extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
| 666 | extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
Heiko Voigt | 0bad611 | 2010-07-07 15:39:11 +0200 | [diff] [blame] | 667 | extern char *git_path_submodule(const char *path, const char *fmt, ...) |
| 668 | __attribute__((format (printf, 2, 3))); |
| 669 | |
Linus Torvalds | 73134b6 | 2005-04-10 14:03:58 -0700 | [diff] [blame] | 670 | extern char *sha1_file_name(const unsigned char *sha1); |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 671 | extern char *sha1_pack_name(const unsigned char *sha1); |
| 672 | extern char *sha1_pack_index_name(const unsigned char *sha1); |
Junio C Hamano | 013f276 | 2005-10-11 15:22:48 -0700 | [diff] [blame] | 673 | extern const char *find_unique_abbrev(const unsigned char *sha1, int); |
Junio C Hamano | 88cd621 | 2005-09-30 14:02:47 -0700 | [diff] [blame] | 674 | extern const unsigned char null_sha1[20]; |
Ingo Molnar | 1a812f3 | 2011-04-28 12:19:02 +0200 | [diff] [blame] | 675 | |
David Rientjes | a89fccd | 2006-08-17 11:54:57 -0700 | [diff] [blame] | 676 | static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) |
| 677 | { |
Ingo Molnar | 1a812f3 | 2011-04-28 12:19:02 +0200 | [diff] [blame] | 678 | int i; |
| 679 | |
| 680 | for (i = 0; i < 20; i++, sha1++, sha2++) { |
| 681 | if (*sha1 != *sha2) |
| 682 | return *sha1 - *sha2; |
| 683 | } |
| 684 | |
| 685 | return 0; |
David Rientjes | a89fccd | 2006-08-17 11:54:57 -0700 | [diff] [blame] | 686 | } |
Ingo Molnar | 1a812f3 | 2011-04-28 12:19:02 +0200 | [diff] [blame] | 687 | |
| 688 | static inline int is_null_sha1(const unsigned char *sha1) |
| 689 | { |
| 690 | return !hashcmp(sha1, null_sha1); |
| 691 | } |
| 692 | |
Shawn Pearce | e702496 | 2006-08-23 02:49:00 -0400 | [diff] [blame] | 693 | static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) |
| 694 | { |
| 695 | memcpy(sha_dst, sha_src, 20); |
| 696 | } |
Junio C Hamano | a8e0d16 | 2006-08-23 13:57:23 -0700 | [diff] [blame] | 697 | static inline void hashclr(unsigned char *hash) |
| 698 | { |
| 699 | memset(hash, 0, 20); |
| 700 | } |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 701 | |
Jeff King | 14d9c57 | 2008-11-12 03:17:52 -0500 | [diff] [blame] | 702 | #define EMPTY_TREE_SHA1_HEX \ |
| 703 | "4b825dc642cb6eb9a060e54bf8d69288fbee4904" |
Jonathan Nieder | dab0d41 | 2011-02-07 02:17:27 -0600 | [diff] [blame] | 704 | #define EMPTY_TREE_SHA1_BIN_LITERAL \ |
Jeff King | 14d9c57 | 2008-11-12 03:17:52 -0500 | [diff] [blame] | 705 | "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \ |
| 706 | "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04" |
Jonathan Nieder | dab0d41 | 2011-02-07 02:17:27 -0600 | [diff] [blame] | 707 | #define EMPTY_TREE_SHA1_BIN \ |
| 708 | ((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL) |
Jeff King | 14d9c57 | 2008-11-12 03:17:52 -0500 | [diff] [blame] | 709 | |
Holger Eitzenberger | f2db68e | 2005-08-04 22:43:03 +0200 | [diff] [blame] | 710 | int git_mkstemp(char *path, size_t n, const char *template); |
| 711 | |
David Aguilar | 003b33a | 2009-05-31 01:35:52 -0700 | [diff] [blame] | 712 | int git_mkstemps(char *path, size_t n, const char *template, int suffix_len); |
| 713 | |
Matthieu Moy | b862b61 | 2010-02-22 23:32:13 +0100 | [diff] [blame] | 714 | /* set default permissions by passing mode arguments to open(2) */ |
| 715 | int git_mkstemps_mode(char *pattern, int suffix_len, int mode); |
| 716 | int git_mkstemp_mode(char *pattern, int mode); |
| 717 | |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 718 | /* |
| 719 | * NOTE NOTE NOTE!! |
| 720 | * |
| 721 | * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must |
| 722 | * not be changed. Old repositories have core.sharedrepository written in |
| 723 | * numeric format, and therefore these values are preserved for compatibility |
| 724 | * reasons. |
| 725 | */ |
Junio C Hamano | 94df250 | 2006-06-09 23:09:49 -0700 | [diff] [blame] | 726 | enum sharedrepo { |
Heikki Orsila | 06cbe85 | 2008-04-16 11:34:24 +0300 | [diff] [blame] | 727 | PERM_UMASK = 0, |
| 728 | OLD_PERM_GROUP = 1, |
| 729 | OLD_PERM_EVERYBODY = 2, |
| 730 | PERM_GROUP = 0660, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 731 | PERM_EVERYBODY = 0664 |
Junio C Hamano | 94df250 | 2006-06-09 23:09:49 -0700 | [diff] [blame] | 732 | }; |
| 733 | int git_config_perm(const char *var, const char *value); |
Junio C Hamano | 17e61b8 | 2009-03-27 23:21:00 -0700 | [diff] [blame] | 734 | int set_shared_perm(const char *path, int mode); |
| 735 | #define adjust_shared_perm(path) set_shared_perm((path), 0) |
Junio C Hamano | b2cb942 | 2005-07-06 01:11:52 -0700 | [diff] [blame] | 736 | int safe_create_leading_directories(char *path); |
Jeff King | 8e21d63 | 2008-06-25 01:41:34 -0400 | [diff] [blame] | 737 | int safe_create_leading_directories_const(const char *path); |
Junio C Hamano | 90a6464 | 2011-03-10 16:02:50 -0800 | [diff] [blame] | 738 | int mkdir_in_gitdir(const char *path); |
Matthieu Moy | 395de25 | 2009-11-17 18:24:25 +0100 | [diff] [blame] | 739 | extern char *expand_user_path(const char *path); |
Erik Faye-Lund | 1c64b48 | 2011-10-04 16:02:00 -0400 | [diff] [blame] | 740 | const char *enter_repo(const char *path, int strict); |
Johannes Schindelin | e5392c5 | 2007-08-01 01:28:59 +0100 | [diff] [blame] | 741 | static inline int is_absolute_path(const char *path) |
| 742 | { |
Theo Niessink | 8813520 | 2011-05-27 18:00:38 +0200 | [diff] [blame] | 743 | return is_dir_sep(path[0]) || has_dos_drive_prefix(path); |
Johannes Schindelin | e5392c5 | 2007-08-01 01:28:59 +0100 | [diff] [blame] | 744 | } |
Junio C Hamano | 90b4a71 | 2008-09-09 01:27:07 -0700 | [diff] [blame] | 745 | int is_directory(const char *); |
Carlos Martín Nieto | e2a57aa | 2011-03-17 12:26:46 +0100 | [diff] [blame] | 746 | const char *real_path(const char *path); |
| 747 | const char *absolute_path(const char *path); |
| 748 | const char *relative_path(const char *abs, const char *base); |
Johannes Sixt | f3cad0a | 2009-02-07 16:08:28 +0100 | [diff] [blame] | 749 | int normalize_path_copy(char *dst, const char *src); |
David Reiss | 0454dd9 | 2008-05-19 23:49:26 -0700 | [diff] [blame] | 750 | int longest_ancestor_length(const char *path, const char *prefix_list); |
Johannes Schindelin | 4fcc86b | 2009-02-19 20:10:49 +0100 | [diff] [blame] | 751 | char *strip_path_suffix(const char *path, const char *suffix); |
Shawn O. Pearce | 34b6cb8 | 2009-11-09 11:26:43 -0800 | [diff] [blame] | 752 | int daemon_avoid_alias(const char *path); |
Nguyễn Thái Ngọc Duy | 4bb43de | 2010-02-16 12:22:08 +0700 | [diff] [blame] | 753 | int offset_1st_component(const char *path); |
Junio C Hamano | b2cb942 | 2005-07-06 01:11:52 -0700 | [diff] [blame] | 754 | |
Junio C Hamano | e1111ce | 2011-05-15 12:54:53 -0700 | [diff] [blame] | 755 | /* object replacement */ |
Junio C Hamano | 5bf29b9 | 2011-05-15 12:54:54 -0700 | [diff] [blame] | 756 | #define READ_SHA1_FILE_REPLACE 1 |
| 757 | extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag); |
Christian Couder | f5552ae | 2009-01-23 10:07:01 +0100 | [diff] [blame] | 758 | static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) |
| 759 | { |
Junio C Hamano | 5bf29b9 | 2011-05-15 12:54:54 -0700 | [diff] [blame] | 760 | return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE); |
Christian Couder | f5552ae | 2009-01-23 10:07:01 +0100 | [diff] [blame] | 761 | } |
Junio C Hamano | e1111ce | 2011-05-15 12:54:53 -0700 | [diff] [blame] | 762 | extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1); |
| 763 | static inline const unsigned char *lookup_replace_object(const unsigned char *sha1) |
| 764 | { |
| 765 | if (!read_replace_refs) |
| 766 | return sha1; |
| 767 | return do_lookup_replace_object(sha1); |
| 768 | } |
| 769 | |
Nicolas Pitre | 21666f1 | 2007-02-26 14:55:59 -0500 | [diff] [blame] | 770 | /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ |
Nicolas Pitre | 21666f1 | 2007-02-26 14:55:59 -0500 | [diff] [blame] | 771 | extern int sha1_object_info(const unsigned char *, unsigned long *); |
Nicolas Pitre | ce9fbf1 | 2007-03-20 16:02:09 -0400 | [diff] [blame] | 772 | extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1); |
Jeff King | c00e657 | 2010-04-01 20:03:18 -0400 | [diff] [blame] | 773 | extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1); |
Nicolas Pitre | 21666f1 | 2007-02-26 14:55:59 -0500 | [diff] [blame] | 774 | extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); |
Nicolas Pitre | bbac731 | 2008-05-14 01:32:48 -0400 | [diff] [blame] | 775 | extern int force_object_loose(const unsigned char *sha1, time_t mtime); |
Junio C Hamano | f0270ef | 2011-05-14 19:42:10 -0700 | [diff] [blame] | 776 | extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size); |
Junio C Hamano | eb4f407 | 2011-07-19 09:33:03 -0700 | [diff] [blame] | 777 | extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); |
Junio C Hamano | f0270ef | 2011-05-14 19:42:10 -0700 | [diff] [blame] | 778 | extern int parse_sha1_header(const char *hdr, unsigned long *sizep); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 779 | |
Nicolas Pitre | 0e8189e | 2008-10-31 11:31:08 -0400 | [diff] [blame] | 780 | /* global flag to enable extra checks when accessing packed objects */ |
| 781 | extern int do_check_packed_object_crc; |
| 782 | |
Junio C Hamano | 5f44324 | 2011-07-06 19:08:55 -0700 | [diff] [blame] | 783 | /* for development: log offset of pack access */ |
| 784 | extern const char *log_pack_access; |
| 785 | |
Jason McMullan | 5d6ccf5 | 2005-06-03 11:05:39 -0400 | [diff] [blame] | 786 | 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] | 787 | |
Junio C Hamano | 839837b | 2006-09-01 00:17:47 -0700 | [diff] [blame] | 788 | extern int move_temp_to_file(const char *tmpfile, const char *filename); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 789 | |
Junio C Hamano | cd673c1 | 2009-02-27 23:15:53 -0800 | [diff] [blame] | 790 | extern int has_sha1_pack(const unsigned char *sha1); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 791 | extern int has_sha1_file(const unsigned char *sha1); |
Brandon Casey | 0f4dc14 | 2008-11-09 23:59:57 -0600 | [diff] [blame] | 792 | extern int has_loose_object_nonlocal(const unsigned char *sha1); |
Daniel Barkalow | 8237b18 | 2005-04-23 18:47:23 -0700 | [diff] [blame] | 793 | |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 794 | extern int has_pack_index(const unsigned char *sha1); |
| 795 | |
Jeff King | 40d52ff | 2010-04-01 20:05:23 -0400 | [diff] [blame] | 796 | extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect); |
| 797 | |
Linus Torvalds | 192a6be | 2007-05-30 10:32:19 -0700 | [diff] [blame] | 798 | extern const signed char hexval_table[256]; |
| 799 | static inline unsigned int hexval(unsigned char c) |
Junio C Hamano | e49521b | 2006-09-20 16:04:46 -0700 | [diff] [blame] | 800 | { |
| 801 | return hexval_table[c]; |
| 802 | } |
| 803 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 804 | /* Convert to/from hex/sha1 representation */ |
Linus Torvalds | dce9648 | 2010-10-28 11:28:04 -0700 | [diff] [blame] | 805 | #define MINIMUM_ABBREV minimum_abbrev |
| 806 | #define DEFAULT_ABBREV default_abbrev |
Junio C Hamano | 46a6c26 | 2006-01-25 01:03:18 -0800 | [diff] [blame] | 807 | |
Clément Poulain | 573285e | 2010-06-09 19:02:06 +0200 | [diff] [blame] | 808 | struct object_context { |
| 809 | unsigned char tree[20]; |
| 810 | char path[PATH_MAX]; |
| 811 | unsigned mode; |
| 812 | }; |
| 813 | |
Linus Torvalds | 3c249c9 | 2005-05-01 16:36:56 -0700 | [diff] [blame] | 814 | extern int get_sha1(const char *str, unsigned char *sha1); |
Junio C Hamano | 2e83b66 | 2011-05-10 12:02:54 -0700 | [diff] [blame] | 815 | extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int only_to_die, const char *prefix); |
Matthieu Moy | 009fee4 | 2009-12-07 11:10:50 +0100 | [diff] [blame] | 816 | static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode) |
| 817 | { |
Junio C Hamano | 2e83b66 | 2011-05-10 12:02:54 -0700 | [diff] [blame] | 818 | return get_sha1_with_mode_1(str, sha1, mode, 0, NULL); |
Matthieu Moy | 009fee4 | 2009-12-07 11:10:50 +0100 | [diff] [blame] | 819 | } |
Junio C Hamano | 2e83b66 | 2011-05-10 12:02:54 -0700 | [diff] [blame] | 820 | extern int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *orc, int only_to_die, const char *prefix); |
Clément Poulain | 573285e | 2010-06-09 19:02:06 +0200 | [diff] [blame] | 821 | static inline int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc) |
| 822 | { |
Junio C Hamano | 2e83b66 | 2011-05-10 12:02:54 -0700 | [diff] [blame] | 823 | return get_sha1_with_context_1(str, sha1, orc, 0, NULL); |
Clément Poulain | 573285e | 2010-06-09 19:02:06 +0200 | [diff] [blame] | 824 | } |
Michael Haggerty | d4e85a1 | 2011-09-23 15:38:36 +0200 | [diff] [blame] | 825 | |
| 826 | /* |
| 827 | * Try to read a SHA1 in hexadecimal format from the 40 characters |
| 828 | * starting at hex. Write the 20-byte result to sha1 in binary form. |
| 829 | * Return 0 on success. Reading stops if a NUL is encountered in the |
| 830 | * input, so it is safe to pass this function an arbitrary |
| 831 | * null-terminated string. |
| 832 | */ |
Linus Torvalds | 197ee8c | 2005-04-09 12:09:27 -0700 | [diff] [blame] | 833 | extern int get_sha1_hex(const char *hex, unsigned char *sha1); |
Michael Haggerty | d4e85a1 | 2011-09-23 15:38:36 +0200 | [diff] [blame] | 834 | |
Linus Torvalds | 197ee8c | 2005-04-09 12:09:27 -0700 | [diff] [blame] | 835 | extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ |
Michael Haggerty | dfefa93 | 2011-12-12 06:38:09 +0100 | [diff] [blame] | 836 | extern int read_ref_full(const char *refname, unsigned char *sha1, |
Nguyễn Thái Ngọc Duy | c689332 | 2011-11-13 17:22:14 +0700 | [diff] [blame] | 837 | int reading, int *flags); |
Michael Haggerty | dfefa93 | 2011-12-12 06:38:09 +0100 | [diff] [blame] | 838 | extern int read_ref(const char *refname, unsigned char *sha1); |
Michael Haggerty | 7cb3684 | 2011-09-15 23:10:42 +0200 | [diff] [blame] | 839 | |
| 840 | /* |
| 841 | * Resolve a reference, recursively following symbolic refererences. |
| 842 | * |
| 843 | * Store the referred-to object's name in sha1 and return the name of |
| 844 | * the non-symbolic reference that ultimately pointed at it. The |
| 845 | * return value, if not NULL, is a pointer into either a static buffer |
| 846 | * or the input ref. |
| 847 | * |
| 848 | * If the reference cannot be resolved to an object, the behavior |
| 849 | * depends on the "reading" argument: |
| 850 | * |
| 851 | * - If reading is set, return NULL. |
| 852 | * |
| 853 | * - If reading is not set, clear sha1 and return the name of the last |
| 854 | * reference name in the chain, which will either be a non-symbolic |
| 855 | * reference or an undefined reference. If this is a prelude to |
| 856 | * "writing" to the ref, the return value is the name of the ref |
| 857 | * that will actually be created or changed. |
| 858 | * |
| 859 | * If flag is non-NULL, set the value that it points to the |
| 860 | * combination of REF_ISPACKED (if the reference was found among the |
| 861 | * packed references) and REF_ISSYMREF (if the initial reference was a |
| 862 | * symbolic reference). |
| 863 | * |
| 864 | * If ref is not a properly-formatted, normalized reference, return |
| 865 | * NULL. If more than MAXDEPTH recursive symbolic lookups are needed, |
| 866 | * give up and return NULL. |
| 867 | * |
| 868 | * errno is sometimes set on errors, but not always. |
| 869 | */ |
Nguyễn Thái Ngọc Duy | 8cad474 | 2011-12-12 18:20:32 +0700 | [diff] [blame] | 870 | extern const char *resolve_ref_unsafe(const char *ref, unsigned char *sha1, int reading, int *flag); |
Nguyễn Thái Ngọc Duy | 96ec7b1 | 2011-12-13 21:17:48 +0700 | [diff] [blame] | 871 | extern char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag); |
Michael Haggerty | 7cb3684 | 2011-09-15 23:10:42 +0200 | [diff] [blame] | 872 | |
Junio C Hamano | e86eb66 | 2007-01-19 01:15:15 -0800 | [diff] [blame] | 873 | extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref); |
Johannes Schindelin | eb3a482 | 2007-02-09 01:28:23 +0100 | [diff] [blame] | 874 | extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref); |
Junio C Hamano | 431b196 | 2009-03-21 12:51:34 -0700 | [diff] [blame] | 875 | extern int interpret_branch_name(const char *str, struct strbuf *); |
Junio C Hamano | 619a644 | 2009-10-18 12:34:56 -0700 | [diff] [blame] | 876 | extern int get_sha1_mb(const char *str, unsigned char *sha1); |
Junio C Hamano | e86eb66 | 2007-01-19 01:15:15 -0800 | [diff] [blame] | 877 | |
Steffen Prohaska | 7980332 | 2007-11-11 15:01:46 +0100 | [diff] [blame] | 878 | extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules); |
| 879 | extern const char *ref_rev_parse_rules[]; |
Junio C Hamano | dd621df | 2011-11-04 14:14:05 -0700 | [diff] [blame] | 880 | #define ref_fetch_rules ref_rev_parse_rules |
Steffen Prohaska | 7980332 | 2007-11-11 15:01:46 +0100 | [diff] [blame] | 881 | |
Nicolas Pitre | 8b5157e | 2007-01-26 17:26:10 -0500 | [diff] [blame] | 882 | extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg); |
Junio C Hamano | c847f53 | 2007-01-01 23:31:08 -0800 | [diff] [blame] | 883 | extern int validate_headref(const char *ref); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 884 | |
Linus Torvalds | 958ba6c | 2005-05-20 09:09:18 -0700 | [diff] [blame] | 885 | extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); |
Linus Torvalds | 0ab9e1e | 2008-03-05 18:25:10 -0800 | [diff] [blame] | 886 | extern int df_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] | 887 | 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] | 888 | |
Junio C Hamano | 40469ee | 2005-04-28 16:42:27 -0700 | [diff] [blame] | 889 | extern void *read_object_with_reference(const unsigned char *sha1, |
Brian Gerst | bf0f910 | 2005-05-18 08:14:09 -0400 | [diff] [blame] | 890 | const char *required_type, |
Junio C Hamano | 40469ee | 2005-04-28 16:42:27 -0700 | [diff] [blame] | 891 | unsigned long *size, |
| 892 | unsigned char *sha1_ret); |
Junio C Hamano | f4913f9 | 2005-04-20 18:06:49 -0700 | [diff] [blame] | 893 | |
Junio C Hamano | 8177631 | 2007-12-24 00:51:01 -0800 | [diff] [blame] | 894 | extern struct object *peel_to_type(const char *name, int namelen, |
| 895 | struct object *o, enum object_type); |
| 896 | |
Junio C Hamano | 73013af | 2007-07-13 23:14:52 -0700 | [diff] [blame] | 897 | enum date_mode { |
| 898 | DATE_NORMAL = 0, |
| 899 | DATE_RELATIVE, |
| 900 | DATE_SHORT, |
| 901 | DATE_LOCAL, |
| 902 | DATE_ISO8601, |
Linus Torvalds | 7dff9b3 | 2009-02-20 14:15:22 -0800 | [diff] [blame] | 903 | DATE_RFC2822, |
| 904 | DATE_RAW |
Junio C Hamano | 73013af | 2007-07-13 23:14:52 -0700 | [diff] [blame] | 905 | }; |
| 906 | |
Johannes Schindelin | f8493ec | 2007-02-27 16:21:04 +0100 | [diff] [blame] | 907 | const char *show_date(unsigned long time, int timezone, enum date_mode mode); |
Alex Riesen | 33012fc | 2009-08-30 22:26:05 -0400 | [diff] [blame] | 908 | const char *show_date_relative(unsigned long time, int tz, |
| 909 | const struct timeval *now, |
| 910 | char *timebuf, |
| 911 | size_t timebuf_size); |
Linus Torvalds | 2a39064 | 2005-09-19 15:53:50 -0700 | [diff] [blame] | 912 | int parse_date(const char *date, char *buf, int bufsize); |
Jonathan Nieder | 9644c06 | 2010-07-15 18:22:57 +0200 | [diff] [blame] | 913 | int parse_date_basic(const char *date, unsigned long *timestamp, int *offset); |
Edgar Toernig | ecee9d9 | 2005-04-30 09:46:49 -0700 | [diff] [blame] | 914 | void datestamp(char *buf, int bufsize); |
Junio C Hamano | 93cfa7c | 2010-01-26 11:58:00 -0800 | [diff] [blame] | 915 | #define approxidate(s) approxidate_careful((s), NULL) |
| 916 | unsigned long approxidate_careful(const char *, int *); |
Alex Riesen | 33012fc | 2009-08-30 22:26:05 -0400 | [diff] [blame] | 917 | unsigned long approxidate_relative(const char *date, const struct timeval *now); |
Andy Parkins | 856665f | 2007-09-28 15:17:31 +0100 | [diff] [blame] | 918 | enum date_mode parse_date_format(const char *format); |
Edgar Toernig | ecee9d9 | 2005-04-30 09:46:49 -0700 | [diff] [blame] | 919 | |
Junio C Hamano | 774751a | 2007-12-08 17:32:08 -0800 | [diff] [blame] | 920 | #define IDENT_WARN_ON_NO_NAME 1 |
| 921 | #define IDENT_ERROR_ON_NO_NAME 2 |
| 922 | #define IDENT_NO_DATE 4 |
Junio C Hamano | 749be72 | 2006-02-18 20:31:05 -0800 | [diff] [blame] | 923 | extern const char *git_author_info(int); |
| 924 | extern const char *git_committer_info(int); |
Junio C Hamano | 798123a | 2007-02-04 17:50:14 -0800 | [diff] [blame] | 925 | extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int); |
Junio C Hamano | d9ccfe7 | 2007-12-02 13:43:34 -0800 | [diff] [blame] | 926 | extern const char *fmt_name(const char *name, const char *email); |
Jonathan Nieder | 44fcb49 | 2009-11-11 18:01:27 -0600 | [diff] [blame] | 927 | extern const char *git_editor(void); |
Jonathan Nieder | 64778d2 | 2010-02-14 05:59:59 -0600 | [diff] [blame] | 928 | extern const char *git_pager(int stdout_is_tty); |
Linus Torvalds | 6aa33f4 | 2005-07-12 11:49:27 -0700 | [diff] [blame] | 929 | |
Linus Torvalds | 12dccc1 | 2005-06-05 21:59:54 -0700 | [diff] [blame] | 930 | struct checkout { |
| 931 | const char *base_dir; |
| 932 | int base_dir_len; |
| 933 | unsigned force:1, |
| 934 | quiet:1, |
| 935 | not_new:1, |
| 936 | refresh_cache:1; |
| 937 | }; |
| 938 | |
Luiz Fernando N. Capitulino | efbc583 | 2007-04-25 11:18:08 -0300 | [diff] [blame] | 939 | extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); |
Linus Torvalds | b9fd284 | 2009-07-09 13:35:31 -0700 | [diff] [blame] | 940 | |
| 941 | struct cache_def { |
| 942 | char path[PATH_MAX + 1]; |
| 943 | int len; |
| 944 | int flags; |
| 945 | int track_flags; |
| 946 | int prefix_len_stat_func; |
| 947 | }; |
| 948 | |
Kjetil Barvik | 5719989 | 2009-02-09 21:54:06 +0100 | [diff] [blame] | 949 | extern int has_symlink_leading_path(const char *name, int len); |
Linus Torvalds | b9fd284 | 2009-07-09 13:35:31 -0700 | [diff] [blame] | 950 | extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); |
Clemens Buchacher | f66caaf | 2010-10-09 15:53:00 +0200 | [diff] [blame] | 951 | extern int check_leading_path(const char *name, int len); |
Kjetil Barvik | 5719989 | 2009-02-09 21:54:06 +0100 | [diff] [blame] | 952 | extern int has_dirs_only_path(const char *name, int len, int prefix_len); |
Kjetil Barvik | 7847892 | 2009-02-09 21:54:07 +0100 | [diff] [blame] | 953 | extern void schedule_dir_for_removal(const char *name, int len); |
| 954 | extern void remove_scheduled_dirs(void); |
Linus Torvalds | 12dccc1 | 2005-06-05 21:59:54 -0700 | [diff] [blame] | 955 | |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 956 | extern struct alternate_object_database { |
Junio C Hamano | d5a63b9 | 2005-08-14 17:25:57 -0700 | [diff] [blame] | 957 | struct alternate_object_database *next; |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 958 | char *name; |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 959 | char base[FLEX_ARRAY]; /* more */ |
Junio C Hamano | d5a63b9 | 2005-08-14 17:25:57 -0700 | [diff] [blame] | 960 | } *alt_odb_list; |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 961 | extern void prepare_alt_odb(void); |
Daniel Barkalow | bef70b2 | 2008-04-17 19:32:30 -0400 | [diff] [blame] | 962 | extern void add_to_alternates_file(const char *reference); |
Junio C Hamano | d79796b | 2008-09-09 01:27:10 -0700 | [diff] [blame] | 963 | typedef int alt_odb_fn(struct alternate_object_database *, void *); |
| 964 | extern void foreach_alt_odb(alt_odb_fn, void*); |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 965 | |
Shawn O. Pearce | c41ee58 | 2006-12-23 02:33:44 -0500 | [diff] [blame] | 966 | struct pack_window { |
| 967 | struct pack_window *next; |
| 968 | unsigned char *base; |
| 969 | off_t offset; |
| 970 | size_t len; |
| 971 | unsigned int last_used; |
| 972 | unsigned int inuse_cnt; |
| 973 | }; |
| 974 | |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 975 | extern struct packed_git { |
| 976 | struct packed_git *next; |
Shawn O. Pearce | c41ee58 | 2006-12-23 02:33:44 -0500 | [diff] [blame] | 977 | struct pack_window *windows; |
Shawn O. Pearce | 2dc3a23 | 2006-12-23 02:33:47 -0500 | [diff] [blame] | 978 | off_t pack_size; |
Nicolas Pitre | 5705909 | 2007-04-09 01:06:28 -0400 | [diff] [blame] | 979 | const void *index_data; |
| 980 | size_t index_size; |
| 981 | uint32_t num_objects; |
Nicolas Pitre | 8eca0b4 | 2008-06-23 21:23:39 -0400 | [diff] [blame] | 982 | uint32_t num_bad_objects; |
| 983 | unsigned char *bad_object_sha1; |
Nicolas Pitre | 4287307 | 2007-03-16 16:42:50 -0400 | [diff] [blame] | 984 | int index_version; |
Nicolas Pitre | 5705909 | 2007-04-09 01:06:28 -0400 | [diff] [blame] | 985 | time_t mtime; |
Shawn O. Pearce | 9bc879c | 2006-12-23 02:34:01 -0500 | [diff] [blame] | 986 | int pack_fd; |
Brandon Casey | 8d25931 | 2008-11-12 11:59:03 -0600 | [diff] [blame] | 987 | unsigned pack_local:1, |
Shawn O. Pearce | d131b7a | 2011-03-02 10:01:54 -0800 | [diff] [blame] | 988 | pack_keep:1, |
| 989 | do_not_close:1; |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 990 | unsigned char sha1[20]; |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 991 | /* something like ".git/objects/pack/xxxxx.pack" */ |
| 992 | char pack_name[FLEX_ARRAY]; /* more */ |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 993 | } *packed_git; |
Junio C Hamano | f3bf922 | 2005-06-30 17:15:39 -0700 | [diff] [blame] | 994 | |
| 995 | struct pack_entry { |
Shawn O. Pearce | c4001d9 | 2007-03-06 20:44:30 -0500 | [diff] [blame] | 996 | off_t offset; |
Junio C Hamano | f3bf922 | 2005-06-30 17:15:39 -0700 | [diff] [blame] | 997 | unsigned char sha1[20]; |
| 998 | struct packed_git *p; |
| 999 | }; |
| 1000 | |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 1001 | struct ref { |
| 1002 | struct ref *next; |
| 1003 | unsigned char old_sha1[20]; |
| 1004 | unsigned char new_sha1[20]; |
Daniel Barkalow | be885d9 | 2008-04-26 15:53:12 -0400 | [diff] [blame] | 1005 | char *symref; |
Shawn O. Pearce | 9f8a15c | 2007-11-18 04:31:37 -0500 | [diff] [blame] | 1006 | unsigned int force:1, |
| 1007 | merge:1, |
| 1008 | nonfastforward:1, |
| 1009 | deletion:1; |
Jeff King | 8736a84 | 2007-11-17 07:54:27 -0500 | [diff] [blame] | 1010 | enum { |
| 1011 | REF_STATUS_NONE = 0, |
| 1012 | REF_STATUS_OK, |
| 1013 | REF_STATUS_REJECT_NONFASTFORWARD, |
| 1014 | REF_STATUS_REJECT_NODELETE, |
| 1015 | REF_STATUS_UPTODATE, |
Jeff King | ca74c45 | 2007-11-17 07:56:03 -0500 | [diff] [blame] | 1016 | REF_STATUS_REMOTE_REJECT, |
Gary V. Vaughan | 4b05548 | 2010-05-14 09:31:35 +0000 | [diff] [blame] | 1017 | REF_STATUS_EXPECTING_REPORT |
Jeff King | 8736a84 | 2007-11-17 07:54:27 -0500 | [diff] [blame] | 1018 | } status; |
Jeff King | 2a0fe89 | 2007-11-18 02:16:52 -0500 | [diff] [blame] | 1019 | char *remote_status; |
Junio C Hamano | f88395a | 2005-08-03 16:35:29 -0700 | [diff] [blame] | 1020 | struct ref *peer_ref; /* when renaming */ |
Junio C Hamano | 8f1d2e6 | 2006-01-07 01:33:54 -0800 | [diff] [blame] | 1021 | char name[FLEX_ARRAY]; /* more */ |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 1022 | }; |
| 1023 | |
Linus Torvalds | 2718ff0 | 2006-07-04 12:29:10 -0700 | [diff] [blame] | 1024 | #define REF_NORMAL (1u << 0) |
| 1025 | #define REF_HEADS (1u << 1) |
| 1026 | #define REF_TAGS (1u << 2) |
| 1027 | |
Jeff King | 5483f79 | 2009-02-25 03:32:10 -0500 | [diff] [blame] | 1028 | extern struct ref *find_ref_by_name(const struct ref *list, const char *name); |
Jeff King | cda69f4 | 2007-11-18 02:13:10 -0500 | [diff] [blame] | 1029 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 1030 | #define CONNECT_VERBOSE (1u << 0) |
Daniel Barkalow | 4577370 | 2007-10-29 21:05:40 -0400 | [diff] [blame] | 1031 | extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags); |
Johannes Sixt | 98158e9 | 2007-10-19 21:47:53 +0200 | [diff] [blame] | 1032 | extern int finish_connect(struct child_process *conn); |
Jeff King | 7ffe853 | 2011-05-16 02:52:11 -0400 | [diff] [blame] | 1033 | extern int git_connection_is_socket(struct child_process *conn); |
Junio C Hamano | 40c155f | 2008-09-09 01:27:09 -0700 | [diff] [blame] | 1034 | struct extra_have_objects { |
| 1035 | int nr, alloc; |
| 1036 | unsigned char (*array)[20]; |
| 1037 | }; |
Jeff King | afe7c5f | 2011-12-12 19:41:37 -0500 | [diff] [blame] | 1038 | extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *); |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 1039 | extern int server_supports(const char *feature); |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 1040 | extern const char *parse_feature_request(const char *features, const char *feature); |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 1041 | |
Shawn O. Pearce | 7b64469 | 2010-04-19 07:23:08 -0700 | [diff] [blame] | 1042 | extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path); |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 1043 | |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 1044 | extern void prepare_packed_git(void); |
Shawn Pearce | fc04c41 | 2006-11-01 17:06:21 -0500 | [diff] [blame] | 1045 | extern void reprepare_packed_git(void); |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 1046 | extern void install_packed_git(struct packed_git *pack); |
| 1047 | |
Junio C Hamano | a6080a0 | 2007-06-07 00:04:01 -0700 | [diff] [blame] | 1048 | extern struct packed_git *find_sha1_pack(const unsigned char *sha1, |
barkalow@iabervon.org | bf592c5 | 2005-07-31 20:53:44 -0400 | [diff] [blame] | 1049 | struct packed_git *packs); |
| 1050 | |
Chris Wedgwood | 276bc2c | 2007-01-16 22:28:02 -0800 | [diff] [blame] | 1051 | extern void pack_report(void); |
Shawn O. Pearce | d079837 | 2007-05-26 01:24:19 -0400 | [diff] [blame] | 1052 | extern int open_pack_index(struct packed_git *); |
Shawn O. Pearce | fa5fc15 | 2010-04-19 07:23:06 -0700 | [diff] [blame] | 1053 | extern void close_pack_index(struct packed_git *); |
Junio C Hamano | ef49a7a | 2011-06-10 11:52:15 -0700 | [diff] [blame] | 1054 | extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *); |
Shawn O. Pearce | c9ced05 | 2008-01-17 22:57:00 -0500 | [diff] [blame] | 1055 | extern void close_pack_windows(struct packed_git *); |
Shawn O. Pearce | 03e79c8 | 2006-12-23 02:34:08 -0500 | [diff] [blame] | 1056 | extern void unuse_pack(struct pack_window **); |
Nicolas Pitre | c74faea | 2008-12-09 14:26:52 -0500 | [diff] [blame] | 1057 | extern void free_pack_by_name(const char *); |
Shawn O. Pearce | 3d20c63 | 2009-02-10 13:36:12 -0800 | [diff] [blame] | 1058 | extern void clear_delta_base_cache(void); |
Nicolas Pitre | 4287307 | 2007-03-16 16:42:50 -0400 | [diff] [blame] | 1059 | extern struct packed_git *add_packed_git(const char *, int, int); |
Shawn O. Pearce | d079837 | 2007-05-26 01:24:19 -0400 | [diff] [blame] | 1060 | extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t); |
Nicolas Pitre | 9909323 | 2008-06-24 23:17:12 -0400 | [diff] [blame] | 1061 | extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t); |
Shawn O. Pearce | c4001d9 | 2007-03-06 20:44:30 -0500 | [diff] [blame] | 1062 | extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); |
Jeff King | 4c08018 | 2011-10-14 14:03:48 -0400 | [diff] [blame] | 1063 | extern int is_pack_valid(struct packed_git *); |
Shawn O. Pearce | c4001d9 | 2007-03-06 20:44:30 -0500 | [diff] [blame] | 1064 | extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); |
Nicolas Pitre | 09ded04 | 2008-10-29 19:02:46 -0400 | [diff] [blame] | 1065 | extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); |
Nicolas Pitre | 54dab52 | 2007-04-16 12:31:56 -0400 | [diff] [blame] | 1066 | extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); |
Junio C Hamano | f8c8abc | 2011-05-13 15:33:33 -0700 | [diff] [blame] | 1067 | extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); |
Junio C Hamano | 9a217f2 | 2005-06-28 14:56:57 -0700 | [diff] [blame] | 1068 | |
Junio C Hamano | 9a49059 | 2011-05-12 15:51:38 -0700 | [diff] [blame] | 1069 | struct object_info { |
| 1070 | /* Request */ |
| 1071 | unsigned long *sizep; |
| 1072 | |
| 1073 | /* Response */ |
| 1074 | enum { |
| 1075 | OI_CACHED, |
| 1076 | OI_LOOSE, |
Junio C Hamano | 5266d36 | 2011-05-13 13:20:43 -0700 | [diff] [blame] | 1077 | OI_PACKED, |
| 1078 | OI_DBCACHED |
Junio C Hamano | 9a49059 | 2011-05-12 15:51:38 -0700 | [diff] [blame] | 1079 | } whence; |
| 1080 | union { |
| 1081 | /* |
| 1082 | * struct { |
| 1083 | * ... Nothing to expose in this case |
| 1084 | * } cached; |
| 1085 | * struct { |
| 1086 | * ... Nothing to expose in this case |
| 1087 | * } loose; |
| 1088 | */ |
| 1089 | struct { |
| 1090 | struct packed_git *pack; |
| 1091 | off_t offset; |
| 1092 | unsigned int is_delta; |
| 1093 | } packed; |
| 1094 | } u; |
| 1095 | }; |
| 1096 | extern int sha1_object_info_extended(const unsigned char *, struct object_info *); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 1097 | |
Junio C Hamano | 8f3f9b0 | 2005-07-23 17:54:41 -0700 | [diff] [blame] | 1098 | /* Dumb servers support */ |
| 1099 | extern int update_server_info(int); |
| 1100 | |
Michael J Gruber | 7a39741 | 2011-05-17 17:38:52 +0200 | [diff] [blame] | 1101 | /* git_config_parse_key() returns these negated: */ |
| 1102 | #define CONFIG_INVALID_KEY 1 |
| 1103 | #define CONFIG_NO_SECTION_OR_NAME 2 |
| 1104 | /* git_config_set(), git_config_set_multivar() return the above or these: */ |
| 1105 | #define CONFIG_NO_LOCK -1 |
| 1106 | #define CONFIG_INVALID_FILE 3 |
| 1107 | #define CONFIG_NO_WRITE 4 |
| 1108 | #define CONFIG_NOTHING_SET 5 |
| 1109 | #define CONFIG_INVALID_PATTERN 6 |
| 1110 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 1111 | typedef int (*config_fn_t)(const char *, const char *, void *); |
| 1112 | extern int git_default_config(const char *, const char *, void *); |
| 1113 | extern int git_config_from_file(config_fn_t fn, const char *, void *); |
Jeff King | 2b64fc8 | 2010-08-23 15:16:00 -0400 | [diff] [blame] | 1114 | extern void git_config_push_parameter(const char *text); |
Thomas Rast | b3d83d9 | 2010-05-21 12:07:47 +0200 | [diff] [blame] | 1115 | extern int git_config_from_parameters(config_fn_t fn, void *data); |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 1116 | extern int git_config(config_fn_t fn, void *); |
Nguyễn Thái Ngọc Duy | dbdf585 | 2010-11-26 22:32:33 +0700 | [diff] [blame] | 1117 | extern int git_config_early(config_fn_t fn, void *, const char *repo_config); |
Brian Downing | 0b87b6e | 2007-07-12 08:32:26 -0500 | [diff] [blame] | 1118 | extern int git_parse_ulong(const char *, unsigned long *); |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 1119 | extern int git_config_int(const char *, const char *); |
Brian Downing | 0b87b6e | 2007-07-12 08:32:26 -0500 | [diff] [blame] | 1120 | extern unsigned long git_config_ulong(const char *, const char *); |
Junio C Hamano | a53f2ec | 2008-04-12 18:33:31 -0700 | [diff] [blame] | 1121 | extern int git_config_bool_or_int(const char *, const char *, int *); |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 1122 | extern int git_config_bool(const char *, const char *); |
Junio C Hamano | 8420ccd | 2010-02-16 23:59:46 -0800 | [diff] [blame] | 1123 | extern int git_config_maybe_bool(const char *, const char *); |
Christian Couder | ea5105a | 2008-02-16 06:00:24 +0100 | [diff] [blame] | 1124 | extern int git_config_string(const char **, const char *, const char *); |
Matthieu Moy | 395de25 | 2009-11-17 18:24:25 +0100 | [diff] [blame] | 1125 | extern int git_config_pathname(const char **, const char *, const char *); |
Ramkumar Ramachandra | 5ec3118 | 2011-08-04 16:09:00 +0530 | [diff] [blame] | 1126 | extern int git_config_set_in_file(const char *, const char *, const char *); |
Johannes Schindelin | 10bea15 | 2005-11-17 22:32:36 +0100 | [diff] [blame] | 1127 | extern int git_config_set(const char *, const char *); |
Libor Pechacek | b09c53a | 2011-01-30 20:40:41 +0100 | [diff] [blame] | 1128 | extern int git_config_parse_key(const char *, char **, int *); |
Johannes Schindelin | 4ddba79 | 2005-11-20 06:52:22 +0100 | [diff] [blame] | 1129 | extern int git_config_set_multivar(const char *, const char *, const char *, int); |
Ramkumar Ramachandra | 5ec3118 | 2011-08-04 16:09:00 +0530 | [diff] [blame] | 1130 | extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); |
Johannes Schindelin | 0667fcf | 2006-12-16 15:14:14 +0100 | [diff] [blame] | 1131 | extern int git_config_rename_section(const char *, const char *); |
Johannes Sixt | 506b17b | 2007-11-13 21:05:05 +0100 | [diff] [blame] | 1132 | extern const char *git_etc_gitconfig(void); |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 1133 | extern int check_repository_format_version(const char *var, const char *value, void *cb); |
Lars R. Damerow | 0ef3716 | 2010-03-17 12:55:51 -0700 | [diff] [blame] | 1134 | extern int git_env_bool(const char *, int); |
Jeff King | ab88c36 | 2008-02-06 05:11:18 -0500 | [diff] [blame] | 1135 | extern int git_config_system(void); |
Junio C Hamano | 40ea4ed | 2008-02-11 10:41:18 -0800 | [diff] [blame] | 1136 | extern int config_error_nonbool(const char *); |
Pat Notz | a6fa599 | 2010-11-02 13:59:07 -0600 | [diff] [blame] | 1137 | extern const char *get_log_output_encoding(void); |
| 1138 | extern const char *get_commit_output_encoding(void); |
| 1139 | |
Jeff King | 2496844 | 2011-06-09 11:56:42 -0400 | [diff] [blame] | 1140 | extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data); |
| 1141 | |
Daniel Barkalow | dc87183 | 2008-06-30 03:37:47 -0400 | [diff] [blame] | 1142 | extern const char *config_exclusive_filename; |
Linus Torvalds | 1771299 | 2005-10-10 16:31:08 -0700 | [diff] [blame] | 1143 | |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 1144 | #define MAX_GITNAME (1000) |
| 1145 | extern char git_default_email[MAX_GITNAME]; |
| 1146 | extern char git_default_name[MAX_GITNAME]; |
Junio C Hamano | 91c38a2 | 2010-01-08 07:39:11 -0800 | [diff] [blame] | 1147 | #define IDENT_NAME_GIVEN 01 |
| 1148 | #define IDENT_MAIL_GIVEN 02 |
| 1149 | #define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN) |
Santi Béjar | bb1ae3f | 2008-05-04 18:04:51 +0200 | [diff] [blame] | 1150 | extern int user_ident_explicitly_given; |
Junio C Hamano | 5aeb3a3 | 2010-01-17 13:54:28 -0800 | [diff] [blame] | 1151 | extern int user_ident_sufficiently_given(void); |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 1152 | |
Shawn O. Pearce | 1a8f274 | 2007-03-12 15:33:18 -0400 | [diff] [blame] | 1153 | extern const char *git_commit_encoding; |
Shawn O. Pearce | 3a55602 | 2007-03-06 20:44:17 -0500 | [diff] [blame] | 1154 | extern const char *git_log_output_encoding; |
Marius Storm-Olsen | d551a48 | 2009-02-08 15:34:27 +0100 | [diff] [blame] | 1155 | extern const char *git_mailmap_file; |
Junio C Hamano | 4e72dce | 2005-11-27 16:09:40 -0800 | [diff] [blame] | 1156 | |
Theodore Ts'o | 06f59e9 | 2007-06-29 13:40:46 -0400 | [diff] [blame] | 1157 | /* IO helper functions */ |
| 1158 | extern void maybe_flush_or_die(FILE *, const char *); |
Junio C Hamano | f3123c4 | 2005-10-22 01:28:13 -0700 | [diff] [blame] | 1159 | extern int copy_fd(int ifd, int ofd); |
Daniel Barkalow | 1468bd4 | 2008-02-25 14:24:48 -0500 | [diff] [blame] | 1160 | extern int copy_file(const char *dst, const char *src, int mode); |
Clemens Buchacher | f7835a2 | 2009-09-12 11:03:48 +0200 | [diff] [blame] | 1161 | extern int copy_file_with_time(const char *dst, const char *src, int mode); |
Rene Scharfe | 7230e6d | 2006-08-21 20:43:43 +0200 | [diff] [blame] | 1162 | 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] | 1163 | extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); |
Andy Whitcroft | e081405 | 2007-01-08 15:57:52 +0000 | [diff] [blame] | 1164 | extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg); |
Linus Torvalds | 4c81b03 | 2008-05-30 08:42:16 -0700 | [diff] [blame] | 1165 | extern void fsync_or_die(int fd, const char *); |
Junio C Hamano | ad89721 | 2005-12-14 22:17:38 -0800 | [diff] [blame] | 1166 | |
Jim Meyering | 2b7ca83 | 2009-09-12 10:54:32 +0200 | [diff] [blame] | 1167 | extern ssize_t read_in_full(int fd, void *buf, size_t count); |
| 1168 | extern ssize_t write_in_full(int fd, const void *buf, size_t count); |
| 1169 | static inline ssize_t write_str_in_full(int fd, const char *str) |
| 1170 | { |
| 1171 | return write_in_full(fd, str, strlen(str)); |
| 1172 | } |
| 1173 | |
Linus Torvalds | f67b45f | 2006-02-28 11:26:21 -0800 | [diff] [blame] | 1174 | /* pager.c */ |
| 1175 | extern void setup_pager(void); |
Christian Couder | 872da32 | 2008-02-16 06:01:11 +0100 | [diff] [blame] | 1176 | extern const char *pager_program; |
Jeff King | 6e9af86 | 2007-12-11 01:27:33 -0500 | [diff] [blame] | 1177 | extern int pager_in_use(void); |
Matthias Lederhofer | aa086eb | 2006-07-30 00:27:43 +0200 | [diff] [blame] | 1178 | extern int pager_use_color; |
Linus Torvalds | f67b45f | 2006-02-28 11:26:21 -0800 | [diff] [blame] | 1179 | |
Christian Couder | ee9601e | 2008-02-16 06:01:41 +0100 | [diff] [blame] | 1180 | extern const char *editor_program; |
Anselm Kruis | d3e7da8 | 2010-08-30 15:38:38 +0200 | [diff] [blame] | 1181 | extern const char *askpass_program; |
Christian Couder | dfb068b | 2008-02-16 06:01:59 +0100 | [diff] [blame] | 1182 | extern const char *excludes_file; |
Johannes Schindelin | 4d87b9c | 2007-07-20 13:06:09 +0100 | [diff] [blame] | 1183 | |
Junio C Hamano | 051308f | 2006-05-04 16:51:44 -0700 | [diff] [blame] | 1184 | /* base85 */ |
Jim Meyering | f981577 | 2007-04-10 00:56:33 +0200 | [diff] [blame] | 1185 | int decode_85(char *dst, const char *line, int linelen); |
| 1186 | void encode_85(char *buf, const unsigned char *data, int bytes); |
Junio C Hamano | 051308f | 2006-05-04 16:51:44 -0700 | [diff] [blame] | 1187 | |
Linus Torvalds | 855419f | 2006-06-19 10:44:15 -0700 | [diff] [blame] | 1188 | /* alloc.c */ |
Linus Torvalds | 100c5f3 | 2007-04-16 22:11:43 -0700 | [diff] [blame] | 1189 | extern void *alloc_blob_node(void); |
| 1190 | extern void *alloc_tree_node(void); |
| 1191 | extern void *alloc_commit_node(void); |
| 1192 | extern void *alloc_tag_node(void); |
| 1193 | extern void *alloc_object_node(void); |
Linus Torvalds | 855419f | 2006-06-19 10:44:15 -0700 | [diff] [blame] | 1194 | extern void alloc_report(void); |
| 1195 | |
Christian Couder | 6ce4e61 | 2006-09-02 18:23:48 +0200 | [diff] [blame] | 1196 | /* trace.c */ |
Tarmigan Casebolt | 28bea9e | 2009-11-14 13:33:13 -0800 | [diff] [blame] | 1197 | __attribute__((format (printf, 1, 2))) |
Christian Couder | 6ce4e61 | 2006-09-02 18:23:48 +0200 | [diff] [blame] | 1198 | extern void trace_printf(const char *format, ...); |
Jeff King | 0679660 | 2011-02-24 09:28:41 -0500 | [diff] [blame] | 1199 | extern void trace_vprintf(const char *key, const char *format, va_list ap); |
Tarmigan Casebolt | 28bea9e | 2009-11-14 13:33:13 -0800 | [diff] [blame] | 1200 | __attribute__((format (printf, 2, 3))) |
Christian Couder | b319ce4 | 2007-12-03 05:51:50 +0100 | [diff] [blame] | 1201 | extern void trace_argv_printf(const char **argv, const char *format, ...); |
Nguyễn Thái Ngọc Duy | a9ca8a8 | 2010-11-26 22:31:57 +0700 | [diff] [blame] | 1202 | extern void trace_repo_setup(const char *prefix); |
Jeff King | 39bc5e4 | 2011-02-24 09:28:59 -0500 | [diff] [blame] | 1203 | extern int trace_want(const char *key); |
Jeff King | 94b3b37 | 2011-02-24 09:29:50 -0500 | [diff] [blame] | 1204 | extern void trace_strbuf(const char *key, const struct strbuf *buf); |
Christian Couder | 6ce4e61 | 2006-09-02 18:23:48 +0200 | [diff] [blame] | 1205 | |
Jeff King | bbc30f9 | 2011-02-24 09:30:19 -0500 | [diff] [blame] | 1206 | void packet_trace_identity(const char *prog); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 1207 | |
Junio C Hamano | b6ec1d6 | 2007-11-18 01:12:04 -0800 | [diff] [blame] | 1208 | /* add */ |
Alex Riesen | 7ae02a3 | 2008-05-12 19:58:10 +0200 | [diff] [blame] | 1209 | /* |
| 1210 | * return 0 if success, 1 - if addition of a file failed and |
| 1211 | * ADD_FILES_IGNORE_ERRORS was specified in flags |
| 1212 | */ |
| 1213 | int add_files_to_cache(const char *prefix, const char **pathspec, int flags); |
Junio C Hamano | b6ec1d6 | 2007-11-18 01:12:04 -0800 | [diff] [blame] | 1214 | |
Junio C Hamano | aecbf91 | 2007-08-31 13:13:42 -0700 | [diff] [blame] | 1215 | /* diff.c */ |
| 1216 | extern int diff_auto_refresh_index; |
| 1217 | |
Junio C Hamano | 68faf68 | 2007-02-15 16:32:45 -0800 | [diff] [blame] | 1218 | /* match-trees.c */ |
| 1219 | void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int); |
Junio C Hamano | 85e51b7 | 2008-06-30 22:18:57 -0700 | [diff] [blame] | 1220 | void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *, const char *); |
Junio C Hamano | 68faf68 | 2007-02-15 16:32:45 -0800 | [diff] [blame] | 1221 | |
Junio C Hamano | a9cc857 | 2007-11-02 00:24:27 -0700 | [diff] [blame] | 1222 | /* |
| 1223 | * whitespace rules. |
| 1224 | * used by both diff and apply |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 1225 | * last two digits are tab width |
Junio C Hamano | a9cc857 | 2007-11-02 00:24:27 -0700 | [diff] [blame] | 1226 | */ |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 1227 | #define WS_BLANK_AT_EOL 0100 |
| 1228 | #define WS_SPACE_BEFORE_TAB 0200 |
| 1229 | #define WS_INDENT_WITH_NON_TAB 0400 |
| 1230 | #define WS_CR_AT_EOL 01000 |
| 1231 | #define WS_BLANK_AT_EOF 02000 |
| 1232 | #define WS_TAB_IN_INDENT 04000 |
Junio C Hamano | aeb84b0 | 2009-09-05 22:21:17 -0700 | [diff] [blame] | 1233 | #define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF) |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 1234 | #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8) |
| 1235 | #define WS_TAB_WIDTH_MASK 077 |
Junio C Hamano | cf1b786 | 2007-12-06 00:14:14 -0800 | [diff] [blame] | 1236 | extern unsigned whitespace_rule_cfg; |
| 1237 | extern unsigned whitespace_rule(const char *); |
| 1238 | extern unsigned parse_whitespace_rule(const char *); |
Junio C Hamano | 8f8841e | 2008-06-26 15:35:21 -0700 | [diff] [blame] | 1239 | extern unsigned ws_check(const char *line, int len, unsigned ws_rule); |
| 1240 | extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); |
Wincent Colaiuta | c1795bb | 2007-12-13 14:32:29 +0100 | [diff] [blame] | 1241 | extern char *whitespace_error_string(unsigned ws); |
Chris Webb | d511bd3 | 2010-04-03 00:37:23 +0100 | [diff] [blame] | 1242 | extern void ws_fix_copy(struct strbuf *, const char *, int, unsigned, int *); |
Junio C Hamano | 877f23c | 2008-06-26 15:36:59 -0700 | [diff] [blame] | 1243 | extern int ws_blank_line(const char *line, int len, unsigned ws_rule); |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 1244 | #define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK) |
Junio C Hamano | a9cc857 | 2007-11-02 00:24:27 -0700 | [diff] [blame] | 1245 | |
Junio C Hamano | ee425e4 | 2007-11-18 01:13:32 -0800 | [diff] [blame] | 1246 | /* ls-files */ |
Clemens Buchacher | 0f64bfa | 2011-08-01 23:19:58 +0200 | [diff] [blame] | 1247 | int report_path_error(const char *ps_matched, const char **pathspec, const char *prefix); |
Junio C Hamano | ee425e4 | 2007-11-18 01:13:32 -0800 | [diff] [blame] | 1248 | void overlay_tree_on_cache(const char *tree_name, const char *prefix); |
| 1249 | |
Jeff King | 9435111 | 2008-02-24 17:17:14 -0500 | [diff] [blame] | 1250 | char *alias_lookup(const char *alias); |
Miklos Vajna | 0989fe9 | 2008-06-27 18:21:54 +0200 | [diff] [blame] | 1251 | int split_cmdline(char *cmdline, const char ***argv); |
Greg Brockman | ad9ac6d | 2010-08-07 01:13:39 -0400 | [diff] [blame] | 1252 | /* Takes a negative value returned by split_cmdline */ |
| 1253 | const char *split_cmdline_strerror(int cmdline_errno); |
Jeff King | 9435111 | 2008-02-24 17:17:14 -0500 | [diff] [blame] | 1254 | |
Nguyễn Thái Ngọc Duy | e37c132 | 2010-08-05 21:40:35 -0500 | [diff] [blame] | 1255 | /* git.c */ |
| 1256 | struct startup_info { |
Nguyễn Thái Ngọc Duy | a60645f | 2010-08-05 21:46:33 -0500 | [diff] [blame] | 1257 | int have_repository; |
Nguyễn Thái Ngọc Duy | f07d6a1 | 2010-12-01 17:33:22 -0600 | [diff] [blame] | 1258 | const char *prefix; |
Nguyễn Thái Ngọc Duy | e37c132 | 2010-08-05 21:40:35 -0500 | [diff] [blame] | 1259 | }; |
| 1260 | extern struct startup_info *startup_info; |
| 1261 | |
Junio C Hamano | cac42b2 | 2010-03-06 21:34:41 +0100 | [diff] [blame] | 1262 | /* builtin/merge.c */ |
| 1263 | int checkout_fast_forward(const unsigned char *from, const unsigned char *to); |
| 1264 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 1265 | #endif /* CACHE_H */ |