diff options
| author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-22 21:56:24 +1000 |
|---|---|---|
| committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 04:44:32 +1000 |
| commit | d680f769d003a19f51158a689e6039d650a3efe0 (patch) | |
| tree | d1bdc7af37ec3f2118bf87cb66c8b5f4b726adf2 /libbb | |
| parent | ef9b20fa7904ee5f72e3a759934560226360842d (diff) | |
| download | busybox-w32-d680f769d003a19f51158a689e6039d650a3efe0.tar.gz busybox-w32-d680f769d003a19f51158a689e6039d650a3efe0.tar.bz2 busybox-w32-d680f769d003a19f51158a689e6039d650a3efe0.zip | |
update imported git files to adapt to new environment
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/git.c | 62 | ||||
| -rw-r--r-- | libbb/git.h | 21 | ||||
| -rw-r--r-- | libbb/mingw.c | 7 | ||||
| -rw-r--r-- | libbb/quote.c | 4 | ||||
| -rw-r--r-- | libbb/run-command.c | 51 | ||||
| -rw-r--r-- | libbb/setenv.c | 4 | ||||
| -rw-r--r-- | libbb/strbuf.c | 21 | ||||
| -rw-r--r-- | libbb/strlcpy.c | 4 | ||||
| -rw-r--r-- | libbb/trace.c | 5 | ||||
| -rw-r--r-- | libbb/usage.c | 3 | ||||
| -rw-r--r-- | libbb/winansi.c | 2 | ||||
| -rw-r--r-- | libbb/write_or_die.c | 3 |
12 files changed, 108 insertions, 79 deletions
diff --git a/libbb/git.c b/libbb/git.c new file mode 100644 index 000000000..3ca8a9424 --- /dev/null +++ b/libbb/git.c | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | #include "libbb.h" | ||
| 2 | #include "git.h" | ||
| 3 | |||
| 4 | ssize_t write_in_full(int fd, const void *buf, size_t count) | ||
| 5 | { | ||
| 6 | const char *p = buf; | ||
| 7 | ssize_t total = 0; | ||
| 8 | |||
| 9 | while (count > 0) { | ||
| 10 | ssize_t written = xwrite(fd, p, count); | ||
| 11 | if (written < 0) | ||
| 12 | return -1; | ||
| 13 | if (!written) { | ||
| 14 | errno = ENOSPC; | ||
| 15 | return -1; | ||
| 16 | } | ||
| 17 | count -= written; | ||
| 18 | p += written; | ||
| 19 | total += written; | ||
| 20 | } | ||
| 21 | |||
| 22 | return total; | ||
| 23 | } | ||
| 24 | |||
| 25 | |||
| 26 | void *xcalloc(size_t nmemb, size_t size) | ||
| 27 | { | ||
| 28 | void *ret = calloc(nmemb, size); | ||
| 29 | if (!ret && (!nmemb || !size)) | ||
| 30 | ret = calloc(1, 1); | ||
| 31 | if (!ret) { | ||
| 32 | ret = calloc(nmemb, size); | ||
| 33 | if (!ret && (!nmemb || !size)) | ||
| 34 | ret = calloc(1, 1); | ||
| 35 | if (!ret) | ||
| 36 | die("Out of memory, calloc failed"); | ||
| 37 | } | ||
| 38 | return ret; | ||
| 39 | } | ||
| 40 | |||
| 41 | /* | ||
| 42 | * This is like mktime, but without normalization of tm_wday and tm_yday. | ||
| 43 | */ | ||
| 44 | time_t tm_to_time_t(const struct tm *tm) | ||
| 45 | { | ||
| 46 | static const int mdays[] = { | ||
| 47 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 | ||
| 48 | }; | ||
| 49 | int year = tm->tm_year - 70; | ||
| 50 | int month = tm->tm_mon; | ||
| 51 | int day = tm->tm_mday; | ||
| 52 | |||
| 53 | if (year < 0 || year > 129) /* algo only works for 1970-2099 */ | ||
| 54 | return -1; | ||
| 55 | if (month < 0 || month > 11) /* array bounds */ | ||
| 56 | return -1; | ||
| 57 | if (month < 2 || (year + 2) % 4) | ||
| 58 | day--; | ||
| 59 | return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + | ||
| 60 | tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; | ||
| 61 | } | ||
| 62 | |||
diff --git a/libbb/git.h b/libbb/git.h new file mode 100644 index 000000000..3274af34d --- /dev/null +++ b/libbb/git.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | ssize_t write_in_full(int fd, const void *buf, size_t count); | ||
| 2 | |||
| 3 | #define alloc_nr(x) (((x)+16)*3/2) | ||
| 4 | |||
| 5 | #define ALLOC_GROW(x, nr, alloc) \ | ||
| 6 | do { \ | ||
| 7 | if ((nr) > alloc) { \ | ||
| 8 | if (alloc_nr(alloc) < (nr)) \ | ||
| 9 | alloc = (nr); \ | ||
| 10 | else \ | ||
| 11 | alloc = alloc_nr(alloc); \ | ||
| 12 | x = xrealloc((x), alloc * sizeof(*(x))); \ | ||
| 13 | } \ | ||
| 14 | } while(0) | ||
| 15 | |||
| 16 | static inline int is_absolute_path(const char *path) | ||
| 17 | { | ||
| 18 | return path[0] == '/' || has_dos_drive_prefix(path); | ||
| 19 | } | ||
| 20 | |||
| 21 | #define NORETURN ATTRIBUTE_NORETURN | ||
diff --git a/libbb/mingw.c b/libbb/mingw.c index 1a9f35f4d..f90fbc1d2 100644 --- a/libbb/mingw.c +++ b/libbb/mingw.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #include "../git-compat-util.h" | 1 | #include "libbb.h" |
| 2 | #include "win32.h" | 2 | #include "win32.h" |
| 3 | #include "../strbuf.h" | 3 | #include "strbuf.h" |
| 4 | #include "run-command.h" | 4 | #include "run-command.h" |
| 5 | 5 | ||
| 6 | unsigned int _CRT_fmode = _O_BINARY; | 6 | unsigned int _CRT_fmode = _O_BINARY; |
| @@ -1277,7 +1277,6 @@ char *strptime(const char *s, const char *format, struct tm *tm) | |||
| 1277 | { | 1277 | { |
| 1278 | return NULL; | 1278 | return NULL; |
| 1279 | } | 1279 | } |
| 1280 | void gitunsetenv(const char *env) | 1280 | void unsetenv(const char *env) |
| 1281 | { | 1281 | { |
| 1282 | } | 1282 | } |
| 1283 | |||
diff --git a/libbb/quote.c b/libbb/quote.c index 7a49fcf69..129dea72f 100644 --- a/libbb/quote.c +++ b/libbb/quote.c | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | #include "cache.h" | 1 | #include "libbb.h" |
| 2 | #include "strbuf.h" | ||
| 2 | #include "quote.h" | 3 | #include "quote.h" |
| 4 | #include "git.h" | ||
| 3 | 5 | ||
| 4 | int quote_path_fully = 1; | 6 | int quote_path_fully = 1; |
| 5 | 7 | ||
diff --git a/libbb/run-command.c b/libbb/run-command.c index b05c734d0..d4d78e9bc 100644 --- a/libbb/run-command.c +++ b/libbb/run-command.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #include "cache.h" | 1 | #include "libbb.h" |
| 2 | #include "run-command.h" | 2 | #include "run-command.h" |
| 3 | #include "exec_cmd.h" | 3 | #include "git.h" |
| 4 | 4 | ||
| 5 | static inline void close_pair(int fd[2]) | 5 | static inline void close_pair(int fd[2]) |
| 6 | { | 6 | { |
| @@ -168,9 +168,11 @@ int start_command(struct child_process *cmd) | |||
| 168 | env = env_setenv(env, *cmd->env); | 168 | env = env_setenv(env, *cmd->env); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | #if 0 | ||
| 171 | if (cmd->git_cmd) { | 172 | if (cmd->git_cmd) { |
| 172 | cmd->argv = prepare_git_cmd(cmd->argv); | 173 | cmd->argv = prepare_git_cmd(cmd->argv); |
| 173 | } | 174 | } |
| 175 | #endif | ||
| 174 | 176 | ||
| 175 | cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env); | 177 | cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env); |
| 176 | 178 | ||
| @@ -352,48 +354,3 @@ int finish_async(struct async *async) | |||
| 352 | #endif | 354 | #endif |
| 353 | return ret; | 355 | return ret; |
| 354 | } | 356 | } |
| 355 | |||
| 356 | int run_hook(const char *index_file, const char *name, ...) | ||
| 357 | { | ||
| 358 | struct child_process hook; | ||
| 359 | const char **argv = NULL, *env[2]; | ||
| 360 | char index[PATH_MAX]; | ||
| 361 | va_list args; | ||
| 362 | int ret; | ||
| 363 | size_t i = 0, alloc = 0; | ||
| 364 | |||
| 365 | if (access(git_path("hooks/%s", name), X_OK) < 0) | ||
| 366 | return 0; | ||
| 367 | |||
| 368 | va_start(args, name); | ||
| 369 | ALLOC_GROW(argv, i + 1, alloc); | ||
| 370 | argv[i++] = git_path("hooks/%s", name); | ||
| 371 | while (argv[i-1]) { | ||
| 372 | ALLOC_GROW(argv, i + 1, alloc); | ||
| 373 | argv[i++] = va_arg(args, const char *); | ||
| 374 | } | ||
| 375 | va_end(args); | ||
| 376 | |||
| 377 | memset(&hook, 0, sizeof(hook)); | ||
| 378 | hook.argv = argv; | ||
| 379 | hook.no_stdin = 1; | ||
| 380 | hook.stdout_to_stderr = 1; | ||
| 381 | if (index_file) { | ||
| 382 | snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); | ||
| 383 | env[0] = index; | ||
| 384 | env[1] = NULL; | ||
| 385 | hook.env = env; | ||
| 386 | } | ||
| 387 | |||
| 388 | ret = start_command(&hook); | ||
| 389 | free(argv); | ||
| 390 | if (ret) { | ||
| 391 | warning("Could not spawn %s", argv[0]); | ||
| 392 | return ret; | ||
| 393 | } | ||
| 394 | ret = finish_command(&hook); | ||
| 395 | if (ret == -ERR_RUN_COMMAND_WAITPID_SIGNAL) | ||
| 396 | warning("%s exited due to uncaught signal", argv[0]); | ||
| 397 | |||
| 398 | return ret; | ||
| 399 | } | ||
diff --git a/libbb/setenv.c b/libbb/setenv.c index 3a22ea7b7..401d0cec5 100644 --- a/libbb/setenv.c +++ b/libbb/setenv.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #include "../git-compat-util.h" | 1 | #include "libbb.h" |
| 2 | 2 | ||
| 3 | int gitsetenv(const char *name, const char *value, int replace) | 3 | int setenv(const char *name, const char *value, int replace) |
| 4 | { | 4 | { |
| 5 | int out; | 5 | int out; |
| 6 | size_t namelen, valuelen; | 6 | size_t namelen, valuelen; |
diff --git a/libbb/strbuf.c b/libbb/strbuf.c index a88496030..d98b0fd41 100644 --- a/libbb/strbuf.c +++ b/libbb/strbuf.c | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #include "cache.h" | 1 | #include "libbb.h" |
| 2 | #include "refs.h" | 2 | #include "strbuf.h" |
| 3 | #include "git.h" | ||
| 3 | 4 | ||
| 4 | int prefixcmp(const char *str, const char *prefix) | 5 | int prefixcmp(const char *str, const char *prefix) |
| 5 | { | 6 | { |
| @@ -358,19 +359,3 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint) | |||
| 358 | 359 | ||
| 359 | return len; | 360 | return len; |
| 360 | } | 361 | } |
| 361 | |||
| 362 | int strbuf_branchname(struct strbuf *sb, const char *name) | ||
| 363 | { | ||
| 364 | int len = strlen(name); | ||
| 365 | if (interpret_branch_name(name, sb) == len) | ||
| 366 | return 0; | ||
| 367 | strbuf_add(sb, name, len); | ||
| 368 | return len; | ||
| 369 | } | ||
| 370 | |||
| 371 | int strbuf_check_branch_ref(struct strbuf *sb, const char *name) | ||
| 372 | { | ||
| 373 | strbuf_branchname(sb, name); | ||
| 374 | strbuf_splice(sb, 0, 0, "refs/heads/", 11); | ||
| 375 | return check_ref_format(sb->buf); | ||
| 376 | } | ||
diff --git a/libbb/strlcpy.c b/libbb/strlcpy.c index 4024c3603..30c9be4c1 100644 --- a/libbb/strlcpy.c +++ b/libbb/strlcpy.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #include "../git-compat-util.h" | 1 | #include "libbb.h" |
| 2 | 2 | ||
| 3 | size_t gitstrlcpy(char *dest, const char *src, size_t size) | 3 | size_t strlcpy(char *dest, const char *src, size_t size) |
| 4 | { | 4 | { |
| 5 | size_t ret = strlen(src); | 5 | size_t ret = strlen(src); |
| 6 | 6 | ||
diff --git a/libbb/trace.c b/libbb/trace.c index 4229ae123..dde0f6051 100644 --- a/libbb/trace.c +++ b/libbb/trace.c | |||
| @@ -22,8 +22,9 @@ | |||
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include "cache.h" | 25 | #include "libbb.h" |
| 26 | #include "quote.h" | 26 | #include "strbuf.h" |
| 27 | #include "git.h" | ||
| 27 | 28 | ||
| 28 | /* Get a trace file descriptor from GIT_TRACE env variable. */ | 29 | /* Get a trace file descriptor from GIT_TRACE env variable. */ |
| 29 | static int get_trace_fd(int *need_close) | 30 | static int get_trace_fd(int *need_close) |
diff --git a/libbb/usage.c b/libbb/usage.c index 820d09f92..86bf68e21 100644 --- a/libbb/usage.c +++ b/libbb/usage.c | |||
| @@ -3,7 +3,8 @@ | |||
| 3 | * | 3 | * |
| 4 | * Copyright (C) Linus Torvalds, 2005 | 4 | * Copyright (C) Linus Torvalds, 2005 |
| 5 | */ | 5 | */ |
| 6 | #include "git-compat-util.h" | 6 | #include "libbb.h" |
| 7 | #include "git.h" | ||
| 7 | 8 | ||
| 8 | static void report(const char *prefix, const char *err, va_list params) | 9 | static void report(const char *prefix, const char *err, va_list params) |
| 9 | { | 10 | { |
diff --git a/libbb/winansi.c b/libbb/winansi.c index 44dc293ad..f3a304436 100644 --- a/libbb/winansi.c +++ b/libbb/winansi.c | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | #include <windows.h> | 5 | #include <windows.h> |
| 6 | #include "../git-compat-util.h" | 6 | #include "libbb.h" |
| 7 | 7 | ||
| 8 | /* | 8 | /* |
| 9 | Functions to be wrapped: | 9 | Functions to be wrapped: |
diff --git a/libbb/write_or_die.c b/libbb/write_or_die.c index 4c29255df..f97ab8ba6 100644 --- a/libbb/write_or_die.c +++ b/libbb/write_or_die.c | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include "cache.h" | 1 | #include "libbb.h" |
| 2 | #include "git.h" | ||
| 2 | 3 | ||
| 3 | /* | 4 | /* |
| 4 | * Some cases use stdio, but want to flush after the write | 5 | * Some cases use stdio, but want to flush after the write |
