Changeset 574 in tailor


Ignore:
Timestamp:
08/15/05 18:03:09 (8 years ago)
Author:
lele@…
Hash name:
20050815160309-97f81-ac9cfbf1dc765959bbdd54a7e0fda198db15e313
Message:

Revised the applyPendingChangesets() to save the state only once
The method was rewriting the state file at each iteration over the
pending changesets, very safe but also very time expensive. Now it
does that just once, before leaving.

Also, introduced a new _handleConflict() that subclasses may override
to prompt the user about conflict raised by application of a changeset.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/source.py

    r573 r574  
    8686            return last, conflicts 
    8787 
    88         remaining = self.pending[:] 
    89         for c in self.pending: 
    90             if not self._willApplyChangeset(c, applyable): 
    91                 break 
    92  
    93             self.log_info("Applying changeset %s" % c.revision) 
    94  
    95             try: 
    96                 res = self._applyChangeset(c) 
    97             except: 
    98                 self.log_error("Couldn't apply changeset %s" % c.revision, 
    99                                exc=True) 
    100                 raise 
    101  
    102             if res: 
    103                 conflicts.append((c, res)) 
     88        try: 
     89            while self.pending: 
     90                c = self.pending[0] 
     91 
     92                # Give the opportunity to subclasses to stop the application 
     93                # of the queue, before the application of the patch by the 
     94                # source backend. 
     95                if not self._willApplyChangeset(c, applyable): 
     96                    break 
     97 
     98                self.log_info("Applying changeset %s" % c.revision) 
     99 
    104100                try: 
    105                     raw_input(CONFLICTS_PROMPT % (str(c), '\n * '.join(res))) 
    106                 except KeyboardInterrupt: 
    107                     self.log_info("INTERRUPTED BY THE USER!") 
    108                     return last, conflicts 
    109  
    110             if not self._didApplyChangeset(c, replayable): 
    111                 continue 
    112  
    113             if replay: 
    114                 replay(c) 
    115  
    116             remaining.remove(c) 
    117             self.state_file.write(c.revision, remaining) 
    118  
    119             if applied: 
    120                 applied(c) 
    121  
    122             last = c 
    123  
    124         self.pending = remaining 
     101                    res = self._applyChangeset(c) 
     102                except: 
     103                    self.log_error("Couldn't apply changeset %s" % c.revision, 
     104                                   exc=True) 
     105                    raise 
     106 
     107                if res: 
     108                    # Uh, we have a conflict: this should not ever 
     109                    # happen, but the user may have manually tweaked 
     110                    # the working directory. Give her a chance of 
     111                    # fixing the situation, or abort with Ctrl-C, or 
     112                    # whatever the subclasses decide. 
     113                    try: 
     114                        self._handleConflict(c, conflicts, res) 
     115                    except KeyboardInterrupt: 
     116                        self.log_info("INTERRUPTED BY THE USER!") 
     117                        break 
     118 
     119                # Give the opportunity to subclasses to skip the commit on 
     120                # the target backend. 
     121                if self._didApplyChangeset(c, replayable): 
     122                    if replay: 
     123                        replay(c) 
     124 
     125                # Remove it from the queue and remember it for the finally 
     126                # clause 
     127                last = self.pending.pop(0) 
     128 
     129                # Another hook (last==c here) 
     130                if applied: 
     131                    applied(last) 
     132        finally: 
     133            # For whatever reason we exit the loop, save the last state 
     134            self.state_file.write(last.revision, self.pending) 
     135 
    125136        return last, conflicts 
    126137 
     
    154165            return True 
    155166 
     167    def _handleConflict(self, changeset, conflicts, conflict): 
     168        """ 
     169        Handle the conflict raised by the application of the upstream changeset. 
     170 
     171        This implementation just append a (changeset, conflict) to the 
     172        list of all conflicts, and present a prompt to the user that 
     173        may abort with Ctrl-C (that in turn generates a KeyboardInterrupt). 
     174        """ 
     175 
     176        conflicts.append((changeset, conflict)) 
     177        raw_input(CONFLICTS_PROMPT % (str(changeset), '\n * '.join(conflict))) 
     178 
    156179    def getPendingChangesets(self, sincerev=None): 
    157180        """ 
Note: See TracChangeset for help on using the changeset viewer.