diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-01-15 15:51:31 +0400 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-01-15 16:32:43 +0400 |
commit | 0b28217bdae4fd64f5b6b8f4cb8a6139518d037e (patch) | |
tree | 68ff2ad34826372104b12ed6de6dd9fecb905151 /src | |
parent | 3c1b3ded12afa443158287c22b81fb9419680072 (diff) |
refs: remove the _with_log differentiation
Any well-behaved program should write a descriptive message to the
reflog whenever it updates a reference. Let's make this more prominent
by removing the version without the reflog parameters.
Diffstat (limited to 'src')
-rw-r--r-- | src/branch.c | 2 | ||||
-rw-r--r-- | src/commit.c | 2 | ||||
-rw-r--r-- | src/push.c | 2 | ||||
-rw-r--r-- | src/refs.c | 112 | ||||
-rw-r--r-- | src/refs.h | 2 | ||||
-rw-r--r-- | src/remote.c | 2 | ||||
-rw-r--r-- | src/repository.c | 8 | ||||
-rw-r--r-- | src/reset.c | 2 | ||||
-rw-r--r-- | src/stash.c | 4 | ||||
-rw-r--r-- | src/tag.c | 4 | ||||
-rw-r--r-- | src/transports/local.c | 2 |
11 files changed, 68 insertions, 74 deletions
diff --git a/src/branch.c b/src/branch.c index 9ed0addb5..3b9aa0d20 100644 --- a/src/branch.c +++ b/src/branch.c @@ -72,7 +72,7 @@ int git_branch_create( goto cleanup; error = git_reference_create(&branch, repository, - git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force); + git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force, NULL, NULL); if (!error) *ref_out = branch; diff --git a/src/commit.c b/src/commit.c index 4ddfafb41..f0e304a84 100644 --- a/src/commit.c +++ b/src/commit.c @@ -112,7 +112,7 @@ int git_commit_create_from_oids( git_buf_free(&commit); if (update_ref != NULL) - return git_reference__update_terminal(repo, update_ref, oid); + return git_reference__update_terminal(repo, update_ref, oid, NULL, NULL); return 0; diff --git a/src/push.c b/src/push.c index dd77864a5..0be82f3b2 100644 --- a/src/push.c +++ b/src/push.c @@ -241,7 +241,7 @@ int git_push_update_tips(git_push *push) giterr_clear(); else goto on_error; - } else if ((error = git_reference_create(NULL, push->remote->repo, git_buf_cstr(&remote_ref_name), &push_spec->loid, 1)) < 0) + } else if ((error = git_reference_create(NULL, push->remote->repo, git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, NULL, NULL)) < 0) goto on_error; } diff --git a/src/refs.c b/src/refs.c index ce172aa27..0f0a380ea 100644 --- a/src/refs.c +++ b/src/refs.c @@ -393,32 +393,20 @@ static int reference__create( return 0; } -int git_reference_create( - git_reference **ref_out, - git_repository *repo, - const char *name, - const git_oid *oid, - int force) +static int log_signature(git_signature **out, git_repository *repo) { - git_signature *who; int error; + git_signature *who; - assert(oid); - - /* Should we return an error if there is no default? */ - if (((error = git_signature_default(&who, repo)) < 0) && - ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) { + if(((error = git_signature_default(&who, repo)) < 0) && + ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) return error; - } - error = reference__create(ref_out, repo, name, oid, NULL, force, who, NULL); - - git_signature_free(who); - - return error; + *out = who; + return 0; } -int git_reference_create_with_log( +int git_reference_create( git_reference **ref_out, git_repository *repo, const char *name, @@ -427,24 +415,26 @@ int git_reference_create_with_log( const git_signature *signature, const char *log_message) { - assert(oid && signature); + int error; + git_signature *who = NULL; + + assert(oid); - return reference__create( + if (!signature) { + if ((error = log_signature(&who, repo)) < 0) + return error; + else + signature = who; + } + + error = reference__create( ref_out, repo, name, oid, NULL, force, signature, log_message); -} -int git_reference_symbolic_create( - git_reference **ref_out, - git_repository *repo, - const char *name, - const char *target, - int force) -{ - assert(target); - return reference__create(ref_out, repo, name, NULL, target, force, NULL, NULL); + git_signature_free(who); + return error; } -int git_reference_symbolic_create_with_log( +int git_reference_symbolic_create( git_reference **ref_out, git_repository *repo, const char *name, @@ -453,10 +443,23 @@ int git_reference_symbolic_create_with_log( const git_signature *signature, const char *log_message) { - assert(target && signature); + int error; + git_signature *who = NULL; + + assert(target); + + if (!signature) { + if ((error = log_signature(&who, repo)) < 0) + return error; + else + signature = who; + } - return reference__create( + error = reference__create( ref_out, repo, name, NULL, target, force, signature, log_message); + + git_signature_free(who); + return error; } static int ensure_is_an_updatable_direct_reference(git_reference *ref) @@ -471,21 +474,6 @@ static int ensure_is_an_updatable_direct_reference(git_reference *ref) int git_reference_set_target( git_reference **out, git_reference *ref, - const git_oid *id) -{ - int error; - - assert(out && ref && id); - - if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0) - return error; - - return git_reference_create(out, ref->db->repo, ref->name, id, 1); -} - -int git_reference_set_target_with_log( - git_reference **out, - git_reference *ref, const git_oid *id, const git_signature *signature, const char *log_message) @@ -493,12 +481,11 @@ int git_reference_set_target_with_log( int error; assert(out && ref && id); - assert(signature && log_message); if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0) return error; - return git_reference_create_with_log( + return git_reference_create( out, ref->db->repo, ref->name, id, 1, signature, log_message); } @@ -514,7 +501,9 @@ static int ensure_is_an_updatable_symbolic_reference(git_reference *ref) int git_reference_symbolic_set_target( git_reference **out, git_reference *ref, - const char *target) + const char *target, + const git_signature *signature, + const char *log_message) { int error; @@ -523,7 +512,8 @@ int git_reference_symbolic_set_target( if ((error = ensure_is_an_updatable_symbolic_reference(ref)) < 0) return error; - return git_reference_symbolic_create(out, ref->db->repo, ref->name, target, 1); + return git_reference_symbolic_create( + out, ref->db->repo, ref->name, target, 1, signature, log_message); } static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force, @@ -1020,7 +1010,9 @@ static int reference__update_terminal( git_repository *repo, const char *ref_name, const git_oid *oid, - int nesting) + int nesting, + const git_signature *signature, + const char *log_message) { git_reference *ref; int error = 0; @@ -1035,7 +1027,7 @@ static int reference__update_terminal( /* If we haven't found the reference at all, create a new reference. */ if (error == GIT_ENOTFOUND) { giterr_clear(); - return git_reference_create(NULL, repo, ref_name, oid, 0); + return git_reference_create(NULL, repo, ref_name, oid, 0, signature, log_message); } if (error < 0) @@ -1044,11 +1036,11 @@ static int reference__update_terminal( /* If the ref is a symbolic reference, follow its target. */ if (git_reference_type(ref) == GIT_REF_SYMBOLIC) { error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid, - nesting+1); + nesting+1, signature, log_message); git_reference_free(ref); } else { git_reference_free(ref); - error = git_reference_create(NULL, repo, ref_name, oid, 1); + error = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message); } return error; @@ -1062,9 +1054,11 @@ static int reference__update_terminal( int git_reference__update_terminal( git_repository *repo, const char *ref_name, - const git_oid *oid) + const git_oid *oid, + const git_signature *signature, + const char *log_message) { - return reference__update_terminal(repo, ref_name, oid, 0); + return reference__update_terminal(repo, ref_name, oid, 0, signature, log_message); } int git_reference_has_log(git_repository *repo, const char *refname) diff --git a/src/refs.h b/src/refs.h index 4d5b6dacb..d57d67026 100644 --- a/src/refs.h +++ b/src/refs.h @@ -68,7 +68,7 @@ git_reference *git_reference__set_name(git_reference *ref, const char *name); int git_reference__normalize_name_lax(char *buffer_out, size_t out_size, const char *name); int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags); -int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid); +int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *signature, const char *log_message); int git_reference__is_valid_name(const char *refname, unsigned int flags); int git_reference__is_branch(const char *ref_name); int git_reference__is_remote(const char *ref_name); diff --git a/src/remote.c b/src/remote.c index 622abbc8c..306cb0b9a 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1027,7 +1027,7 @@ static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vecto continue; /* In autotag mode, don't overwrite any locally-existing tags */ - error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag); + error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag, NULL, NULL); if (error < 0 && error != GIT_EEXISTS) goto on_error; diff --git a/src/repository.c b/src/repository.c index 94f6603aa..c584d30c8 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1863,11 +1863,11 @@ int git_repository_set_head( if (!error) { if (git_reference_is_branch(ref)) - error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, git_reference_name(ref), 1); + error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, git_reference_name(ref), 1, NULL, NULL); else error = git_repository_set_head_detached(repo, git_reference_target(ref)); } else if (looks_like_a_branch(refname)) - error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname, 1); + error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname, 1, NULL, NULL); git_reference_free(ref); git_reference_free(new_head); @@ -1891,7 +1891,7 @@ int git_repository_set_head_detached( if ((error = git_object_peel(&peeled, object, GIT_OBJ_COMMIT)) < 0) goto cleanup; - error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), 1); + error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), 1, NULL, NULL); cleanup: git_object_free(object); @@ -1916,7 +1916,7 @@ int git_repository_detach_head( if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJ_COMMIT)) < 0) goto cleanup; - error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head), 1); + error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head), 1, NULL, NULL); cleanup: git_object_free(object); diff --git a/src/reset.c b/src/reset.c index 261a36576..32e101357 100644 --- a/src/reset.c +++ b/src/reset.c @@ -131,7 +131,7 @@ int git_reset( /* move HEAD to the new target */ if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE, - git_object_id(commit))) < 0) + git_object_id(commit), NULL, NULL)) < 0) goto cleanup; if (reset_type == GIT_RESET_HARD) { diff --git a/src/stash.c b/src/stash.c index 3019816ff..b1dd87b22 100644 --- a/src/stash.c +++ b/src/stash.c @@ -417,7 +417,7 @@ static int update_reflog( if ((error = git_reference_ensure_log(repo, GIT_REFS_STASH_FILE)) < 0) return error; - error = git_reference_create_with_log(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, stasher, message); + error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, stasher, message); git_reference_free(stash); @@ -628,7 +628,7 @@ int git_stash_drop( entry = git_reflog_entry_byindex(reflog, 0); git_reference_free(stash); - if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1) < 0)) + if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1, NULL, NULL) < 0)) goto cleanup; /* We need to undo the writing that we just did */ @@ -271,7 +271,7 @@ static int git_tag_create__internal( } else git_oid_cpy(oid, git_object_id(target)); - error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite); + error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL, NULL); cleanup: git_reference_free(new_ref); @@ -376,7 +376,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu return -1; } - error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite); + error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL, NULL); git_reference_free(new_ref); git_buf_free(&ref_name); diff --git a/src/transports/local.c b/src/transports/local.c index 4635d5dd3..253aca30a 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -315,7 +315,7 @@ static int local_push_update_remote_ref( if (lref) { /* Create or update a ref */ if ((error = git_reference_create(NULL, remote_repo, rref, loid, - !git_oid_iszero(roid))) < 0) + !git_oid_iszero(roid), NULL, NULL)) < 0) return error; } else { /* Delete a ref */ |