comparison mercurial/hg.py @ 441:e8af362cfb01

Permission handling for the other OS -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Permission handling for the other OS From: K Thananchayan <thananck@yahoo.com> Preserve exec permission under Windows on existing source files. Not an ideal solution as there is no way to specify exec permission for a new file. Nevertheless, this helps working on crossplatform projects. manifest hash: c50da52ad4645f40bd6204c4fd458e880bc3f801 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCuvJeywK+sNU5EO8RAscXAJ40eAHZjTip5to6BGPdoXxxL5gNQQCgl5GT 8S1Ckank5I/0ScGtapZKqTA= =QrQp -----END PGP SIGNATURE-----
author mpm@selenic.com
date Thu, 23 Jun 2005 09:33:18 -0800
parents 6aeb4fee51f6
children 3e2aee6c5500
comparison
equal deleted inserted replaced
440:22b5aaeb3637 441:e8af362cfb01
9 import util 9 import util
10 from revlog import * 10 from revlog import *
11 from demandload import * 11 from demandload import *
12 demandload(globals(), "re lock urllib urllib2 transaction time socket") 12 demandload(globals(), "re lock urllib urllib2 transaction time socket")
13 demandload(globals(), "tempfile httprangereader bdiff") 13 demandload(globals(), "tempfile httprangereader bdiff")
14
15 def is_exec(f):
16 return (os.stat(f).st_mode & 0100 != 0)
17
18 def set_exec(f, mode):
19 s = os.stat(f).st_mode
20 if (s & 0100 != 0) == mode:
21 return
22 if mode:
23 # Turn on +x for every +r bit when making a file executable
24 # and obey umask.
25 umask = os.umask(0)
26 os.umask(umask)
27 os.chmod(f, s | (s & 0444) >> 2 & ~umask)
28 else:
29 os.chmod(f, s & 0666)
30 14
31 class filelog(revlog): 15 class filelog(revlog):
32 def __init__(self, opener, path): 16 def __init__(self, opener, path):
33 revlog.__init__(self, opener, 17 revlog.__init__(self, opener,
34 os.path.join("data", path + ".i"), 18 os.path.join("data", path + ".i"),
507 linkrev = self.changelog.count() 491 linkrev = self.changelog.count()
508 self.dirstate.setparents(p1, p2) 492 self.dirstate.setparents(p1, p2)
509 for f in files: 493 for f in files:
510 try: 494 try:
511 t = self.wfile(f).read() 495 t = self.wfile(f).read()
512 tm = is_exec(self.wjoin(f)) 496 tm = util.is_exec(self.wjoin(f), mfm.get(f, False))
513 r = self.file(f) 497 r = self.file(f)
514 mfm[f] = tm 498 mfm[f] = tm
515 mm[f] = r.add(t, {}, tr, linkrev, 499 mm[f] = r.add(t, {}, tr, linkrev,
516 m1.get(f, nullid), m2.get(f, nullid)) 500 m1.get(f, nullid), m2.get(f, nullid))
517 self.dirstate.update([f], "n") 501 self.dirstate.update([f], "n")
563 linkrev = self.changelog.count() 547 linkrev = self.changelog.count()
564 commit.sort() 548 commit.sort()
565 for f in commit: 549 for f in commit:
566 self.ui.note(f + "\n") 550 self.ui.note(f + "\n")
567 try: 551 try:
568 fp = self.wjoin(f) 552 mf1[f] = util.is_exec(self.wjoin(f), mf1.get(f, False))
569 mf1[f] = is_exec(fp)
570 t = self.wfile(f).read() 553 t = self.wfile(f).read()
571 except IOError: 554 except IOError:
572 self.warn("trouble committing %s!\n" % f) 555 self.warn("trouble committing %s!\n" % f)
573 raise 556 raise
574 557
1029 # construct a working dir manifest 1012 # construct a working dir manifest
1030 mw = m1.copy() 1013 mw = m1.copy()
1031 mfw = mf1.copy() 1014 mfw = mf1.copy()
1032 for f in a + c + u: 1015 for f in a + c + u:
1033 mw[f] = "" 1016 mw[f] = ""
1034 mfw[f] = is_exec(self.wjoin(f)) 1017 mfw[f] = util.is_exec(self.wjoin(f), mfw.get(f, False))
1035 for f in d: 1018 for f in d:
1036 if f in mw: del mw[f] 1019 if f in mw: del mw[f]
1037 1020
1038 # If we're jumping between revisions (as opposed to merging), 1021 # If we're jumping between revisions (as opposed to merging),
1039 # and if neither the working directory nor the target rev has 1022 # and if neither the working directory nor the target rev has
1079 mark[f] = 1 1062 mark[f] = 1
1080 1063
1081 if not s and mfw[f] != mf2[f]: 1064 if not s and mfw[f] != mf2[f]:
1082 if force: 1065 if force:
1083 self.ui.debug(" updating permissions for %s\n" % f) 1066 self.ui.debug(" updating permissions for %s\n" % f)
1084 set_exec(self.wjoin(f), mf2[f]) 1067 util.set_exec(self.wjoin(f), mf2[f])
1085 else: 1068 else:
1086 a, b, c = mfa.get(f, 0), mfw[f], mf2[f] 1069 a, b, c = mfa.get(f, 0), mfw[f], mf2[f]
1087 mode = ((a^b) | (a^c)) ^ a 1070 mode = ((a^b) | (a^c)) ^ a
1088 if mode != b: 1071 if mode != b:
1089 self.ui.debug(" updating permissions for %s\n" % f) 1072 self.ui.debug(" updating permissions for %s\n" % f)
1090 set_exec(self.wjoin(f), mode) 1073 util.set_exec(self.wjoin(f), mode)
1091 mark[f] = 1 1074 mark[f] = 1
1092 del m2[f] 1075 del m2[f]
1093 elif f in ma: 1076 elif f in ma:
1094 if not force and n != ma[f]: 1077 if not force and n != ma[f]:
1095 r = "" 1078 r = ""
1167 try: 1150 try:
1168 self.wfile(f, "w").write(t) 1151 self.wfile(f, "w").write(t)
1169 except IOError: 1152 except IOError:
1170 os.makedirs(os.path.dirname(self.wjoin(f))) 1153 os.makedirs(os.path.dirname(self.wjoin(f)))
1171 self.wfile(f, "w").write(t) 1154 self.wfile(f, "w").write(t)
1172 set_exec(self.wjoin(f), mf2[f]) 1155 util.set_exec(self.wjoin(f), mf2[f])
1173 self.dirstate.update([f], mode) 1156 self.dirstate.update([f], mode)
1174 1157
1175 # merge the tricky bits 1158 # merge the tricky bits
1176 files = merge.keys() 1159 files = merge.keys()
1177 files.sort() 1160 files.sort()
1178 for f in files: 1161 for f in files:
1179 self.ui.status("merging %s\n" % f) 1162 self.ui.status("merging %s\n" % f)
1180 m, o, flag = merge[f] 1163 m, o, flag = merge[f]
1181 self.merge3(f, m, o) 1164 self.merge3(f, m, o)
1182 set_exec(self.wjoin(f), flag) 1165 util.set_exec(self.wjoin(f), flag)
1183 self.dirstate.update([f], 'm') 1166 self.dirstate.update([f], 'm')
1184 1167
1185 for f in remove: 1168 for f in remove:
1186 self.ui.note("removing %s\n" % f) 1169 self.ui.note("removing %s\n" % f)
1187 os.unlink(f) 1170 os.unlink(f)