git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 4/6] sha1-name: Teach `get_oid_basic()` to be gentle

From
Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Date
Jul 17, 2018, 12:06 UTC
Message-ID
<d91384ff0e23cd845bcfdf170c8a162ec5551f6b.1531778417.git.ungureanupaulsebastian@gmail.com>
In-Reply-To
<cover.1531778417.git.ungureanupaulsebastian@gmail.com>

After teaching `read_ref_at()` we need to teach `get_oid_basic()` that `read_ref_at()` might not call `exit()`, but report an error through the return value.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
---
 sha1-name.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/sha1-name.c b/sha1-name.c
index d741e1129..74ecbd550 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -778,6 +778,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		timestamp_t at_time;
 		timestamp_t co_time;
 		int co_tz, co_cnt;
+		int ret;
 
 		/* Is it asking for N-th entry, or approxidate? */
 		for (i = nth = 0; 0 <= nth && i < reflog_len; i++) {
@@ -802,8 +803,12 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
-				&co_time, &co_tz, &co_cnt)) {
+
+		ret = read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
+				&co_time, &co_tz, &co_cnt);
+		if (ret == -1)
+			return -1;
+		if (ret) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
 					str = real_ref + 11;
@@ -821,9 +826,12 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 						show_date(co_time, co_tz, DATE_MODE(RFC2822)));
 				}
 			} else {
-				if (flags & GET_OID_QUIETLY) {
-					exit(128);
+				if (flags & GET_OID_GENTLY) {
+					free(real_ref);
+					return -1;
 				}
+				if (flags & GET_OID_QUIETLY)
+					exit(128);
 				die("Log for '%.*s' only has %d entries.",
 				    len, str, co_cnt);
 			}
-- 
2.18.0.rc2.184.ga79db55c2.dirty
Previous: Paul-Sebastian UngureanuNext: Paul-Sebastian Ungureanu
Message 6 of 13 in “Add gentle alternative for `get_oid()`”
  1. 0/6 Add gentle alternative for `get_oid()`Paul-Sebastian Ungureanu, Jul 17, 2018
  2. 5/6 sha1-name: Teach `get_oid_with_context[_1]()` to be gentlePaul-Sebastian Ungureanu, Jul 17, 2018
  3. Junio C HamanoJul 17, 2018
  4. Paul-Sebastian UngureanuJul 18, 2018
  5. 6/6 sha1-name: Add gentle alternative for `get_oid()`Paul-Sebastian Ungureanu, Jul 17, 2018
  6. 4/6 sha1-name: Teach `get_oid_basic()` to be gentlePaul-Sebastian Ungureanu, Jul 17, 2018
  7. 3/6 refs.c: Teach `read_ref_at()` to accept `GET_OID_GENTLY` flagPaul-Sebastian Ungureanu, Jul 17, 2018
  8. 2/6 tree-walk: Add three new gentle helpersPaul-Sebastian Ungureanu, Jul 17, 2018
  9. Junio C HamanoJul 17, 2018
  10. Paul-Sebastian UngureanuJul 18, 2018
  11. 1/6 sha1-name: Add `GET_OID_GENTLY` flagPaul-Sebastian Ungureanu, Jul 17, 2018
  12. Duy NguyenJul 17, 2018
  13. Paul-Sebastian UngureanuJul 18, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.