diff options
author | Ben Straub <bstraub@github.com> | 2012-07-16 16:16:11 -0700 |
---|---|---|
committer | Ben Straub <bstraub@github.com> | 2012-07-16 16:22:41 -0700 |
commit | 1d68fcd04b21a2c5665d0ca6a5543e7166c73457 (patch) | |
tree | 865a768e68ff076dcfa6d374af5234185b93dd5c /src | |
parent | 9587895f572ad4808fb1746dd6510f92ec30c3a6 (diff) | |
download | libgit2-1d68fcd04b21a2c5665d0ca6a5543e7166c73457.tar.gz |
Checkout: handle symlinks.
Includes unfinished win32 implementation.
Diffstat (limited to 'src')
-rw-r--r-- | src/checkout.c | 72 | ||||
-rw-r--r-- | src/unix/posix.h | 1 | ||||
-rw-r--r-- | src/win32/posix.h | 1 | ||||
-rw-r--r-- | src/win32/posix_w32.c | 6 |
4 files changed, 57 insertions, 23 deletions
diff --git a/src/checkout.c b/src/checkout.c index dc4e559e..8ba3cf53 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -32,7 +32,30 @@ typedef struct tree_walk_data } tree_walk_data; -static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf, const git_oid *id, int mode) +static int blob_contents_to_link(git_repository *repo, git_buf *fnbuf, + const git_oid *id) +{ + int retcode = GIT_ERROR; + git_blob *blob; + + /* Get the link target */ + if (!(retcode = git_blob_lookup(&blob, repo, id))) { + git_buf linktarget = GIT_BUF_INIT; + if (!(retcode = git_blob__getbuf(&linktarget, blob))) { + /* Create the link */ + retcode = p_symlink(git_buf_cstr(&linktarget), + git_buf_cstr(fnbuf)); + } + git_buf_free(&linktarget); + git_blob_free(blob); + } + + return retcode; +} + + +static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf, + const git_oid *id, int mode) { int retcode = GIT_ERROR; @@ -62,30 +85,33 @@ static int checkout_walker(const char *path, git_tree_entry *entry, void *payloa /* TODO: handle submodules */ - if (S_ISLNK(attr)) { - printf("It's a link!\n'"); - } else { - switch(git_tree_entry_type(entry)) { - case GIT_OBJ_TREE: - /* Nothing to do; the blob handling creates necessary directories. */ - break; - - case GIT_OBJ_BLOB: - { - git_buf fnbuf = GIT_BUF_INIT; - git_buf_join_n(&fnbuf, '/', 3, - git_repository_workdir(data->repo), - path, - git_tree_entry_name(entry)); - retcode = blob_contents_to_file(data->repo, &fnbuf, git_tree_entry_id(entry), attr); - git_buf_free(&fnbuf); + switch(git_tree_entry_type(entry)) + { + case GIT_OBJ_TREE: + /* Nothing to do; the blob handling creates necessary directories. */ + break; + + case GIT_OBJ_BLOB: + { + git_buf fnbuf = GIT_BUF_INIT; + git_buf_join_n(&fnbuf, '/', 3, + git_repository_workdir(data->repo), + path, + git_tree_entry_name(entry)); + if (S_ISLNK(attr)) { + retcode = blob_contents_to_link(data->repo, &fnbuf, + git_tree_entry_id(entry)); + } else { + retcode = blob_contents_to_file(data->repo, &fnbuf, + git_tree_entry_id(entry), attr); } - break; - - default: - retcode = -1; - break; + git_buf_free(&fnbuf); } + break; + + default: + retcode = -1; + break; } data->stats->processed++; diff --git a/src/unix/posix.h b/src/unix/posix.h index 48b49294..304dd141 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -19,6 +19,7 @@ #define p_lstat(p,b) lstat(p,b) #define p_readlink(a, b, c) readlink(a, b, c) #define p_link(o,n) link(o, n) +#define p_symlink(o,n) symlink(o,n) #define p_unlink(p) unlink(p) #define p_mkdir(p,m) mkdir(p, m) #define p_fsync(fd) fsync(fd) diff --git a/src/win32/posix.h b/src/win32/posix.h index baa4a3b4..14caae41 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -33,6 +33,7 @@ GIT_INLINE(int) p_mkdir(const char *path, mode_t mode) extern int p_unlink(const char *path); extern int p_lstat(const char *file_name, struct stat *buf); extern int p_readlink(const char *link, char *target, size_t target_len); +extern int p_symlink(const char *old, const char *new); extern int p_hide_directory__w32(const char *path); extern char *p_realpath(const char *orig_path, char *buffer); extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr); diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 37956af8..62fbd114 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -217,6 +217,12 @@ int p_readlink(const char *link, char *target, size_t target_len) return dwRet; } +int p_symlink(const char *old, const char *new) +{ + /* TODO */ + return -1; +} + int p_open(const char *path, int flags, ...) { int fd; |