Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e0887d81
Commit
e0887d81
authored
Apr 27, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed goto from state machine loop.
parent
7149a625
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
22 deletions
+17
-22
src/revparse.c
+17
-22
No files found.
src/revparse.c
View file @
e0887d81
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment