summaryrefslogtreecommitdiff
path: root/src/patch_parse.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-11-11 15:30:43 +0000
committerPatrick Steinhardt <ps@pks.im>2017-11-11 17:06:20 +0000
commitef1395f315ba137be64744a3a6b9d784db44fded (patch)
treea4cb6e7f04fbfeeeddec26f5ace6e368bad3e455 /src/patch_parse.h
parent0393ecc6f8bb19e4ba55fd45e7bbde6596f9b334 (diff)
downloadlibgit2-ef1395f315ba137be64744a3a6b9d784db44fded.tar.gz
parse: extract parse module
The `git_patch_parse_ctx` encapsulates both parser state as well as options specific to patch parsing. To advance this state and keep it consistent, we provide a few functions which handle advancing the current position and accessing bytes of the patch contents. In fact, these functions are quite generic and not related to patch-parsing by themselves. Seeing that we have similar logic inside of other modules, it becomes quite enticing to extract this functionality into its own parser module. To do so, we create a new module `parse` with a central struct called `git_parse_ctx`. It encapsulates both the content that is to be parsed as well as its lengths and the current position. `git_patch_parse_ctx` now only contains this `parse_ctx` only, which is then accessed whenever we need to touch the current parser. This is the first step towards re-using this functionality across other modules which require parsing functionality and remove code-duplication.
Diffstat (limited to 'src/patch_parse.h')
-rw-r--r--src/patch_parse.h13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/patch_parse.h b/src/patch_parse.h
index f27651e39..140629da8 100644
--- a/src/patch_parse.h
+++ b/src/patch_parse.h
@@ -9,24 +9,15 @@
#include "common.h"
+#include "parse.h"
#include "patch.h"
typedef struct {
git_refcount rc;
- /* Original content buffer */
- const char *content;
- size_t content_len;
-
git_patch_options opts;
- /* The remaining (unparsed) buffer */
- const char *remain;
- size_t remain_len;
-
- const char *line;
- size_t line_len;
- size_t line_num;
+ git_parse_ctx parse_ctx;
} git_patch_parse_ctx;
extern git_patch_parse_ctx *git_patch_parse_ctx_init(