4 #include "git-compat-util.h"
9 #include "string-list.h"
14 #include "repository.h"
17 typedef struct git_zstream
{
19 unsigned long avail_in
;
20 unsigned long avail_out
;
21 unsigned long total_in
;
22 unsigned long total_out
;
23 unsigned char *next_in
;
24 unsigned char *next_out
;
27 void git_inflate_init(git_zstream
*);
28 void git_inflate_init_gzip_only(git_zstream
*);
29 void git_inflate_end(git_zstream
*);
30 int git_inflate(git_zstream
*, int flush
);
32 void git_deflate_init(git_zstream
*, int level
);
33 void git_deflate_init_gzip(git_zstream
*, int level
);
34 void git_deflate_init_raw(git_zstream
*, int level
);
35 void git_deflate_end(git_zstream
*);
36 int git_deflate_abort(git_zstream
*);
37 int git_deflate_end_gently(git_zstream
*);
38 int git_deflate(git_zstream
*, int flush
);
39 unsigned long git_deflate_bound(git_zstream
*, unsigned long);
41 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
42 #define DTYPE(de) ((de)->d_type)
52 #define DTYPE(de) DT_UNKNOWN
55 /* unknown mode (impossible combination S_IFIFO|S_IFCHR) */
56 #define S_IFINVALID 0030000
59 * A "directory link" is a link to another git directory.
61 * The value 0160000 is not normally a valid mode, and
62 * also just happens to be S_IFDIR + S_IFLNK
64 #define S_IFGITLINK 0160000
65 #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
68 * Some mode bits are also used internally for computations.
70 * They *must* not overlap with any valid modes, and they *must* not be emitted
71 * to outside world - i.e. appear on disk or network. In other words, it's just
72 * temporary fields, which we internally use, but they have to stay in-house.
74 * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git
75 * codebase mode is `unsigned int` which is assumed to be at least 32 bits )
78 /* used internally in tree-diff */
79 #define S_DIFFTREE_IFXMIN_NEQ 0x80000000
83 * Intensive research over the course of many years has shown that
84 * port 9418 is totally unused by anything else. Or
86 * Your search - "port 9418" - did not match any documents.
88 * as www.google.com puts it.
90 * This port has been properly assigned for git use by IANA:
91 * git (Assigned-9418) [I06-050728-0001].
93 * git 9418/tcp git pack transfer service
94 * git 9418/udp git pack transfer service
96 * with Linus Torvalds <torvalds@osdl.org> as the point of
97 * contact. September 2005.
99 * See http://www.iana.org/assignments/port-numbers
101 #define DEFAULT_GIT_PORT 9418
104 * Basic data structures for the directory cache
107 #define CACHE_SIGNATURE 0x44495243 /* "DIRC" */
108 struct cache_header
{
109 uint32_t hdr_signature
;
110 uint32_t hdr_version
;
111 uint32_t hdr_entries
;
114 #define INDEX_FORMAT_LB 2
115 #define INDEX_FORMAT_UB 4
118 struct hashmap_entry ent
;
119 struct stat_data ce_stat_data
;
120 unsigned int ce_mode
;
121 unsigned int ce_flags
;
122 unsigned int mem_pool_allocated
;
123 unsigned int ce_namelen
;
124 unsigned int index
; /* for link extension */
125 struct object_id oid
;
126 char name
[FLEX_ARRAY
]; /* more */
129 #define CE_STAGEMASK (0x3000)
130 #define CE_EXTENDED (0x4000)
131 #define CE_VALID (0x8000)
132 #define CE_STAGESHIFT 12
135 * Range 0xFFFF0FFF in ce_flags is divided into
136 * two parts: in-memory flags and on-disk ones.
137 * Flags in CE_EXTENDED_FLAGS will get saved on-disk
138 * if you want to save a new flag, add it in
141 * In-memory only flags
143 #define CE_UPDATE (1 << 16)
144 #define CE_REMOVE (1 << 17)
145 #define CE_UPTODATE (1 << 18)
146 #define CE_ADDED (1 << 19)
148 #define CE_HASHED (1 << 20)
149 #define CE_FSMONITOR_VALID (1 << 21)
150 #define CE_WT_REMOVE (1 << 22) /* remove in work directory */
151 #define CE_CONFLICTED (1 << 23)
153 #define CE_UNPACKED (1 << 24)
154 #define CE_NEW_SKIP_WORKTREE (1 << 25)
156 /* used to temporarily mark paths matched by pathspecs */
157 #define CE_MATCHED (1 << 26)
159 #define CE_UPDATE_IN_BASE (1 << 27)
160 #define CE_STRIP_NAME (1 << 28)
163 * Extended on-disk flags
165 #define CE_INTENT_TO_ADD (1 << 29)
166 #define CE_SKIP_WORKTREE (1 << 30)
167 /* CE_EXTENDED2 is for future extension */
168 #define CE_EXTENDED2 (1U << 31)
170 #define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
173 * Safeguard to avoid saving wrong flags:
174 * - CE_EXTENDED2 won't get saved until its semantic is known
175 * - Bits in 0x0000FFFF have been saved in ce_flags already
176 * - Bits in 0x003F0000 are currently in-memory flags
178 #if CE_EXTENDED_FLAGS & 0x803FFFFF
179 #error "CE_EXTENDED_FLAGS out of range"
182 #define S_ISSPARSEDIR(m) ((m) == S_IFDIR)
184 /* Forward structure decls */
186 struct child_process
;
190 * Copy the sha1 and stat state of a cache entry from one to
191 * another. But we never change the name, or the hash state!
193 static inline void copy_cache_entry(struct cache_entry
*dst
,
194 const struct cache_entry
*src
)
196 unsigned int state
= dst
->ce_flags
& CE_HASHED
;
197 int mem_pool_allocated
= dst
->mem_pool_allocated
;
199 /* Don't copy hash chain and name */
200 memcpy(&dst
->ce_stat_data
, &src
->ce_stat_data
,
201 offsetof(struct cache_entry
, name
) -
202 offsetof(struct cache_entry
, ce_stat_data
));
204 /* Restore the hash state */
205 dst
->ce_flags
= (dst
->ce_flags
& ~CE_HASHED
) | state
;
207 /* Restore the mem_pool_allocated flag */
208 dst
->mem_pool_allocated
= mem_pool_allocated
;
211 static inline unsigned create_ce_flags(unsigned stage
)
213 return (stage
<< CE_STAGESHIFT
);
216 #define ce_namelen(ce) ((ce)->ce_namelen)
217 #define ce_size(ce) cache_entry_size(ce_namelen(ce))
218 #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
219 #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
220 #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
221 #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
222 #define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
224 #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
225 static inline unsigned int create_ce_mode(unsigned int mode
)
229 if (S_ISSPARSEDIR(mode
))
231 if (S_ISDIR(mode
) || S_ISGITLINK(mode
))
233 return S_IFREG
| ce_permissions(mode
);
235 static inline unsigned int ce_mode_from_stat(const struct cache_entry
*ce
,
238 extern int trust_executable_bit
, has_symlinks
;
239 if (!has_symlinks
&& S_ISREG(mode
) &&
240 ce
&& S_ISLNK(ce
->ce_mode
))
242 if (!trust_executable_bit
&& S_ISREG(mode
)) {
243 if (ce
&& S_ISREG(ce
->ce_mode
))
245 return create_ce_mode(0666);
247 return create_ce_mode(mode
);
249 static inline int ce_to_dtype(const struct cache_entry
*ce
)
251 unsigned ce_mode
= ntohl(ce
->ce_mode
);
252 if (S_ISREG(ce_mode
))
254 else if (S_ISDIR(ce_mode
) || S_ISGITLINK(ce_mode
))
256 else if (S_ISLNK(ce_mode
))
261 static inline unsigned int canon_mode(unsigned int mode
)
264 return S_IFREG
| ce_permissions(mode
);
272 static inline int ce_path_match(struct index_state
*istate
,
273 const struct cache_entry
*ce
,
274 const struct pathspec
*pathspec
,
277 return match_pathspec(istate
, pathspec
, ce
->name
, ce_namelen(ce
), 0, seen
,
278 S_ISDIR(ce
->ce_mode
) || S_ISGITLINK(ce
->ce_mode
));
281 #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
283 #define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */
284 #define CE_ENTRY_CHANGED (1 << 1)
285 #define CE_ENTRY_REMOVED (1 << 2)
286 #define CE_ENTRY_ADDED (1 << 3)
287 #define RESOLVE_UNDO_CHANGED (1 << 4)
288 #define CACHE_TREE_CHANGED (1 << 5)
289 #define SPLIT_INDEX_ORDERED (1 << 6)
290 #define UNTRACKED_CHANGED (1 << 7)
291 #define FSMONITOR_CHANGED (1 << 8)
294 struct untracked_cache
;
298 enum sparse_index_mode
{
300 * There are no sparse directories in the index at all.
302 * Repositories that don't use cone-mode sparse-checkout will
303 * always have their indexes in this mode.
308 * The index has already been collapsed to sparse directories
309 * whereever possible.
314 * The sparse directories that exist are outside the
315 * sparse-checkout boundary, but it is possible that some file
316 * entries could collapse to sparse directory entries.
318 INDEX_PARTIALLY_SPARSE
,
322 struct cache_entry
**cache
;
323 unsigned int version
;
324 unsigned int cache_nr
, cache_alloc
, cache_changed
;
325 struct string_list
*resolve_undo
;
326 struct cache_tree
*cache_tree
;
327 struct split_index
*split_index
;
328 struct cache_time timestamp
;
329 unsigned name_hash_initialized
: 1,
333 updated_skipworktree
: 1,
334 fsmonitor_has_run_once
: 1;
335 enum sparse_index_mode sparse_index
;
336 struct hashmap name_hash
;
337 struct hashmap dir_hash
;
338 struct object_id oid
;
339 struct untracked_cache
*untracked
;
340 char *fsmonitor_last_update
;
341 struct ewah_bitmap
*fsmonitor_dirty
;
342 struct mem_pool
*ce_mem_pool
;
343 struct progress
*progress
;
344 struct repository
*repo
;
345 struct pattern_list
*sparse_checkout_patterns
;
349 * A "struct index_state istate" must be initialized with
350 * INDEX_STATE_INIT or the corresponding index_state_init().
352 * If the variable won't be used again, use release_index() to free()
353 * its resources. If it needs to be used again use discard_index(),
354 * which does the same thing, but will use use index_state_init() at
355 * the end. The discard_index() will use its own "istate->repo" as the
356 * "r" argument to index_state_init() in that case.
358 #define INDEX_STATE_INIT(r) { \
361 void index_state_init(struct index_state
*istate
, struct repository
*r
);
362 void release_index(struct index_state
*istate
);
365 int test_lazy_init_name_hash(struct index_state
*istate
, int try_threaded
);
366 void add_name_hash(struct index_state
*istate
, struct cache_entry
*ce
);
367 void remove_name_hash(struct index_state
*istate
, struct cache_entry
*ce
);
368 void free_name_hash(struct index_state
*istate
);
370 /* Cache entry creation and cleanup */
373 * Create cache_entry intended for use in the specified index. Caller
374 * is responsible for discarding the cache_entry with
375 * `discard_cache_entry`.
377 struct cache_entry
*make_cache_entry(struct index_state
*istate
,
379 const struct object_id
*oid
,
382 unsigned int refresh_options
);
384 struct cache_entry
*make_empty_cache_entry(struct index_state
*istate
,
388 * Create a cache_entry that is not intended to be added to an index. If
389 * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
390 * pool. Caller is responsible for discarding "loose" entries with
391 * `discard_cache_entry()` and the memory pool with
392 * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
394 struct cache_entry
*make_transient_cache_entry(unsigned int mode
,
395 const struct object_id
*oid
,
398 struct mem_pool
*ce_mem_pool
);
400 struct cache_entry
*make_empty_transient_cache_entry(size_t len
,
401 struct mem_pool
*ce_mem_pool
);
404 * Discard cache entry.
406 void discard_cache_entry(struct cache_entry
*ce
);
409 * Check configuration if we should perform extra validation on cache
412 int should_validate_cache_entries(void);
415 * Duplicate a cache_entry. Allocate memory for the new entry from a
416 * memory_pool. Takes into account cache_entry fields that are meant
417 * for managing the underlying memory allocation of the cache_entry.
419 struct cache_entry
*dup_cache_entry(const struct cache_entry
*ce
, struct index_state
*istate
);
422 * Validate the cache entries in the index. This is an internal
423 * consistency check that the cache_entry structs are allocated from
424 * the expected memory pool.
426 void validate_cache_entries(const struct index_state
*istate
);
429 * Bulk prefetch all missing cache entries that are not GITLINKs and that match
430 * the given predicate. This function should only be called if
431 * repo_has_promisor_remote() returns true.
433 typedef int (*must_prefetch_predicate
)(const struct cache_entry
*);
434 void prefetch_cache_entries(const struct index_state
*istate
,
435 must_prefetch_predicate must_prefetch
);
437 #ifdef USE_THE_INDEX_VARIABLE
438 extern struct index_state the_index
;
441 static inline enum object_type
object_type(unsigned int mode
)
443 return S_ISDIR(mode
) ? OBJ_TREE
:
444 S_ISGITLINK(mode
) ? OBJ_COMMIT
:
448 #define INIT_DB_QUIET 0x0001
449 #define INIT_DB_EXIST_OK 0x0002
451 int init_db(const char *git_dir
, const char *real_git_dir
,
452 const char *template_dir
, int hash_algo
,
453 const char *initial_branch
, unsigned int flags
);
454 void initialize_repository_version(int hash_algo
, int reinit
);
456 /* Initialize and use the cache information */
458 void preload_index(struct index_state
*index
,
459 const struct pathspec
*pathspec
,
460 unsigned int refresh_flags
);
461 int do_read_index(struct index_state
*istate
, const char *path
,
462 int must_exist
); /* for testting only! */
463 int read_index_from(struct index_state
*, const char *path
,
465 int is_index_unborn(struct index_state
*);
467 void ensure_full_index(struct index_state
*istate
);
469 /* For use with `write_locked_index()`. */
470 #define COMMIT_LOCK (1 << 0)
471 #define SKIP_IF_UNCHANGED (1 << 1)
474 * Write the index while holding an already-taken lock. Close the lock,
475 * and if `COMMIT_LOCK` is given, commit it.
477 * Unless a split index is in use, write the index into the lockfile.
479 * With a split index, write the shared index to a temporary file,
480 * adjust its permissions and rename it into place, then write the
481 * split index to the lockfile. If the temporary file for the shared
482 * index cannot be created, fall back to the behavior described in
483 * the previous paragraph.
485 * With `COMMIT_LOCK`, the lock is always committed or rolled back.
486 * Without it, the lock is closed, but neither committed nor rolled
489 * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
490 * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
492 int write_locked_index(struct index_state
*, struct lock_file
*lock
, unsigned flags
);
494 void discard_index(struct index_state
*);
495 void move_index_extensions(struct index_state
*dst
, struct index_state
*src
);
496 int unmerged_index(const struct index_state
*);
499 * Returns 1 if istate differs from tree, 0 otherwise. If tree is NULL,
500 * compares istate to HEAD. If tree is NULL and on an unborn branch,
501 * returns 1 if there are entries in istate, 0 otherwise. If an strbuf is
502 * provided, the space-separated list of files that differ will be appended
505 int repo_index_has_changes(struct repository
*repo
,
509 int verify_path(const char *path
, unsigned mode
);
510 int strcmp_offset(const char *s1
, const char *s2
, size_t *first_change
);
511 int index_dir_exists(struct index_state
*istate
, const char *name
, int namelen
);
512 void adjust_dirname_case(struct index_state
*istate
, char *name
);
513 struct cache_entry
*index_file_exists(struct index_state
*istate
, const char *name
, int namelen
, int igncase
);
516 * Searches for an entry defined by name and namelen in the given index.
517 * If the return value is positive (including 0) it is the position of an
518 * exact match. If the return value is negative, the negated value minus 1
519 * is the position where the entry would be inserted.
520 * Example: The current index consists of these files and its stages:
524 * index_name_pos(&index, "a", 1) -> -1
525 * index_name_pos(&index, "b", 1) -> 0
526 * index_name_pos(&index, "c", 1) -> -2
527 * index_name_pos(&index, "d", 1) -> 1
528 * index_name_pos(&index, "e", 1) -> -3
529 * index_name_pos(&index, "f", 1) -> -3
530 * index_name_pos(&index, "g", 1) -> -5
532 int index_name_pos(struct index_state
*, const char *name
, int namelen
);
535 * Like index_name_pos, returns the position of an entry of the given name in
536 * the index if one exists, otherwise returns a negative value where the negated
537 * value minus 1 is the position where the index entry would be inserted. Unlike
538 * index_name_pos, however, a sparse index is not expanded to find an entry
539 * inside a sparse directory.
541 int index_name_pos_sparse(struct index_state
*, const char *name
, int namelen
);
544 * Determines whether an entry with the given name exists within the
545 * given index. The return value is 1 if an exact match is found, otherwise
546 * it is 0. Note that, unlike index_name_pos, this function does not expand
547 * the index if it is sparse. If an item exists within the full index but it
548 * is contained within a sparse directory (and not in the sparse index), 0 is
551 int index_entry_exists(struct index_state
*, const char *name
, int namelen
);
554 * Some functions return the negative complement of an insert position when a
555 * precise match was not found but a position was found where the entry would
556 * need to be inserted. This helper protects that logic from any integer
559 static inline int index_pos_to_insert_pos(uintmax_t pos
)
562 die("overflow: -1 - %"PRIuMAX
, pos
);
563 return -1 - (int)pos
;
566 #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
567 #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
568 #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */
569 #define ADD_CACHE_JUST_APPEND 8 /* Append only */
570 #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */
571 #define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */
572 #define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */
573 int add_index_entry(struct index_state
*, struct cache_entry
*ce
, int option
);
574 void rename_index_entry_at(struct index_state
*, int pos
, const char *new_name
);
576 /* Remove entry, return true if there are more entries to go. */
577 int remove_index_entry_at(struct index_state
*, int pos
);
579 void remove_marked_cache_entries(struct index_state
*istate
, int invalidate
);
580 int remove_file_from_index(struct index_state
*, const char *path
);
581 #define ADD_CACHE_VERBOSE 1
582 #define ADD_CACHE_PRETEND 2
583 #define ADD_CACHE_IGNORE_ERRORS 4
584 #define ADD_CACHE_IGNORE_REMOVAL 8
585 #define ADD_CACHE_INTENT 16
587 * These two are used to add the contents of the file at path
588 * to the index, marking the working tree up-to-date by storing
589 * the cached stat info in the resulting cache entry. A caller
590 * that has already run lstat(2) on the path can call
591 * add_to_index(), and all others can call add_file_to_index();
592 * the latter will do necessary lstat(2) internally before
593 * calling the former.
595 int add_to_index(struct index_state
*, const char *path
, struct stat
*, int flags
);
596 int add_file_to_index(struct index_state
*, const char *path
, int flags
);
598 int chmod_index_entry(struct index_state
*, struct cache_entry
*ce
, char flip
);
599 int ce_same_name(const struct cache_entry
*a
, const struct cache_entry
*b
);
600 void set_object_name_for_intent_to_add_entry(struct cache_entry
*ce
);
601 int index_name_is_other(struct index_state
*, const char *, int);
602 void *read_blob_data_from_index(struct index_state
*, const char *, unsigned long *);
604 /* do stat comparison even if CE_VALID is true */
605 #define CE_MATCH_IGNORE_VALID 01
606 /* do not check the contents but report dirty on racily-clean entries */
607 #define CE_MATCH_RACY_IS_DIRTY 02
608 /* do stat comparison even if CE_SKIP_WORKTREE is true */
609 #define CE_MATCH_IGNORE_SKIP_WORKTREE 04
610 /* ignore non-existent files during stat update */
611 #define CE_MATCH_IGNORE_MISSING 0x08
612 /* enable stat refresh */
613 #define CE_MATCH_REFRESH 0x10
614 /* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
615 #define CE_MATCH_IGNORE_FSMONITOR 0X20
616 int is_racy_timestamp(const struct index_state
*istate
,
617 const struct cache_entry
*ce
);
618 int has_racy_timestamp(struct index_state
*istate
);
619 int ie_match_stat(struct index_state
*, const struct cache_entry
*, struct stat
*, unsigned int);
620 int ie_modified(struct index_state
*, const struct cache_entry
*, struct stat
*, unsigned int);
622 #define HASH_WRITE_OBJECT 1
623 #define HASH_FORMAT_CHECK 2
624 #define HASH_RENORMALIZE 4
625 #define HASH_SILENT 8
626 int index_fd(struct index_state
*istate
, struct object_id
*oid
, int fd
, struct stat
*st
, enum object_type type
, const char *path
, unsigned flags
);
627 int index_path(struct index_state
*istate
, struct object_id
*oid
, const char *path
, struct stat
*st
, unsigned flags
);
630 * Record to sd the data from st that we use to check whether a file
631 * might have changed.
633 void fill_stat_data(struct stat_data
*sd
, struct stat
*st
);
636 * Return 0 if st is consistent with a file not having been changed
637 * since sd was filled. If there are differences, return a
638 * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
639 * INODE_CHANGED, and DATA_CHANGED.
641 int match_stat_data(const struct stat_data
*sd
, struct stat
*st
);
642 int match_stat_data_racy(const struct index_state
*istate
,
643 const struct stat_data
*sd
, struct stat
*st
);
645 void fill_stat_cache_info(struct index_state
*istate
, struct cache_entry
*ce
, struct stat
*st
);
647 #define REFRESH_REALLY (1 << 0) /* ignore_valid */
648 #define REFRESH_UNMERGED (1 << 1) /* allow unmerged */
649 #define REFRESH_QUIET (1 << 2) /* be quiet about it */
650 #define REFRESH_IGNORE_MISSING (1 << 3) /* ignore non-existent */
651 #define REFRESH_IGNORE_SUBMODULES (1 << 4) /* ignore submodules */
652 #define REFRESH_IN_PORCELAIN (1 << 5) /* user friendly output, not "needs update" */
653 #define REFRESH_PROGRESS (1 << 6) /* show progress bar if stderr is tty */
654 #define REFRESH_IGNORE_SKIP_WORKTREE (1 << 7) /* ignore skip_worktree entries */
655 int refresh_index(struct index_state
*, unsigned int flags
, const struct pathspec
*pathspec
, char *seen
, const char *header_msg
);
657 * Refresh the index and write it to disk.
659 * 'refresh_flags' is passed directly to 'refresh_index()', while
660 * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
661 * the lockfile is always either committed or rolled back.
663 * If 'gentle' is passed, errors locking the index are ignored.
665 * Return 1 if refreshing the index returns an error, -1 if writing
666 * the index to disk fails, 0 on success.
668 * Note that if refreshing the index returns an error, we still write
669 * out the index (unless locking fails).
671 int repo_refresh_and_write_index(struct repository
*, unsigned int refresh_flags
, unsigned int write_flags
, int gentle
, const struct pathspec
*, char *seen
, const char *header_msg
);
673 struct cache_entry
*refresh_cache_entry(struct index_state
*, struct cache_entry
*, unsigned int);
675 void set_alternate_index_output(const char *);
677 extern int verify_index_checksum
;
678 extern int verify_ce_order
;
680 extern int quote_path_fully
;
682 #define MTIME_CHANGED 0x0001
683 #define CTIME_CHANGED 0x0002
684 #define OWNER_CHANGED 0x0004
685 #define MODE_CHANGED 0x0008
686 #define INODE_CHANGED 0x0010
687 #define DATA_CHANGED 0x0020
688 #define TYPE_CHANGED 0x0040
691 * Create the directory containing the named path, using care to be
692 * somewhat safe against races. Return one of the scld_error values to
693 * indicate success/failure. On error, set errno to describe the
696 * SCLD_VANISHED indicates that one of the ancestor directories of the
697 * path existed at one point during the function call and then
698 * suddenly vanished, probably because another process pruned the
699 * directory while we were working. To be robust against this kind of
700 * race, callers might want to try invoking the function again when it
701 * returns SCLD_VANISHED.
703 * safe_create_leading_directories() temporarily changes path while it
704 * is working but restores it before returning.
705 * safe_create_leading_directories_const() doesn't modify path, even
706 * temporarily. Both these variants adjust the permissions of the
707 * created directories to honor core.sharedRepository, so they are best
708 * suited for files inside the git dir. For working tree files, use
709 * safe_create_leading_directories_no_share() instead, as it ignores
710 * the core.sharedRepository setting.
719 enum scld_error
safe_create_leading_directories(char *path
);
720 enum scld_error
safe_create_leading_directories_const(const char *path
);
721 enum scld_error
safe_create_leading_directories_no_share(char *path
);
723 int mkdir_in_gitdir(const char *path
);
725 int git_open_cloexec(const char *name
, int flags
);
726 #define git_open(name) git_open_cloexec(name, O_RDONLY)
729 * unpack_loose_header() initializes the data stream needed to unpack
730 * a loose object header.
734 * - ULHR_OK on success
735 * - ULHR_BAD on error
736 * - ULHR_TOO_LONG if the header was too long
738 * It will only parse up to MAX_HEADER_LEN bytes unless an optional
739 * "hdrbuf" argument is non-NULL. This is intended for use with
740 * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error)
741 * reporting. The full header will be extracted to "hdrbuf" for use
742 * with parse_loose_header(), ULHR_TOO_LONG will still be returned
743 * from this function to indicate that the header was too long.
745 enum unpack_loose_header_result
{
750 enum unpack_loose_header_result
unpack_loose_header(git_zstream
*stream
,
752 unsigned long mapsize
,
754 unsigned long bufsiz
,
755 struct strbuf
*hdrbuf
);
758 * parse_loose_header() parses the starting "<type> <len>\0" of an
759 * object. If it doesn't follow that format -1 is returned. To check
760 * the validity of the <type> populate the "typep" in the "struct
761 * object_info". It will be OBJ_BAD if the object type is unknown. The
762 * parsed <len> can be retrieved via "oi->sizep", and from there
763 * passed to unpack_loose_rest().
766 int parse_loose_header(const char *hdr
, struct object_info
*oi
);
769 * With in-core object data in "buf", rehash it to make sure the
770 * object name actually matches "oid" to detect object corruption.
772 * A negative value indicates an error, usually that the OID is not
773 * what we expected, but it might also indicate another error.
775 int check_object_signature(struct repository
*r
, const struct object_id
*oid
,
776 void *map
, unsigned long size
,
777 enum object_type type
);
780 * A streaming version of check_object_signature().
781 * Try reading the object named with "oid" using
782 * the streaming interface and rehash it to do the same.
784 int stream_object_signature(struct repository
*r
, const struct object_id
*oid
);
786 int finalize_object_file(const char *tmpfile
, const char *filename
);
788 /* Helper to check and "touch" a file */
789 int check_and_freshen_file(const char *fn
, int freshen
);
791 int base_name_compare(const char *name1
, size_t len1
, int mode1
,
792 const char *name2
, size_t len2
, int mode2
);
793 int df_name_compare(const char *name1
, size_t len1
, int mode1
,
794 const char *name2
, size_t len2
, int mode2
);
795 int name_compare(const char *name1
, size_t len1
, const char *name2
, size_t len2
);
796 int cache_name_stage_compare(const char *name1
, int len1
, int stage1
, const char *name2
, int len2
, int stage2
);
798 void *read_object_with_reference(struct repository
*r
,
799 const struct object_id
*oid
,
800 enum object_type required_type
,
802 struct object_id
*oid_ret
);
804 const char *git_editor(void);
805 const char *git_sequence_editor(void);
806 const char *git_pager(int stdout_is_tty
);
807 int is_terminal_dumb(void);
813 int prefix_len_stat_func
;
815 #define CACHE_DEF_INIT { \
816 .path = STRBUF_INIT, \
818 static inline void cache_def_clear(struct cache_def
*cache
)
820 strbuf_release(&cache
->path
);
823 int has_symlink_leading_path(const char *name
, int len
);
824 int threaded_has_symlink_leading_path(struct cache_def
*, const char *, int);
825 int check_leading_path(const char *name
, int len
, int warn_on_lstat_err
);
826 int has_dirs_only_path(const char *name
, int len
, int prefix_len
);
827 void invalidate_lstat_cache(void);
828 void schedule_dir_for_removal(const char *name
, int len
);
829 void remove_scheduled_dirs(void);
832 struct pack_window
*next
;
836 unsigned int last_used
;
837 unsigned int inuse_cnt
;
842 struct packed_git
*p
;
846 * Set this to 0 to prevent oid_object_info_extended() from fetching missing
847 * blobs. This has a difference only if extensions.partialClone is set.
849 * Its default value is 1.
851 extern int fetch_if_missing
;
853 /* Dumb servers support */
854 int update_server_info(int);
856 extern const char *git_mailmap_file
;
857 extern const char *git_mailmap_blob
;
859 #define COPY_READ_ERROR (-2)
860 #define COPY_WRITE_ERROR (-3)
861 int copy_fd(int ifd
, int ofd
);
862 int copy_file(const char *dst
, const char *src
, int mode
);
863 int copy_file_with_time(const char *dst
, const char *src
, int mode
);
866 void setup_pager(void);
867 int pager_in_use(void);
868 extern int pager_use_color
;
869 int term_columns(void);
870 void term_clear_line(void);
871 int decimal_width(uintmax_t);
872 int check_pager_config(const char *cmd
);
873 void prepare_pager_args(struct child_process
*, const char *pager
);
876 int decode_85(char *dst
, const char *line
, int linelen
);
877 void encode_85(char *buf
, const unsigned char *data
, int bytes
);
880 void packet_trace_identity(const char *prog
);
884 * return 0 if success, 1 - if addition of a file failed and
885 * ADD_FILES_IGNORE_ERRORS was specified in flags
887 int add_files_to_cache(const char *prefix
, const struct pathspec
*pathspec
, int flags
);
890 extern int diff_auto_refresh_index
;
893 void shift_tree(struct repository
*, const struct object_id
*, const struct object_id
*, struct object_id
*, int);
894 void shift_tree_by(struct repository
*, const struct object_id
*, const struct object_id
*, struct object_id
*, const char *);
898 * used by both diff and apply
899 * last two digits are tab width
901 #define WS_BLANK_AT_EOL 0100
902 #define WS_SPACE_BEFORE_TAB 0200
903 #define WS_INDENT_WITH_NON_TAB 0400
904 #define WS_CR_AT_EOL 01000
905 #define WS_BLANK_AT_EOF 02000
906 #define WS_TAB_IN_INDENT 04000
907 #define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
908 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8)
909 #define WS_TAB_WIDTH_MASK 077
910 /* All WS_* -- when extended, adapt diff.c emit_symbol */
911 #define WS_RULE_MASK 07777
912 extern unsigned whitespace_rule_cfg
;
913 unsigned whitespace_rule(struct index_state
*, const char *);
914 unsigned parse_whitespace_rule(const char *);
915 unsigned ws_check(const char *line
, int len
, unsigned ws_rule
);
916 void ws_check_emit(const char *line
, int len
, unsigned ws_rule
, FILE *stream
, const char *set
, const char *reset
, const char *ws
);
917 char *whitespace_error_string(unsigned ws
);
918 void ws_fix_copy(struct strbuf
*, const char *, int, unsigned, int *);
919 int ws_blank_line(const char *line
, int len
);
920 #define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK)
923 void overlay_tree_on_index(struct index_state
*istate
,
924 const char *tree_name
, const char *prefix
);
928 int try_merge_command(struct repository
*r
,
929 const char *strategy
, size_t xopts_nr
,
930 const char **xopts
, struct commit_list
*common
,
931 const char *head_arg
, struct commit_list
*remotes
);
932 int checkout_fast_forward(struct repository
*r
,
933 const struct object_id
*from
,
934 const struct object_id
*to
,
935 int overwrite_ignore
);
938 int sane_execvp(const char *file
, char *const argv
[]);
941 * A struct to encapsulate the concept of whether a file has changed
942 * since we last checked it. This uses criteria similar to those used
945 struct stat_validity
{
946 struct stat_data
*sd
;
949 void stat_validity_clear(struct stat_validity
*sv
);
952 * Returns 1 if the path is a regular file (or a symlink to a regular
953 * file) and matches the saved stat_validity, 0 otherwise. A missing
954 * or inaccessible file is considered a match if the struct was just
955 * initialized, or if the previous update found an inaccessible file.
957 int stat_validity_check(struct stat_validity
*sv
, const char *path
);
960 * Update the stat_validity from a file opened at descriptor fd. If
961 * the file is missing, inaccessible, or not a regular file, then
962 * future calls to stat_validity_check will match iff one of those
963 * conditions continues to be true.
965 void stat_validity_update(struct stat_validity
*sv
, int fd
);
967 int versioncmp(const char *s1
, const char *s2
);