@@ -667,9 +667,10 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
667
667
}
668
668
669
669
/* Finalize a file on disk, and close it. */
670
- static void close_loose_object (int fd , const char * filename )
670
+ static void close_loose_object (struct odb_source * source ,
671
+ int fd , const char * filename )
671
672
{
672
- if (the_repository -> objects -> sources -> will_destroy )
673
+ if (source -> will_destroy )
673
674
goto out ;
674
675
675
676
if (batch_fsync_enabled (FSYNC_COMPONENT_LOOSE_OBJECT ))
@@ -701,7 +702,8 @@ static inline int directory_size(const char *filename)
701
702
* We want to avoid cross-directory filename renames, because those
702
703
* can have problems on various filesystems (FAT, NFS, Coda).
703
704
*/
704
- static int create_tmpfile (struct strbuf * tmp , const char * filename )
705
+ static int create_tmpfile (struct repository * repo ,
706
+ struct strbuf * tmp , const char * filename )
705
707
{
706
708
int fd , dirlen = directory_size (filename );
707
709
@@ -720,7 +722,7 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
720
722
strbuf_add (tmp , filename , dirlen - 1 );
721
723
if (mkdir (tmp -> buf , 0777 ) && errno != EEXIST )
722
724
return -1 ;
723
- if (adjust_shared_perm (the_repository , tmp -> buf ))
725
+ if (adjust_shared_perm (repo , tmp -> buf ))
724
726
return -1 ;
725
727
726
728
/* Try again */
@@ -741,26 +743,26 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
741
743
* Returns a "fd", which should later be provided to
742
744
* end_loose_object_common().
743
745
*/
744
- static int start_loose_object_common (struct strbuf * tmp_file ,
746
+ static int start_loose_object_common (struct odb_source * source ,
747
+ struct strbuf * tmp_file ,
745
748
const char * filename , unsigned flags ,
746
749
git_zstream * stream ,
747
750
unsigned char * buf , size_t buflen ,
748
751
struct git_hash_ctx * c , struct git_hash_ctx * compat_c ,
749
752
char * hdr , int hdrlen )
750
753
{
751
- struct repository * repo = the_repository ;
752
- const struct git_hash_algo * algo = repo -> hash_algo ;
753
- const struct git_hash_algo * compat = repo -> compat_hash_algo ;
754
+ const struct git_hash_algo * algo = source -> odb -> repo -> hash_algo ;
755
+ const struct git_hash_algo * compat = source -> odb -> repo -> compat_hash_algo ;
754
756
int fd ;
755
757
756
- fd = create_tmpfile (tmp_file , filename );
758
+ fd = create_tmpfile (source -> odb -> repo , tmp_file , filename );
757
759
if (fd < 0 ) {
758
760
if (flags & WRITE_OBJECT_SILENT )
759
761
return -1 ;
760
762
else if (errno == EACCES )
761
763
return error (_ ("insufficient permission for adding "
762
764
"an object to repository database %s" ),
763
- repo_get_object_directory ( the_repository ) );
765
+ source -> path );
764
766
else
765
767
return error_errno (
766
768
_ ("unable to create temporary file" ));
@@ -790,14 +792,14 @@ static int start_loose_object_common(struct strbuf *tmp_file,
790
792
* Common steps for the inner git_deflate() loop for writing loose
791
793
* objects. Returns what git_deflate() returns.
792
794
*/
793
- static int write_loose_object_common (struct git_hash_ctx * c , struct git_hash_ctx * compat_c ,
795
+ static int write_loose_object_common (struct odb_source * source ,
796
+ struct git_hash_ctx * c , struct git_hash_ctx * compat_c ,
794
797
git_zstream * stream , const int flush ,
795
798
unsigned char * in0 , const int fd ,
796
799
unsigned char * compressed ,
797
800
const size_t compressed_len )
798
801
{
799
- struct repository * repo = the_repository ;
800
- const struct git_hash_algo * compat = repo -> compat_hash_algo ;
802
+ const struct git_hash_algo * compat = source -> odb -> repo -> compat_hash_algo ;
801
803
int ret ;
802
804
803
805
ret = git_deflate (stream , flush ? Z_FINISH : 0 );
@@ -818,12 +820,12 @@ static int write_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx
818
820
* - End the compression of zlib stream.
819
821
* - Get the calculated oid to "oid".
820
822
*/
821
- static int end_loose_object_common (struct git_hash_ctx * c , struct git_hash_ctx * compat_c ,
823
+ static int end_loose_object_common (struct odb_source * source ,
824
+ struct git_hash_ctx * c , struct git_hash_ctx * compat_c ,
822
825
git_zstream * stream , struct object_id * oid ,
823
826
struct object_id * compat_oid )
824
827
{
825
- struct repository * repo = the_repository ;
826
- const struct git_hash_algo * compat = repo -> compat_hash_algo ;
828
+ const struct git_hash_algo * compat = source -> odb -> repo -> compat_hash_algo ;
827
829
int ret ;
828
830
829
831
ret = git_deflate_end_gently (stream );
@@ -836,7 +838,8 @@ static int end_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *
836
838
return Z_OK ;
837
839
}
838
840
839
- static int write_loose_object (const struct object_id * oid , char * hdr ,
841
+ static int write_loose_object (struct odb_source * source ,
842
+ const struct object_id * oid , char * hdr ,
840
843
int hdrlen , const void * buf , unsigned long len ,
841
844
time_t mtime , unsigned flags )
842
845
{
@@ -851,9 +854,9 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
851
854
if (batch_fsync_enabled (FSYNC_COMPONENT_LOOSE_OBJECT ))
852
855
prepare_loose_object_bulk_checkin ();
853
856
854
- odb_loose_path (the_repository -> objects -> sources , & filename , oid );
857
+ odb_loose_path (source , & filename , oid );
855
858
856
- fd = start_loose_object_common (& tmp_file , filename .buf , flags ,
859
+ fd = start_loose_object_common (source , & tmp_file , filename .buf , flags ,
857
860
& stream , compressed , sizeof (compressed ),
858
861
& c , NULL , hdr , hdrlen );
859
862
if (fd < 0 )
@@ -865,22 +868,22 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
865
868
do {
866
869
unsigned char * in0 = stream .next_in ;
867
870
868
- ret = write_loose_object_common (& c , NULL , & stream , 1 , in0 , fd ,
871
+ ret = write_loose_object_common (source , & c , NULL , & stream , 1 , in0 , fd ,
869
872
compressed , sizeof (compressed ));
870
873
} while (ret == Z_OK );
871
874
872
875
if (ret != Z_STREAM_END )
873
876
die (_ ("unable to deflate new object %s (%d)" ), oid_to_hex (oid ),
874
877
ret );
875
- ret = end_loose_object_common (& c , NULL , & stream , & parano_oid , NULL );
878
+ ret = end_loose_object_common (source , & c , NULL , & stream , & parano_oid , NULL );
876
879
if (ret != Z_OK )
877
880
die (_ ("deflateEnd on object %s failed (%d)" ), oid_to_hex (oid ),
878
881
ret );
879
882
if (!oideq (oid , & parano_oid ))
880
883
die (_ ("confused by unstable object source data for %s" ),
881
884
oid_to_hex (oid ));
882
885
883
- close_loose_object (fd , tmp_file .buf );
886
+ close_loose_object (source , fd , tmp_file .buf );
884
887
885
888
if (mtime ) {
886
889
struct utimbuf utb ;
@@ -891,7 +894,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
891
894
warning_errno (_ ("failed utime() on %s" ), tmp_file .buf );
892
895
}
893
896
894
- return finalize_object_file_flags (the_repository , tmp_file .buf , filename .buf ,
897
+ return finalize_object_file_flags (source -> odb -> repo , tmp_file .buf , filename .buf ,
895
898
FOF_SKIP_COLLISION_CHECK );
896
899
}
897
900
@@ -921,10 +924,11 @@ static int freshen_packed_object(struct object_database *odb,
921
924
return 1 ;
922
925
}
923
926
924
- int stream_loose_object (struct input_stream * in_stream , size_t len ,
927
+ int stream_loose_object (struct odb_source * source ,
928
+ struct input_stream * in_stream , size_t len ,
925
929
struct object_id * oid )
926
930
{
927
- const struct git_hash_algo * compat = the_repository -> compat_hash_algo ;
931
+ const struct git_hash_algo * compat = source -> odb -> repo -> compat_hash_algo ;
928
932
struct object_id compat_oid ;
929
933
int fd , ret , err = 0 , flush = 0 ;
930
934
unsigned char compressed [4096 ];
@@ -940,7 +944,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
940
944
prepare_loose_object_bulk_checkin ();
941
945
942
946
/* Since oid is not determined, save tmp file to odb path. */
943
- strbuf_addf (& filename , "%s/" , repo_get_object_directory ( the_repository ) );
947
+ strbuf_addf (& filename , "%s/" , source -> path );
944
948
hdrlen = format_object_header (hdr , sizeof (hdr ), OBJ_BLOB , len );
945
949
946
950
/*
@@ -951,7 +955,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
951
955
* - Setup zlib stream for compression.
952
956
* - Start to feed header to zlib stream.
953
957
*/
954
- fd = start_loose_object_common (& tmp_file , filename .buf , 0 ,
958
+ fd = start_loose_object_common (source , & tmp_file , filename .buf , 0 ,
955
959
& stream , compressed , sizeof (compressed ),
956
960
& c , & compat_c , hdr , hdrlen );
957
961
if (fd < 0 ) {
@@ -971,7 +975,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
971
975
if (in_stream -> is_finished )
972
976
flush = 1 ;
973
977
}
974
- ret = write_loose_object_common (& c , & compat_c , & stream , flush , in0 , fd ,
978
+ ret = write_loose_object_common (source , & c , & compat_c , & stream , flush , in0 , fd ,
975
979
compressed , sizeof (compressed ));
976
980
/*
977
981
* Unlike write_loose_object(), we do not have the entire
@@ -994,26 +998,26 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
994
998
*/
995
999
if (ret != Z_STREAM_END )
996
1000
die (_ ("unable to stream deflate new object (%d)" ), ret );
997
- ret = end_loose_object_common (& c , & compat_c , & stream , oid , & compat_oid );
1001
+ ret = end_loose_object_common (source , & c , & compat_c , & stream , oid , & compat_oid );
998
1002
if (ret != Z_OK )
999
1003
die (_ ("deflateEnd on stream object failed (%d)" ), ret );
1000
- close_loose_object (fd , tmp_file .buf );
1004
+ close_loose_object (source , fd , tmp_file .buf );
1001
1005
1002
- if (freshen_packed_object (the_repository -> objects , oid ) ||
1003
- freshen_loose_object (the_repository -> objects , oid )) {
1006
+ if (freshen_packed_object (source -> odb , oid ) ||
1007
+ freshen_loose_object (source -> odb , oid )) {
1004
1008
unlink_or_warn (tmp_file .buf );
1005
1009
goto cleanup ;
1006
1010
}
1007
1011
1008
- odb_loose_path (the_repository -> objects -> sources , & filename , oid );
1012
+ odb_loose_path (source , & filename , oid );
1009
1013
1010
1014
/* We finally know the object path, and create the missing dir. */
1011
1015
dirlen = directory_size (filename .buf );
1012
1016
if (dirlen ) {
1013
1017
struct strbuf dir = STRBUF_INIT ;
1014
1018
strbuf_add (& dir , filename .buf , dirlen );
1015
1019
1016
- if (safe_create_dir_in_gitdir (the_repository , dir .buf ) &&
1020
+ if (safe_create_dir_in_gitdir (source -> odb -> repo , dir .buf ) &&
1017
1021
errno != EEXIST ) {
1018
1022
err = error_errno (_ ("unable to create directory %s" ), dir .buf );
1019
1023
strbuf_release (& dir );
@@ -1022,23 +1026,23 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
1022
1026
strbuf_release (& dir );
1023
1027
}
1024
1028
1025
- err = finalize_object_file_flags (the_repository , tmp_file .buf , filename .buf ,
1029
+ err = finalize_object_file_flags (source -> odb -> repo , tmp_file .buf , filename .buf ,
1026
1030
FOF_SKIP_COLLISION_CHECK );
1027
1031
if (!err && compat )
1028
- err = repo_add_loose_object_map (the_repository -> objects -> sources , oid , & compat_oid );
1032
+ err = repo_add_loose_object_map (source , oid , & compat_oid );
1029
1033
cleanup :
1030
1034
strbuf_release (& tmp_file );
1031
1035
strbuf_release (& filename );
1032
1036
return err ;
1033
1037
}
1034
1038
1035
- int write_object_file (const void * buf , unsigned long len ,
1039
+ int write_object_file (struct odb_source * source ,
1040
+ const void * buf , unsigned long len ,
1036
1041
enum object_type type , struct object_id * oid ,
1037
1042
struct object_id * compat_oid_in , unsigned flags )
1038
1043
{
1039
- struct repository * repo = the_repository ;
1040
- const struct git_hash_algo * algo = repo -> hash_algo ;
1041
- const struct git_hash_algo * compat = repo -> compat_hash_algo ;
1044
+ const struct git_hash_algo * algo = source -> odb -> repo -> hash_algo ;
1045
+ const struct git_hash_algo * compat = source -> odb -> repo -> compat_hash_algo ;
1042
1046
struct object_id compat_oid ;
1043
1047
char hdr [MAX_HEADER_LEN ];
1044
1048
int hdrlen = sizeof (hdr );
@@ -1051,7 +1055,7 @@ int write_object_file(const void *buf, unsigned long len,
1051
1055
hash_object_file (compat , buf , len , type , & compat_oid );
1052
1056
else {
1053
1057
struct strbuf converted = STRBUF_INIT ;
1054
- convert_object_file (the_repository , & converted , algo , compat ,
1058
+ convert_object_file (source -> odb -> repo , & converted , algo , compat ,
1055
1059
buf , len , type , 0 );
1056
1060
hash_object_file (compat , converted .buf , converted .len ,
1057
1061
type , & compat_oid );
@@ -1063,13 +1067,13 @@ int write_object_file(const void *buf, unsigned long len,
1063
1067
* it out into .git/objects/??/?{38} file.
1064
1068
*/
1065
1069
write_object_file_prepare (algo , buf , len , type , oid , hdr , & hdrlen );
1066
- if (freshen_packed_object (repo -> objects , oid ) ||
1067
- freshen_loose_object (repo -> objects , oid ))
1070
+ if (freshen_packed_object (source -> odb , oid ) ||
1071
+ freshen_loose_object (source -> odb , oid ))
1068
1072
return 0 ;
1069
- if (write_loose_object (oid , hdr , hdrlen , buf , len , 0 , flags ))
1073
+ if (write_loose_object (source , oid , hdr , hdrlen , buf , len , 0 , flags ))
1070
1074
return -1 ;
1071
1075
if (compat )
1072
- return repo_add_loose_object_map (repo -> objects -> sources , oid , & compat_oid );
1076
+ return repo_add_loose_object_map (source , oid , & compat_oid );
1073
1077
return 0 ;
1074
1078
}
1075
1079
@@ -1101,7 +1105,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
1101
1105
oid_to_hex (oid ), compat -> name );
1102
1106
}
1103
1107
hdrlen = format_object_header (hdr , sizeof (hdr ), type , len );
1104
- ret = write_loose_object (oid , hdr , hdrlen , buf , len , mtime , 0 );
1108
+ ret = write_loose_object (repo -> objects -> sources , oid , hdr , hdrlen , buf , len , mtime , 0 );
1105
1109
if (!ret && compat )
1106
1110
ret = repo_add_loose_object_map (the_repository -> objects -> sources , oid , & compat_oid );
1107
1111
free (buf );
0 commit comments