Commit e0887d81 by Ben Straub

Removed goto from state machine loop.

parent 7149a625
...@@ -21,12 +21,9 @@ GIT_BEGIN_DECL ...@@ -21,12 +21,9 @@ GIT_BEGIN_DECL
typedef enum { typedef enum {
REVPARSE_STATE_INIT, REVPARSE_STATE_INIT,
/* for "^{...}" and ^... */
REVPARSE_STATE_CARET, REVPARSE_STATE_CARET,
/* For "~..." */
REVPARSE_STATE_LINEAR, REVPARSE_STATE_LINEAR,
REVPARSE_STATE_DONE,
} revparse_state; } revparse_state;
static void set_invalid_syntax_err(const char *spec) static void set_invalid_syntax_err(const char *spec)
...@@ -272,11 +269,12 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec ...@@ -272,11 +269,12 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
git_object *next_obj = NULL; git_object *next_obj = NULL;
git_buf specbuffer = GIT_BUF_INIT; git_buf specbuffer = GIT_BUF_INIT;
git_buf stepbuffer = GIT_BUF_INIT; git_buf stepbuffer = GIT_BUF_INIT;
int keep_looping = 1;
int retcode = 0; int retcode = 0;
assert(out && repo && spec); assert(out && repo && spec);
while (1) { while (keep_looping) {
switch (current_state) { switch (current_state) {
case REVPARSE_STATE_INIT: case REVPARSE_STATE_INIT:
if (!*spec_cur) { if (!*spec_cur) {
...@@ -286,7 +284,7 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec ...@@ -286,7 +284,7 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
/* '@' syntax doesn't allow chaining */ /* '@' syntax doesn't allow chaining */
git_buf_puts(&stepbuffer, spec_cur); git_buf_puts(&stepbuffer, spec_cur);
retcode = walk_ref_history(out, git_buf_cstr(&specbuffer), git_buf_cstr(&stepbuffer)); retcode = walk_ref_history(out, git_buf_cstr(&specbuffer), git_buf_cstr(&stepbuffer));
goto cleanup; next_state = REVPARSE_STATE_DONE;
} else if (*spec_cur == '^') { } else if (*spec_cur == '^') {
next_state = REVPARSE_STATE_CARET; next_state = REVPARSE_STATE_CARET;
} else if (*spec_cur == '~') { } else if (*spec_cur == '~') {
...@@ -300,7 +298,7 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec ...@@ -300,7 +298,7 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
/* Leaving INIT state, find the object specified, in case that state needs it */ /* Leaving INIT state, find the object specified, in case that state needs it */
retcode = revparse_lookup_object(&next_obj, repo, git_buf_cstr(&specbuffer)); retcode = revparse_lookup_object(&next_obj, repo, git_buf_cstr(&specbuffer));
if (retcode < 0) { if (retcode < 0) {
goto cleanup; next_state = REVPARSE_STATE_DONE;
} }
} }
break; break;
...@@ -309,24 +307,18 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec ...@@ -309,24 +307,18 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
case REVPARSE_STATE_CARET: case REVPARSE_STATE_CARET:
/* Gather characters until NULL, '~', or '^' */ /* Gather characters until NULL, '~', or '^' */
if (!*spec_cur) { if (!*spec_cur) {
retcode = handle_caret_syntax(out, retcode = handle_caret_syntax(out, cur_obj, git_buf_cstr(&stepbuffer));
cur_obj, next_state = REVPARSE_STATE_DONE;
git_buf_cstr(&stepbuffer));
goto cleanup;
} else if (*spec_cur == '~') { } else if (*spec_cur == '~') {
retcode = handle_caret_syntax(&next_obj, retcode = handle_caret_syntax(&next_obj, cur_obj, git_buf_cstr(&stepbuffer));
cur_obj,
git_buf_cstr(&stepbuffer));
git_buf_clear(&stepbuffer); git_buf_clear(&stepbuffer);
if (retcode < 0) goto cleanup; next_state = !retcode ? REVPARSE_STATE_LINEAR : REVPARSE_STATE_DONE;
next_state = REVPARSE_STATE_LINEAR;
} else if (*spec_cur == '^') { } else if (*spec_cur == '^') {
retcode = handle_caret_syntax(&next_obj, retcode = handle_caret_syntax(&next_obj, cur_obj, git_buf_cstr(&stepbuffer));
cur_obj,
git_buf_cstr(&stepbuffer));
git_buf_clear(&stepbuffer); git_buf_clear(&stepbuffer);
if (retcode < 0) goto cleanup; if (retcode < 0) {
next_state = REVPARSE_STATE_CARET; next_state = REVPARSE_STATE_DONE;
}
} else { } else {
git_buf_putc(&stepbuffer, *spec_cur); git_buf_putc(&stepbuffer, *spec_cur);
} }
...@@ -342,6 +334,10 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec ...@@ -342,6 +334,10 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
} }
spec_cur++; spec_cur++;
break; break;
case REVPARSE_STATE_DONE:
keep_looping = 0;
break;
} }
current_state = next_state; current_state = next_state;
...@@ -351,7 +347,6 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec ...@@ -351,7 +347,6 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
} }
} }
cleanup:
git_buf_free(&specbuffer); git_buf_free(&specbuffer);
git_buf_free(&stepbuffer); git_buf_free(&stepbuffer);
return retcode; return retcode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment