127
}
128
}
129
130
-static int update(struct command *cmd)
130
+static const char *update(struct command *cmd)
131
{
132
const char *name = cmd->ref_name;
133
unsigned char *old_sha1 = cmd->old_sha1;
134
unsigned char *new_sha1 = cmd->new_sha1;
135
struct ref_lock *lock;
136
137
- cmd->error_string = NULL;
137
if (!prefixcmp(name, "refs/") && check_ref_format(name + 5)) {
139
- cmd->error_string = "funny refname";
140
- return error("refusing to create funny ref '%s' locally",
141
- name);
138
+ error("refusing to create funny ref '%s' locally", name);
139
+ return "funny refname";
140
}
141
142
if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) {
145
- cmd->error_string = "bad pack";
146
- return error("unpack should have generated %s, "
147
- "but I can't find it!", sha1_to_hex(new_sha1));
143
+ error("unpack should have generated %s, "
144
+ "but I can't find it!", sha1_to_hex(new_sha1));
145
+ return "bad pack";
146
}
147
if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
148
!is_null_sha1(old_sha1) &&
157
if (!hashcmp(old_sha1, ent->item->object.sha1))
158
break;
159
free_commit_list(bases);
162
- if (!ent)
163
- return error("denying non-fast forward;"
164
- " you should pull first");
160
+ if (!ent) {
161
+ error("denying non-fast forward %s"
162
+ " (you should pull first)", name);
163
+ return "non-fast forward";
164
+ }
165
}
166
if (run_hook(update_hook, cmd, 1)) {
167
- cmd->error_string = "hook declined";
168
- return error("hook declined to update %s", name);
167
+ error("hook declined to update %s", name);
168
+ return "hook declined";
169
}
170
171
if (is_null_sha1(new_sha1)) {
172
if (delete_ref(name, old_sha1)) {
173
- cmd->error_string = "failed to delete";
174
- return error("failed to delete %s", name);
173
+ error("failed to delete %s", name);
174
+ return "failed to delete";
175
}
176
fprintf(stderr, "%s: %s -> deleted\n", name,
177
sha1_to_hex(old_sha1));
178
+ return NULL; /* good */
179
}
180
else {
181
lock = lock_any_ref_for_update(name, old_sha1);
182
if (!lock) {
182
- cmd->error_string = "failed to lock";
183
- return error("failed to lock %s", name);
183
+ error("failed to lock %s", name);
184
+ return "failed to lock";
185
}
186
if (write_ref_sha1(lock, new_sha1, "push")) {
186
- cmd->error_string = "failed to write";
187
- return -1; /* error() already called */
187
+ return "failed to write"; /* error() already called */
188
}
189
fprintf(stderr, "%s: %s -> %s\n", name,
190
sha1_to_hex(old_sha1), sha1_to_hex(new_sha1));
191
+ return NULL; /* good */
192
}
192
- return 0;
193
}
194
195
static char update_post_hook[] = "hooks/post-update";
224
| RUN_COMMAND_STDOUT_TO_STDERR);
225
}
226
227
-/*
228
- * This gets called after(if) we've successfully
229
- * unpacked the data payload.
230
- */
231
-static void execute_commands(void)
227
+static void execute_commands(const char *unpacker_error)
228
{
229
struct command *cmd = commands;
230
+
231
+ if (unpacker_error) {
232
+ while (cmd) {
233
+ cmd->error_string = "n/a (unpacker error)";
234
+ cmd = cmd->next;
235
+ }
236
+ return;
237
+ }
238
+
239
while (cmd) {
235
- update(cmd);
240
+ cmd->error_string = update(cmd);
241
cmd = cmd->next;
242
}
243
}
275
hashcpy(cmd->old_sha1, old_sha1);
276
hashcpy(cmd->new_sha1, new_sha1);
277
memcpy(cmd->ref_name, line + 82, len - 81);
273
- cmd->error_string = "n/a (unpacker error)";
278
+ cmd->error_string = NULL;
279
cmd->next = NULL;
280
*p = cmd;
281
p = &cmd->next;
478
479
if (!delete_only(commands))
480
unpack_status = unpack();
476
- if (!unpack_status)
477
- execute_commands();
481
+ execute_commands(unpack_status);
482
if (pack_lockfile)
483
unlink(pack_lockfile);
484
if (report_status)