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
1750 lines (1534 loc) · 61 KB
/
Copy pathcache.h
File metadata and controls
1750 lines (1534 loc) · 61 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"advice.h"
#include"gettext.h"
#include"convert.h"
#include"trace.h"
#include"string-list.h"
#includeSHA1_HEADER
#ifndefgit_SHA_CTX
#definegit_SHA_CTX SHA_CTX
#definegit_SHA1_Init SHA1_Init
#definegit_SHA1_Update SHA1_Update
#definegit_SHA1_Final SHA1_Final
#endif
#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);
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
#defineGIT_SHA1_RAWSZ 20
#defineGIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
structobject_id {
unsigned charhash[GIT_SHA1_RAWSZ];
};
#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 intce_namelen;
unsigned intindex; /* for link extension */
unsigned charsha1[20];
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_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 (1 << 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
structpathspec;
/*
* 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;
/* 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;
}
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_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
staticinlineunsigned intcreate_ce_mode(unsigned intmode)
{
if (S_ISLNK(mode))
returnS_IFLNK;
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)
structsplit_index;
structuntracked_cache;
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;
structhashmapname_hash;
structhashmapdir_hash;
unsigned charsha1[20];
structuntracked_cache*untracked;
};
externstructindex_statethe_index;
/* Name hashing */
externvoidadd_name_hash(structindex_state*istate, structcache_entry*ce);
externvoidremove_name_hash(structindex_state*istate, structcache_entry*ce);
externvoidfree_name_hash(structindex_state*istate);
#ifndefNO_THE_INDEX_COMPATIBILITY_MACROS
#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() read_index(&the_index)
#defineread_cache_from(path) read_index_from(&the_index, (path))
#defineread_cache_preload(pathspec) read_index_preload(&the_index, (pathspec))
#defineis_cache_unborn() is_index_unborn(&the_index)
#defineread_cache_unmerged() read_index_unmerged(&the_index)
#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))
#definerefresh_cache(flags) refresh_index(&the_index, (flags), 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))
#endif
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"
#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"
#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]"
#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"
/*
* 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[];
externintis_bare_repository_cfg;
externintis_bare_repository(void);
externintis_inside_git_dir(void);
externchar*git_work_tree_cfg;
externintis_inside_work_tree(void);
externconstchar*get_git_dir(void);
externconstchar*get_git_common_dir(void);
externintis_git_directory(constchar*path);
externchar*get_object_directory(void);
externchar*get_index_file(void);
externchar*get_graft_file(void);
externintset_git_dir(constchar*path);
externintget_common_dir_noenv(structstrbuf*sb, constchar*gitdir);
externintget_common_dir(structstrbuf*sb, constchar*gitdir);
externconstchar*get_git_namespace(void);
externconstchar*strip_namespace(constchar*namespaced_ref);
externconstchar*get_git_work_tree(void);
#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
externconstchar*read_gitfile_gently(constchar*path, int*return_error_code);
#defineread_gitfile(path) read_gitfile_gently((path), NULL)
externconstchar*resolve_gitdir(constchar*suspect);
externvoidset_git_work_tree(constchar*tree);
#defineALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
externconstchar**get_pathspec(constchar*prefix, constchar**pathspec);
externvoidsetup_work_tree(void);
externconstchar*setup_git_directory_gently(int*);
externconstchar*setup_git_directory(void);
externchar*prefix_path(constchar*prefix, intlen, constchar*path);
externchar*prefix_path_gently(constchar*prefix, intlen, int*remaining, constchar*path);
externconstchar*prefix_filename(constchar*prefix, intlen, constchar*path);
externintcheck_filename(constchar*prefix, constchar*name);
externvoidverify_filename(constchar*prefix,
constchar*name,
intdiagnose_misspelt_rev);
externvoidverify_non_filename(constchar*prefix, constchar*name);
externintpath_inside_repo(constchar*prefix, constchar*path);
#defineINIT_DB_QUIET 0x0001
externintset_git_dir_init(constchar*git_dir, constchar*real_git_dir, int);
externintinit_db(constchar*template_dir, unsigned intflags);
externvoidsanitize_stdfds(void);
externintdaemonize(void);
#definealloc_nr(x) (((x)+16)*3/2)
/*
* Realloc the buffer pointed at by variable 'x' so that it can hold
* at least 'nr' entries; the number of entries currently allocated
* is 'alloc', using the standard growing factor alloc_nr() macro.
*
* 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)
/* Initialize and use the cache information */
structlock_file;
externintread_index(structindex_state*);
externintread_index_preload(structindex_state*, conststructpathspec*pathspec);
externintdo_read_index(structindex_state*istate, constchar*path,
intmust_exist); /* for testting only! */
externintread_index_from(structindex_state*, constchar*path);
externintis_index_unborn(structindex_state*);
externintread_index_unmerged(structindex_state*);
#defineCOMMIT_LOCK (1 << 0)
#defineCLOSE_LOCK (1 << 1)
externintwrite_locked_index(structindex_state*, structlock_file*lock, unsignedflags);
externintdiscard_index(structindex_state*);
externintunmerged_index(conststructindex_state*);
externintverify_path(constchar*path);
externintindex_dir_exists(structindex_state*istate, constchar*name, intnamelen);
externvoidadjust_dirname_case(structindex_state*istate, char*name);
externstructcache_entry*index_file_exists(structindex_state*istate, constchar*name, intnamelen, intigncase);
externintindex_name_pos(conststructindex_state*, constchar*name, intnamelen);
#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; tree.c::read_tree() */
#defineADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */
#defineADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */
externintadd_index_entry(structindex_state*, structcache_entry*ce, intoption);
externvoidrename_index_entry_at(structindex_state*, intpos, constchar*new_name);
externintremove_index_entry_at(structindex_state*, intpos);
externvoidremove_marked_cache_entries(structindex_state*istate);
externintremove_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
externintadd_to_index(structindex_state*, constchar*path, structstat*, intflags);
externintadd_file_to_index(structindex_state*, constchar*path, intflags);
externstructcache_entry*make_cache_entry(unsigned intmode, constunsigned char*sha1, constchar*path, intstage, unsigned intrefresh_options);
externintce_same_name(conststructcache_entry*a, conststructcache_entry*b);
externvoidset_object_name_for_intent_to_add_entry(structcache_entry*ce);
externintindex_name_is_other(conststructindex_state*, constchar*, int);
externvoid*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
externintie_match_stat(conststructindex_state*, conststructcache_entry*, structstat*, unsigned int);
externintie_modified(conststructindex_state*, conststructcache_entry*, structstat*, unsigned int);
#defineHASH_WRITE_OBJECT 1
#defineHASH_FORMAT_CHECK 2
externintindex_fd(unsigned char*sha1, intfd, structstat*st, enumobject_typetype, constchar*path, unsignedflags);
externintindex_path(unsigned char*sha1, constchar*path, structstat*st, unsignedflags);
/*
* Record to sd the data from st that we use to check whether a file
* might have changed.
*/
externvoidfill_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.
*/
externintmatch_stat_data(conststructstat_data*sd, structstat*st);
externintmatch_stat_data_racy(conststructindex_state*istate,
conststructstat_data*sd, structstat*st);
externvoidfill_stat_cache_info(structcache_entry*ce, structstat*st);
#defineREFRESH_REALLY 0x0001 /* ignore_valid */
#defineREFRESH_UNMERGED 0x0002 /* allow unmerged */
#defineREFRESH_QUIET 0x0004 /* be quiet about it */
#defineREFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */
#defineREFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */
#defineREFRESH_IN_PORCELAIN 0x0020 /* user friendly output, not "needs update" */
externintrefresh_index(structindex_state*, unsigned intflags, conststructpathspec*pathspec, char*seen, constchar*header_msg);
externvoidupdate_index_if_able(structindex_state*, structlock_file*);
externinthold_locked_index(structlock_file*, int);
externvoidset_alternate_index_output(constchar*);
/* 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;
externintlog_all_ref_updates;
externintwarn_ambiguous_refs;
externintwarn_on_object_refname_ambiguity;
externintshared_repository;
externconstchar*apply_default_whitespace;
externconstchar*apply_default_ignorewhitespace;
externconstchar*git_attributes_file;
externintzlib_compression_level;
externintcore_compression_level;
externintcore_compression_seen;
externsize_tpacked_git_window_size;
externsize_tpacked_git_limit;
externsize_tdelta_base_cache_limit;
externunsigned longbig_file_threshold;
externunsigned longpack_size_limit_cfg;
/*
* 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. As an
* optimization it is also set to false if replace references have
* been sought but there were none.
*/
externintcheck_replace_refs;
externchar*git_replace_ref_base;
externintfsync_object_files;
externintcore_preload_index;
externintcore_apply_sparse_checkout;
externintprecomposed_unicode;
externintprotect_hfs;
externintprotect_ntfs;
externintgit_db_env, git_index_env, git_graft_env, git_common_dir_env;
/*
* Include broken refs in all ref iterations, which will
* generally choke dangerous operations rather than letting
* them silently proceed without taking the broken ref into
* account.
*/
externintref_paranoia;
/*
* The character that begins a commented line in user-editable file
* that is subject to stripspace.
*/
externcharcomment_line_char;
externintauto_comment_line_char;
enumbranch_track {
BRANCH_TRACK_UNSPECIFIED=-1,
BRANCH_TRACK_NEVER=0,
BRANCH_TRACK_REMOTE,
BRANCH_TRACK_ALWAYS,
BRANCH_TRACK_EXPLICIT,
BRANCH_TRACK_OVERRIDE
};
enumrebase_setup_type {
AUTOREBASE_NEVER=0,
AUTOREBASE_LOCAL,
AUTOREBASE_REMOTE,
AUTOREBASE_ALWAYS
};
enumpush_default_type {
PUSH_DEFAULT_NOTHING=0,
PUSH_DEFAULT_MATCHING,
PUSH_DEFAULT_SIMPLE,
PUSH_DEFAULT_UPSTREAM,
PUSH_DEFAULT_CURRENT,
PUSH_DEFAULT_UNSPECIFIED
};
externenumbranch_trackgit_branch_track;
externenumrebase_setup_typeautorebase;
externenumpush_default_typepush_default;
enumobject_creation_mode {
OBJECT_CREATION_USES_HARDLINKS=0,
OBJECT_CREATION_USES_RENAMES=1
};
externenumobject_creation_modeobject_creation_mode;
externchar*notes_ref_name;
externintgrafts_replace_parents;
/*
* GIT_REPO_VERSION is the version we write by default. The
* _READ variant is the highest number we know how to
* handle.
*/
#defineGIT_REPO_VERSION 0
#defineGIT_REPO_VERSION_READ 1
externintrepository_format_version;
externintrepository_format_precious_objects;
externintcheck_repository_format(void);
#defineMTIME_CHANGED 0x0001
#defineCTIME_CHANGED 0x0002
#defineOWNER_CHANGED 0x0004
#defineMODE_CHANGED 0x0008
#defineINODE_CHANGED 0x0010
#defineDATA_CHANGED 0x0020
#defineTYPE_CHANGED 0x0040
/*
* Return a statically allocated filename, either generically (mkpath), in
* the repository directory (git_path), or in a submodule's repository
* directory (git_path_submodule). In all cases, note that the result
* may be overwritten by another call to _any_ of the functions. Consider
* using the safer "dup" or "strbuf" formats below (in some cases, the
* unsafe versions have already been removed).
*/
externconstchar*mkpath(constchar*fmt, ...) __attribute__((format (printf, 1, 2)));
externconstchar*git_path(constchar*fmt, ...) __attribute__((format (printf, 1, 2)));
externchar*mksnpath(char*buf, size_tn, constchar*fmt, ...)
__attribute__((format (printf, 3, 4)));
externvoidstrbuf_git_path(structstrbuf*sb, constchar*fmt, ...)
__attribute__((format (printf, 2, 3)));
externchar*git_path_buf(structstrbuf*buf, constchar*fmt, ...)
__attribute__((format (printf, 2, 3)));
externvoidstrbuf_git_path_submodule(structstrbuf*sb, constchar*path,
constchar*fmt, ...)
__attribute__((format (printf, 3, 4)));
externchar*git_pathdup(constchar*fmt, ...)
__attribute__((format (printf, 1, 2)));
externchar*mkpathdup(constchar*fmt, ...)
__attribute__((format (printf, 1, 2)));
externchar*git_pathdup_submodule(constchar*path, constchar*fmt, ...)
__attribute__((format (printf, 2, 3)));
externvoidreport_linked_checkout_garbage(void);
/*
* You can define a static memoized git path like:
*
* static GIT_PATH_FUNC(git_path_foo, "FOO");
*
* or use one of the global ones below.
*/
#defineGIT_PATH_FUNC(func, filename) \
const char *func(void) \
{ \
static char *ret; \
if (!ret) \
ret = git_pathdup(filename); \
return ret; \
}
constchar*git_path_cherry_pick_head(void);
constchar*git_path_revert_head(void);
constchar*git_path_squash_msg(void);
constchar*git_path_merge_msg(void);
constchar*git_path_merge_rr(void);
constchar*git_path_merge_mode(void);
constchar*git_path_merge_head(void);
constchar*git_path_fetch_head(void);
constchar*git_path_shallow(void);
/*
* Return the name of the file in the local object database that would
* be used to store a loose object with the specified sha1. The
* return value is a pointer to a statically allocated buffer that is
* overwritten each time the function is called.
*/
externconstchar*sha1_file_name(constunsigned char*sha1);
/*
* Return the name of the (local) packfile with the specified sha1 in
* its name. The return value is a pointer to memory that is
* overwritten each time this function is called.
*/
externchar*sha1_pack_name(constunsigned char*sha1);
/*
* Return the name of the (local) pack index file with the specified
* sha1 in its name. The return value is a pointer to memory that is
* overwritten each time this function is called.
*/
externchar*sha1_pack_index_name(constunsigned char*sha1);
/*
* Return an abbreviated sha1 unique within this repository's object database.
* The result will be at least `len` characters long, and will be NUL
* terminated.
*
* The non-`_r` version returns a static buffer which will be overwritten by
* subsequent calls.
*
* The `_r` variant writes to a buffer supplied by the caller, which must be at
* least `GIT_SHA1_HEXSZ + 1` bytes. The return value is the number of bytes
* written (excluding the NUL terminator).
*
* Note that while this version avoids the static buffer, it is not fully
* reentrant, as it calls into other non-reentrant git code.
*/
externconstchar*find_unique_abbrev(constunsigned char*sha1, intlen);
externintfind_unique_abbrev_r(char*hex, constunsigned char*sha1, intlen);
externconstunsigned charnull_sha1[GIT_SHA1_RAWSZ];
staticinlineinthashcmp(constunsigned char*sha1, constunsigned char*sha2)
{
inti;
for (i=0; i<GIT_SHA1_RAWSZ; i++, sha1++, sha2++) {
if (*sha1!=*sha2)
return*sha1-*sha2;
}
return0;
}
staticinlineintoidcmp(conststructobject_id*oid1, conststructobject_id*oid2)
{
returnhashcmp(oid1->hash, oid2->hash);
}
staticinlineintis_null_sha1(constunsigned char*sha1)
{
return !hashcmp(sha1, null_sha1);
}
staticinlineintis_null_oid(conststructobject_id*oid)
{
return !hashcmp(oid->hash, null_sha1);
}
staticinlinevoidhashcpy(unsigned char*sha_dst, constunsigned char*sha_src)
{
memcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);
}
staticinlinevoidoidcpy(structobject_id*dst, conststructobject_id*src)
{
hashcpy(dst->hash, src->hash);
}
staticinlinevoidhashclr(unsigned char*hash)
{
memset(hash, 0, GIT_SHA1_RAWSZ);
}
staticinlinevoidoidclr(structobject_id*oid)
{
hashclr(oid->hash);
}
#defineEMPTY_TREE_SHA1_HEX \
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
#defineEMPTY_TREE_SHA1_BIN_LITERAL \
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
#defineEMPTY_TREE_SHA1_BIN \
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)
#defineEMPTY_BLOB_SHA1_HEX \
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
#defineEMPTY_BLOB_SHA1_BIN_LITERAL \
"\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
"\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
#defineEMPTY_BLOB_SHA1_BIN \
((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL)
staticinlineintis_empty_blob_sha1(constunsigned char*sha1)
{
return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
}
intgit_mkstemp(char*path, size_tn, constchar*template);
intgit_mkstemps(char*path, size_tn, constchar*template, intsuffix_len);
/* set default permissions by passing mode arguments to open(2) */
intgit_mkstemps_mode(char*pattern, intsuffix_len, intmode);
intgit_mkstemp_mode(char*pattern, intmode);
/*
* NOTE NOTE NOTE!!
*
* PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must
* not be changed. Old repositories have core.sharedrepository written in
* numeric format, and therefore these values are preserved for compatibility
* reasons.
*/
enumsharedrepo {
PERM_UMASK=0,
OLD_PERM_GROUP=1,
OLD_PERM_EVERYBODY=2,
PERM_GROUP=0660,
PERM_EVERYBODY=0664
};
intgit_config_perm(constchar*var, constchar*value);
intadjust_shared_perm(constchar*path);
/*
* Create the directory containing the named path, using care to be
* somewhat safe against races. Return one of the scld_error values
* to indicate success/failure.
*
* SCLD_VANISHED indicates that one of the ancestor directories of the
* path existed at one point during the function call and then
* suddenly vanished, probably because another process pruned the
* directory while we were working. To be robust against this kind of
* race, callers might want to try invoking the function again when it
* returns SCLD_VANISHED.
*/
enumscld_error {
SCLD_OK=0,
SCLD_FAILED=-1,
SCLD_PERMS=-2,
SCLD_EXISTS=-3,
SCLD_VANISHED=-4
};
enumscld_errorsafe_create_leading_directories(char*path);
enumscld_errorsafe_create_leading_directories_const(constchar*path);
intmkdir_in_gitdir(constchar*path);
externchar*expand_user_path(constchar*path);
constchar*enter_repo(constchar*path, intstrict);
staticinlineintis_absolute_path(constchar*path)
{
returnis_dir_sep(path[0]) ||has_dos_drive_prefix(path);
}
intis_directory(constchar*);
constchar*real_path(constchar*path);
constchar*real_path_if_valid(constchar*path);
constchar*absolute_path(constchar*path);
constchar*remove_leading_path(constchar*in, constchar*prefix);
constchar*relative_path(constchar*in, constchar*prefix, structstrbuf*sb);
intnormalize_path_copy_len(char*dst, constchar*src, int*prefix_len);
intnormalize_path_copy(char*dst, constchar*src);
intlongest_ancestor_length(constchar*path, structstring_list*prefixes);
char*strip_path_suffix(constchar*path, constchar*suffix);
intdaemon_avoid_alias(constchar*path);
externintis_ntfs_dotgit(constchar*name);
/**
* Return a newly allocated string with the evaluation of
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
* "$HOME/.config/git/$filename". Return NULL upon error.
*/
externchar*xdg_config_home(constchar*filename);
/* object replacement */
#defineLOOKUP_REPLACE_OBJECT 1
#defineLOOKUP_UNKNOWN_OBJECT 2
externvoid*read_sha1_file_extended(constunsigned char*sha1, enumobject_type*type, unsigned long*size, unsignedflag);
staticinlinevoid*read_sha1_file(constunsigned char*sha1, enumobject_type*type, unsigned long*size)
{
returnread_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT);
}
/*
* This internal function is only declared here for the benefit of
* lookup_replace_object(). Please do not call it directly.
*/
externconstunsigned char*do_lookup_replace_object(constunsigned char*sha1);
/*
* If object sha1 should be replaced, return the replacement object's
* name (replaced recursively, if necessary). The return value is
* either sha1 or a pointer to a permanently-allocated value. When
* object replacement is suppressed, always return sha1.
*/
staticinlineconstunsigned char*lookup_replace_object(constunsigned char*sha1)
{
if (!check_replace_refs)
returnsha1;
returndo_lookup_replace_object(sha1);
}
staticinlineconstunsigned char*lookup_replace_object_extended(constunsigned char*sha1, unsignedflag)
{
if (!(flag&LOOKUP_REPLACE_OBJECT))
returnsha1;
returnlookup_replace_object(sha1);
}
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
externintsha1_object_info(constunsigned char*, unsigned long*);
externinthash_sha1_file(constvoid*buf, unsigned longlen, constchar*type, unsigned char*sha1);
externintwrite_sha1_file(constvoid*buf, unsigned longlen, constchar*type, unsigned char*return_sha1);
externinthash_sha1_file_literally(constvoid*buf, unsigned longlen, constchar*type, unsigned char*sha1, unsignedflags);