refs.h: rename the action_on_err constants
Given that these constants are only being used when updating references, it is inappropriate to give them such generic names as "DIE_ON_ERR". So prefix their names with "UPDATE_REFS_". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 7, 2014 at 15:47 UTC
f412411245d4329307dec8ac0b1860c791cdb212
11 files changed
+40
-29
builtin/checkout.c
+1
-1
@@ -624,7 +624,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
624
/* Nothing to do. */
625
} else if (opts->force_detach || !new->path) { /* No longer on any branch. */
626
update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL,
627
- REF_NODEREF, DIE_ON_ERR);
627
+ REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
628
if (!opts->quiet) {
629
if (old->path && advice_detached_head)
630
detach_advice(new->name);
builtin/clone.c
+5
-4
@@ -521,7 +521,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
521
if (!has_sha1_file(ref->old_sha1))
522
continue;
523
update_ref(msg, ref->name, ref->old_sha1,
524
- NULL, 0, DIE_ON_ERR);
524
+ NULL, 0, UPDATE_REFS_DIE_ON_ERR);
525
}
526
}
527
@@ -589,14 +589,15 @@ static void update_head(const struct ref *our, const struct ref *remote,
589
create_symref("HEAD", our->name, NULL);
590
if (!option_bare) {
591
const char *head = skip_prefix(our->name, "refs/heads/");
592
- update_ref(msg, "HEAD", our->old_sha1, NULL, 0, DIE_ON_ERR);
592
+ update_ref(msg, "HEAD", our->old_sha1, NULL, 0,
593
+ UPDATE_REFS_DIE_ON_ERR);
594
install_branch_config(0, head, option_origin, our->name);
595
}
596
} else if (our) {
597
struct commit *c = lookup_commit_reference(our->old_sha1);
598
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
599
update_ref(msg, "HEAD", c->object.sha1,
599
- NULL, REF_NODEREF, DIE_ON_ERR);
600
+ NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
601
} else if (remote) {
602
/*
603
* We know remote HEAD points to a non-branch, or
@@ -604,7 +605,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
605
* Detach HEAD in all these cases.
606
*/
607
update_ref(msg, "HEAD", remote->old_sha1,
607
- NULL, REF_NODEREF, DIE_ON_ERR);
608
+ NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
609
}
610
}
611
builtin/merge.c
+3
-3
@@ -398,7 +398,7 @@ static void finish(struct commit *head_commit,
398
const char *argv_gc_auto[] = { "gc", "--auto", NULL };
399
update_ref(reflog_message.buf, "HEAD",
400
new_head, head, 0,
401
- DIE_ON_ERR);
401
+ UPDATE_REFS_DIE_ON_ERR);
402
/*
403
* We ignore errors in 'gc --auto', since the
404
* user should see them.
@@ -1222,7 +1222,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1222
die(_("%s - not something we can merge"), argv[0]);
1223
read_empty(remote_head->object.sha1, 0);
1224
update_ref("initial pull", "HEAD", remote_head->object.sha1,
1225
- NULL, 0, DIE_ON_ERR);
1225
+ NULL, 0, UPDATE_REFS_DIE_ON_ERR);
1226
goto done;
1227
} else {
1228
struct strbuf merge_names = STRBUF_INIT;
@@ -1339,7 +1339,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1339
}
1340
1341
update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1,
1342
- NULL, 0, DIE_ON_ERR);
1342
+ NULL, 0, UPDATE_REFS_DIE_ON_ERR);
1343
1344
if (remoteheads && !common)
1345
; /* No common ancestors found. We need a real merge. */
builtin/notes.c
+3
-3
@@ -717,7 +717,7 @@ static int merge_commit(struct notes_merge_options *o)
717
strbuf_insert(&msg, 0, "notes: ", 7);
718
update_ref(msg.buf, o->local_ref, sha1,
719
is_null_sha1(parent_sha1) ? NULL : parent_sha1,
720
- 0, DIE_ON_ERR);
720
+ 0, UPDATE_REFS_DIE_ON_ERR);
721
722
free_notes(t);
723
strbuf_release(&msg);
@@ -812,11 +812,11 @@ static int merge(int argc, const char **argv, const char *prefix)
812
if (result >= 0) /* Merge resulted (trivially) in result_sha1 */
813
/* Update default notes ref with new commit */
814
update_ref(msg.buf, default_notes_ref(), result_sha1, NULL,
815
- 0, DIE_ON_ERR);
815
+ 0, UPDATE_REFS_DIE_ON_ERR);
816
else { /* Merge has unresolved conflicts */
817
/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
818
update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL,
819
- 0, DIE_ON_ERR);
819
+ 0, UPDATE_REFS_DIE_ON_ERR);
820
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
821
if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL))
822
die("Failed to store link to current notes ref (%s)",
builtin/reset.c
+4
-2
@@ -252,11 +252,13 @@ static int reset_refs(const char *rev, const unsigned char *sha1)
252
if (!get_sha1("HEAD", sha1_orig)) {
253
orig = sha1_orig;
254
set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
255
- update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0, MSG_ON_ERR);
255
+ update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
256
+ UPDATE_REFS_MSG_ON_ERR);
257
} else if (old_orig)
258
delete_ref("ORIG_HEAD", old_orig, 0);
259
set_reflog_message(&msg, "updating HEAD", rev);
259
- update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0, MSG_ON_ERR);
260
+ update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0,
261
+ UPDATE_REFS_MSG_ON_ERR);
262
strbuf_release(&msg);
263
return update_ref_status;
264
}
builtin/update-ref.c
+3
-2
@@ -282,7 +282,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
282
if (end_null)
283
line_termination = '\0';
284
update_refs_stdin();
285
- return update_refs(msg, updates, updates_count, DIE_ON_ERR);
285
+ return update_refs(msg, updates, updates_count,
286
+ UPDATE_REFS_DIE_ON_ERR);
287
}
288
289
if (end_null)
@@ -314,5 +315,5 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
315
return delete_ref(refname, oldval ? oldsha1 : NULL, flags);
316
else
317
return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
317
- flags, DIE_ON_ERR);
318
+ flags, UPDATE_REFS_DIE_ON_ERR);
319
}
contrib/examples/builtin-fetch--tool.c
+2
-1
@@ -31,7 +31,8 @@ static int update_ref_env(const char *action,
31
rla = "(reflog update)";
32
if (snprintf(msg, sizeof(msg), "%s: %s", rla, action) >= sizeof(msg))
33
warning("reflog message too long: %.*s...", 50, msg);
34
- return update_ref(msg, refname, sha1, oldval, 0, QUIET_ON_ERR);
34
+ return update_ref(msg, refname, sha1, oldval, 0,
35
+ UPDATE_REFS_QUIET_ON_ERR);
36
}
37
38
static int update_local_ref(const char *name,
notes-cache.c
+1
-1
@@ -62,7 +62,7 @@ int notes_cache_write(struct notes_cache *c)
62
if (commit_tree(&msg, tree_sha1, NULL, commit_sha1, NULL, NULL) < 0)
63
return -1;
64
if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL,
65
- 0, QUIET_ON_ERR) < 0)
65
+ 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
66
return -1;
67
68
return 0;
notes-utils.c
+2
-1
@@ -48,7 +48,8 @@ void commit_notes(struct notes_tree *t, const char *msg)
48
49
create_notes_commit(t, NULL, &buf, commit_sha1);
50
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
51
- update_ref(buf.buf, t->ref, commit_sha1, NULL, 0, DIE_ON_ERR);
51
+ update_ref(buf.buf, t->ref, commit_sha1, NULL, 0,
52
+ UPDATE_REFS_DIE_ON_ERR);
53
54
strbuf_release(&buf);
55
}
refs.c
+9
-9
@@ -3243,9 +3243,9 @@ static struct ref_lock *update_ref_lock(const char *refname,
3243
if (!lock) {
3244
const char *str = "Cannot lock the ref '%s'.";
3245
switch (onerr) {
3246
- case MSG_ON_ERR: error(str, refname); break;
3247
- case DIE_ON_ERR: die(str, refname); break;
3248
- case QUIET_ON_ERR: break;
3246
+ case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
3247
+ case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
3248
+ case UPDATE_REFS_QUIET_ON_ERR: break;
3249
}
3250
}
3251
return lock;
@@ -3258,9 +3258,9 @@ static int update_ref_write(const char *action, const char *refname,
3258
if (write_ref_sha1(lock, sha1, action) < 0) {
3259
const char *str = "Cannot update the ref '%s'.";
3260
switch (onerr) {
3261
- case MSG_ON_ERR: error(str, refname); break;
3262
- case DIE_ON_ERR: die(str, refname); break;
3263
- case QUIET_ON_ERR: break;
3261
+ case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
3262
+ case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
3263
+ case UPDATE_REFS_QUIET_ON_ERR: break;
3264
}
3265
return 1;
3266
}
@@ -3294,11 +3294,11 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
3294
const char *str =
3295
"Multiple updates for ref '%s' not allowed.";
3296
switch (onerr) {
3297
- case MSG_ON_ERR:
3297
+ case UPDATE_REFS_MSG_ON_ERR:
3298
error(str, updates[i]->ref_name); break;
3299
- case DIE_ON_ERR:
3299
+ case UPDATE_REFS_DIE_ON_ERR:
3300
die(str, updates[i]->ref_name); break;
3301
- case QUIET_ON_ERR:
3301
+ case UPDATE_REFS_QUIET_ON_ERR:
3302
break;
3303
}
3304
return 1;
refs.h
+7
-2
@@ -214,8 +214,13 @@ extern int rename_ref(const char *oldref, const char *newref, const char *logmsg
214
*/
215
extern int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1);
216
217
-/** lock a ref and then write its file */
218
-enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR };
217
+enum action_on_err {
218
+ UPDATE_REFS_MSG_ON_ERR,
219
+ UPDATE_REFS_DIE_ON_ERR,
220
+ UPDATE_REFS_QUIET_ON_ERR
221
+};
222
+
223
+/** Lock a ref and then write its file */
224
int update_ref(const char *action, const char *refname,
225
const unsigned char *sha1, const unsigned char *oldval,
226
int flags, enum action_on_err onerr);