MCPcopy Index your code
hub / github.com/git/git / parse_traditional_patch

Function parse_traditional_patch

apply.c:856–908  ·  view source on GitHub ↗

* Get the name etc info from the ---/+++ lines of a traditional patch header * * FIXME! The end-of-filename heuristics are kind of screwy. For existing * files, we can happily check the index for a match, but for creating a * new file we should try to match whatever "patch" does. I have no idea. */

Source from the content-addressed store, hash-verified

854 * new file we should try to match whatever "patch" does. I have no idea.
855 */
856static int parse_traditional_patch(struct apply_state *state,
857 const char *first,
858 const char *second,
859 struct patch *patch)
860{
861 char *name;
862
863 first += 4; /* skip "--- " */
864 second += 4; /* skip "+++ " */
865 if (!state->p_value_known) {
866 int p, q;
867 p = guess_p_value(state, first);
868 q = guess_p_value(state, second);
869 if (p < 0) p = q;
870 if (0 <= p && p == q) {
871 state->p_value = p;
872 state->p_value_known = 1;
873 }
874 }
875 if (is_dev_null(first)) {
876 patch->is_new = 1;
877 patch->is_delete = 0;
878 name = find_name_traditional(&state->root, second, NULL, state->p_value);
879 patch->new_name = name;
880 } else if (is_dev_null(second)) {
881 patch->is_new = 0;
882 patch->is_delete = 1;
883 name = find_name_traditional(&state->root, first, NULL, state->p_value);
884 patch->old_name = name;
885 } else {
886 char *first_name;
887 first_name = find_name_traditional(&state->root, first, NULL, state->p_value);
888 name = find_name_traditional(&state->root, second, first_name, state->p_value);
889 free(first_name);
890 if (has_epoch_timestamp(first)) {
891 patch->is_new = 1;
892 patch->is_delete = 0;
893 patch->new_name = name;
894 } else if (has_epoch_timestamp(second)) {
895 patch->is_new = 0;
896 patch->is_delete = 1;
897 patch->old_name = name;
898 } else {
899 patch->old_name = name;
900 patch->new_name = xstrdup_or_null(name);
901 }
902 }
903 if (!name)
904 return error(_("unable to find filename in patch at %s:%d"),
905 state->patch_input_file, state->linenr);
906
907 return 0;
908}
909
910static int gitdiff_hdrend(struct gitdiff_data *state UNUSED,
911 const char *line UNUSED,

Callers 1

find_headerFunction · 0.85

Calls 6

guess_p_valueFunction · 0.85
is_dev_nullFunction · 0.85
find_name_traditionalFunction · 0.85
has_epoch_timestampFunction · 0.85
xstrdup_or_nullFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected