Make git-stripspace a builtin
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
Lukas Sandström committed
Jun 13, 2006 at 22:21 UTC
7499c996156ea99702fe13e203b97ae60d8868ad
4 files changed
+19
-9
Makefile
+3
-3
@@ -144,7 +144,7 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
144
145
# The ones that do not have to link with lcrypto, lz nor xdiff.
146
SIMPLE_PROGRAMS = \
147
- git-stripspace$X git-daemon$X
147
+ git-daemon$X
148
149
# ... and all the rest that could be moved out of bindir to gitexecdir
150
PROGRAMS = \
@@ -165,7 +165,7 @@ PROGRAMS = \
165
166
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
167
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
168
- git-grep$X git-add$X git-rm$X git-rev-list$X \
168
+ git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
169
git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
170
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
171
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
@@ -226,7 +226,7 @@ BUILTIN_OBJS = \
226
builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
227
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
228
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
229
- builtin-cat-file.o builtin-mailsplit.o
229
+ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o
230
231
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
232
LIBS = $(GITLIBS) -lz
builtin-stripspace.c
renamed
+11
-5
@@ -1,6 +1,7 @@
1
#include <stdio.h>
2
#include <string.h>
3
#include <ctype.h>
4
+#include "builtin.h"
5
6
/*
7
* Remove empty lines from the beginning and end.
@@ -28,21 +29,21 @@ static int cleanup(char *line)
29
return 1;
30
}
31
31
-int main(int argc, char **argv)
32
+void stripspace(FILE *in, FILE *out)
33
{
34
int empties = -1;
35
int incomplete = 0;
36
char line[1024];
37
37
- while (fgets(line, sizeof(line), stdin)) {
38
+ while (fgets(line, sizeof(line), in)) {
39
incomplete = cleanup(line);
40
41
/* Not just an empty line? */
42
if (line[0] != '\n') {
43
if (empties > 0)
43
- putchar('\n');
44
+ fputc('\n', out);
45
empties = 0;
45
- fputs(line, stdout);
46
+ fputs(line, out);
47
continue;
48
}
49
if (empties < 0)
@@ -50,6 +51,11 @@ int main(int argc, char **argv)
51
empties++;
52
}
53
if (incomplete)
53
- putchar('\n');
54
+ fputc('\n', out);
55
+}
56
+
57
+int cmd_stripspace(int argc, const char **argv, char **envp)
58
+{
59
+ stripspace(stdin, stdout);
60
return 0;
61
}
builtin.h
+3
@@ -56,4 +56,7 @@ extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr
56
57
extern int cmd_mailinfo(int argc, const char **argv, char **envp);
58
extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch);
59
+
60
+extern int cmd_stripspace(int argc, const char **argv, char **envp);
61
+extern void stripspace(FILE *in, FILE *out);
62
#endif
git.c
+2
-1
@@ -181,7 +181,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
181
{ "rev-parse", cmd_rev_parse },
182
{ "write-tree", cmd_write_tree },
183
{ "mailsplit", cmd_mailsplit },
184
- { "mailinfo", cmd_mailinfo }
184
+ { "mailinfo", cmd_mailinfo },
185
+ { "stripspace", cmd_stripspace }
186
};
187
int i;
188