]> git.proxmox.com Git - libgit2.git/blobdiff - src/diff_stats.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / src / diff_stats.c
index a0681712fc375ffb63d4246ebc2961d9600cfc73..f5fda7925318fbcb7fcb01ef173df9455f0796a9 100644 (file)
@@ -46,23 +46,23 @@ static int digits_for_value(size_t val)
        return count;
 }
 
-int git_diff_file_stats__full_to_buf(
+static int diff_file_stats_full_to_buf(
        git_buf *out,
        const git_diff_delta *delta,
        const diff_file_stats *filestat,
        const git_diff_stats *stats,
        size_t width)
 {
-       const char *old_path = NULL, *new_path = NULL;
+       const char *old_path = NULL, *new_path = NULL, *adddel_path = NULL;
        size_t padding;
-       git_off_t old_size, new_size;
+       git_object_size_t old_size, new_size;
 
        old_path = delta->old_file.path;
        new_path = delta->new_file.path;
        old_size = delta->old_file.size;
        new_size = delta->new_file.size;
 
-       if (strcmp(old_path, new_path) != 0) {
+       if (old_path && new_path && strcmp(old_path, new_path) != 0) {
                size_t common_dirlen;
                int error;
 
@@ -82,10 +82,11 @@ int git_diff_file_stats__full_to_buf(
                if (error < 0)
                        goto on_error;
        } else {
-               if (git_buf_printf(out, " %s", old_path) < 0)
+               adddel_path = new_path ? new_path : old_path;
+               if (git_buf_printf(out, " %s", adddel_path) < 0)
                        goto on_error;
 
-               padding = stats->max_name - strlen(old_path);
+               padding = stats->max_name - strlen(adddel_path);
 
                if (stats->renames > 0)
                        padding += strlen(DIFF_RENAME_FILE_SEPARATOR);
@@ -134,7 +135,7 @@ on_error:
        return (git_buf_oom(out) ? -1 : 0);
 }
 
-int git_diff_file_stats__number_to_buf(
+static int diff_file_stats_number_to_buf(
        git_buf *out,
        const git_diff_delta *delta,
        const diff_file_stats *filestats)
@@ -151,7 +152,7 @@ int git_diff_file_stats__number_to_buf(
        return error;
 }
 
-int git_diff_file_stats__summary_to_buf(
+static int diff_file_stats_summary_to_buf(
        git_buf *out,
        const git_diff_delta *delta)
 {
@@ -211,7 +212,7 @@ int git_diff_get_stats(
 
                /* TODO ugh */
                namelen = strlen(delta->new_file.path);
-               if (strcmp(delta->old_file.path, delta->new_file.path) != 0) {
+               if (delta->old_file.path && strcmp(delta->old_file.path, delta->new_file.path) != 0) {
                        namelen += strlen(delta->old_file.path);
                        stats->renames++;
                }
@@ -288,7 +289,7 @@ int git_diff_stats_to_buf(
                        if ((delta = git_diff_get_delta(stats->diff, i)) == NULL)
                                continue;
 
-                       error = git_diff_file_stats__number_to_buf(
+                       error = diff_file_stats_number_to_buf(
                                out, delta, &stats->filestats[i]);
                        if (error < 0)
                                return error;
@@ -309,7 +310,7 @@ int git_diff_stats_to_buf(
                        if ((delta = git_diff_get_delta(stats->diff, i)) == NULL)
                                continue;
 
-                       error = git_diff_file_stats__full_to_buf(
+                       error = diff_file_stats_full_to_buf(
                                out, delta, &stats->filestats[i], stats, width);
                        if (error < 0)
                                return error;
@@ -342,7 +343,7 @@ int git_diff_stats_to_buf(
                        if ((delta = git_diff_get_delta(stats->diff, i)) == NULL)
                                continue;
 
-                       error = git_diff_file_stats__summary_to_buf(out, delta);
+                       error = diff_file_stats_summary_to_buf(out, delta);
                        if (error < 0)
                                return error;
                }