]> git.proxmox.com Git - libgit2.git/blobdiff - src/diff_generate.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / diff_generate.c
index aba9e52ba7fa94470fa38073a69eabc0bd91644f..cfaefba66c21c42a24d00584dcd771aab8a80ccb 100644 (file)
@@ -117,6 +117,26 @@ static bool diff_pathspec_match(
                matched_pathspec, NULL);
 }
 
+static void diff_delta__flag_known_size(git_diff_file *file)
+{
+       /*
+        * If we don't know the ID, that can only come from the workdir
+        * iterator, which means we *do* know the file size.  This is a
+        * leaky abstraction, but alas.  Otherwise, we test against the
+        * empty blob id.
+        */
+       if (file->size ||
+           !(file->flags & GIT_DIFF_FLAG_VALID_ID) ||
+           git_oid_equal(&file->id, &git_oid__empty_blob_sha1))
+               file->flags |= GIT_DIFF_FLAG_VALID_SIZE;
+}
+
+static void diff_delta__flag_known_sizes(git_diff_delta *delta)
+{
+       diff_delta__flag_known_size(&delta->old_file);
+       diff_delta__flag_known_size(&delta->new_file);
+}
+
 static int diff_delta__from_one(
        git_diff_generated *diff,
        git_delta_t status,
@@ -182,6 +202,8 @@ static int diff_delta__from_one(
        if (has_old || !git_oid_is_zero(&delta->new_file.id))
                delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
 
+       diff_delta__flag_known_sizes(delta);
+
        return diff_insert_delta(diff, delta, matched_pathspec);
 }
 
@@ -244,6 +266,8 @@ static int diff_delta__from_two(
                        delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
        }
 
+       diff_delta__flag_known_sizes(delta);
+
        return diff_insert_delta(diff, delta, matched_pathspec);
 }
 
@@ -586,7 +610,7 @@ int git_diff__oid_for_entry(
        const git_oid *update_match)
 {
        git_diff_generated *diff;
-       git_buf full_path = GIT_BUF_INIT;
+       git_str full_path = GIT_STR_INIT;
        git_index_entry entry = *src;
        git_filter_list *fl = NULL;
        int error = 0;
@@ -605,8 +629,8 @@ int git_diff__oid_for_entry(
                diff->base.perf.stat_calls++;
 
                if (p_stat(full_path.ptr, &st) < 0) {
-                       error = git_path_set_error(errno, entry.path, "stat");
-                       git_buf_dispose(&full_path);
+                       error = git_fs_path_set_error(errno, entry.path, "stat");
+                       git_str_dispose(&full_path);
                        return error;
                }
 
@@ -669,7 +693,7 @@ int git_diff__oid_for_entry(
                }
        }
 
-       git_buf_dispose(&full_path);
+       git_str_dispose(&full_path);
        return error;
 }
 
@@ -1023,10 +1047,10 @@ static int handle_unmatched_new_item(
 
                /* do not advance into directories that contain a .git file */
                if (recurse_into_dir && !contains_oitem) {
-                       git_buf *full = NULL;
+                       git_str *full = NULL;
                        if (git_iterator_current_workdir_path(&full, info->new_iter) < 0)
                                return -1;
-                       if (full && git_path_contains(full, DOT_GIT)) {
+                       if (full && git_fs_path_contains(full, DOT_GIT)) {
                                /* TODO: warning if not a valid git repository */
                                recurse_into_dir = false;
                        }