git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Use light stacking for non-option arguments.

From
Andreas Ericsson <exon@op5.se>
Date
Jan 11, 2006, 20:42 UTC
Message-ID
<20060111204236.187A95BEC0@nox.op5.se>

This patch adds some simple library code that can help C-programs in the git suite ignore argument ordering without interfering with the current argument parsing code too much.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 Makefile |    4 ++--
 stack.c  |   42 ++++++++++++++++++++++++++++++++++++++++++
 stack.h  |    9 +++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 stack.c
 create mode 100644 stack.h
5ebd4cbfef1a2c369f763eb3a98f079ffb4f6b5d
diff --git a/Makefile b/Makefile
index c9c15b5..ba861fb 100644
--- a/Makefile
+++ b/Makefile
@@ -165,7 +165,7 @@ LIB_FILE=libgit.a
 LIB_H = \
 	blob.h cache.h commit.h count-delta.h csum-file.h delta.h \
 	diff.h epoch.h object.h pack.h pkt-line.h quote.h refs.h \
-	run-command.h strbuf.h tag.h tree.h git-compat-util.h
+	run-command.h stack.h strbuf.h tag.h tree.h git-compat-util.h
 
 DIFF_OBJS = \
 	diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
@@ -176,7 +176,7 @@ LIB_OBJS = \
 	date.o diff-delta.o entry.o ident.o index.o \
 	object.o pack-check.o patch-delta.o path.o pkt-line.o \
 	quote.o read-cache.o refs.o run-command.o \
-	server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
+	server-info.o setup.o sha1_file.o sha1_name.o stack.o strbuf.o \
 	tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
 	fetch-clone.o \
 	$(DIFF_OBJS)
diff --git a/stack.c b/stack.c
new file mode 100644
index 0000000..e76a197
--- /dev/null
+++ b/stack.c
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#include <string.h>
+#include "stack.h"
+#include "git-compat-util.h"
+
+struct stack *stack_push(struct stack *s, const void *ptr)
+{
+	if (!s)
+		s = xcalloc(1, sizeof(struct stack));
+
+	if (s) {
+		s->stack = xrealloc(s->stack, sizeof(void *) * s->ents + 1);
+		s->stack[s->ents++] = (void *)ptr;
+	}
+
+	return s;
+}
+
+/* pull is from top, pop from bottom */
+void *stack_pull(struct stack *s)
+{
+	if (s && s->next < s->ents)
+		return s->stack[s->next++];
+
+	return NULL;
+}
+
+void *stack_pop(struct stack *s)
+{
+	if (s && s->ents)
+		return s->stack[--s->ents];
+
+	return NULL;
+}
+
+void stack_destroy(struct stack *s)
+{
+	if (s && s->stack) {
+		free(s->stack);
+		memset(s, 0, sizeof(struct stack));
+	}
+}
diff --git a/stack.h b/stack.h
new file mode 100644
index 0000000..5682559
--- /dev/null
+++ b/stack.h
@@ -0,0 +1,9 @@
+struct stack {
+	void **stack;
+	unsigned ents, next;
+};
+
+struct stack *stack_push(struct stack *s, const void *ptr);
+void *stack_pull(struct stack *s);
+void *stack_pop(struct stack *s);
+void stack_destroy(struct stack *s);
-- 
1.1.0
Message 1 of 1 in “Use light stacking for non-option arguments.”
  1. 1/2 Use light stacking for non-option arguments.Andreas Ericsson, Jan 11, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.