Skip to content

Commit

Permalink
update_ref(): improve documentation
Browse files Browse the repository at this point in the history
Add a docstring for update_ref(), emphasizing its similarity to
ref_transaction_update(). Rename its parameters to match those of
ref_transaction_update().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Feb 17, 2015
1 parent 1618033 commit 4b7b520
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3738,17 +3738,17 @@ int ref_transaction_verify(struct ref_transaction *transaction,
flags, NULL, err);
}

int update_ref(const char *action, const char *refname,
const unsigned char *sha1, const unsigned char *oldval,
int update_ref(const char *msg, const char *refname,
const unsigned char *new_sha1, const unsigned char *old_sha1,
unsigned int flags, enum action_on_err onerr)
{
struct ref_transaction *t;
struct strbuf err = STRBUF_INIT;

t = ref_transaction_begin(&err);
if (!t ||
ref_transaction_update(t, refname, sha1, oldval,
flags, action, &err) ||
ref_transaction_update(t, refname, new_sha1, old_sha1,
flags, msg, &err) ||
ref_transaction_commit(t, &err)) {
const char *str = "update_ref failed for ref '%s': %s";

Expand Down
13 changes: 10 additions & 3 deletions refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,16 @@ int ref_transaction_commit(struct ref_transaction *transaction,
*/
void ref_transaction_free(struct ref_transaction *transaction);

/** Lock a ref and then write its file */
int update_ref(const char *action, const char *refname,
const unsigned char *sha1, const unsigned char *oldval,
/**
* Lock, update, and unlock a single reference. This function
* basically does a transaction containing a single call to
* ref_transaction_update(). The parameters to this function have the
* same meaning as the corresponding parameters to
* ref_transaction_update(). Handle errors as requested by the `onerr`
* argument.
*/
int update_ref(const char *msg, const char *refname,
const unsigned char *new_sha1, const unsigned char *old_sha1,
unsigned int flags, enum action_on_err onerr);

extern int parse_hide_refs_config(const char *var, const char *value, const char *);
Expand Down

0 comments on commit 4b7b520

Please sign in to comment.