Skip to content

Commit 6fefba7

Browse files
Mikachu2333ccmywish
authored andcommitted
修复pr review 中提到的所有问题
1 parent cd940b2 commit 6fefba7

4 files changed

Lines changed: 96 additions & 74 deletions

File tree

‎src/chsrc-main.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ chefs_handle_Get_Source (Dish_t *dish, const char *input, char *option)
788788
Dish_t *sub_dish = xy_seq_at (dish->sub_dishes, i);
789789
sub_dish->preparefn();
790790
println (bdpurple(sub_dish->aliases));
791-
chsrc_set_dish_group_mode();
792791
chefs_handle_Get_Source (sub_dish, dish_get_first_alias(sub_dish), option);
793792
br();
794793
}
@@ -814,7 +813,7 @@ chefs_handle_Set_Source (Dish_t *dish, const char *input, char *option)
814813
{
815814
if (dish_has_sub_dishes(dish))
816815
{
817-
chsrc_begin_combo_source_resolution (dish, option);
816+
chsrc_begin_combo_source_resolution (dish);
818817

819818
for (size_t i=0; i<xy_seq_len(dish->sub_dishes); i++)
820819
{

‎src/framework/core.c‎

Lines changed: 68 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
static int chsrc_get_cpucore ();
3737

38+
/* 定义于 dish.c,core.c 在 combo 源解析时需要提前声明 */
39+
bool dish_has_source_from_mirror (Dish_t *dish, const char *code);
40+
3841

3942
/* Global Program Mode */
4043
struct
@@ -43,9 +46,6 @@ struct
4346
bool MeasureMode;
4447
bool ResetMode;
4548

46-
// 内部实现
47-
bool DishGroupMode;
48-
4949
// 用户命令选项
5050
bool Ipv6Mode;
5151
Scope_t Scope;
@@ -57,7 +57,6 @@ ProgMode =
5757
{
5858
.MeasureMode = false,
5959
.ResetMode = false,
60-
.DishGroupMode = false,
6160
.Ipv6Mode = false,
6261
.Scope = ImplementationDefinedScope,
6362
.EnglishMode = false,
@@ -66,10 +65,9 @@ ProgMode =
6665
};
6766

6867
/* recipe 相关 mode */
69-
bool chsrc_in_dish_group_mode() {return ProgMode.DishGroupMode;}
70-
// 并非作为 sub dish,而是自身作为一个独立的 dish 执行
71-
bool chsrc_in_standalone_mode() {return !ProgMode.DishGroupMode;}
72-
void chsrc_set_dish_group_mode(){ProgMode.DishGroupMode = true;}
68+
// combo dish 递归不再复用旧的 DishGroupMode;每个 leaf dish 仍负责自己的
69+
// 确认和收尾输出。
70+
bool chsrc_in_standalone_mode() {return true;}
7371

7472
bool chsrc_in_reset_mode(){return ProgMode.ResetMode;}
7573
/* 默认换源作用域就是 ImplementationDefinedScope */
@@ -113,35 +111,31 @@ typedef enum ChgType_t
113111
ChgType_Untested
114112
} ChgType_t;
115113

114+
#define MaxComboStackDepth 16
116115

117116
/* Global Program Status */
118117
struct
119118
{
120-
int leader_selected_index; /* combo dish 选中的索引 */
121-
ChgType_t chgtype; /* 换源实现的类型 */
119+
ChgType_t chgtype; /* 换源实现的类型 */
122120

123121
/* 此时 chsrc_run() 不再是recipe中指定要运行的一个外部命令,而是作为一个功能实现的支撑 */
124122
bool chsrc_run_faas;
125123
char *user_agent;
124+
125+
/* combo dish 源解析上下文。用户只给一个 code/URL,但不同 sub dish 可能
126+
* 使用不同的源列表;该栈记录当前正在处理的 combo dish。 */
127+
Dish_t *ComboStack[MaxComboStackDepth];
128+
XySeq_t *ComboBackedUpPaths[MaxComboStackDepth];
129+
int ComboStackDepth;
126130
}
127131
ProgStatus =
128132
{
129-
.leader_selected_index = -1,
130133
.chgtype = ChgType_Auto,
131134
.chsrc_run_faas = false,
132135
.user_agent = "chsrc/" Chsrc_Version,
136+
.ComboStackDepth = 0,
133137
};
134138

135-
/* Combo dish source resolution context.
136-
* When a combo dish is being handled, each sub dish may use a different
137-
* source list, but the user only supplied one mirror code. This context lets
138-
* the framework decide whether a sub dish should use the code directly, or
139-
* auto-select its fastest mirror because the code belongs to a sibling. */
140-
#define MaxComboSourceResolutionDepth 16
141-
static Dish_t *ComboSourceResolutionDishStack[MaxComboSourceResolutionDepth];
142-
static char *ComboBackedUpPaths[MaxComboSourceResolutionDepth];
143-
static int ComboSourceResolutionDepth = 0;
144-
145139

146140
/* Global Program Store */
147141
struct
@@ -186,27 +180,28 @@ ProgStore =
186180
bool
187181
chsrc_in_combo_source_resolution (void)
188182
{
189-
return ComboSourceResolutionDepth > 0;
183+
return ProgStatus.ComboStackDepth > 0;
190184
}
191185

192186
void
193-
chsrc_begin_combo_source_resolution (Dish_t *dish, char *option)
187+
chsrc_begin_combo_source_resolution (Dish_t *dish)
194188
{
195-
if (ComboSourceResolutionDepth >= MaxComboSourceResolutionDepth)
189+
if (ProgStatus.ComboStackDepth >= MaxComboStackDepth)
196190
chsrc_breakdown ("combo dish 嵌套层级过深");
197191

198-
ComboSourceResolutionDishStack[ComboSourceResolutionDepth] = dish;
199-
ComboBackedUpPaths[ComboSourceResolutionDepth] = NULL;
200-
ComboSourceResolutionDepth++;
192+
int depth = ProgStatus.ComboStackDepth;
193+
ProgStatus.ComboStack[depth] = dish;
194+
ProgStatus.ComboBackedUpPaths[depth] = xy_seq_new ();
195+
ProgStatus.ComboStackDepth++;
201196
}
202197

203198
void
204199
chsrc_end_combo_source_resolution (void)
205200
{
206-
if (ComboSourceResolutionDepth <= 0)
201+
if (ProgStatus.ComboStackDepth <= 0)
207202
chsrc_breakdown ("combo dish 解析上下文已为空");
208203

209-
ComboSourceResolutionDepth--;
204+
ProgStatus.ComboStackDepth--;
210205
}
211206

212207
#define faint(str) xy_str2faint(str)
@@ -1074,27 +1069,12 @@ source_has_empty_url (Source_t *source)
10741069
}
10751070

10761071
static bool
1077-
combo_subdish_has_source_code (Dish_t *dish, const char *code)
1072+
subdish_sibling_has_source_from_mirror (Dish_t *current, const char *code)
10781073
{
1079-
if (!dish || !dish->sources || !code)
1074+
if (ProgStatus.ComboStackDepth <= 0)
10801075
return false;
10811076

1082-
for (int i=0; i < dish->sources_n; i++)
1083-
{
1084-
if (xy_streql (dish->sources[i].mirror->code, code))
1085-
return true;
1086-
}
1087-
1088-
return false;
1089-
}
1090-
1091-
static bool
1092-
combo_sibling_has_source_code (Dish_t *current, const char *code)
1093-
{
1094-
if (ComboSourceResolutionDepth <= 0)
1095-
return false;
1096-
1097-
Dish_t *combo = ComboSourceResolutionDishStack[ComboSourceResolutionDepth - 1];
1077+
Dish_t *combo = ProgStatus.ComboStack[ProgStatus.ComboStackDepth - 1];
10981078
if (!combo || !combo->sub_dishes)
10991079
return false;
11001080

@@ -1107,7 +1087,7 @@ combo_sibling_has_source_code (Dish_t *current, const char *code)
11071087
if (!sub_dish->inited)
11081088
sub_dish->preparefn ();
11091089

1110-
if (combo_subdish_has_source_code (sub_dish, code))
1090+
if (dish_has_source_from_mirror (sub_dish, code))
11111091
return true;
11121092
}
11131093

@@ -1124,13 +1104,16 @@ combo_sibling_has_source_code (Dish_t *current, const char *code)
11241104
int
11251105
chsrc_resolve_combo_subdish_source (Dish_t *dish, char *option)
11261106
{
1127-
if (combo_subdish_has_source_code (dish, option))
1107+
if (dish_has_source_from_mirror (dish, option))
11281108
return query_mirror_exist (dish->sources, dish->sources_n, dish->aliases, option);
11291109

1130-
if (combo_sibling_has_source_code (dish, option))
1110+
if (subdish_sibling_has_source_from_mirror (dish, option))
11311111
return auto_select_mirror (dish->sources, dish->sources_n, dish->aliases);
11321112

1133-
return query_mirror_exist (dish->sources, dish->sources_n, dish->aliases, option);
1113+
chsrc_breakdown (ENGLISH
1114+
? "This combo sub dish has no source from the requested mirror"
1115+
: "该 combo sub dish 没有所请求镜像站的源");
1116+
return 0;
11341117
}
11351118

11361119

@@ -1145,10 +1128,9 @@ chsrc_resolve_combo_subdish_source (Dish_t *dish, char *option)
11451128
* 3. 用户什么都没指定, 即 chsrc set <dish>
11461129
* 4. 用户正在重置源, 即 chsrc reset <dish>
11471130
*
1148-
* 如果处于 Dish Group 模式下,combo dish 已经测速过了,sub dish
1149-
* 不能再次测速,而是直接选择 combo dish 测过的结果
1150-
*
1151-
* 5. combo dish 测速出来的某个源
1131+
* 如果处于 combo source resolution 上下文中,则按 sub dish 与 sibling
1132+
* 的源列表集中决定:code 命中本 dish 则直接使用;命中 sibling 则本 dish
1133+
* 自动测速;传入 URL 时,支持自定义 URL 的 sub dish 使用 URL,其余自动测速。
11521134
*
11531135
*/
11541136
Source_t
@@ -1163,19 +1145,29 @@ chsrc_yield_source (Dish_t *dish, char *option)
11631145
if (!dish->inited) dish->preparefn();
11641146

11651147
Source_t source;
1166-
if (chsrc_in_combo_source_resolution() && option && !hp_is_url (option))
1167-
{
1168-
int index = chsrc_resolve_combo_subdish_source (dish, option);
1169-
source = dish->sources[index];
1170-
}
1171-
else if (chsrc_in_dish_group_mode() && ProgStatus.leader_selected_index==-1)
1148+
if (chsrc_in_combo_source_resolution() && option)
11721149
{
1173-
ProgStatus.leader_selected_index = use_specific_mirror_or_auto_select (option, dish);
1174-
source = dish->sources[ProgStatus.leader_selected_index];
1175-
}
1176-
else if (chsrc_in_dish_group_mode() && ProgStatus.leader_selected_index!=-1)
1177-
{
1178-
source = dish->sources[ProgStatus.leader_selected_index];
1150+
if (hp_is_url (option))
1151+
{
1152+
/* combo dish 传入 URL 时,支持该 sub dish 自定义 URL 的则直接使用;
1153+
* 不支持则自动选择该 sub dish 的最快源。这样 uv 可只把 URL 当作
1154+
* PyPI index,而 python-install-mirror 仍自动选择。 */
1155+
if (dish->can_user_define)
1156+
{
1157+
Source_t tmp = { &UserDefinedProvider, option };
1158+
source = tmp;
1159+
}
1160+
else
1161+
{
1162+
int index = auto_select_mirror (dish->sources, dish->sources_n, dish->aliases);
1163+
source = dish->sources[index];
1164+
}
1165+
}
1166+
else
1167+
{
1168+
int index = chsrc_resolve_combo_subdish_source (dish, option);
1169+
source = dish->sources[index];
1170+
}
11791171
}
11801172
else if (hp_is_url (option))
11811173
{
@@ -2075,11 +2067,16 @@ chsrc_backup (const char *path)
20752067
* 已经保留原始内容后,后续 sub dish 不应再覆盖该备份。 */
20762068
if (chsrc_in_combo_source_resolution())
20772069
{
2078-
int depth = ComboSourceResolutionDepth - 1;
2079-
if (ComboBackedUpPaths[depth] && xy_streql (ComboBackedUpPaths[depth], path))
2080-
goto log_anyway;
2070+
int depth = ProgStatus.ComboStackDepth - 1;
2071+
XySeq_t *backed_up_paths = ProgStatus.ComboBackedUpPaths[depth];
2072+
2073+
for (size_t i=0; i < xy_seq_len(backed_up_paths); i++)
2074+
{
2075+
if (xy_streql (xy_seq_at (backed_up_paths, i), path))
2076+
goto log_anyway;
2077+
}
20812078

2082-
ComboBackedUpPaths[depth] = xy_strdup (path);
2079+
xy_seq_push (backed_up_paths, xy_strdup (path));
20832080
}
20842081

20852082
if (xy.on_bsd || xy.on_macos)

‎src/framework/dish.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,26 @@ dish_has_sub_dishes (Dish_t *dish)
3535
{
3636
return (dish->sub_dishes && xy_seq_len(dish->sub_dishes) > 1);
3737
}
38+
39+
40+
41+
bool
42+
dish_has_source_from_mirror (Dish_t *dish, const char *code)
43+
{
44+
if (!dish || !dish->sources || !code)
45+
return false;
46+
47+
if (xy_streql (code, "upstream"))
48+
return dish->sources_n > 0;
49+
50+
if (xy_streql (code, "first"))
51+
return dish->sources_n > 1;
52+
53+
for (int i=0; i < dish->sources_n; i++)
54+
{
55+
if (xy_streql (dish->sources[i].mirror->code, code))
56+
return true;
57+
}
58+
59+
return false;
60+
}

‎src/recipe/lang/Python/uv/uv-python-build.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ pl_uv_python_build_prepare (void)
3737
chef_set_default_scope (this, UserScope);
3838

3939
chef_deny_english (this);
40-
chef_allow_user_define (this);
40+
chef_deny_user_define (this);
41+
this->can_user_define_explain =
42+
CHINESE ? "python-install-mirror 不支持手动指定,chsrc 会自动选择"
43+
: "python-install-mirror cannot be specified manually; chsrc selects it automatically";
4144

4245
def_sources_begin ()
4346
{&UpstreamProvider, "https://github.com/astral-sh/python-build-standalone/releases/download", DelegateToUpstream},

0 commit comments

Comments
 (0)