Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 7150:6d1d61bb2984
patch: map changed files to patchmeta directly
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sat, 18 Oct 2008 23:45:45 +0200 |
parents | 01a056c54385 |
children | b5bc5293021c |
comparison
equal
deleted
inserted
replaced
7149:01a056c54385 | 7150:6d1d61bb2984 |
---|---|
923 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or | 923 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or |
924 ((context or context == None) and x.startswith('***************')))): | 924 ((context or context == None) and x.startswith('***************')))): |
925 try: | 925 try: |
926 if context == None and x.startswith('***************'): | 926 if context == None and x.startswith('***************'): |
927 context = True | 927 context = True |
928 gpatch = changed.get(bfile[2:], (None, None))[1] | 928 gpatch = changed.get(bfile[2:]) |
929 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD' | 929 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD' |
930 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE' | 930 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE' |
931 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove) | 931 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove) |
932 except PatchError, err: | 932 except PatchError, err: |
933 ui.debug(err) | 933 ui.debug(err) |
936 hunknum += 1 | 936 hunknum += 1 |
937 if emitfile: | 937 if emitfile: |
938 emitfile = False | 938 emitfile = False |
939 yield 'file', (afile, bfile, current_hunk) | 939 yield 'file', (afile, bfile, current_hunk) |
940 elif state == BFILE and x.startswith('GIT binary patch'): | 940 elif state == BFILE and x.startswith('GIT binary patch'): |
941 current_hunk = binhunk(changed[bfile[2:]][1]) | 941 current_hunk = binhunk(changed[bfile[2:]]) |
942 hunknum += 1 | 942 hunknum += 1 |
943 if emitfile: | 943 if emitfile: |
944 emitfile = False | 944 emitfile = False |
945 yield 'file', (afile, bfile, current_hunk) | 945 yield 'file', (afile, bfile, current_hunk) |
946 current_hunk.extract(fp) | 946 current_hunk.extract(fp) |
952 if not git: | 952 if not git: |
953 git = True | 953 git = True |
954 fp, dopatch, gitpatches = scangitpatch(fp, x) | 954 fp, dopatch, gitpatches = scangitpatch(fp, x) |
955 yield 'git', gitpatches | 955 yield 'git', gitpatches |
956 for gp in gitpatches: | 956 for gp in gitpatches: |
957 changed[gp.path] = (gp.op, gp) | 957 changed[gp.path] = gp |
958 # else error? | 958 # else error? |
959 # copy/rename + modify should modify target, not source | 959 # copy/rename + modify should modify target, not source |
960 gitop = changed.get(bfile[2:], (None, None))[0] | 960 gp = changed.get(bfile[2:]) |
961 if gitop in ('COPY', 'DELETE', 'RENAME'): | 961 if gp and gp.op in ('COPY', 'DELETE', 'RENAME'): |
962 afile = bfile | 962 afile = bfile |
963 gitworkdone = True | 963 gitworkdone = True |
964 newfile = True | 964 newfile = True |
965 elif x.startswith('---'): | 965 elif x.startswith('---'): |
966 # check for a unified diff | 966 # check for a unified diff |
1024 if not current_file: | 1024 if not current_file: |
1025 continue | 1025 continue |
1026 current_hunk = values | 1026 current_hunk = values |
1027 ret = current_file.apply(current_hunk, reverse) | 1027 ret = current_file.apply(current_hunk, reverse) |
1028 if ret >= 0: | 1028 if ret >= 0: |
1029 changed.setdefault(current_file.fname, (None, None)) | 1029 changed.setdefault(current_file.fname, None) |
1030 if ret > 0: | 1030 if ret > 0: |
1031 err = 1 | 1031 err = 1 |
1032 elif state == 'file': | 1032 elif state == 'file': |
1033 rejects += closefile() | 1033 rejects += closefile() |
1034 afile, bfile, first_hunk = values | 1034 afile, bfile, first_hunk = values |
1050 for gp in gitpatches: | 1050 for gp in gitpatches: |
1051 if gp.op in ('COPY', 'RENAME'): | 1051 if gp.op in ('COPY', 'RENAME'): |
1052 src, dst = [util.canonpath(cwd, cwd, x) | 1052 src, dst = [util.canonpath(cwd, cwd, x) |
1053 for x in [gp.oldpath, gp.path]] | 1053 for x in [gp.oldpath, gp.path]] |
1054 copyfile(src, dst) | 1054 copyfile(src, dst) |
1055 changed[gp.path] = (gp.op, gp) | 1055 changed[gp.path] = gp |
1056 else: | 1056 else: |
1057 raise util.Abort(_('unsupported parser state: %s') % state) | 1057 raise util.Abort(_('unsupported parser state: %s') % state) |
1058 | 1058 |
1059 rejects += closefile() | 1059 rejects += closefile() |
1060 | 1060 |
1085 cfiles = patches.keys() | 1085 cfiles = patches.keys() |
1086 cwd = repo.getcwd() | 1086 cwd = repo.getcwd() |
1087 if cwd: | 1087 if cwd: |
1088 cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] | 1088 cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] |
1089 for f in patches: | 1089 for f in patches: |
1090 ctype, gp = patches[f] | 1090 gp = patches[f] |
1091 if ctype == 'RENAME': | 1091 if not gp: |
1092 continue | |
1093 if gp.op == 'RENAME': | |
1092 copies.append((gp.oldpath, gp.path)) | 1094 copies.append((gp.oldpath, gp.path)) |
1093 removes[gp.oldpath] = 1 | 1095 removes[gp.oldpath] = 1 |
1094 elif ctype == 'COPY': | 1096 elif gp.op == 'COPY': |
1095 copies.append((gp.oldpath, gp.path)) | 1097 copies.append((gp.oldpath, gp.path)) |
1096 elif ctype == 'DELETE': | 1098 elif gp.op == 'DELETE': |
1097 removes[gp.path] = 1 | 1099 removes[gp.path] = 1 |
1098 for src, dst in copies: | 1100 for src, dst in copies: |
1099 repo.copy(src, dst) | 1101 repo.copy(src, dst) |
1100 removes = removes.keys() | 1102 removes = removes.keys() |
1101 if removes: | 1103 if removes: |
1102 repo.remove(util.sort(removes), True) | 1104 repo.remove(util.sort(removes), True) |
1103 for f in patches: | 1105 for f in patches: |
1104 ctype, gp = patches[f] | 1106 gp = patches[f] |
1105 if gp and gp.mode: | 1107 if gp and gp.mode: |
1106 islink, isexec = gp.mode | 1108 islink, isexec = gp.mode |
1107 dst = os.path.join(repo.root, gp.path) | 1109 dst = os.path.join(repo.root, gp.path) |
1108 # patch won't create empty files | 1110 # patch won't create empty files |
1109 if ctype == 'ADD' and not os.path.exists(dst): | 1111 if gp.op == 'ADD' and not os.path.exists(dst): |
1110 flags = (isexec and 'x' or '') + (islink and 'l' or '') | 1112 flags = (isexec and 'x' or '') + (islink and 'l' or '') |
1111 repo.wwrite(gp.path, '', flags) | 1113 repo.wwrite(gp.path, '', flags) |
1112 else: | 1114 else: |
1113 util.set_flags(dst, islink, isexec) | 1115 util.set_flags(dst, islink, isexec) |
1114 cmdutil.addremove(repo, cfiles) | 1116 cmdutil.addremove(repo, cfiles) |