##// END OF EJS Templates
patch: add git symlink support
Brendan Cully -
r5116:35d47b06 default
parent child Browse files
Show More
@@ -202,9 +202,9 b' def readgitpatch(fp, firstline=None):'
202 gp.op = 'DELETE'
202 gp.op = 'DELETE'
203 elif line.startswith('new file mode '):
203 elif line.startswith('new file mode '):
204 gp.op = 'ADD'
204 gp.op = 'ADD'
205 gp.mode = int(line.rstrip()[-3:], 8)
205 gp.mode = int(line.rstrip()[-6:], 8)
206 elif line.startswith('new mode '):
206 elif line.startswith('new mode '):
207 gp.mode = int(line.rstrip()[-3:], 8)
207 gp.mode = int(line.rstrip()[-6:], 8)
208 elif line.startswith('GIT binary patch'):
208 elif line.startswith('GIT binary patch'):
209 dopatch |= GP_BINARY
209 dopatch |= GP_BINARY
210 gp.binary = True
210 gp.binary = True
@@ -1048,11 +1048,14 b' def updatedir(ui, repo, patches):'
1048 ctype, gp = patches[f]
1048 ctype, gp = patches[f]
1049 if gp and gp.mode:
1049 if gp and gp.mode:
1050 x = gp.mode & 0100 != 0
1050 x = gp.mode & 0100 != 0
1051 l = gp.mode & 020000 != 0
1051 dst = os.path.join(repo.root, gp.path)
1052 dst = os.path.join(repo.root, gp.path)
1052 # patch won't create empty files
1053 # patch won't create empty files
1053 if ctype == 'ADD' and not os.path.exists(dst):
1054 if ctype == 'ADD' and not os.path.exists(dst):
1054 repo.wwrite(gp.path, '', x and 'x' or '')
1055 repo.wwrite(gp.path, '', x and 'x' or '')
1055 else:
1056 else:
1057 util.set_link(dst, l)
1058 if not l:
1056 util.set_exec(dst, x)
1059 util.set_exec(dst, x)
1057 cmdutil.addremove(repo, cfiles)
1060 cmdutil.addremove(repo, cfiles)
1058 files = patches.keys()
1061 files = patches.keys()
@@ -1145,11 +1148,15 b' def diff(repo, node1=None, node2=None, f'
1145 if node2:
1148 if node2:
1146 ctx2 = context.changectx(repo, node2)
1149 ctx2 = context.changectx(repo, node2)
1147 execf2 = ctx2.manifest().execf
1150 execf2 = ctx2.manifest().execf
1151 linkf2 = ctx2.manifest().linkf
1148 else:
1152 else:
1149 ctx2 = context.workingctx(repo)
1153 ctx2 = context.workingctx(repo)
1150 execf2 = util.execfunc(repo.root, None)
1154 execf2 = util.execfunc(repo.root, None)
1155 linkf2 = util.linkfunc(repo.root, None)
1151 if execf2 is None:
1156 if execf2 is None:
1152 execf2 = ctx2.parents()[0].manifest().copy().execf
1157 mc = ctx2.parents()[0].manifest().copy()
1158 execf2 = mc.execf
1159 linkf2 = mc.linkf
1153
1160
1154 # returns False if there was no rename between ctx1 and ctx2
1161 # returns False if there was no rename between ctx1 and ctx2
1155 # returns None if the file was created between ctx1 and ctx2
1162 # returns None if the file was created between ctx1 and ctx2
@@ -1206,8 +1213,8 b' def diff(repo, node1=None, node2=None, f'
1206 if f not in removed:
1213 if f not in removed:
1207 tn = getfilectx(f, ctx2).data()
1214 tn = getfilectx(f, ctx2).data()
1208 if opts.git:
1215 if opts.git:
1209 def gitmode(x):
1216 def gitmode(x, l):
1210 return x and '100755' or '100644'
1217 return l and '120000' or (x and '100755' or '100644')
1211 def addmodehdr(header, omode, nmode):
1218 def addmodehdr(header, omode, nmode):
1212 if omode != nmode:
1219 if omode != nmode:
1213 header.append('old mode %s\n' % omode)
1220 header.append('old mode %s\n' % omode)
@@ -1215,10 +1222,10 b' def diff(repo, node1=None, node2=None, f'
1215
1222
1216 a, b = f, f
1223 a, b = f, f
1217 if f in added:
1224 if f in added:
1218 mode = gitmode(execf2(f))
1225 mode = gitmode(execf2(f), linkf2(f))
1219 if f in copied:
1226 if f in copied:
1220 a = copied[f]
1227 a = copied[f]
1221 omode = gitmode(man1.execf(a))
1228 omode = gitmode(man1.execf(a), man1.linkf(a))
1222 addmodehdr(header, omode, mode)
1229 addmodehdr(header, omode, mode)
1223 if a in removed and a not in gone:
1230 if a in removed and a not in gone:
1224 op = 'rename'
1231 op = 'rename'
@@ -1236,11 +1243,11 b' def diff(repo, node1=None, node2=None, f'
1236 if f in srcs:
1243 if f in srcs:
1237 dodiff = False
1244 dodiff = False
1238 else:
1245 else:
1239 mode = gitmode(man1.execf(f))
1246 mode = gitmode(man1.execf(f), man1.linkf(f))
1240 header.append('deleted file mode %s\n' % mode)
1247 header.append('deleted file mode %s\n' % mode)
1241 else:
1248 else:
1242 omode = gitmode(man1.execf(f))
1249 omode = gitmode(man1.execf(f), man1.linkf(f))
1243 nmode = gitmode(execf2(f))
1250 nmode = gitmode(execf2(f), linkf2(f))
1244 addmodehdr(header, omode, nmode)
1251 addmodehdr(header, omode, nmode)
1245 if util.binary(to) or util.binary(tn):
1252 if util.binary(to) or util.binary(tn):
1246 dodiff = 'binary'
1253 dodiff = 'binary'
@@ -20,3 +20,20 b' 1. commit a symlink'
20 adding a/b/c/demo
20 adding a/b/c/demo
21 2. clone it
21 2. clone it
22 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
22 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
23 # git symlink diff
24 diff --git a/a/b/c/demo b/a/b/c/demo
25 new file mode 120000
26 --- /dev/null
27 +++ b/a/b/c/demo
28 @@ -0,0 +1,1 @@
29 +/path/to/symlink/source
30 \ No newline at end of file
31 # import git symlink diff
32 applying ../sl.diff
33 diff --git a/a/b/c/demo b/a/b/c/demo
34 new file mode 120000
35 --- /dev/null
36 +++ b/a/b/c/demo
37 @@ -0,0 +1,1 @@
38 +/path/to/symlink/source
39 \ No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now