@matheusbsbs / matheus-bagliano / commits / 4886b89f8f
Fork 0

refs: improve comments about "reading" argument of "resolve_ref"

The existing in-code comment was misleading. An access that is not "reading" may often be "writing", but it does not have to be. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Sep 9, 2008 at 07:10 UTC 4886b89f8fde57b76738c96761eecbfbd0b13112
1 file changed +13 -7
refs.c
+13 -7
@@ -390,6 +390,18 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re
390 return retval;
391 }
392
393 +/*
394 + * If the "reading" argument is set, this function finds out what _object_
395 + * the ref points at by "reading" the ref. The ref, if it is not symbolic,
396 + * has to exist, and if it is symbolic, it has to point at an existing ref,
397 + * because the "read" goes through the symref to the ref it points at.
398 + *
399 + * The access that is not "reading" may often be "writing", but does not
400 + * have to; it can be merely checking _where it leads to_. If it is a
401 + * prelude to "writing" to the ref, a write to a symref that points at
402 + * yet-to-be-born ref will create the real ref pointed by the symref.
403 + * reading=0 allows the caller to check where such a symref leads to.
404 + */
405 const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag)
406 {
407 int depth = MAXDEPTH;
@@ -409,13 +421,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
421 if (--depth < 0)
422 return NULL;
423
412 - /* Special case: non-existing file.
413 - * Not having the refs/heads/new-branch is OK
414 - * if we are writing into it, so is .git/HEAD
415 - * that points at refs/heads/master still to be
416 - * born. It is NOT OK if we are resolving for
417 - * reading.
418 - */
424 + /* Special case: non-existing file. */
425 if (lstat(path, &st) < 0) {
426 struct ref_list *list = get_packed_refs();
427 while (list) {