scalar-[un]register: clearly indicate source of error

When a step in 'register_dir()' or 'unregister_dir()' fails, indicate which step failed with an error message, rather than silently assigning a nonzero return code. Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Victoria Dye committed Aug 18, 2022 at 21:40 UTC d2a79bc953375ed7dd8cb06fd3db92f85c64c206
1 file changed +9 -8
contrib/scalar/scalar.c
+9 -8
@@ -208,15 +208,16 @@ static int add_or_remove_enlistment(int add)
208
209 static int register_dir(void)
210 {
211 - int res = add_or_remove_enlistment(1);
211 + if (add_or_remove_enlistment(1))
212 + return error(_("could not add enlistment"));
213
213 - if (!res)
214 - res = set_recommended_config(0);
214 + if (set_recommended_config(0))
215 + return error(_("could not set recommended config"));
216
216 - if (!res)
217 - res = toggle_maintenance(1);
217 + if (toggle_maintenance(1))
218 + return error(_("could not turn on maintenance"));
219
219 - return res;
220 + return 0;
221 }
222
223 static int unregister_dir(void)
@@ -224,10 +225,10 @@ static int unregister_dir(void)
225 int res = 0;
226
227 if (toggle_maintenance(0))
227 - res = -1;
228 + res = error(_("could not turn off maintenance"));
229
230 if (add_or_remove_enlistment(0))
230 - res = -1;
231 + res = error(_("could not remove enlistment"));
232
233 return res;
234 }