commit d82ad331dd0534d30ff4b9f4b180949377be04c1 from: Stefan Sperling date: Wed May 09 18:53:57 2018 UTC add get_head_commit_id() helper function to tog commit - 5da4c0f8c9d650fb453e89ebf9a08883d6d6ecc1 commit + d82ad331dd0534d30ff4b9f4b180949377be04c1 blob - 05264b31220545ef2b839e448e4714330439e160 blob + 30c2779376b3b0fffa8e8fe586ab2ea6d27f9f88 --- tog/tog.c +++ tog/tog.c @@ -347,6 +347,28 @@ draw_commits(struct commit_queue *commits, int selecte } static const struct got_error * +get_head_commit_id(struct got_object_id **head_id, struct got_repository *repo) +{ + const struct got_error *err = NULL; + struct got_reference *head_ref; + + *head_id = NULL; + + err = got_ref_open(&head_ref, repo, GOT_REF_HEAD); + if (err) + return err; + + err = got_ref_resolve(head_id, repo, head_ref); + got_ref_close(head_ref); + if (err) { + *head_id = NULL; + return err; + } + + return NULL; +} + +static const struct got_error * show_log_view(struct got_object_id *start_id, struct got_repository *repo) { const struct got_error *err = NULL; @@ -511,14 +533,9 @@ cmd_log(int argc, char *argv[]) return error; if (start_commit == NULL) { - struct got_reference *head_ref; - error = got_ref_open(&head_ref, repo, GOT_REF_HEAD); + error = get_head_commit_id(&id, repo); if (error != NULL) return error; - error = got_ref_resolve(&id, repo, head_ref); - got_ref_close(head_ref); - if (error != NULL) - return error; } else { struct got_object *obj; error = got_object_open_by_id_str(&obj, repo, start_commit);