##// END OF EJS Templates
simplify flag handling...
Matt Mackall -
r6743:86e8187b default
parent child Browse files
Show More
@@ -387,7 +387,7 b' def files(ui, repo, *pats, **opts):'
387 files += unknown
387 files += unknown
388 files.sort()
388 files.sort()
389 wctx = repo.changectx(None)
389 wctx = repo.changectx(None)
390 islink = lambda p: 'l' in wctx.fileflags(p)
390 islink = lambda p: 'l' in wctx.flags(p)
391 kwfiles = [f for f in files if kwt.iskwfile(f, islink)]
391 kwfiles = [f for f in files if kwt.iskwfile(f, islink)]
392 cwd = pats and repo.getcwd() or ''
392 cwd = pats and repo.getcwd() or ''
393 kwfstats = not opts.get('ignore') and (('K', kwfiles),) or ()
393 kwfstats = not opts.get('ignore') and (('K', kwfiles),) or ()
@@ -2480,7 +2480,7 b' def revert(ui, repo, *pats, **opts):'
2480 if not opts.get('dry_run'):
2480 if not opts.get('dry_run'):
2481 def checkout(f):
2481 def checkout(f):
2482 fc = ctx[f]
2482 fc = ctx[f]
2483 repo.wwrite(f, fc.data(), fc.fileflags())
2483 repo.wwrite(f, fc.data(), fc.flags())
2484
2484
2485 audit_path = util.path_auditor(repo.root)
2485 audit_path = util.path_auditor(repo.root)
2486 for f in remove[0]:
2486 for f in remove[0]:
@@ -118,7 +118,7 b' class changectx(object):'
118 def filenode(self, path):
118 def filenode(self, path):
119 return self._fileinfo(path)[0]
119 return self._fileinfo(path)[0]
120
120
121 def fileflags(self, path):
121 def flags(self, path):
122 try:
122 try:
123 return self._fileinfo(path)[1]
123 return self._fileinfo(path)[1]
124 except revlog.LookupError:
124 except revlog.LookupError:
@@ -237,9 +237,9 b' class filectx(object):'
237
237
238 def filerev(self): return self._filerev
238 def filerev(self): return self._filerev
239 def filenode(self): return self._filenode
239 def filenode(self): return self._filenode
240 def fileflags(self): return self._changectx.fileflags(self._path)
240 def flags(self): return self._changectx.flags(self._path)
241 def isexec(self): return 'x' in self.fileflags()
241 def isexec(self): return 'x' in self.flags()
242 def islink(self): return 'l' in self.fileflags()
242 def islink(self): return 'l' in self.flags()
243 def filelog(self): return self._filelog
243 def filelog(self): return self._filelog
244
244
245 def rev(self):
245 def rev(self):
@@ -509,16 +509,14 b' class workingctx(changectx):'
509
509
510 man = self._parents[0].manifest().copy()
510 man = self._parents[0].manifest().copy()
511 copied = self._repo.dirstate.copies()
511 copied = self._repo.dirstate.copies()
512 is_exec = util.execfunc(self._repo.root,
512 cf = lambda x: man.flags(copied.get(x, x))
513 lambda p: man.execf(copied.get(p,p)))
513 ff = self._repo.dirstate.flagfunc(cf)
514 is_link = util.linkfunc(self._repo.root,
515 lambda p: man.linkf(copied.get(p,p)))
516 modified, added, removed, deleted, unknown = self._status[:5]
514 modified, added, removed, deleted, unknown = self._status[:5]
517 for i, l in (("a", added), ("m", modified), ("u", unknown)):
515 for i, l in (("a", added), ("m", modified), ("u", unknown)):
518 for f in l:
516 for f in l:
519 man[f] = man.get(copied.get(f, f), nullid) + i
517 man[f] = man.get(copied.get(f, f), nullid) + i
520 try:
518 try:
521 man.set(f, is_exec(f), is_link(f))
519 man.set(f, ff(f))
522 except OSError:
520 except OSError:
523 pass
521 pass
524
522
@@ -555,7 +553,7 b' class workingctx(changectx):'
555 def children(self):
553 def children(self):
556 return []
554 return []
557
555
558 def fileflags(self, path):
556 def flags(self, path):
559 if '_manifest' in self.__dict__:
557 if '_manifest' in self.__dict__:
560 try:
558 try:
561 return self._manifest.flags(path)
559 return self._manifest.flags(path)
@@ -565,12 +563,9 b' class workingctx(changectx):'
565 pnode = self._parents[0].changeset()[0]
563 pnode = self._parents[0].changeset()[0]
566 orig = self._repo.dirstate.copies().get(path, path)
564 orig = self._repo.dirstate.copies().get(path, path)
567 node, flag = self._repo.manifest.find(pnode, orig)
565 node, flag = self._repo.manifest.find(pnode, orig)
568 is_link = util.linkfunc(self._repo.root,
569 lambda p: flag and 'l' in flag)
570 is_exec = util.execfunc(self._repo.root,
571 lambda p: flag and 'x' in flag)
572 try:
566 try:
573 return (is_link(path) and 'l' or '') + (is_exec(path) and 'x' or '')
567 ff = self._repo.dirstate.flagfunc(lambda x: flag or '')
568 return ff(path)
574 except OSError:
569 except OSError:
575 pass
570 pass
576
571
@@ -724,6 +719,7 b' class memctx(object):'
724 def clean(self): return self._status[5]
719 def clean(self): return self._status[5]
725 def branch(self): return self._extra['branch']
720 def branch(self): return self._extra['branch']
726 def extra(self): return self._extra
721 def extra(self): return self._extra
722 def flags(self, f): return self[f].flags()
727
723
728 def parents(self):
724 def parents(self):
729 """return contexts for each parent changeset"""
725 """return contexts for each parent changeset"""
@@ -750,7 +746,7 b' class memfilectx(object):'
750 def __str__(self): return "%s@%s" % (self.path(), self._changectx)
746 def __str__(self): return "%s@%s" % (self.path(), self._changectx)
751 def path(self): return self._path
747 def path(self): return self._path
752 def data(self): return self._data
748 def data(self): return self._data
753 def fileflags(self): return self._flags
749 def flags(self): return self._flags
754 def isexec(self): return 'x' in self._flags
750 def isexec(self): return 'x' in self._flags
755 def islink(self): return 'l' in self._flags
751 def islink(self): return 'l' in self._flags
756 def renamed(self): return self._copied
752 def renamed(self): return self._copied
@@ -70,6 +70,9 b' class dirstate(object):'
70 elif name == '_slash':
70 elif name == '_slash':
71 self._slash = self._ui.configbool('ui', 'slash') and os.sep != '/'
71 self._slash = self._ui.configbool('ui', 'slash') and os.sep != '/'
72 return self._slash
72 return self._slash
73 elif name == '_checklink':
74 self._checklink = util.checklink(self._root)
75 return self._checklink
73 elif name == '_checkexec':
76 elif name == '_checkexec':
74 self._checkexec = util.checkexec(self._root)
77 self._checkexec = util.checkexec(self._root)
75 return self._checkexec
78 return self._checkexec
@@ -91,6 +94,34 b' class dirstate(object):'
91 def folding(self):
94 def folding(self):
92 return self._folding
95 return self._folding
93
96
97 def flagfunc(self, fallback):
98 if self._checklink:
99 if self._checkexec:
100 def f(x):
101 p = os.path.join(self._root, x)
102 if os.path.islink(p):
103 return 'l'
104 if util.is_exec(p):
105 return 'x'
106 return ''
107 return f
108 def f(x):
109 if os.path.islink(os.path.join(self._root, x)):
110 return 'l'
111 if 'x' in fallback(x):
112 return 'x'
113 return ''
114 return f
115 if self._checkexec:
116 def f(x):
117 if 'l' in fallback(x):
118 return 'l'
119 if util.is_exec(os.path.join(self._root, x)):
120 return 'x'
121 return ''
122 return f
123 return fallback
124
94 def getcwd(self):
125 def getcwd(self):
95 cwd = os.getcwd()
126 cwd = os.getcwd()
96 if cwd == self._root: return ''
127 if cwd == self._root: return ''
@@ -146,7 +146,7 b' def filemerge(repo, mynode, orig, fcd, f'
146 if tool == "internal:local":
146 if tool == "internal:local":
147 return 0
147 return 0
148 if tool == "internal:other":
148 if tool == "internal:other":
149 repo.wwrite(fd, fco.data(), fco.fileflags())
149 repo.wwrite(fd, fco.data(), fco.flags())
150 return 0
150 return 0
151 if tool == "internal:fail":
151 if tool == "internal:fail":
152 return 1
152 return 1
@@ -837,19 +837,16 b' class localrepository(repo.repository):'
837 self.ui.note(f + "\n")
837 self.ui.note(f + "\n")
838 try:
838 try:
839 fctx = wctx.filectx(f)
839 fctx = wctx.filectx(f)
840 newflags = fctx.flags()
840 new[f] = self.filecommit(fctx, m1, m2, linkrev, trp, changed)
841 new[f] = self.filecommit(fctx, m1, m2, linkrev, trp, changed)
841 new_exec = fctx.isexec()
842 new_link = fctx.islink()
843 if ((not changed or changed[-1] != f) and
842 if ((not changed or changed[-1] != f) and
844 m2.get(f) != new[f]):
843 m2.get(f) != new[f]):
845 # mention the file in the changelog if some
844 # mention the file in the changelog if some
846 # flag changed, even if there was no content
845 # flag changed, even if there was no content
847 # change.
846 # change.
848 old_exec = m1.execf(f)
847 if m1.flags(f) != newflags:
849 old_link = m1.linkf(f)
850 if old_exec != new_exec or old_link != new_link:
851 changed.append(f)
848 changed.append(f)
852 m1.set(f, new_exec, new_link)
849 m1.set(f, newflags)
853 if use_dirstate:
850 if use_dirstate:
854 self.dirstate.normal(f)
851 self.dirstate.normal(f)
855
852
@@ -1009,14 +1006,9 b' class localrepository(repo.repository):'
1009 fixup = []
1006 fixup = []
1010 # do a full compare of any files that might have changed
1007 # do a full compare of any files that might have changed
1011 ctx = self.changectx('')
1008 ctx = self.changectx('')
1012 mexec = lambda f: 'x' in ctx.fileflags(f)
1009 ff = self.dirstate.flagfunc(ctx.flags)
1013 mlink = lambda f: 'l' in ctx.fileflags(f)
1014 is_exec = util.execfunc(self.root, mexec)
1015 is_link = util.linkfunc(self.root, mlink)
1016 def flags(f):
1017 return is_link(f) and 'l' or is_exec(f) and 'x' or ''
1018 for f in lookup:
1010 for f in lookup:
1019 if (f not in ctx or flags(f) != ctx.fileflags(f)
1011 if (f not in ctx or ff(f) != ctx.flags(f)
1020 or ctx[f].cmp(self.wread(f))):
1012 or ctx[f].cmp(self.wread(f))):
1021 modified.append(f)
1013 modified.append(f)
1022 else:
1014 else:
@@ -1042,11 +1034,10 b' class localrepository(repo.repository):'
1042 # generate a pseudo-manifest for the working dir
1034 # generate a pseudo-manifest for the working dir
1043 # XXX: create it in dirstate.py ?
1035 # XXX: create it in dirstate.py ?
1044 mf2 = mfmatches(self.dirstate.parents()[0])
1036 mf2 = mfmatches(self.dirstate.parents()[0])
1045 is_exec = util.execfunc(self.root, mf2.execf)
1037 ff = self.dirstate.flagfunc(mf2.flags)
1046 is_link = util.linkfunc(self.root, mf2.linkf)
1047 for f in lookup + modified + added:
1038 for f in lookup + modified + added:
1048 mf2[f] = ""
1039 mf2[f] = ""
1049 mf2.set(f, is_exec(f), is_link(f))
1040 mf2.set(f, ff(f))
1050 for f in removed:
1041 for f in removed:
1051 if f in mf2:
1042 if f in mf2:
1052 del mf2[f]
1043 del mf2[f]
@@ -24,10 +24,8 b' class manifestdict(dict):'
24 def linkf(self, f):
24 def linkf(self, f):
25 "test for symlink in manifest flags"
25 "test for symlink in manifest flags"
26 return "l" in self.flags(f)
26 return "l" in self.flags(f)
27 def set(self, f, execf=False, linkf=False):
27 def set(self, f, flags):
28 if linkf: self._flags[f] = "l"
28 self._flags[f] = flags
29 elif execf: self._flags[f] = "x"
30 else: self._flags[f] = ""
31 def copy(self):
29 def copy(self):
32 return manifestdict(dict.copy(self), dict.copy(self._flags))
30 return manifestdict(dict.copy(self), dict.copy(self._flags))
33
31
@@ -1193,16 +1193,6 b' def diff(repo, node1=None, node2=None, m'
1193 return
1193 return
1194
1194
1195 ctx2 = repo.changectx(node2)
1195 ctx2 = repo.changectx(node2)
1196 if node2:
1197 execf2 = ctx2.manifest().execf
1198 linkf2 = ctx2.manifest().linkf
1199 else:
1200 execf2 = util.execfunc(repo.root, None)
1201 linkf2 = util.linkfunc(repo.root, None)
1202 if execf2 is None:
1203 mc = ctx2.parents()[0].manifest().copy()
1204 execf2 = mc.execf
1205 linkf2 = mc.linkf
1206
1196
1207 if repo.ui.quiet:
1197 if repo.ui.quiet:
1208 r = None
1198 r = None
@@ -1219,6 +1209,8 b' def diff(repo, node1=None, node2=None, m'
1219 all.sort()
1209 all.sort()
1220 gone = {}
1210 gone = {}
1221
1211
1212 gitmode = {'l': '120000', 'x': '100755', '': '100644'}
1213
1222 for f in all:
1214 for f in all:
1223 to = None
1215 to = None
1224 tn = None
1216 tn = None
@@ -1230,18 +1222,16 b' def diff(repo, node1=None, node2=None, m'
1230 tn = getfilectx(f, ctx2).data()
1222 tn = getfilectx(f, ctx2).data()
1231 a, b = f, f
1223 a, b = f, f
1232 if opts.git:
1224 if opts.git:
1233 def gitmode(x, l):
1234 return l and '120000' or (x and '100755' or '100644')
1235 def addmodehdr(header, omode, nmode):
1225 def addmodehdr(header, omode, nmode):
1236 if omode != nmode:
1226 if omode != nmode:
1237 header.append('old mode %s\n' % omode)
1227 header.append('old mode %s\n' % omode)
1238 header.append('new mode %s\n' % nmode)
1228 header.append('new mode %s\n' % nmode)
1239
1229
1240 if f in added:
1230 if f in added:
1241 mode = gitmode(execf2(f), linkf2(f))
1231 mode = gitmode[ctx2.flags(f)]
1242 if f in copy:
1232 if f in copy:
1243 a = copy[f]
1233 a = copy[f]
1244 omode = gitmode(man1.execf(a), man1.linkf(a))
1234 omode = gitmode[man1.flags(a)]
1245 addmodehdr(header, omode, mode)
1235 addmodehdr(header, omode, mode)
1246 if a in removed and a not in gone:
1236 if a in removed and a not in gone:
1247 op = 'rename'
1237 op = 'rename'
@@ -1260,11 +1250,11 b' def diff(repo, node1=None, node2=None, m'
1260 if f in copy and copy[f] in added and copy[copy[f]] == f:
1250 if f in copy and copy[f] in added and copy[copy[f]] == f:
1261 dodiff = False
1251 dodiff = False
1262 else:
1252 else:
1263 mode = gitmode(man1.execf(f), man1.linkf(f))
1253 header.append('deleted file mode %s\n' %
1264 header.append('deleted file mode %s\n' % mode)
1254 gitmode[man1.flags(f)])
1265 else:
1255 else:
1266 omode = gitmode(man1.execf(f), man1.linkf(f))
1256 omode = gitmode[man1.flags(f)]
1267 nmode = gitmode(execf2(f), linkf2(f))
1257 nmode = gitmode[ctx2.flags(f)]
1268 addmodehdr(header, omode, nmode)
1258 addmodehdr(header, omode, nmode)
1269 if util.binary(to) or util.binary(tn):
1259 if util.binary(to) or util.binary(tn):
1270 dodiff = 'binary'
1260 dodiff = 'binary'
@@ -933,12 +933,6 b' def checkexec(path):'
933 return False
933 return False
934 return not (new_file_has_exec or exec_flags_cannot_flip)
934 return not (new_file_has_exec or exec_flags_cannot_flip)
935
935
936 def execfunc(path, fallback):
937 '''return an is_exec() function with default to fallback'''
938 if checkexec(path):
939 return lambda x: is_exec(os.path.join(path, x))
940 return fallback
941
942 def checklink(path):
936 def checklink(path):
943 """check whether the given path is on a symlink-capable filesystem"""
937 """check whether the given path is on a symlink-capable filesystem"""
944 # mktemp is not racy because symlink creation will fail if the
938 # mktemp is not racy because symlink creation will fail if the
@@ -951,12 +945,6 b' def checklink(path):'
951 except (OSError, AttributeError):
945 except (OSError, AttributeError):
952 return False
946 return False
953
947
954 def linkfunc(path, fallback):
955 '''return an is_link() function with default to fallback'''
956 if checklink(path):
957 return lambda x: os.path.islink(os.path.join(path, x))
958 return fallback
959
960 _umask = os.umask(0)
948 _umask = os.umask(0)
961 os.umask(_umask)
949 os.umask(_umask)
962
950
General Comments 0
You need to be logged in to leave comments. Login now