Re: [PATCH 01/15] Move split_cmdline() to alias.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Miklos Vajna a écrit :
> split_cmdline() is currently used for aliases only, but later it can be
> useful for other builtins as well. Move it to alias.c for now,
> indicating that originally it's for aliases, but we'll have it in libgit
> this way.

This function does not trim cmdline. 

Perhaps, the following patch can be inserted after 1/15.

-- >8 --
From: Olivier Marin <dkr@xxxxxxxxxxx>
Date: Sat, 28 Jun 2008 13:06:21 +0200
Subject: [PATCH] split_cmdline(): ignore whitespace at start/end of cmdline

Signed-off-by: Olivier Marin <dkr@xxxxxxxxxxx>
---
 alias.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/alias.c b/alias.c
index ccb1108..7b69d18 100644
--- a/alias.c
+++ b/alias.c
@@ -24,14 +24,16 @@ char *alias_lookup(const char *alias)
 
 int split_cmdline(char *cmdline, const char ***argv)
 {
-       int src, dst, count = 0, size = 16;
+       int src = 0, dst, count = 0, size = 16;
        char quoted = 0;
 
        *argv = xmalloc(sizeof(char*) * size);
 
        /* split alias_string */
-       (*argv)[count++] = cmdline;
-       for (src = dst = 0; cmdline[src];) {
+       while (cmdline[src] && isspace(cmdline[src]))
+               src++;
+       (*argv)[count++] = cmdline + src;
+       for (dst = src; cmdline[src];) {
                char c = cmdline[src];
                if (!quoted && isspace(c)) {
                        cmdline[dst++] = 0;
@@ -42,7 +44,8 @@ int split_cmdline(char *cmdline, const char ***argv)
                                size += 16;
                                *argv = xrealloc(*argv, sizeof(char*) * size);
                        }
-                       (*argv)[count++] = cmdline + dst;
+                       if (cmdline[src])
+                               (*argv)[count++] = cmdline + dst;
                } else if (!quoted && (c == '\'' || c == '"')) {
                        quoted = c;
                        src++;
-- 
1.5.6.1.103.g191a2.dirty


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux