Changeset 10 in tailor


Ignore:
Timestamp:
06/04/04 01:52:49 (9 years ago)
Author:
lele@…
Hash name:
20040603235249-97f81-63a5499dd42daeded7553f33fa8d1ddeebf5049d
Message:

Preliminary support for darcs in cvsync

Location:
cvsync
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • cvsync/svn.py

    r9 r10  
    1717 
    1818from shwrap import SystemCommand 
     19from target import SyncronizableTargetWorkingDir 
    1920 
    2021class SvnUpdate(SystemCommand): 
     
    2324 
    2425class SvnCommit(SystemCommand): 
    25     COMMAND = "svn commit --quiet %(message)s %(logfile)s %(entry)s" 
     26    COMMAND = "svn commit --quiet %(logfile)s %(entry)s" 
    2627 
    2728    def __call__(self, output=None, dry_run=False, **kwargs): 
    2829        logfile = kwargs.get('logfile') 
    29         if logfile: 
    30             kwargs['logfile'] = '--file %s' % logfile 
    31         else: 
    32             kwargs['logfile'] = '' 
    33  
    34             message = kwargs.get('message') 
    35             if message: 
    36                 kwargs['message'] = '--message %s' % repr(message) 
    37             else: 
    38                 kwargs['message'] = '' 
     30        if not logfile: 
     31            from tempfile import NamedTemporaryFile 
     32 
     33            log = NamedTemporaryFile(bufsize=0) 
     34            logmessage = kwargs.get('logmessage') 
     35            if logmessage: 
     36                print >>log, logmessage 
     37             
     38            kwargs['logfile'] = log.name 
    3939         
    4040        return SystemCommand.__call__(self, output=output, 
     
    159159 
    160160 
    161 class SvnWorkingDir(object): 
     161class SvnWorkingDir(SyncronizableTargetWorkingDir): 
    162162    """Represent a SVN working directory.""" 
    163  
    164     __slots__ = ('root',) 
    165  
    166     def __init__(self, root): 
    167         """Initialize a SvnWorkingDir instance.""" 
    168          
    169         self.root = root 
    170         """The directory in question.""" 
    171163 
    172164    def _makeabs(self, mayberel): 
     
    227219                    else: 
    228220                        self.current_path_action = attributes['action'] 
    229                          
    230221 
    231222            def endElement(self, name): 
     
    267258        return result 
    268259     
    269     def commit(self, logfile=None, message=None): 
     260    def commit(self, remark, changelog): 
    270261        """Commit the changes.""" 
    271262 
    272263        svnci = SvnCommit() 
    273         svnci(logfile=logfile, message=message, entry=repr(self.root)) 
     264        svnci(logmessage='\n\n'.join([remark,changelog]), 
     265              entry=repr(self.root)) 
    274266        return svnci.exit_status 
    275267 
  • cvsync/sync.py

    r1 r10  
    2929from optparse import OptionParser, make_option 
    3030from cvsync.cvs import CvsWorkingDir, CvsUpdateError, CvsLogError 
    31 from cvsync.svn import SvnWorkingDir 
    3231 
    3332LOG_MESSAGE_FILE_NAME = 'cvsync.log.message' 
     
    4241PRE_COMMIT_PROMPT = """\ 
    4342I'm about to commit. You can suspend (Ctrl-Z) the session 
    44 to inspect the working copy status and edit the log message 
    45 in "%s", or cancel (Ctrl-C) it.""" 
     43to inspect the working copy status or abort (Ctrl-C) it.""" 
    4644 
    4745CONFIRM_REPLAY_PROMPT = """\ 
     
    5048Hit Ctrl-C now if that is not what you intended, and remove the file.""" 
    5149 
    52 class Syncronizer(object): 
     50class AbstractSyncronizer(object): 
    5351    """Perform the needed steps to syncronize CVS world with SVN.""" 
    5452     
     
    5957        """The directory under both CVS and SVN version control.""" 
    6058         
    61         self.cvs_wc = CvsWorkingDir(self.root) 
     59        self.source_wc = CvsWorkingDir(self.root) 
    6260        """The CVS point-of-view.""" 
    63          
    64         self.svn_wc = SvnWorkingDir(self.root) 
    65         """The SVN point-of-view.""" 
     61 
     62        self.target_wc = None 
     63        """The target VC engine.""" 
     64         
     65        self.setTargetWC() 
     66 
     67    def setTargetWC(self): 
     68        """The target VC engine.""" 
     69 
     70        raise "This MUST be overridden by subclasses."         
    6671 
    6772    def __call__(self, options): 
     
    8893            # Bring the svnwc up-to-date 
    8994            if options.svn_update: 
    90                 self.svn_wc.update() 
     95                self.target_wc.update() 
    9196             
    9297        # Do a cvs update and collect the changes 
    9398        try: 
    94             changes = self.cvs_wc.update(options=options, 
    95                                          prevlog=prevlog) 
     99            changes = self.source_wc.update(options=options, 
     100                                            prevlog=prevlog) 
    96101        except CvsUpdateError, e: 
    97102            print "Gasp!  Underlying CVS update command failed: ", e 
     
    128133                print "I left the logs and the cache, for debug." 
    129134                 
    130         if options.changelog: 
    131             logname = LOG_MESSAGE_FILE_NAME 
    132             changelog = open(logname, 'w') 
    133             changelog.write(str(changes)) 
    134             changelog.close() 
    135         else: 
    136             logname = None 
    137              
    138         if self.cvs_wc.conflicts or options.dry_run: 
    139             if self.cvs_wc.conflicts: 
     135        if self.source_wc.conflicts or options.dry_run: 
     136            if self.source_wc.conflicts: 
    140137                print "CAUTION: the CVS update reported a few conflicts:" 
    141                 print ' -', '\n - '.join(self.cvs_wc.conflicts) 
     138                print ' -', '\n - '.join(self.source_wc.conflicts) 
    142139                print 
    143140                 
    144             if self.cvs_wc.obstructing: 
     141            if self.source_wc.obstructing: 
    145142                print "Some of the conflicts are due to files that are already" 
    146143                print "there, but are not under revision control, yet:" 
    147144 
    148                 print ' -', '\n -'.join(self.cvs_wc.obstructing) 
     145                print ' -', '\n -'.join(self.source_wc.obstructing) 
    149146                print 
    150147                 
    151148                print "You should remove them, otherwise CVS will refuse to update them.\n" 
    152149                 
    153             if self.cvs_wc.added: 
     150            if self.source_wc.added: 
    154151                print "Some files were added and need to be registered with:" 
    155                 print "  svn add %s" % ' '.join(self.cvs_wc.added) 
    156             if self.cvs_wc.removed: 
     152                print "  svn add %s" % ' '.join(self.source_wc.added) 
     153            if self.source_wc.removed: 
    157154                print "You should unregister removed files with:" 
    158                 print "  svn remove %s" % ' '.join(self.cvs_wc.removed) 
     155                print "  svn remove %s" % ' '.join(self.source_wc.removed) 
    159156 
    160157            if options.changelog: 
    161158                if not options.dry_run: 
     159                    logname = LOG_MESSAGE_FILE_NAME 
     160                    changelog = open(logname, 'w') 
     161                    changelog.write(str(changes)) 
     162                    changelog.close() 
     163 
    162164                    print "I left the ChangeLog in %s." % logname 
    163165                    print "Once solved the conflicts, issue:" 
     
    166168                    print changes 
    167169        else: 
    168             added, removed = self.cvs_wc.compareDirectories() 
     170            added, removed = self.source_wc.compareDirectories() 
    169171            print 
    170172             
    171             added.extend(self.cvs_wc.added) 
    172             removed.extend(self.cvs_wc.removed) 
     173            added.extend(self.source_wc.added) 
     174            removed.extend(self.source_wc.removed) 
    173175             
    174176            for a in added: 
    175                 self.svn_wc.add(a) 
     177                self.target_wc.add(a) 
    176178 
    177179            for r in removed: 
    178                 self.svn_wc.remove(r) 
     180                self.target_wc.remove(r) 
    179181 
    180182            if options.commit: 
    181183                try: 
    182                     raw_input(PRE_COMMIT_PROMPT % logname) 
    183  
    184                     status = self.svn_wc.commit(logfile=logname, 
    185                                                 message=options.message) 
     184                    raw_input(PRE_COMMIT_PROMPT) 
     185 
     186                    status = self.target_wc.commit( 
     187                        options.message or "Upstream changes", changes) 
    186188 
    187189                    if not status: 
     
    201203                print "  svn ci --file %s" % logname 
    202204 
     205 
     206class SyncronizerForSubversion(AbstractSyncronizer): 
     207    """Specialize the syncronizer for Subversion.""" 
     208 
     209    def setTargetWC(self): 
     210        from cvsync.svn import SvnWorkingDir 
     211         
     212        self.target_wc = SvnWorkingDir(self.root) 
     213 
     214 
     215class SyncronizerForDarcs(AbstractSyncronizer): 
     216    """Specialize the syncronizer for Darcs.""" 
     217     
     218    def setTargetWC(self): 
     219        from cvsync.darcs import DarcsWorkingDir 
     220         
     221        self.target_wc = DarcsWorkingDir(self.root) 
     222 
     223 
    203224OPTIONS = [ 
    204225    make_option("-d", "--dry-run", dest="dry_run", 
     
    220241                default="", 
    221242                help="Commit message, when using --no-changelog."), 
     243    make_option("--darcs", action="store_true", default=False, 
     244                help="Target is darcs instead of subversion."), 
    222245    make_option("-u", "--no-svn-update", dest="svn_update", 
    223246                action="store_false", default=True, 
     
    256279        print "export CVS_RSH=ssh" 
    257280        environ['CVS_RSH'] = 'ssh' 
     281 
     282    if options.darcs: 
     283        Syncronizer = SyncronizerForDarcs 
     284    else: 
     285        Syncronizer = SyncronizerForSubversion 
    258286         
    259287    base = getcwd() 
  • cvsync/darcs.py

    r7 r10  
    1515 
    1616from shwrap import SystemCommand 
     17from target import SyncronizableTargetWorkingDir 
    1718 
    1819AUTHOR = "tailor@localhost" 
    1920 
     21 
    2022class DarcsInitialize(SystemCommand): 
    2123    COMMAND = "darcs initialize" 
     24 
    2225 
    2326class DarcsRecord(SystemCommand): 
     
    4245                                      **kwargs) 
    4346 
     47 
    4448class DarcsMv(SystemCommand): 
    4549    COMMAND = "darcs mv %(old)s %(new)s" 
     50 
    4651 
    4752class DarcsRemove(SystemCommand): 
    4853    COMMAND = "darcs remove %(entry)s" 
    4954 
     55 
    5056class DarcsAdd(SystemCommand): 
    5157    COMMAND = "darcs add %(entry)s" 
    52      
    53 class DarcsWorkingDir(object): 
     58 
     59 
     60class DarcsWorkingDir(SyncronizableTargetWorkingDir): 
    5461    """Represent a Darcs working directory.""" 
    55  
    56     __slots__ = ('root',) 
    57  
    58     def __init__(self, root): 
    59         """Initialize a DarcsWorkingDir instance.""" 
    60          
    61         self.root = root 
    62         """The directory in question.""" 
    6362 
    6463    def initialize(self): 
     
    6867        di(output=True) 
    6968         
    70     def record(self, patchname, logmessage=None): 
     69    def commit(self, remark, changelog): 
    7170        """Record current changes in a darcs patch.""" 
    7271 
    7372        drec = DarcsRecord(working_dir=self.root) 
    74         drec(output=True, patchname=patchname, logmessage=logmessage) 
     73        drec(output=True, patchname=remark, logmessage=changelog) 
    7574 
    7675    def rename(self, old, new): 
    7776        """Rename something named old to new.""" 
    78          
    79         # strip initial '/' 
    80         old = old[1:] 
    81         new = new[1:] 
    8277         
    8378        dvm = DarcsMv(working_dir=self.root) 
     
    8782        """Remove an entry from the darcs repos.""" 
    8883         
    89         # strip initial '/' 
    90         entry = entry[1:] 
    91  
    9284        drm = DarcsRemove(working_dir=self.root) 
    9385        drm(entry=entry) 
     
    9688        """Add a new entry to the darcs repos.""" 
    9789         
    98         # strip initial '/' 
    99         entry = entry[1:] 
    100  
    10190        dadd = DarcsAdd(working_dir=self.root) 
    10291        dadd(entry=entry) 
    10392         
     93    def update(self, revision): 
     94        """No op for darcs.""" 
     95 
     96        pass 
     97     
Note: See TracChangeset for help on using the changeset viewer.