Skip to contentSkip to conversation

Move option parsing code to parse-options.[ch].

PATCH In review Kristian Høgsberg 2 participants 4 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Move option parsing code to parse-options.[ch].

---
 Makefile         |    2 +-
 builtin-commit.c |  117 ++++++++----------------------------------------------
 parse-options.c  |   74 ++++++++++++++++++++++++++++++++++
 parse-options.h  |   29 +++++++++++++
 4 files changed, 121 insertions(+), 101 deletions(-)
 create mode 100644 parse-options.c
 create mode 100644 parse-options.h
Makefile +1 -1
index 69ebc7a..2612465 100644
@@ -310,7 +310,7 @@ LIB_OBJS = \
 	alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \
 	color.o wt-status.o archive-zip.o archive-tar.o shallow.o utf8.o \
 	convert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o \
-	transport.o bundle.o
+	transport.o bundle.o parse-options.o
 
 BUILTIN_OBJS = \
 	builtin-add.o \
builtin-commit.c +17 -100

145 lines not on this page · raw message

parse-options.c new file +74 -0

74 lines not on this page · raw message

parse-options.h new file +29 -0
new file mode 100644
index 0000000..39399c3
@@ -0,0 +1,29 @@
+#ifndef PARSE_OPTIONS_H
+#define PARSE_OPTIONS_H
+
+enum option_type {
+    OPTION_BOOLEAN,
+    OPTION_STRING,
+    OPTION_INTEGER,
+    OPTION_LAST,
+};
+
+struct option {
+    enum option_type type;
+    const char *long_name;
+    char short_name;
+    void *value;
+};
+
+/* Parse the given options against the list of known options.  The
+ * order of the option structs matters, in that ambiguous
+ * abbreviations (eg, --in could be short for --include or
+ * --interactive) are matched by the first option that share the
+ * prefix.
+ */
+
+extern int parse_options(const char ***argv,
+			 struct option *options, int count,
+			 const char *usage_string);
+
+#endif
Signature · 1 line
1.5.2.5
#1 lore raw

PATCH 1/1 Share add_files_to_cache() with builtin-add.c

This removes the extra copy in builtin-commit.c and uses the update() function from builtin-add.c.

---
 builtin-add.c    |    8 +++---
 builtin-commit.c |   65 +++++++++++------------------------------------------
 commit.h         |    2 +
 3 files changed, 20 insertions(+), 55 deletions(-)
builtin-add.c +4 -4
index 5e30380..966e145 100644
@@ -107,7 +107,7 @@ static void update_callback(struct diff_queue_struct *q,
 	}
 }
 
-static void update(int verbose, const char *prefix, const char **files)
+void add_files_to_cache(int verbose, const char *prefix, const char **files)
 {
 	struct rev_info rev;
 	init_revisions(&rev, prefix);
@@ -116,8 +116,6 @@ static void update(int verbose, const char *prefix, const char **files)
 	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
 	rev.diffopt.format_callback = update_callback;
 	rev.diffopt.format_callback_data = &verbose;
-	if (read_cache() < 0)
-		die("index file corrupt");
 	run_diff_files(&rev, 0);
 }
 
@@ -218,7 +216,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	}
 
 	if (take_worktree_changes) {
-		update(verbose, prefix, argv + i);
+		if (read_cache() < 0)
+			die("index file corrupt");
+		add_files_to_cache(verbose, prefix, argv + i);
 		goto finish;
 	}
 
builtin-commit.c +14 -51

91 lines not on this page · raw message

commit.h +2 -0
index cc8d890..89caa12 100644
@@ -130,6 +130,8 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 int in_merge_bases(struct commit *, struct commit **, int);
 
 extern int interactive_add(void);
+extern void add_files_to_cache(int verbose,
+			       const char *prefix, const char **files);
 extern int rerere(void);
 
 #endif /* COMMIT_H */
Signature · 1 line
1.5.2.5
#2 lore raw
In reply to Kristian Høgsberg
Quoted 9 lines · Kristian Høgsberg
---
 Makefile         |    2 +-
 builtin-commit.c |  117 ++++++++----------------------------------------------
 parse-options.c  |   74 ++++++++++++++++++++++++++++++++++
 parse-options.h  |   29 +++++++++++++
 4 files changed, 121 insertions(+), 101 deletions(-)
 create mode 100644 parse-options.c
 create mode 100644 parse-options.h

Hmmmmmmm. Is it too much to ask to pretend as if the previous "builtin-commit.c" that had these parts that did not belong to it in the first place never happened?

#3 lore raw
Quoted 12 lines · Junio C Hamano
Quoted 9 lines · Kristian Høgsberg
---
 Makefile         |    2 +-
 builtin-commit.c |  117 ++++++++----------------------------------------------
 parse-options.c  |   74 ++++++++++++++++++++++++++++++++++
 parse-options.h  |   29 +++++++++++++
 4 files changed, 121 insertions(+), 101 deletions(-)
 create mode 100644 parse-options.c
 create mode 100644 parse-options.h
Quoted 3 lines

Hmmmmmmm. Is it too much to ask to pretend as if the previous "builtin-commit.c" that had these parts that did not belong to it in the first place never happened?

No problem, I wasn't sure whether to update the patches or to just send follow-up patches now that it was in pu. I'll resend 7/7 as 3 new patches that exports add_files_to_cache(), adds option parsing, and finally builtin-commit.

Kristian