mirror of
https://github.com/git/git.git
synced 2026-01-18 06:34:21 +00:00
Merge branch 'jc/apply'
This commit is contained in:
@@ -10,7 +10,8 @@ SYNOPSIS
|
||||
--------
|
||||
[verse]
|
||||
'git-apply' [--stat] [--numstat] [--summary] [--check] [--index] [--apply]
|
||||
[--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM]
|
||||
[--no-add] [--index-info] [--allow-binary-replacement]
|
||||
[--reverse] [-z] [-pNUM]
|
||||
[-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>]
|
||||
[<patch>...]
|
||||
|
||||
@@ -62,6 +63,9 @@ OPTIONS
|
||||
the original version of the blob is available locally,
|
||||
outputs information about them to the standard output.
|
||||
|
||||
--reverse::
|
||||
Apply the patch in reverse.
|
||||
|
||||
-z::
|
||||
When showing the index information, do not munge paths,
|
||||
but use NUL terminated machine readable format. Without
|
||||
|
||||
@@ -43,7 +43,7 @@ static int show_index_info;
|
||||
static int line_termination = '\n';
|
||||
static unsigned long p_context = -1;
|
||||
static const char apply_usage[] =
|
||||
"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
|
||||
"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
|
||||
|
||||
static enum whitespace_eol {
|
||||
nowarn_whitespace,
|
||||
@@ -1063,8 +1063,12 @@ static struct fragment *parse_binary_hunk(char **buf_p,
|
||||
llen = linelen(buffer, size);
|
||||
used += llen;
|
||||
linenr++;
|
||||
if (llen == 1)
|
||||
if (llen == 1) {
|
||||
/* consume the blank line */
|
||||
buffer++;
|
||||
size--;
|
||||
break;
|
||||
}
|
||||
/* Minimum line is "A00000\n" which is 7-byte long,
|
||||
* and the line length must be multiple of 5 plus 2.
|
||||
*/
|
||||
@@ -1618,7 +1622,7 @@ static int apply_binary_fragment(struct buffer_desc *desc, struct patch *patch)
|
||||
"without the reverse hunk to '%s'",
|
||||
patch->new_name
|
||||
? patch->new_name : patch->old_name);
|
||||
fragment = fragment;
|
||||
fragment = fragment->next;
|
||||
}
|
||||
data = (void*) fragment->patch;
|
||||
switch (fragment->binary_patch_method) {
|
||||
@@ -1717,7 +1721,7 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch)
|
||||
write_sha1_file_prepare(desc->buffer, desc->size, blob_type,
|
||||
sha1, hdr, &hdrlen);
|
||||
if (strcmp(sha1_to_hex(sha1), patch->new_sha1_prefix))
|
||||
return error("binary patch to '%s' creates incorrect result", name);
|
||||
return error("binary patch to '%s' creates incorrect result (expecting %s, got %s)", name, patch->new_sha1_prefix, sha1_to_hex(sha1));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -175,61 +175,12 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
static inline void indent(int in)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < in; i++) putchar(' ');
|
||||
}
|
||||
|
||||
static void dump_pattern_exp(struct grep_expr *x, int in)
|
||||
{
|
||||
switch (x->node) {
|
||||
case GREP_NODE_ATOM:
|
||||
indent(in);
|
||||
puts(x->u.atom->pattern);
|
||||
break;
|
||||
case GREP_NODE_NOT:
|
||||
indent(in);
|
||||
puts("--not");
|
||||
dump_pattern_exp(x->u.unary, in+1);
|
||||
break;
|
||||
case GREP_NODE_AND:
|
||||
dump_pattern_exp(x->u.binary.left, in+1);
|
||||
indent(in);
|
||||
puts("--and");
|
||||
dump_pattern_exp(x->u.binary.right, in+1);
|
||||
break;
|
||||
case GREP_NODE_OR:
|
||||
dump_pattern_exp(x->u.binary.left, in+1);
|
||||
indent(in);
|
||||
puts("--or");
|
||||
dump_pattern_exp(x->u.binary.right, in+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void looking_at(const char *msg, struct grep_pat **list)
|
||||
{
|
||||
struct grep_pat *p = *list;
|
||||
fprintf(stderr, "%s: looking at ", msg);
|
||||
if (!p)
|
||||
fprintf(stderr, "empty\n");
|
||||
else
|
||||
fprintf(stderr, "<%s>\n", p->pattern);
|
||||
}
|
||||
#else
|
||||
#define looking_at(a,b) do {} while(0)
|
||||
#endif
|
||||
|
||||
static struct grep_expr *compile_pattern_expr(struct grep_pat **);
|
||||
static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
|
||||
{
|
||||
struct grep_pat *p;
|
||||
struct grep_expr *x;
|
||||
|
||||
looking_at("atom", list);
|
||||
|
||||
p = *list;
|
||||
switch (p->token) {
|
||||
case GREP_PATTERN: /* atom */
|
||||
@@ -257,8 +208,6 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
|
||||
struct grep_pat *p;
|
||||
struct grep_expr *x;
|
||||
|
||||
looking_at("not", list);
|
||||
|
||||
p = *list;
|
||||
switch (p->token) {
|
||||
case GREP_NOT:
|
||||
@@ -281,8 +230,6 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
|
||||
struct grep_pat *p;
|
||||
struct grep_expr *x, *y, *z;
|
||||
|
||||
looking_at("and", list);
|
||||
|
||||
x = compile_pattern_not(list);
|
||||
p = *list;
|
||||
if (p && p->token == GREP_AND) {
|
||||
@@ -306,8 +253,6 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)
|
||||
struct grep_pat *p;
|
||||
struct grep_expr *x, *y, *z;
|
||||
|
||||
looking_at("or", list);
|
||||
|
||||
x = compile_pattern_and(list);
|
||||
p = *list;
|
||||
if (x && p && p->token != GREP_CLOSE_PAREN) {
|
||||
@@ -325,8 +270,6 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)
|
||||
|
||||
static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
|
||||
{
|
||||
looking_at("expr", list);
|
||||
|
||||
return compile_pattern_or(list);
|
||||
}
|
||||
|
||||
|
||||
25
builtin-mv.c
25
builtin-mv.c
@@ -17,12 +17,19 @@ static const char builtin_mv_usage[] =
|
||||
static const char **copy_pathspec(const char *prefix, const char **pathspec,
|
||||
int count, int base_name)
|
||||
{
|
||||
int i;
|
||||
const char **result = xmalloc((count + 1) * sizeof(const char *));
|
||||
memcpy(result, pathspec, count * sizeof(const char *));
|
||||
result[count] = NULL;
|
||||
if (base_name) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
int length = strlen(result[i]);
|
||||
if (length > 0 && result[i][length - 1] == '/') {
|
||||
char *without_slash = xmalloc(length);
|
||||
memcpy(without_slash, result[i], length - 1);
|
||||
without_slash[length] = '\0';
|
||||
result[i] = without_slash;
|
||||
}
|
||||
if (base_name) {
|
||||
const char *last_slash = strrchr(result[i], '/');
|
||||
if (last_slash)
|
||||
result[i] = last_slash + 1;
|
||||
@@ -129,6 +136,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||
if (lstat(source[i], &st) < 0)
|
||||
bad = "bad source";
|
||||
|
||||
if (!bad &&
|
||||
(length = strlen(source[i])) >= 0 &&
|
||||
!strncmp(destination[i], source[i], length) &&
|
||||
(destination[i][length] == 0 || destination[i][length] == '/'))
|
||||
bad = "can not move directory into itself";
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
const char *dir = source[i], *dest_dir = destination[i];
|
||||
int first, last, len = strlen(dir);
|
||||
@@ -204,12 +217,6 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||
}
|
||||
}
|
||||
|
||||
if (!bad &&
|
||||
(length = strlen(source[i])) >= 0 &&
|
||||
!strncmp(destination[i], source[i], length) &&
|
||||
(destination[i][length] == 0 || destination[i][length] == '/'))
|
||||
bad = "can not move directory into itself";
|
||||
|
||||
if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
|
||||
bad = "not under version control";
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
(let* ((dir (file-name-directory file))
|
||||
(name (file-relative-name file dir)))
|
||||
(when dir (cd dir))
|
||||
(and (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name))
|
||||
(and (ignore-errors (eq 0 (call-process "git" nil '(t nil) nil "ls-files" "-c" "-z" "--" name)))
|
||||
(let ((str (buffer-string)))
|
||||
(and (> (length str) (length name))
|
||||
(string= (substring str 0 (1+ (length name))) (concat name "\0"))))))))
|
||||
|
||||
10
diff.c
10
diff.c
@@ -838,7 +838,7 @@ static unsigned char *deflate_it(char *data,
|
||||
return deflated;
|
||||
}
|
||||
|
||||
static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
|
||||
static void emit_binary_diff_body(mmfile_t *one, mmfile_t *two)
|
||||
{
|
||||
void *cp;
|
||||
void *delta;
|
||||
@@ -849,7 +849,6 @@ static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
|
||||
unsigned long deflate_size;
|
||||
unsigned long data_size;
|
||||
|
||||
printf("GIT binary patch\n");
|
||||
/* We could do deflated delta, or we could do just deflated two,
|
||||
* whichever is smaller.
|
||||
*/
|
||||
@@ -898,6 +897,13 @@ static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
|
||||
{
|
||||
printf("GIT binary patch\n");
|
||||
emit_binary_diff_body(one, two);
|
||||
emit_binary_diff_body(two, one);
|
||||
}
|
||||
|
||||
#define FIRST_FEW_BYTES 8000
|
||||
static int mmfile_is_binary(mmfile_t *mf)
|
||||
{
|
||||
|
||||
@@ -533,6 +533,16 @@ sub git_get_project_description {
|
||||
return $descr;
|
||||
}
|
||||
|
||||
sub git_get_project_url_list {
|
||||
my $path = shift;
|
||||
|
||||
open my $fd, "$projectroot/$path/cloneurl" or return undef;
|
||||
my @git_project_url_list = map { chomp; $_ } <$fd>;
|
||||
close $fd;
|
||||
|
||||
return wantarray ? @git_project_url_list : \@git_project_url_list;
|
||||
}
|
||||
|
||||
sub git_get_projects_list {
|
||||
my @list;
|
||||
|
||||
@@ -1697,10 +1707,14 @@ sub git_summary {
|
||||
"<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
|
||||
"<tr><td>owner</td><td>$owner</td></tr>\n" .
|
||||
"<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
|
||||
# use per project git URL list in $projectroot/$project/cloneurl
|
||||
# or make project git URL from git base URL and project name
|
||||
my $url_tag = "URL";
|
||||
foreach my $git_base_url (@git_base_url_list) {
|
||||
next unless $git_base_url;
|
||||
print "<tr><td>$url_tag</td><td>$git_base_url/$project</td></tr>\n";
|
||||
my @url_list = git_get_project_url_list($project);
|
||||
@url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
|
||||
foreach my $git_url (@url_list) {
|
||||
next unless $git_url;
|
||||
print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
|
||||
$url_tag = "";
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
@@ -22,25 +22,64 @@ test_expect_success setup '
|
||||
tr "[mon]" '\''[\0\1\2]'\'' <file1 >file2 &&
|
||||
|
||||
git commit -a -m second &&
|
||||
git tag second &&
|
||||
|
||||
git diff --binary -R initial >patch
|
||||
git diff --binary initial second >patch
|
||||
|
||||
'
|
||||
|
||||
test_expect_success 'apply in forward' '
|
||||
|
||||
T0=`git rev-parse "second^{tree}"` &&
|
||||
git reset --hard initial &&
|
||||
git apply --index --binary patch &&
|
||||
git diff initial >diff &&
|
||||
diff -u /dev/null diff
|
||||
|
||||
T1=`git write-tree` &&
|
||||
test "$T0" = "$T1"
|
||||
'
|
||||
|
||||
test_expect_success 'apply in reverse' '
|
||||
|
||||
git reset --hard second &&
|
||||
git apply --reverse --binary --index patch &&
|
||||
git diff >diff &&
|
||||
diff -u /dev/null diff
|
||||
|
||||
'
|
||||
|
||||
test_expect_success 'setup separate repository lacking postimage' '
|
||||
|
||||
git tar-tree initial initial | tar xf - &&
|
||||
(
|
||||
cd initial && git init-db && git add .
|
||||
) &&
|
||||
|
||||
git tar-tree second second | tar xf - &&
|
||||
(
|
||||
cd second && git init-db && git add .
|
||||
)
|
||||
|
||||
'
|
||||
|
||||
test_expect_success 'apply in forward without postimage' '
|
||||
|
||||
T0=`git rev-parse "second^{tree}"` &&
|
||||
(
|
||||
cd initial &&
|
||||
git apply --index --binary ../patch &&
|
||||
T1=`git write-tree` &&
|
||||
test "$T0" = "$T1"
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'apply in reverse without postimage' '
|
||||
|
||||
T0=`git rev-parse "initial^{tree}"` &&
|
||||
(
|
||||
cd second &&
|
||||
git apply --index --binary --reverse ../patch &&
|
||||
T1=`git write-tree` &&
|
||||
test "$T0" = "$T1"
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user