# HG changeset patch # User Thomas Arendsen Hein # Date 2011-10-16 09:28:03 # Node ID 01860816029920a4b725001bedc1bba3abafff46 # Parent 2ed335669e186192ddcd735984c7829b3f4203c0 largefiles: use separate try/except and try/finally as needed for python2.4 cfccd3bee7b3 introduced a try/except/finally block, which breaks compatibility with python2.4 diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py --- a/hgext/largefiles/overrides.py +++ b/hgext/largefiles/overrides.py @@ -320,14 +320,15 @@ def override_copy(orig, ui, repo, pats, nonormalfiles = False nolfiles = False try: - installnormalfilesmatchfn(repo[None].manifest()) - result = orig(ui, repo, pats, opts, rename) - except util.Abort, e: - if str(e) != 'no files to copy': - raise e - else: - nonormalfiles = True - result = 0 + try: + installnormalfilesmatchfn(repo[None].manifest()) + result = orig(ui, repo, pats, opts, rename) + except util.Abort, e: + if str(e) != 'no files to copy': + raise e + else: + nonormalfiles = True + result = 0 finally: restorematchfn() @@ -339,80 +340,81 @@ def override_copy(orig, ui, repo, pats, return result try: - # When we call orig below it creates the standins but we don't add them - # to the dir state until later so lock during that time. - wlock = repo.wlock() + try: + # When we call orig below it creates the standins but we don't add them + # to the dir state until later so lock during that time. + wlock = repo.wlock() - manifest = repo[None].manifest() - oldmatch = None # for the closure - def override_match(repo, pats=[], opts={}, globbed=False, - default='relpath'): - newpats = [] - # The patterns were previously mangled to add the standin - # directory; we need to remove that now + manifest = repo[None].manifest() + oldmatch = None # for the closure + def override_match(repo, pats=[], opts={}, globbed=False, + default='relpath'): + newpats = [] + # The patterns were previously mangled to add the standin + # directory; we need to remove that now + for pat in pats: + if match_.patkind(pat) is None and lfutil.shortname in pat: + newpats.append(pat.replace(lfutil.shortname, '')) + else: + newpats.append(pat) + match = oldmatch(repo, newpats, opts, globbed, default) + m = copy.copy(match) + lfile = lambda f: lfutil.standin(f) in manifest + m._files = [lfutil.standin(f) for f in m._files if lfile(f)] + m._fmap = set(m._files) + orig_matchfn = m.matchfn + m.matchfn = lambda f: (lfutil.isstandin(f) and + lfile(lfutil.splitstandin(f)) and + orig_matchfn(lfutil.splitstandin(f)) or + None) + return m + oldmatch = installmatchfn(override_match) + listpats = [] for pat in pats: - if match_.patkind(pat) is None and lfutil.shortname in pat: - newpats.append(pat.replace(lfutil.shortname, '')) + if match_.patkind(pat) is not None: + listpats.append(pat) else: - newpats.append(pat) - match = oldmatch(repo, newpats, opts, globbed, default) - m = copy.copy(match) - lfile = lambda f: lfutil.standin(f) in manifest - m._files = [lfutil.standin(f) for f in m._files if lfile(f)] - m._fmap = set(m._files) - orig_matchfn = m.matchfn - m.matchfn = lambda f: (lfutil.isstandin(f) and - lfile(lfutil.splitstandin(f)) and - orig_matchfn(lfutil.splitstandin(f)) or - None) - return m - oldmatch = installmatchfn(override_match) - listpats = [] - for pat in pats: - if match_.patkind(pat) is not None: - listpats.append(pat) - else: - listpats.append(makestandin(pat)) + listpats.append(makestandin(pat)) - try: - origcopyfile = util.copyfile - copiedfiles = [] - def override_copyfile(src, dest): - if lfutil.shortname in src and lfutil.shortname in dest: - destlfile = dest.replace(lfutil.shortname, '') - if not opts['force'] and os.path.exists(destlfile): - raise IOError('', - _('destination largefile already exists')) - copiedfiles.append((src, dest)) - origcopyfile(src, dest) + try: + origcopyfile = util.copyfile + copiedfiles = [] + def override_copyfile(src, dest): + if lfutil.shortname in src and lfutil.shortname in dest: + destlfile = dest.replace(lfutil.shortname, '') + if not opts['force'] and os.path.exists(destlfile): + raise IOError('', + _('destination largefile already exists')) + copiedfiles.append((src, dest)) + origcopyfile(src, dest) - util.copyfile = override_copyfile - result += orig(ui, repo, listpats, opts, rename) - finally: - util.copyfile = origcopyfile + util.copyfile = override_copyfile + result += orig(ui, repo, listpats, opts, rename) + finally: + util.copyfile = origcopyfile - lfdirstate = lfutil.openlfdirstate(ui, repo) - for (src, dest) in copiedfiles: - if lfutil.shortname in src and lfutil.shortname in dest: - srclfile = src.replace(lfutil.shortname, '') - destlfile = dest.replace(lfutil.shortname, '') - destlfiledir = os.path.dirname(destlfile) or '.' - if not os.path.isdir(destlfiledir): - os.makedirs(destlfiledir) - if rename: - os.rename(srclfile, destlfile) - lfdirstate.remove(os.path.relpath(srclfile, + lfdirstate = lfutil.openlfdirstate(ui, repo) + for (src, dest) in copiedfiles: + if lfutil.shortname in src and lfutil.shortname in dest: + srclfile = src.replace(lfutil.shortname, '') + destlfile = dest.replace(lfutil.shortname, '') + destlfiledir = os.path.dirname(destlfile) or '.' + if not os.path.isdir(destlfiledir): + os.makedirs(destlfiledir) + if rename: + os.rename(srclfile, destlfile) + lfdirstate.remove(os.path.relpath(srclfile, + repo.root)) + else: + util.copyfile(srclfile, destlfile) + lfdirstate.add(os.path.relpath(destlfile, repo.root)) - else: - util.copyfile(srclfile, destlfile) - lfdirstate.add(os.path.relpath(destlfile, - repo.root)) - lfdirstate.write() - except util.Abort, e: - if str(e) != 'no files to copy': - raise e - else: - nolfiles = True + lfdirstate.write() + except util.Abort, e: + if str(e) != 'no files to copy': + raise e + else: + nolfiles = True finally: restorematchfn() wlock.release()