[PATCH 02/18] is_refname_available(): explain the reason for an early exit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The reason why we can exit early if we find a reference in skip whose
name is a prefix of refname is a bit subtle, so explain it in a
comment.

Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx>
---
 refs.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/refs.c b/refs.c
index 2bdd93c..ab438a5 100644
--- a/refs.c
+++ b/refs.c
@@ -907,8 +907,20 @@ static int is_refname_available(const char *refname,
 		pos = search_ref_dir(dir, refname, slash - refname);
 		if (pos >= 0) {
 			struct ref_entry *entry = dir->entries[pos];
-			if (entry_matches(entry, skip))
+			if (entry_matches(entry, skip)) {
+				/*
+				 * The fact that entry is a ref whose
+				 * name is a prefix of refname means
+				 * that there cannot be any other ref
+				 * whose name starts with that prefix
+				 * (because it would have been a D/F
+				 * conflict with entry). So, since we
+				 * don't care about entry (because it
+				 * is in skip), we can stop looking
+				 * now and return true.
+				 */
 				return 1;
+			}
 			report_refname_conflict(entry, refname);
 			return 0;
 		}
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]