@@ -117,6 +117,8 @@ static unsigned long window_memory_limit = 0;
117
117
118
118
static struct list_objects_filter_options filter_options ;
119
119
120
+ static struct string_list uri_protocols = STRING_LIST_INIT_NODUP ;
121
+
120
122
enum missing_action {
121
123
MA_ERROR = 0 , /* fail if any missing objects are encountered */
122
124
MA_ALLOW_ANY , /* silently allow ALL missing objects */
@@ -125,6 +127,15 @@ enum missing_action {
125
127
static enum missing_action arg_missing_action ;
126
128
static show_object_fn fn_show_object ;
127
129
130
+ struct configured_exclusion {
131
+ struct oidmap_entry e ;
132
+ char * pack_hash_hex ;
133
+ char * uri ;
134
+ };
135
+ static struct oidmap configured_exclusions ;
136
+
137
+ static struct oidset excluded_by_config ;
138
+
128
139
/*
129
140
* stats
130
141
*/
@@ -969,6 +980,25 @@ static void write_reused_pack(struct hashfile *f)
969
980
unuse_pack (& w_curs );
970
981
}
971
982
983
+ static void write_excluded_by_configs (void )
984
+ {
985
+ struct oidset_iter iter ;
986
+ const struct object_id * oid ;
987
+
988
+ oidset_iter_init (& excluded_by_config , & iter );
989
+ while ((oid = oidset_iter_next (& iter ))) {
990
+ struct configured_exclusion * ex =
991
+ oidmap_get (& configured_exclusions , oid );
992
+
993
+ if (!ex )
994
+ BUG ("configured exclusion wasn't configured" );
995
+ write_in_full (1 , ex -> pack_hash_hex , strlen (ex -> pack_hash_hex ));
996
+ write_in_full (1 , " " , 1 );
997
+ write_in_full (1 , ex -> uri , strlen (ex -> uri ));
998
+ write_in_full (1 , "\n" , 1 );
999
+ }
1000
+ }
1001
+
972
1002
static const char no_split_warning [] = N_ (
973
1003
"disabling bitmap writing, packs are split due to pack.packSizeLimit"
974
1004
);
@@ -1266,6 +1296,25 @@ static int want_object_in_pack(const struct object_id *oid,
1266
1296
}
1267
1297
}
1268
1298
1299
+ if (uri_protocols .nr ) {
1300
+ struct configured_exclusion * ex =
1301
+ oidmap_get (& configured_exclusions , oid );
1302
+ int i ;
1303
+ const char * p ;
1304
+
1305
+ if (ex ) {
1306
+ for (i = 0 ; i < uri_protocols .nr ; i ++ ) {
1307
+ if (skip_prefix (ex -> uri ,
1308
+ uri_protocols .items [i ].string ,
1309
+ & p ) &&
1310
+ * p == ':' ) {
1311
+ oidset_insert (& excluded_by_config , oid );
1312
+ return 0 ;
1313
+ }
1314
+ }
1315
+ }
1316
+ }
1317
+
1269
1318
return 1 ;
1270
1319
}
1271
1320
@@ -2864,6 +2913,29 @@ static int git_pack_config(const char *k, const char *v, void *cb)
2864
2913
pack_idx_opts .version );
2865
2914
return 0 ;
2866
2915
}
2916
+ if (!strcmp (k , "uploadpack.blobpackfileuri" )) {
2917
+ struct configured_exclusion * ex = xmalloc (sizeof (* ex ));
2918
+ const char * oid_end , * pack_end ;
2919
+ /*
2920
+ * Stores the pack hash. This is not a true object ID, but is
2921
+ * of the same form.
2922
+ */
2923
+ struct object_id pack_hash ;
2924
+
2925
+ if (parse_oid_hex (v , & ex -> e .oid , & oid_end ) ||
2926
+ * oid_end != ' ' ||
2927
+ parse_oid_hex (oid_end + 1 , & pack_hash , & pack_end ) ||
2928
+ * pack_end != ' ' )
2929
+ die (_ ("value of uploadpack.blobpackfileuri must be "
2930
+ "of the form '<object-hash> <pack-hash> <uri>' (got '%s')" ), v );
2931
+ if (oidmap_get (& configured_exclusions , & ex -> e .oid ))
2932
+ die (_ ("object already configured in another "
2933
+ "uploadpack.blobpackfileuri (got '%s')" ), v );
2934
+ ex -> pack_hash_hex = xcalloc (1 , pack_end - oid_end );
2935
+ memcpy (ex -> pack_hash_hex , oid_end + 1 , pack_end - oid_end - 1 );
2936
+ ex -> uri = xstrdup (pack_end + 1 );
2937
+ oidmap_put (& configured_exclusions , ex );
2938
+ }
2867
2939
return git_default_config (k , v , cb );
2868
2940
}
2869
2941
@@ -3462,6 +3534,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3462
3534
N_ ("do not pack objects in promisor packfiles" )),
3463
3535
OPT_BOOL (0 , "delta-islands" , & use_delta_islands ,
3464
3536
N_ ("respect islands during delta compression" )),
3537
+ OPT_STRING_LIST (0 , "uri-protocol" , & uri_protocols ,
3538
+ N_ ("protocol" ),
3539
+ N_ ("exclude any configured uploadpack.blobpackfileuri with this protocol" )),
3465
3540
OPT_END (),
3466
3541
};
3467
3542
@@ -3650,6 +3725,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3650
3725
}
3651
3726
3652
3727
trace2_region_enter ("pack-objects" , "write-pack-file" , the_repository );
3728
+ write_excluded_by_configs ();
3653
3729
write_pack_file ();
3654
3730
trace2_region_leave ("pack-objects" , "write-pack-file" , the_repository );
3655
3731
0 commit comments