@@ -115,6 +115,8 @@ static unsigned long window_memory_limit = 0;
115115
116116static struct list_objects_filter_options filter_options ;
117117
118+ static struct string_list uri_protocols = STRING_LIST_INIT_NODUP ;
119+
118120enum missing_action {
119121 MA_ERROR = 0 , /* fail if any missing objects are encountered */
120122 MA_ALLOW_ANY , /* silently allow ALL missing objects */
@@ -123,6 +125,15 @@ enum missing_action {
123125static enum missing_action arg_missing_action ;
124126static show_object_fn fn_show_object ;
125127
128+ struct configured_exclusion {
129+ struct oidmap_entry e ;
130+ char * pack_hash_hex ;
131+ char * uri ;
132+ };
133+ static struct oidmap configured_exclusions ;
134+
135+ static struct oidset excluded_by_config ;
136+
126137/*
127138 * stats
128139 */
@@ -837,6 +848,25 @@ static off_t write_reused_pack(struct hashfile *f)
837848 return reuse_packfile_offset - sizeof (struct pack_header );
838849}
839850
851+ static void write_excluded_by_configs (void )
852+ {
853+ struct oidset_iter iter ;
854+ const struct object_id * oid ;
855+
856+ oidset_iter_init (& excluded_by_config , & iter );
857+ while ((oid = oidset_iter_next (& iter ))) {
858+ struct configured_exclusion * ex =
859+ oidmap_get (& configured_exclusions , oid );
860+
861+ if (!ex )
862+ BUG ("configured exclusion wasn't configured" );
863+ write_in_full (1 , ex -> pack_hash_hex , strlen (ex -> pack_hash_hex ));
864+ write_in_full (1 , " " , 1 );
865+ write_in_full (1 , ex -> uri , strlen (ex -> uri ));
866+ write_in_full (1 , "\n" , 1 );
867+ }
868+ }
869+
840870static const char no_split_warning [] = N_ (
841871"disabling bitmap writing, packs are split due to pack.packSizeLimit"
842872);
@@ -1133,6 +1163,25 @@ static int want_object_in_pack(const struct object_id *oid,
11331163 }
11341164 }
11351165
1166+ if (uri_protocols .nr ) {
1167+ struct configured_exclusion * ex =
1168+ oidmap_get (& configured_exclusions , oid );
1169+ int i ;
1170+ const char * p ;
1171+
1172+ if (ex ) {
1173+ for (i = 0 ; i < uri_protocols .nr ; i ++ ) {
1174+ if (skip_prefix (ex -> uri ,
1175+ uri_protocols .items [i ].string ,
1176+ & p ) &&
1177+ * p == ':' ) {
1178+ oidset_insert (& excluded_by_config , oid );
1179+ return 0 ;
1180+ }
1181+ }
1182+ }
1183+ }
1184+
11361185 return 1 ;
11371186}
11381187
@@ -2734,6 +2783,29 @@ static int git_pack_config(const char *k, const char *v, void *cb)
27342783 pack_idx_opts .version );
27352784 return 0 ;
27362785 }
2786+ if (!strcmp (k , "uploadpack.blobpackfileuri" )) {
2787+ struct configured_exclusion * ex = xmalloc (sizeof (* ex ));
2788+ const char * oid_end , * pack_end ;
2789+ /*
2790+ * Stores the pack hash. This is not a true object ID, but is
2791+ * of the same form.
2792+ */
2793+ struct object_id pack_hash ;
2794+
2795+ if (parse_oid_hex (v , & ex -> e .oid , & oid_end ) ||
2796+ * oid_end != ' ' ||
2797+ parse_oid_hex (oid_end + 1 , & pack_hash , & pack_end ) ||
2798+ * pack_end != ' ' )
2799+ die (_ ("value of uploadpack.blobpackfileuri must be "
2800+ "of the form '<object-hash> <pack-hash> <uri>' (got '%s')" ), v );
2801+ if (oidmap_get (& configured_exclusions , & ex -> e .oid ))
2802+ die (_ ("object already configured in another "
2803+ "uploadpack.blobpackfileuri (got '%s')" ), v );
2804+ ex -> pack_hash_hex = xcalloc (1 , pack_end - oid_end );
2805+ memcpy (ex -> pack_hash_hex , oid_end + 1 , pack_end - oid_end - 1 );
2806+ ex -> uri = xstrdup (pack_end + 1 );
2807+ oidmap_put (& configured_exclusions , ex );
2808+ }
27372809 return git_default_config (k , v , cb );
27382810}
27392811
@@ -3331,6 +3403,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
33313403 N_ ("do not pack objects in promisor packfiles" )),
33323404 OPT_BOOL (0 , "delta-islands" , & use_delta_islands ,
33333405 N_ ("respect islands during delta compression" )),
3406+ OPT_STRING_LIST (0 , "uri-protocol" , & uri_protocols ,
3407+ N_ ("protocol" ),
3408+ N_ ("exclude any configured uploadpack.blobpackfileuri with this protocol" )),
33343409 OPT_END (),
33353410 };
33363411
@@ -3519,6 +3594,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
35193594 the_repository );
35203595 }
35213596
3597+ write_excluded_by_configs ();
35223598 trace2_region_enter ("pack-objects" , "write-pack-file" , the_repository );
35233599 write_pack_file ();
35243600 trace2_region_leave ("pack-objects" , "write-pack-file" , the_repository );
0 commit comments