Uh oh!
There was an error while loading. Please reload this page.
forked from git/git
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.h
More file actions
Latest commit
1906 lines (1689 loc) · 66.6 KB
/
Copy pathcache.h
File metadata and controls
1906 lines (1689 loc) · 66.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndefCACHE_H
#defineCACHE_H
#include"git-compat-util.h"
#include"strbuf.h"
#include"hashmap.h"
#include"list.h"
#include"advice.h"
#include"gettext.h"
#include"convert.h"
#include"trace.h"
#include"trace2.h"
#include"string-list.h"
#include"pack-revindex.h"
#include"hash.h"
#include"path.h"
#include"oid-array.h"
#include"repository.h"
#include"mem-pool.h"
#include<zlib.h>
typedefstructgit_zstream {
z_streamz;
unsigned longavail_in;
unsigned longavail_out;
unsigned longtotal_in;
unsigned longtotal_out;
unsigned char*next_in;
unsigned char*next_out;
} git_zstream;
voidgit_inflate_init(git_zstream*);
voidgit_inflate_init_gzip_only(git_zstream*);
voidgit_inflate_end(git_zstream*);
intgit_inflate(git_zstream*, intflush);
voidgit_deflate_init(git_zstream*, intlevel);
voidgit_deflate_init_gzip(git_zstream*, intlevel);
voidgit_deflate_init_raw(git_zstream*, intlevel);
voidgit_deflate_end(git_zstream*);
intgit_deflate_abort(git_zstream*);
intgit_deflate_end_gently(git_zstream*);
intgit_deflate(git_zstream*, intflush);
unsigned longgit_deflate_bound(git_zstream*, unsigned long);
#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
#defineDTYPE(de) ((de)->d_type)
#else
#undef DT_UNKNOWN
#undef DT_DIR
#undef DT_REG
#undef DT_LNK
#defineDT_UNKNOWN 0
#defineDT_DIR 1
#defineDT_REG 2
#defineDT_LNK 3
#defineDTYPE(de) DT_UNKNOWN
#endif
/* unknown mode (impossible combination S_IFIFO|S_IFCHR) */
#defineS_IFINVALID 0030000
/*
* A "directory link" is a link to another git directory.
*
* The value 0160000 is not normally a valid mode, and
* also just happens to be S_IFDIR + S_IFLNK
*/
#defineS_IFGITLINK 0160000
#defineS_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
/*
* Some mode bits are also used internally for computations.
*
* They *must* not overlap with any valid modes, and they *must* not be emitted
* to outside world - i.e. appear on disk or network. In other words, it's just
* temporary fields, which we internally use, but they have to stay in-house.
*
* ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git
* codebase mode is `unsigned int` which is assumed to be at least 32 bits )
*/
/* used internally in tree-diff */
#defineS_DIFFTREE_IFXMIN_NEQ 0x80000000
/*
* Intensive research over the course of many years has shown that
* port 9418 is totally unused by anything else. Or
*
* Your search - "port 9418" - did not match any documents.
*
* as www.google.com puts it.
*
* This port has been properly assigned for git use by IANA:
* git (Assigned-9418) [I06-050728-0001].
*
* git 9418/tcp git pack transfer service
* git 9418/udp git pack transfer service
*
* with Linus Torvalds <torvalds@osdl.org> as the point of
* contact. September 2005.
*
* See http://www.iana.org/assignments/port-numbers
*/
#defineDEFAULT_GIT_PORT 9418
/*
* Basic data structures for the directory cache
*/
#defineCACHE_SIGNATURE 0x44495243 /* "DIRC" */
structcache_header {
uint32_thdr_signature;
uint32_thdr_version;
uint32_thdr_entries;
};
#defineINDEX_FORMAT_LB 2
#defineINDEX_FORMAT_UB 4
/*
* The "cache_time" is just the low 32 bits of the
* time. It doesn't matter if it overflows - we only
* check it for equality in the 32 bits we save.
*/
structcache_time {
uint32_tsec;
uint32_tnsec;
};
structstat_data {
structcache_timesd_ctime;
structcache_timesd_mtime;
unsigned intsd_dev;
unsigned intsd_ino;
unsigned intsd_uid;
unsigned intsd_gid;
unsigned intsd_size;
};
structcache_entry {
structhashmap_entryent;
structstat_datace_stat_data;
unsigned intce_mode;
unsigned intce_flags;
unsigned intmem_pool_allocated;
unsigned intce_namelen;
unsigned intindex; /* for link extension */
structobject_idoid;
charname[FLEX_ARRAY]; /* more */
};
#defineCE_STAGEMASK (0x3000)
#defineCE_EXTENDED (0x4000)
#defineCE_VALID (0x8000)
#defineCE_STAGESHIFT 12
/*
* Range 0xFFFF0FFF in ce_flags is divided into
* two parts: in-memory flags and on-disk ones.
* Flags in CE_EXTENDED_FLAGS will get saved on-disk
* if you want to save a new flag, add it in
* CE_EXTENDED_FLAGS
*
* In-memory only flags
*/
#defineCE_UPDATE (1 << 16)
#defineCE_REMOVE (1 << 17)
#defineCE_UPTODATE (1 << 18)
#defineCE_ADDED (1 << 19)
#defineCE_HASHED (1 << 20)
#defineCE_FSMONITOR_VALID (1 << 21)
#defineCE_WT_REMOVE (1 << 22) /* remove in work directory */
#defineCE_CONFLICTED (1 << 23)
#defineCE_UNPACKED (1 << 24)
#defineCE_NEW_SKIP_WORKTREE (1 << 25)
/* used to temporarily mark paths matched by pathspecs */
#defineCE_MATCHED (1 << 26)
#defineCE_UPDATE_IN_BASE (1 << 27)
#defineCE_STRIP_NAME (1 << 28)
/*
* Extended on-disk flags
*/
#defineCE_INTENT_TO_ADD (1 << 29)
#defineCE_SKIP_WORKTREE (1 << 30)
/* CE_EXTENDED2 is for future extension */
#defineCE_EXTENDED2 (1U << 31)
#defineCE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
/*
* Safeguard to avoid saving wrong flags:
* - CE_EXTENDED2 won't get saved until its semantic is known
* - Bits in 0x0000FFFF have been saved in ce_flags already
* - Bits in 0x003F0000 are currently in-memory flags
*/
#ifCE_EXTENDED_FLAGS&0x803FFFFF
#error "CE_EXTENDED_FLAGS out of range"
#endif
#defineS_ISSPARSEDIR(m) ((m) == S_IFDIR)
/* Forward structure decls */
structpathspec;
structchild_process;
structtree;
/*
* Copy the sha1 and stat state of a cache entry from one to
* another. But we never change the name, or the hash state!
*/
staticinlinevoidcopy_cache_entry(structcache_entry*dst,
conststructcache_entry*src)
{
unsigned intstate=dst->ce_flags&CE_HASHED;
intmem_pool_allocated=dst->mem_pool_allocated;
/* Don't copy hash chain and name */
memcpy(&dst->ce_stat_data, &src->ce_stat_data,
offsetof(structcache_entry, name) -
offsetof(structcache_entry, ce_stat_data));
/* Restore the hash state */
dst->ce_flags= (dst->ce_flags& ~CE_HASHED) | state;
/* Restore the mem_pool_allocated flag */
dst->mem_pool_allocated=mem_pool_allocated;
}
staticinlineunsignedcreate_ce_flags(unsignedstage)
{
return (stage << CE_STAGESHIFT);
}
#definece_namelen(ce) ((ce)->ce_namelen)
#definece_size(ce) cache_entry_size(ce_namelen(ce))
#definece_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
#definece_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
#definece_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
#definece_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
#definece_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
#definece_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
staticinlineunsigned intcreate_ce_mode(unsigned intmode)
{
if (S_ISLNK(mode))
returnS_IFLNK;
if (S_ISSPARSEDIR(mode))
returnS_IFDIR;
if (S_ISDIR(mode) ||S_ISGITLINK(mode))
returnS_IFGITLINK;
returnS_IFREG | ce_permissions(mode);
}
staticinlineunsigned intce_mode_from_stat(conststructcache_entry*ce,
unsigned intmode)
{
externinttrust_executable_bit, has_symlinks;
if (!has_symlinks&&S_ISREG(mode) &&
ce&&S_ISLNK(ce->ce_mode))
returnce->ce_mode;
if (!trust_executable_bit&&S_ISREG(mode)) {
if (ce&&S_ISREG(ce->ce_mode))
returnce->ce_mode;
returncreate_ce_mode(0666);
}
returncreate_ce_mode(mode);
}
staticinlineintce_to_dtype(conststructcache_entry*ce)
{
unsignedce_mode=ntohl(ce->ce_mode);
if (S_ISREG(ce_mode))
returnDT_REG;
elseif (S_ISDIR(ce_mode) ||S_ISGITLINK(ce_mode))
returnDT_DIR;
elseif (S_ISLNK(ce_mode))
returnDT_LNK;
else
returnDT_UNKNOWN;
}
staticinlineunsigned intcanon_mode(unsigned intmode)
{
if (S_ISREG(mode))
returnS_IFREG | ce_permissions(mode);
if (S_ISLNK(mode))
returnS_IFLNK;
if (S_ISDIR(mode))
returnS_IFDIR;
returnS_IFGITLINK;
}
#definecache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
#defineSOMETHING_CHANGED (1 << 0) /* unclassified changes go here */
#defineCE_ENTRY_CHANGED (1 << 1)
#defineCE_ENTRY_REMOVED (1 << 2)
#defineCE_ENTRY_ADDED (1 << 3)
#defineRESOLVE_UNDO_CHANGED (1 << 4)
#defineCACHE_TREE_CHANGED (1 << 5)
#defineSPLIT_INDEX_ORDERED (1 << 6)
#defineUNTRACKED_CHANGED (1 << 7)
#defineFSMONITOR_CHANGED (1 << 8)
structsplit_index;
structuntracked_cache;
structprogress;
structpattern_list;
structindex_state {
structcache_entry**cache;
unsigned intversion;
unsigned intcache_nr, cache_alloc, cache_changed;
structstring_list*resolve_undo;
structcache_tree*cache_tree;
structsplit_index*split_index;
structcache_timetimestamp;
unsignedname_hash_initialized : 1,
initialized : 1,
drop_cache_tree : 1,
updated_workdir : 1,
updated_skipworktree : 1,
fsmonitor_has_run_once : 1,
/*
* sparse_index == 1 when sparse-directory
* entries exist. Requires sparse-checkout
* in cone mode.
*/
sparse_index : 1;
structhashmapname_hash;
structhashmapdir_hash;
structobject_idoid;
structuntracked_cache*untracked;
char*fsmonitor_last_update;
structewah_bitmap*fsmonitor_dirty;
structmem_pool*ce_mem_pool;
structprogress*progress;
structrepository*repo;
structpattern_list*sparse_checkout_patterns;
};
/* Name hashing */
inttest_lazy_init_name_hash(structindex_state*istate, inttry_threaded);
voidadd_name_hash(structindex_state*istate, structcache_entry*ce);
voidremove_name_hash(structindex_state*istate, structcache_entry*ce);
voidfree_name_hash(structindex_state*istate);
voidensure_full_index(structindex_state*istate);
/* Cache entry creation and cleanup */
/*
* Create cache_entry intended for use in the specified index. Caller
* is responsible for discarding the cache_entry with
* `discard_cache_entry`.
*/
structcache_entry*make_cache_entry(structindex_state*istate,
unsigned intmode,
conststructobject_id*oid,
constchar*path,
intstage,
unsigned intrefresh_options);
structcache_entry*make_empty_cache_entry(structindex_state*istate,
size_tname_len);
/*
* Create a cache_entry that is not intended to be added to an index. If
* `ce_mem_pool` is not NULL, the entry is allocated within the given memory
* pool. Caller is responsible for discarding "loose" entries with
* `discard_cache_entry()` and the memory pool with
* `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
*/
structcache_entry*make_transient_cache_entry(unsigned intmode,
conststructobject_id*oid,
constchar*path,
intstage,
structmem_pool*ce_mem_pool);
structcache_entry*make_empty_transient_cache_entry(size_tlen,
structmem_pool*ce_mem_pool);
/*
* Discard cache entry.
*/
voiddiscard_cache_entry(structcache_entry*ce);
/*
* Check configuration if we should perform extra validation on cache
* entries.
*/
intshould_validate_cache_entries(void);
/*
* Duplicate a cache_entry. Allocate memory for the new entry from a
* memory_pool. Takes into account cache_entry fields that are meant
* for managing the underlying memory allocation of the cache_entry.
*/
structcache_entry*dup_cache_entry(conststructcache_entry*ce, structindex_state*istate);
/*
* Validate the cache entries in the index. This is an internal
* consistency check that the cache_entry structs are allocated from
* the expected memory pool.
*/
voidvalidate_cache_entries(conststructindex_state*istate);
/*
* Bulk prefetch all missing cache entries that are not GITLINKs and that match
* the given predicate. This function should only be called if
* has_promisor_remote() returns true.
*/
typedefint (*must_prefetch_predicate)(conststructcache_entry*);
voidprefetch_cache_entries(conststructindex_state*istate,
must_prefetch_predicatemust_prefetch);
#ifdefUSE_THE_INDEX_COMPATIBILITY_MACROS
externstructindex_statethe_index;
#defineactive_cache (the_index.cache)
#defineactive_nr (the_index.cache_nr)
#defineactive_alloc (the_index.cache_alloc)
#defineactive_cache_changed (the_index.cache_changed)
#defineactive_cache_tree (the_index.cache_tree)
#defineread_cache() repo_read_index(the_repository)
#defineread_cache_from(path) read_index_from(&the_index, (path), (get_git_dir()))
#defineread_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)
#defineis_cache_unborn() is_index_unborn(&the_index)
#defineread_cache_unmerged() repo_read_index_unmerged(the_repository)
#definediscard_cache() discard_index(&the_index)
#defineunmerged_cache() unmerged_index(&the_index)
#definecache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
#defineadd_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))
#definerename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))
#defineremove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))
#defineremove_file_from_cache(path) remove_file_from_index(&the_index, (path))
#defineadd_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))
#defineadd_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))
#definechmod_cache_entry(ce, flip) chmod_index_entry(&the_index, (ce), (flip))
#definerefresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
#definerefresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL)
#definece_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
#definece_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
#definecache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen))
#definecache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))
#definecache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))
#defineresolve_undo_clear() resolve_undo_clear_index(&the_index)
#defineunmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
#defineunmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
#defineread_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))
#definehold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
#endif
#defineTYPE_BITS 3
/*
* Values in this enum (except those outside the 3 bit range) are part
* of pack file format. See Documentation/technical/pack-format.txt
* for more information.
*/
enumobject_type {
OBJ_BAD=-1,
OBJ_NONE=0,
OBJ_COMMIT=1,
OBJ_TREE=2,
OBJ_BLOB=3,
OBJ_TAG=4,
/* 5 for future expansion */
OBJ_OFS_DELTA=6,
OBJ_REF_DELTA=7,
OBJ_ANY,
OBJ_MAX
};
staticinlineenumobject_typeobject_type(unsigned intmode)
{
returnS_ISDIR(mode) ? OBJ_TREE :
S_ISGITLINK(mode) ? OBJ_COMMIT :
OBJ_BLOB;
}
/* Double-check local_repo_env below if you add to this list. */
#defineGIT_DIR_ENVIRONMENT "GIT_DIR"
#defineGIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR"
#defineGIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
#defineGIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
#defineGIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
#defineGIT_SUPER_PREFIX_ENVIRONMENT "GIT_INTERNAL_SUPER_PREFIX"
#defineDEFAULT_GIT_DIR_ENVIRONMENT ".git"
#defineDB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
#defineINDEX_ENVIRONMENT "GIT_INDEX_FILE"
#defineGRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
#defineGIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE"
#defineTEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
#defineCONFIG_ENVIRONMENT "GIT_CONFIG"
#defineCONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS"
#defineCONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT"
#defineEXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
#defineCEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
#defineNO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
#defineGIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
#defineGITATTRIBUTES_FILE ".gitattributes"
#defineINFOATTRIBUTES_FILE "info/attributes"
#defineATTRIBUTE_MACRO_PREFIX "[attr]"
#defineGITMODULES_FILE ".gitmodules"
#defineGITMODULES_INDEX ":.gitmodules"
#defineGITMODULES_HEAD "HEAD:.gitmodules"
#defineGIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
#defineGIT_NOTES_DEFAULT_REF "refs/notes/commits"
#defineGIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF"
#defineGIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF"
#defineGIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"
#defineGIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS"
#defineGIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS"
#defineGIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS"
#defineGIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
#defineGIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
#defineGIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
#defineGIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
/*
* Environment variable used in handshaking the wire protocol.
* Contains a colon ':' separated list of keys with optional values
* 'key[=value]'. Presence of unknown keys and values must be
* ignored.
*/
#defineGIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL"
/* HTTP header used to handshake the wire protocol */
#defineGIT_PROTOCOL_HEADER "Git-Protocol"
/*
* This environment variable is expected to contain a boolean indicating
* whether we should or should not treat:
*
* GIT_DIR=foo.git git ...
*
* as if GIT_WORK_TREE=. was given. It's not expected that users will make use
* of this, but we use it internally to communicate to sub-processes that we
* are in a bare repo. If not set, defaults to true.
*/
#defineGIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE"
/*
* Repository-local GIT_* environment variables; these will be cleared
* when git spawns a sub-process that runs inside another repository.
* The array is NULL-terminated, which makes it easy to pass in the "env"
* parameter of a run-command invocation, or to do a simple walk.
*/
externconstchar*constlocal_repo_env[];
voidsetup_git_env(constchar*git_dir);
/*
* Returns true iff we have a configured git repository (either via
* setup_git_directory, or in the environment via $GIT_DIR).
*/
inthave_git_dir(void);
externintis_bare_repository_cfg;
intis_bare_repository(void);
intis_inside_git_dir(void);
externchar*git_work_tree_cfg;
intis_inside_work_tree(void);
constchar*get_git_dir(void);
constchar*get_git_common_dir(void);
char*get_object_directory(void);
char*get_index_file(void);
char*get_graft_file(structrepository*r);
voidset_git_dir(constchar*path, intmake_realpath);
intget_common_dir_noenv(structstrbuf*sb, constchar*gitdir);
intget_common_dir(structstrbuf*sb, constchar*gitdir);
constchar*get_git_namespace(void);
constchar*strip_namespace(constchar*namespaced_ref);
constchar*get_super_prefix(void);
constchar*get_git_work_tree(void);
/*
* Return true if the given path is a git directory; note that this _just_
* looks at the directory itself. If you want to know whether "foo/.git"
* is a repository, you must feed that path, not just "foo".
*/
intis_git_directory(constchar*path);
/*
* Return 1 if the given path is the root of a git repository or
* submodule, else 0. Will not return 1 for bare repositories with the
* exception of creating a bare repository in "foo/.git" and calling
* is_git_repository("foo").
*
* If we run into read errors, we err on the side of saying "yes, it is",
* as we usually consider sub-repos precious, and would prefer to err on the
* side of not disrupting or deleting them.
*/
intis_nonbare_repository_dir(structstrbuf*path);
#defineREAD_GITFILE_ERR_STAT_FAILED 1
#defineREAD_GITFILE_ERR_NOT_A_FILE 2
#defineREAD_GITFILE_ERR_OPEN_FAILED 3
#defineREAD_GITFILE_ERR_READ_FAILED 4
#defineREAD_GITFILE_ERR_INVALID_FORMAT 5
#defineREAD_GITFILE_ERR_NO_PATH 6
#defineREAD_GITFILE_ERR_NOT_A_REPO 7
#defineREAD_GITFILE_ERR_TOO_LARGE 8
voidread_gitfile_error_die(interror_code, constchar*path, constchar*dir);
constchar*read_gitfile_gently(constchar*path, int*return_error_code);
#defineread_gitfile(path) read_gitfile_gently((path), NULL)
constchar*resolve_gitdir_gently(constchar*suspect, int*return_error_code);
#defineresolve_gitdir(path) resolve_gitdir_gently((path), NULL)
voidset_git_work_tree(constchar*tree);
#defineALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
voidsetup_work_tree(void);
/*
* Find the commondir and gitdir of the repository that contains the current
* working directory, without changing the working directory or other global
* state. The result is appended to commondir and gitdir. If the discovered
* gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
* both have the same result appended to the buffer. The return value is
* either 0 upon success and non-zero if no repository was found.
*/
intdiscover_git_directory(structstrbuf*commondir,
structstrbuf*gitdir);
constchar*setup_git_directory_gently(int*);
constchar*setup_git_directory(void);
char*prefix_path(constchar*prefix, intlen, constchar*path);
char*prefix_path_gently(constchar*prefix, intlen, int*remaining, constchar*path);
/*
* Concatenate "prefix" (if len is non-zero) and "path", with no
* connecting characters (so "prefix" should end with a "/").
* Unlike prefix_path, this should be used if the named file does
* not have to interact with index entry; i.e. name of a random file
* on the filesystem.
*
* The return value is always a newly allocated string (even if the
* prefix was empty).
*/
char*prefix_filename(constchar*prefix, constchar*path);
intcheck_filename(constchar*prefix, constchar*name);
voidverify_filename(constchar*prefix,
constchar*name,
intdiagnose_misspelt_rev);
voidverify_non_filename(constchar*prefix, constchar*name);
intpath_inside_repo(constchar*prefix, constchar*path);
#defineINIT_DB_QUIET 0x0001
#defineINIT_DB_EXIST_OK 0x0002
intinit_db(constchar*git_dir, constchar*real_git_dir,
constchar*template_dir, inthash_algo,
constchar*initial_branch, unsigned intflags);
voidinitialize_repository_version(inthash_algo, intreinit);
voidsanitize_stdfds(void);
intdaemonize(void);
#definealloc_nr(x) (((x)+16)*3/2)
/**
* Dynamically growing an array using realloc() is error prone and boring.
*
* Define your array with:
*
* - a pointer (`item`) that points at the array, initialized to `NULL`
* (although please name the variable based on its contents, not on its
* type);
*
* - an integer variable (`alloc`) that keeps track of how big the current
* allocation is, initialized to `0`;
*
* - another integer variable (`nr`) to keep track of how many elements the
* array currently has, initialized to `0`.
*
* Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,
* alloc)`. This ensures that the array can hold at least `n` elements by
* calling `realloc(3)` and adjusting `alloc` variable.
*
* ------------
* sometype *item;
* size_t nr;
* size_t alloc
*
* for (i = 0; i < nr; i++)
* if (we like item[i] already)
* return;
*
* // we did not like any existing one, so add one
* ALLOC_GROW(item, nr + 1, alloc);
* item[nr++] = value you like;
* ------------
*
* You are responsible for updating the `nr` variable.
*
* If you need to specify the number of elements to allocate explicitly
* then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
*
* Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
* added niceties.
*
* DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
*/
#defineALLOC_GROW(x, nr, alloc) \
do { \
if ((nr) > alloc) { \
if (alloc_nr(alloc) < (nr)) \
alloc = (nr); \
else \
alloc = alloc_nr(alloc); \
REALLOC_ARRAY(x, alloc); \
} \
} while (0)
/*
* Similar to ALLOC_GROW but handles updating of the nr value and
* zeroing the bytes of the newly-grown array elements.
*
* DO NOT USE any expression with side-effect for any of the
* arguments.
*/
#defineALLOC_GROW_BY(x, nr, increase, alloc) \
do { \
if (increase) { \
size_t new_nr = nr + (increase); \
if (new_nr < nr) \
BUG("negative growth in ALLOC_GROW_BY"); \
ALLOC_GROW(x, new_nr, alloc); \
memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
nr = new_nr; \
} \
} while (0)
/* Initialize and use the cache information */
structlock_file;
voidpreload_index(structindex_state*index,
conststructpathspec*pathspec,
unsigned intrefresh_flags);
intdo_read_index(structindex_state*istate, constchar*path,
intmust_exist); /* for testting only! */
intread_index_from(structindex_state*, constchar*path,
constchar*gitdir);
intis_index_unborn(structindex_state*);
voidensure_full_index(structindex_state*istate);
/* For use with `write_locked_index()`. */
#defineCOMMIT_LOCK (1 << 0)
#defineSKIP_IF_UNCHANGED (1 << 1)
/*
* Write the index while holding an already-taken lock. Close the lock,
* and if `COMMIT_LOCK` is given, commit it.
*
* Unless a split index is in use, write the index into the lockfile.
*
* With a split index, write the shared index to a temporary file,
* adjust its permissions and rename it into place, then write the
* split index to the lockfile. If the temporary file for the shared
* index cannot be created, fall back to the behavior described in
* the previous paragraph.
*
* With `COMMIT_LOCK`, the lock is always committed or rolled back.
* Without it, the lock is closed, but neither committed nor rolled
* back.
*
* If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
* is written (and the lock is rolled back if `COMMIT_LOCK` is given).
*/
intwrite_locked_index(structindex_state*, structlock_file*lock, unsignedflags);
intdiscard_index(structindex_state*);
voidmove_index_extensions(structindex_state*dst, structindex_state*src);
intunmerged_index(conststructindex_state*);
/**
* Returns 1 if istate differs from tree, 0 otherwise. If tree is NULL,
* compares istate to HEAD. If tree is NULL and on an unborn branch,
* returns 1 if there are entries in istate, 0 otherwise. If an strbuf is
* provided, the space-separated list of files that differ will be appended
* to it.
*/
intrepo_index_has_changes(structrepository*repo,
structtree*tree,
structstrbuf*sb);
intverify_path(constchar*path, unsignedmode);
intstrcmp_offset(constchar*s1, constchar*s2, size_t*first_change);
intindex_dir_exists(structindex_state*istate, constchar*name, intnamelen);
voidadjust_dirname_case(structindex_state*istate, char*name);
structcache_entry*index_file_exists(structindex_state*istate, constchar*name, intnamelen, intigncase);
/*
* Searches for an entry defined by name and namelen in the given index.
* If the return value is positive (including 0) it is the position of an
* exact match. If the return value is negative, the negated value minus 1
* is the position where the entry would be inserted.
* Example: The current index consists of these files and its stages:
*
* b#0, d#0, f#1, f#3
*
* index_name_pos(&index, "a", 1) -> -1
* index_name_pos(&index, "b", 1) -> 0
* index_name_pos(&index, "c", 1) -> -2
* index_name_pos(&index, "d", 1) -> 1
* index_name_pos(&index, "e", 1) -> -3
* index_name_pos(&index, "f", 1) -> -3
* index_name_pos(&index, "g", 1) -> -5
*/
intindex_name_pos(structindex_state*, constchar*name, intnamelen);
/*
* Some functions return the negative complement of an insert position when a
* precise match was not found but a position was found where the entry would
* need to be inserted. This helper protects that logic from any integer
* underflow.
*/
staticinlineintindex_pos_to_insert_pos(uintmax_tpos)
{
if (pos>INT_MAX)
die("overflow: -1 - %"PRIuMAX, pos);
return-1- (int)pos;
}
#defineADD_CACHE_OK_TO_ADD 1 /* Ok to add */
#defineADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
#defineADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */
#defineADD_CACHE_JUST_APPEND 8 /* Append only */
#defineADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */
#defineADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */
#defineADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */
intadd_index_entry(structindex_state*, structcache_entry*ce, intoption);
voidrename_index_entry_at(structindex_state*, intpos, constchar*new_name);
/* Remove entry, return true if there are more entries to go. */
intremove_index_entry_at(structindex_state*, intpos);
voidremove_marked_cache_entries(structindex_state*istate, intinvalidate);
intremove_file_from_index(structindex_state*, constchar*path);
#defineADD_CACHE_VERBOSE 1
#defineADD_CACHE_PRETEND 2
#defineADD_CACHE_IGNORE_ERRORS 4
#defineADD_CACHE_IGNORE_REMOVAL 8
#defineADD_CACHE_INTENT 16
/*
* These two are used to add the contents of the file at path
* to the index, marking the working tree up-to-date by storing
* the cached stat info in the resulting cache entry. A caller
* that has already run lstat(2) on the path can call
* add_to_index(), and all others can call add_file_to_index();
* the latter will do necessary lstat(2) internally before
* calling the former.
*/
intadd_to_index(structindex_state*, constchar*path, structstat*, intflags);
intadd_file_to_index(structindex_state*, constchar*path, intflags);
intchmod_index_entry(structindex_state*, structcache_entry*ce, charflip);
intce_same_name(conststructcache_entry*a, conststructcache_entry*b);
voidset_object_name_for_intent_to_add_entry(structcache_entry*ce);
intindex_name_is_other(structindex_state*, constchar*, int);
void*read_blob_data_from_index(structindex_state*, constchar*, unsigned long*);
/* do stat comparison even if CE_VALID is true */
#defineCE_MATCH_IGNORE_VALID 01
/* do not check the contents but report dirty on racily-clean entries */
#defineCE_MATCH_RACY_IS_DIRTY 02
/* do stat comparison even if CE_SKIP_WORKTREE is true */
#defineCE_MATCH_IGNORE_SKIP_WORKTREE 04
/* ignore non-existent files during stat update */
#defineCE_MATCH_IGNORE_MISSING 0x08
/* enable stat refresh */
#defineCE_MATCH_REFRESH 0x10
/* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
#defineCE_MATCH_IGNORE_FSMONITOR 0X20
intis_racy_timestamp(conststructindex_state*istate,
conststructcache_entry*ce);
intie_match_stat(structindex_state*, conststructcache_entry*, structstat*, unsigned int);
intie_modified(structindex_state*, conststructcache_entry*, structstat*, unsigned int);
#defineHASH_WRITE_OBJECT 1
#defineHASH_FORMAT_CHECK 2
#defineHASH_RENORMALIZE 4
intindex_fd(structindex_state*istate, structobject_id*oid, intfd, structstat*st, enumobject_typetype, constchar*path, unsignedflags);
intindex_path(structindex_state*istate, structobject_id*oid, constchar*path, structstat*st, unsignedflags);
/*
* Record to sd the data from st that we use to check whether a file
* might have changed.
*/
voidfill_stat_data(structstat_data*sd, structstat*st);
/*
* Return 0 if st is consistent with a file not having been changed
* since sd was filled. If there are differences, return a
* combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
* INODE_CHANGED, and DATA_CHANGED.
*/
intmatch_stat_data(conststructstat_data*sd, structstat*st);
intmatch_stat_data_racy(conststructindex_state*istate,
conststructstat_data*sd, structstat*st);
voidfill_stat_cache_info(structindex_state*istate, structcache_entry*ce, structstat*st);
#defineREFRESH_REALLY (1 << 0) /* ignore_valid */
#defineREFRESH_UNMERGED (1 << 1) /* allow unmerged */
#defineREFRESH_QUIET (1 << 2) /* be quiet about it */
#defineREFRESH_IGNORE_MISSING (1 << 3) /* ignore non-existent */
#defineREFRESH_IGNORE_SUBMODULES (1 << 4) /* ignore submodules */
#defineREFRESH_IN_PORCELAIN (1 << 5) /* user friendly output, not "needs update" */
#defineREFRESH_PROGRESS (1 << 6) /* show progress bar if stderr is tty */
#defineREFRESH_IGNORE_SKIP_WORKTREE (1 << 7) /* ignore skip_worktree entries */
intrefresh_index(structindex_state*, unsigned intflags, conststructpathspec*pathspec, char*seen, constchar*header_msg);
/*
* Refresh the index and write it to disk.
*
* 'refresh_flags' is passed directly to 'refresh_index()', while
* 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
* the lockfile is always either committed or rolled back.
*
* If 'gentle' is passed, errors locking the index are ignored.
*
* Return 1 if refreshing the index returns an error, -1 if writing
* the index to disk fails, 0 on success.
*
* Note that if refreshing the index returns an error, we still write
* out the index (unless locking fails).
*/
intrepo_refresh_and_write_index(structrepository*, unsigned intrefresh_flags, unsigned intwrite_flags, intgentle, conststructpathspec*, char*seen, constchar*header_msg);
structcache_entry*refresh_cache_entry(structindex_state*, structcache_entry*, unsigned int);
voidset_alternate_index_output(constchar*);
externintverify_index_checksum;
externintverify_ce_order;
/* Environment bits from configuration mechanism */
externinttrust_executable_bit;
externinttrust_ctime;
externintcheck_stat;
externintquote_path_fully;
externinthas_symlinks;
externintminimum_abbrev, default_abbrev;
externintignore_case;
externintassume_unchanged;
externintprefer_symlink_refs;
externintwarn_ambiguous_refs;
externintwarn_on_object_refname_ambiguity;
externchar*apply_default_whitespace;
externchar*apply_default_ignorewhitespace;
externconstchar*git_attributes_file;
externconstchar*git_hooks_path;
externintzlib_compression_level;
externintcore_compression_level;
externintpack_compression_level;
externsize_tpacked_git_window_size;
externsize_tpacked_git_limit;
externsize_tdelta_base_cache_limit;
externunsigned longbig_file_threshold;
externunsigned longpack_size_limit_cfg;
/*
* Accessors for the core.sharedrepository config which lazy-load the value
* from the config (if not already set). The "reset" function can be
* used to unset "set" or cached value, meaning that the value will be loaded
* fresh from the config file on the next call to get_shared_repository().
*/
voidset_shared_repository(intvalue);
intget_shared_repository(void);
voidreset_shared_repository(void);
/*
* Do replace refs need to be checked this run? This variable is
* initialized to true unless --no-replace-object is used or
* $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some
* commands that do not want replace references to be active.
*/
externintread_replace_refs;
externchar*git_replace_ref_base;
externintfsync_object_files;
externintcore_preload_index;
externintprecomposed_unicode;
externintprotect_hfs;
externintprotect_ntfs;
externconstchar*core_fsmonitor;
externintcore_apply_sparse_checkout;
externintcore_sparse_checkout_cone;
/*
* Include broken refs in all ref iterations, which will
* generally choke dangerous operations rather than letting