summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-01-13 13:02:58 -0600
committerEdward Thomson <ethomson@microsoft.com>2015-01-20 17:12:58 -0600
commitb4cbd67f5fdefb4595ce96c2e2bd1ab6e0b4f41d (patch)
tree4ee0a4dd8be9f13882416eadc5e25d771b11d8e5
parentfe598f0903012e361eca53c4cb65c27e4e8dfac9 (diff)
downloadlibgit2-b4cbd67f5fdefb4595ce96c2e2bd1ab6e0b4f41d.tar.gz
checkout: don't recreate previous directory
Don't bother trying to recreate the previously created directory during checkout, for a modest reduction in the number of stats.
-rw-r--r--src/checkout.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/checkout.c b/src/checkout.c
index aad17f8b1..1d29865a1 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -68,6 +68,7 @@ typedef struct {
size_t total_steps;
size_t completed_steps;
git_checkout_perfdata perfdata;
+ git_buf last_mkdir;
} checkout_data;
typedef struct {
@@ -1312,9 +1313,24 @@ static int checkout_mkdir(
static int mkpath2file(
checkout_data *data, const char *path, unsigned int mode)
{
- return checkout_mkdir(
- data, path, git_repository_workdir(data->repo), mode,
- GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
+ git_buf *mkdir_path = &data->tmp;
+ int error;
+
+ if ((error = git_buf_sets(mkdir_path, path)) < 0)
+ return error;
+
+ git_buf_rtruncate_at_char(mkdir_path, '/');
+
+ if (data->last_mkdir.size && mkdir_path->size == data->last_mkdir.size &&
+ memcmp(mkdir_path->ptr, data->last_mkdir.ptr, mkdir_path->size) == 0)
+ return 0;
+
+ if ((error = checkout_mkdir(
+ data, mkdir_path->ptr, data->opts.target_directory, mode,
+ GIT_MKDIR_PATH | GIT_MKDIR_VERIFY_DIR)) == 0)
+ git_buf_swap(&data->last_mkdir, mkdir_path);
+
+ return error;
}
static int buffer_to_file(