From 8280bbebd1ecc4633b969a439ed4ca653d1bc958 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 2 Mar 2015 10:29:51 +0100 Subject: write_ref_sha1(): remove check for lock == NULL None of the callers pass NULL to this function, and there doesn't seem to be any usefulness to allowing them to do so. Signed-off-by: Michael Haggerty Reviewed-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index c5fa709..d1130e2 100644 --- a/refs.c +++ b/refs.c @@ -3080,10 +3080,6 @@ static int write_ref_sha1(struct ref_lock *lock, static char term = '\n'; struct object *o; - if (!lock) { - errno = EINVAL; - return -1; - } if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) { unlock_ref(lock); return 0; -- cgit v0.10.2-6-g49f6 From 706d5f816fbcb1299c19f4d41bea60f1e229165e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 2 Mar 2015 10:29:52 +0100 Subject: write_ref_sha1(): move write elision test to callers write_ref_sha1() previously skipped the write if the reference already had the desired value, unless lock->force_write was set. Instead, perform that test at the callers. Two of the callers (in rename_ref()) unconditionally set force_write just before calling write_ref_sha1(), so they don't need the extra check at all. Nor do they need to set force_write anymore. The last caller, in ref_transaction_commit(), still needs the test. Signed-off-by: Michael Haggerty Reviewed-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index d1130e2..651e37e 100644 --- a/refs.c +++ b/refs.c @@ -2878,7 +2878,6 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms error("unable to lock %s for update", newrefname); goto rollback; } - lock->force_write = 1; hashcpy(lock->old_sha1, orig_sha1); if (write_ref_sha1(lock, orig_sha1, logmsg)) { error("unable to write current sha1 into %s", newrefname); @@ -2894,7 +2893,6 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms goto rollbacklog; } - lock->force_write = 1; flag = log_all_ref_updates; log_all_ref_updates = 0; if (write_ref_sha1(lock, orig_sha1, NULL)) @@ -3080,10 +3078,6 @@ static int write_ref_sha1(struct ref_lock *lock, static char term = '\n'; struct object *o; - if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) { - unlock_ref(lock); - return 0; - } o = parse_object(sha1); if (!o) { error("Trying to write ref %s with nonexistent object %s", @@ -3797,15 +3791,21 @@ int ref_transaction_commit(struct ref_transaction *transaction, struct ref_update *update = updates[i]; if (!is_null_sha1(update->new_sha1)) { - if (write_ref_sha1(update->lock, update->new_sha1, - update->msg)) { + if (!update->lock->force_write && + !hashcmp(update->lock->old_sha1, update->new_sha1)) { + unlock_ref(update->lock); + update->lock = NULL; + } else if (write_ref_sha1(update->lock, update->new_sha1, + update->msg)) { update->lock = NULL; /* freed by write_ref_sha1 */ strbuf_addf(err, "Cannot update the ref '%s'.", update->refname); ret = TRANSACTION_GENERIC_ERROR; goto cleanup; + } else { + /* freed by write_ref_sha1(): */ + update->lock = NULL; } - update->lock = NULL; /* freed by write_ref_sha1 */ } } -- cgit v0.10.2-6-g49f6 From 074336e5ed4ff10577f22c6812e092e3f6607405 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 2 Mar 2015 10:29:53 +0100 Subject: lock_ref_sha1_basic(): do not set force_write for missing references If a reference is missing, its SHA-1 will be null_sha1, which can't possibly match a new value that ref_transaction_commit() is trying to update it to. So there is no need to set force_write in this scenario. Signed-off-by: Michael Haggerty Reviewed-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 651e37e..b6a2535 100644 --- a/refs.c +++ b/refs.c @@ -2259,7 +2259,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, int type, lflags; int mustexist = (old_sha1 && !is_null_sha1(old_sha1)); int resolve_flags = 0; - int missing = 0; int attempts_remaining = 3; lock = xcalloc(1, sizeof(struct ref_lock)); @@ -2298,13 +2297,13 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, orig_refname, strerror(errno)); goto error_return; } - missing = is_null_sha1(lock->old_sha1); - /* When the ref did not exist and we are creating it, - * make sure there is no existing ref that is packed - * whose name begins with our refname, nor a ref whose - * name is a proper prefix of our refname. + /* + * If the ref did not exist and we are creating it, make sure + * there is no existing packed ref whose name begins with our + * refname, nor a packed ref whose name is a proper prefix of + * our refname. */ - if (missing && + if (is_null_sha1(lock->old_sha1) && !is_refname_available(refname, skip, get_packed_refs(&ref_cache))) { last_errno = ENOTDIR; goto error_return; @@ -2320,8 +2319,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, lock->ref_name = xstrdup(refname); lock->orig_ref_name = xstrdup(orig_refname); ref_file = git_path("%s", refname); - if (missing) - lock->force_write = 1; if ((flags & REF_NODEREF) && (type & REF_ISSYMREF)) lock->force_write = 1; -- cgit v0.10.2-6-g49f6 From 5a6f47077b31be45bfadd6cef3b8b1a79ad57de5 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 3 Mar 2015 12:43:14 +0100 Subject: struct ref_lock: delete the force_write member Instead, compute the value when it is needed. Signed-off-by: Stefan Beller Edited-by: Michael Haggerty Signed-off-by: Michael Haggerty Reviewed-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index b6a2535..5d8d57d 100644 --- a/refs.c +++ b/refs.c @@ -12,7 +12,6 @@ struct ref_lock { struct lock_file *lk; unsigned char old_sha1[20]; int lock_fd; - int force_write; }; /* @@ -2319,8 +2318,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, lock->ref_name = xstrdup(refname); lock->orig_ref_name = xstrdup(orig_refname); ref_file = git_path("%s", refname); - if ((flags & REF_NODEREF) && (type & REF_ISSYMREF)) - lock->force_write = 1; retry: switch (safe_create_leading_directories(ref_file)) { @@ -3788,8 +3785,15 @@ int ref_transaction_commit(struct ref_transaction *transaction, struct ref_update *update = updates[i]; if (!is_null_sha1(update->new_sha1)) { - if (!update->lock->force_write && - !hashcmp(update->lock->old_sha1, update->new_sha1)) { + int overwriting_symref = ((update->type & REF_ISSYMREF) && + (update->flags & REF_NODEREF)); + + if (!overwriting_symref + && !hashcmp(update->lock->old_sha1, update->new_sha1)) { + /* + * The reference already has the desired + * value, so we don't need to write it. + */ unlock_ref(update->lock); update->lock = NULL; } else if (write_ref_sha1(update->lock, update->new_sha1, -- cgit v0.10.2-6-g49f6 From fe2a18165c97d3e0937bb99fda449e1f64e5c867 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Tue, 3 Mar 2015 12:43:15 +0100 Subject: reflog: improve and update documentation Revamp the "git reflog" usage documentation in the manpage and the command help to match the current reality and improve its clarity: * Add documentation for some options that had been left out. * Group the subcommands and options more logically and move more common subcommands/options higher. * Improve some explanations. Signed-off-by: Michael Haggerty Reviewed-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/Documentation/git-reflog.txt b/Documentation/git-reflog.txt index 70791b9..730106c 100644 --- a/Documentation/git-reflog.txt +++ b/Documentation/git-reflog.txt @@ -17,85 +17,112 @@ The command takes various subcommands, and different options depending on the subcommand: [verse] -'git reflog expire' [--dry-run] [--stale-fix] [--verbose] - [--expire=