{"thread":{"id":"3042","subject":"[PATCH 1/2] Use light stacking for non-option arguments.","startedAt":"2006-01-11T20:42:36Z","lastAt":"2006-01-11T20:42:36Z","messageCount":1,"participants":["Andreas Ericsson"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"14503","messageId":"20060111204236.187A95BEC0@nox.op5.se","threadId":"3042","inReplyTo":null,"subject":"[PATCH 1/2] Use light stacking for non-option arguments.","fromName":"Andreas Ericsson","fromEmail":"exon@op5.se","sentAt":"2006-01-11T20:42:36Z","receivedAt":"2006-01-11T20:42:36Z","isPatch":true,"sender":{"key":"exon@op5.se","avatar":"https://gravatar.com/avatar/b948c4f759e868f8e721e545e37afe2cf89cfa8e2ee8b70a432f0d76aee39891?d=mp&s=160"},"body":"This patch adds some simple library code that can help C-programs\nin the git suite ignore argument ordering without interfering\nwith the current argument parsing code too much.\n\nSigned-off-by: Andreas Ericsson <ae@op5.se>\n\n---\n\n Makefile |    4 ++--\n stack.c  |   42 ++++++++++++++++++++++++++++++++++++++++++\n stack.h  |    9 +++++++++\n 3 files changed, 53 insertions(+), 2 deletions(-)\n create mode 100644 stack.c\n create mode 100644 stack.h\n\n5ebd4cbfef1a2c369f763eb3a98f079ffb4f6b5d\ndiff --git a/Makefile b/Makefile\nindex c9c15b5..ba861fb 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -165,7 +165,7 @@ LIB_FILE=libgit.a\n LIB_H = \\\n \tblob.h cache.h commit.h count-delta.h csum-file.h delta.h \\\n \tdiff.h epoch.h object.h pack.h pkt-line.h quote.h refs.h \\\n-\trun-command.h strbuf.h tag.h tree.h git-compat-util.h\n+\trun-command.h stack.h strbuf.h tag.h tree.h git-compat-util.h\n \n DIFF_OBJS = \\\n \tdiff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \\\n@@ -176,7 +176,7 @@ LIB_OBJS = \\\n \tdate.o diff-delta.o entry.o ident.o index.o \\\n \tobject.o pack-check.o patch-delta.o path.o pkt-line.o \\\n \tquote.o read-cache.o refs.o run-command.o \\\n-\tserver-info.o setup.o sha1_file.o sha1_name.o strbuf.o \\\n+\tserver-info.o setup.o sha1_file.o sha1_name.o stack.o strbuf.o \\\n \ttag.o tree.o usage.o config.o environment.o ctype.o copy.o \\\n \tfetch-clone.o \\\n \t$(DIFF_OBJS)\ndiff --git a/stack.c b/stack.c\nnew file mode 100644\nindex 0000000..e76a197\n--- /dev/null\n+++ b/stack.c\n@@ -0,0 +1,42 @@\n+#include <stdlib.h>\n+#include <string.h>\n+#include \"stack.h\"\n+#include \"git-compat-util.h\"\n+\n+struct stack *stack_push(struct stack *s, const void *ptr)\n+{\n+\tif (!s)\n+\t\ts = xcalloc(1, sizeof(struct stack));\n+\n+\tif (s) {\n+\t\ts->stack = xrealloc(s->stack, sizeof(void *) * s->ents + 1);\n+\t\ts->stack[s->ents++] = (void *)ptr;\n+\t}\n+\n+\treturn s;\n+}\n+\n+/* pull is from top, pop from bottom */\n+void *stack_pull(struct stack *s)\n+{\n+\tif (s && s->next < s->ents)\n+\t\treturn s->stack[s->next++];\n+\n+\treturn NULL;\n+}\n+\n+void *stack_pop(struct stack *s)\n+{\n+\tif (s && s->ents)\n+\t\treturn s->stack[--s->ents];\n+\n+\treturn NULL;\n+}\n+\n+void stack_destroy(struct stack *s)\n+{\n+\tif (s && s->stack) {\n+\t\tfree(s->stack);\n+\t\tmemset(s, 0, sizeof(struct stack));\n+\t}\n+}\ndiff --git a/stack.h b/stack.h\nnew file mode 100644\nindex 0000000..5682559\n--- /dev/null\n+++ b/stack.h\n@@ -0,0 +1,9 @@\n+struct stack {\n+\tvoid **stack;\n+\tunsigned ents, next;\n+};\n+\n+struct stack *stack_push(struct stack *s, const void *ptr);\n+void *stack_pull(struct stack *s);\n+void *stack_pop(struct stack *s);\n+void stack_destroy(struct stack *s);\n-- \n1.1.0\n"}]}