Mercurial > evolve
comparison hgext/evolve.py @ 1729:8ed0266c58a3
evolve: removed redundant try/finally blocks
There were two todo's to remove the redundant try finally blocks.
Done that and also fixed the indentation afterwards.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 01 Sep 2016 04:38:56 +0530 |
parents | 192cdab2884e |
children | f4047fba5e90 |
comparison
equal
deleted
inserted
replaced
1728:f4b2617051ad | 1729:8ed0266c58a3 |
---|---|
962 'not be updated\n') % sha1) | 962 'not be updated\n') % sha1) |
963 | 963 |
964 tr = repo.currenttransaction() | 964 tr = repo.currenttransaction() |
965 assert tr is not None | 965 assert tr is not None |
966 try: | 966 try: |
967 try: | 967 r = _evolvemerge(repo, orig, dest, pctx, keepbranch) |
968 r = _evolvemerge(repo, orig, dest, pctx, keepbranch) | 968 if r[-1]: #some conflict |
969 if r[-1]: #some conflict | 969 raise error.Abort( |
970 raise error.Abort( | 970 'unresolved merge conflicts (see hg help resolve)') |
971 'unresolved merge conflicts (see hg help resolve)') | 971 nodenew = _relocatecommit(repo, orig, commitmsg) |
972 nodenew = _relocatecommit(repo, orig, commitmsg) | 972 except error.Abort as exc: |
973 except error.Abort as exc: | 973 repo.dirstate.beginparentchange() |
974 repo.dirstate.beginparentchange() | 974 repo.setparents(repo['.'].node(), nullid) |
975 repo.setparents(repo['.'].node(), nullid) | 975 writedirstate(repo.dirstate, tr) |
976 writedirstate(repo.dirstate, tr) | 976 # fix up dirstate for copies and renames |
977 # fix up dirstate for copies and renames | 977 copies.duplicatecopies(repo, dest.rev(), orig.p1().rev()) |
978 copies.duplicatecopies(repo, dest.rev(), orig.p1().rev()) | 978 repo.dirstate.endparentchange() |
979 repo.dirstate.endparentchange() | 979 class LocalMergeFailure(MergeFailure, exc.__class__): |
980 class LocalMergeFailure(MergeFailure, exc.__class__): | 980 pass |
981 pass | 981 exc.__class__ = LocalMergeFailure |
982 exc.__class__ = LocalMergeFailure | 982 tr.close() # to keep changes in this transaction (e.g. dirstate) |
983 tr.close() # to keep changes in this transaction (e.g. dirstate) | 983 raise |
984 raise | 984 oldbookmarks = repo.nodebookmarks(nodesrc) |
985 oldbookmarks = repo.nodebookmarks(nodesrc) | 985 _finalizerelocate(repo, orig, dest, nodenew, tr) |
986 _finalizerelocate(repo, orig, dest, nodenew, tr) | |
987 finally: | |
988 pass # TODO: remove this redundant try/finally block | |
989 return nodenew | 986 return nodenew |
990 | 987 |
991 def _bookmarksupdater(repo, oldid, tr): | 988 def _bookmarksupdater(repo, oldid, tr): |
992 """Return a callable update(newid) updating the current bookmark | 989 """Return a callable update(newid) updating the current bookmark |
993 and bookmarks bound to oldid to newid. | 990 and bookmarks bound to oldid to newid. |
1996 tmpctx = bumped | 1993 tmpctx = bumped |
1997 # Basic check for common parent. Far too complicated and fragile | 1994 # Basic check for common parent. Far too complicated and fragile |
1998 tr = repo.currenttransaction() | 1995 tr = repo.currenttransaction() |
1999 assert tr is not None | 1996 assert tr is not None |
2000 bmupdate = _bookmarksupdater(repo, bumped.node(), tr) | 1997 bmupdate = _bookmarksupdater(repo, bumped.node(), tr) |
2001 try: | 1998 if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)): |
2002 if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)): | 1999 # Need to rebase the changeset at the right place |
2003 # Need to rebase the changeset at the right place | 2000 repo.ui.status( |
2004 repo.ui.status( | 2001 _('rebasing to destination parent: %s\n') % prec.p1()) |
2005 _('rebasing to destination parent: %s\n') % prec.p1()) | 2002 try: |
2006 try: | 2003 tmpid = relocate(repo, bumped, prec.p1()) |
2007 tmpid = relocate(repo, bumped, prec.p1()) | 2004 if tmpid is not None: |
2008 if tmpid is not None: | 2005 tmpctx = repo[tmpid] |
2009 tmpctx = repo[tmpid] | 2006 obsolete.createmarkers(repo, [(bumped, (tmpctx,))]) |
2010 obsolete.createmarkers(repo, [(bumped, (tmpctx,))]) | 2007 except MergeFailure: |
2011 except MergeFailure: | 2008 repo.opener.write('graftstate', bumped.hex() + '\n') |
2012 repo.opener.write('graftstate', bumped.hex() + '\n') | 2009 repo.ui.write_err(_('evolution failed!\n')) |
2013 repo.ui.write_err(_('evolution failed!\n')) | 2010 repo.ui.write_err( |
2014 repo.ui.write_err( | 2011 _('fix conflict and run "hg evolve --continue"\n')) |
2015 _('fix conflict and run "hg evolve --continue"\n')) | 2012 raise |
2016 raise | 2013 # Create the new commit context |
2017 # Create the new commit context | 2014 repo.ui.status(_('computing new diff\n')) |
2018 repo.ui.status(_('computing new diff\n')) | 2015 files = set() |
2019 files = set() | 2016 copied = copies.pathcopies(prec, bumped) |
2020 copied = copies.pathcopies(prec, bumped) | 2017 precmanifest = prec.manifest() |
2021 precmanifest = prec.manifest() | 2018 # 3.3.2 needs a list. |
2022 # 3.3.2 needs a list. | 2019 # future 3.4 don't detect the size change during iteration |
2023 # future 3.4 don't detect the size change during iteration | 2020 # this is fishy |
2024 # this is fishy | 2021 for key, val in list(bumped.manifest().iteritems()): |
2025 for key, val in list(bumped.manifest().iteritems()): | 2022 precvalue = precmanifest.get(key, None) |
2026 precvalue = precmanifest.get(key, None) | 2023 if precvalue is not None: |
2027 if precvalue is not None: | 2024 del precmanifest[key] |
2028 del precmanifest[key] | 2025 if precvalue != val: |
2029 if precvalue != val: | 2026 files.add(key) |
2030 files.add(key) | 2027 files.update(precmanifest) # add missing files |
2031 files.update(precmanifest) # add missing files | 2028 # commit it |
2032 # commit it | 2029 if files: # something to commit! |
2033 if files: # something to commit! | 2030 def filectxfn(repo, ctx, path): |
2034 def filectxfn(repo, ctx, path): | 2031 if path in bumped: |
2035 if path in bumped: | 2032 fctx = bumped[path] |
2036 fctx = bumped[path] | 2033 flags = fctx.flags() |
2037 flags = fctx.flags() | 2034 mctx = memfilectx(repo, fctx.path(), fctx.data(), |
2038 mctx = memfilectx(repo, fctx.path(), fctx.data(), | 2035 islink='l' in flags, |
2039 islink='l' in flags, | 2036 isexec='x' in flags, |
2040 isexec='x' in flags, | 2037 copied=copied.get(path)) |
2041 copied=copied.get(path)) | 2038 return mctx |
2042 return mctx | 2039 return None |
2043 return None | 2040 text = 'bumped update to %s:\n\n' % prec |
2044 text = 'bumped update to %s:\n\n' % prec | 2041 text += bumped.description() |
2045 text += bumped.description() | 2042 |
2046 | 2043 new = context.memctx(repo, |
2047 new = context.memctx(repo, | 2044 parents=[prec.node(), node.nullid], |
2048 parents=[prec.node(), node.nullid], | 2045 text=text, |
2049 text=text, | 2046 files=files, |
2050 files=files, | 2047 filectxfn=filectxfn, |
2051 filectxfn=filectxfn, | 2048 user=bumped.user(), |
2052 user=bumped.user(), | 2049 date=bumped.date(), |
2053 date=bumped.date(), | 2050 extra=bumped.extra()) |
2054 extra=bumped.extra()) | 2051 |
2055 | 2052 newid = repo.commitctx(new) |
2056 newid = repo.commitctx(new) | 2053 if newid is None: |
2057 if newid is None: | 2054 obsolete.createmarkers(repo, [(tmpctx, ())]) |
2058 obsolete.createmarkers(repo, [(tmpctx, ())]) | 2055 newid = prec.node() |
2059 newid = prec.node() | 2056 else: |
2060 else: | 2057 phases.retractboundary(repo, tr, bumped.phase(), [newid]) |
2061 phases.retractboundary(repo, tr, bumped.phase(), [newid]) | 2058 obsolete.createmarkers(repo, [(tmpctx, (repo[newid],))], |
2062 obsolete.createmarkers(repo, [(tmpctx, (repo[newid],))], | 2059 flag=obsolete.bumpedfix) |
2063 flag=obsolete.bumpedfix) | 2060 bmupdate(newid) |
2064 bmupdate(newid) | 2061 repo.ui.status(_('committed as %s\n') % node.short(newid)) |
2065 repo.ui.status(_('committed as %s\n') % node.short(newid)) | |
2066 finally: | |
2067 pass # TODO: remove this redundant try/finally block | |
2068 # reroute the working copy parent to the new changeset | 2062 # reroute the working copy parent to the new changeset |
2069 repo.dirstate.beginparentchange() | 2063 repo.dirstate.beginparentchange() |
2070 repo.dirstate.setparents(newid, node.nullid) | 2064 repo.dirstate.setparents(newid, node.nullid) |
2071 repo.dirstate.endparentchange() | 2065 repo.dirstate.endparentchange() |
2072 | 2066 |