Changeset 10 in tailor
- Timestamp:
- 06/04/04 01:52:49 (9 years ago)
- Hash name:
- 20040603235249-97f81-63a5499dd42daeded7553f33fa8d1ddeebf5049d
- Location:
- cvsync
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cvsync/svn.py
r9 r10 17 17 18 18 from shwrap import SystemCommand 19 from target import SyncronizableTargetWorkingDir 19 20 20 21 class SvnUpdate(SystemCommand): … … 23 24 24 25 class SvnCommit(SystemCommand): 25 COMMAND = "svn commit --quiet %( message)s %(logfile)s %(entry)s"26 COMMAND = "svn commit --quiet %(logfile)s %(entry)s" 26 27 27 28 def __call__(self, output=None, dry_run=False, **kwargs): 28 29 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 39 39 40 40 return SystemCommand.__call__(self, output=output, … … 159 159 160 160 161 class SvnWorkingDir( object):161 class SvnWorkingDir(SyncronizableTargetWorkingDir): 162 162 """Represent a SVN working directory.""" 163 164 __slots__ = ('root',)165 166 def __init__(self, root):167 """Initialize a SvnWorkingDir instance."""168 169 self.root = root170 """The directory in question."""171 163 172 164 def _makeabs(self, mayberel): … … 227 219 else: 228 220 self.current_path_action = attributes['action'] 229 230 221 231 222 def endElement(self, name): … … 267 258 return result 268 259 269 def commit(self, logfile=None, message=None):260 def commit(self, remark, changelog): 270 261 """Commit the changes.""" 271 262 272 263 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)) 274 266 return svnci.exit_status 275 267 -
cvsync/sync.py
r1 r10 29 29 from optparse import OptionParser, make_option 30 30 from cvsync.cvs import CvsWorkingDir, CvsUpdateError, CvsLogError 31 from cvsync.svn import SvnWorkingDir32 31 33 32 LOG_MESSAGE_FILE_NAME = 'cvsync.log.message' … … 42 41 PRE_COMMIT_PROMPT = """\ 43 42 I'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.""" 43 to inspect the working copy status or abort (Ctrl-C) it.""" 46 44 47 45 CONFIRM_REPLAY_PROMPT = """\ … … 50 48 Hit Ctrl-C now if that is not what you intended, and remove the file.""" 51 49 52 class Syncronizer(object):50 class AbstractSyncronizer(object): 53 51 """Perform the needed steps to syncronize CVS world with SVN.""" 54 52 … … 59 57 """The directory under both CVS and SVN version control.""" 60 58 61 self. cvs_wc = CvsWorkingDir(self.root)59 self.source_wc = CvsWorkingDir(self.root) 62 60 """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." 66 71 67 72 def __call__(self, options): … … 88 93 # Bring the svnwc up-to-date 89 94 if options.svn_update: 90 self. svn_wc.update()95 self.target_wc.update() 91 96 92 97 # Do a cvs update and collect the changes 93 98 try: 94 changes = self. cvs_wc.update(options=options,95 prevlog=prevlog)99 changes = self.source_wc.update(options=options, 100 prevlog=prevlog) 96 101 except CvsUpdateError, e: 97 102 print "Gasp! Underlying CVS update command failed: ", e … … 128 133 print "I left the logs and the cache, for debug." 129 134 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: 140 137 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) 142 139 print 143 140 144 if self. cvs_wc.obstructing:141 if self.source_wc.obstructing: 145 142 print "Some of the conflicts are due to files that are already" 146 143 print "there, but are not under revision control, yet:" 147 144 148 print ' -', '\n -'.join(self. cvs_wc.obstructing)145 print ' -', '\n -'.join(self.source_wc.obstructing) 149 146 print 150 147 151 148 print "You should remove them, otherwise CVS will refuse to update them.\n" 152 149 153 if self. cvs_wc.added:150 if self.source_wc.added: 154 151 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: 157 154 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) 159 156 160 157 if options.changelog: 161 158 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 162 164 print "I left the ChangeLog in %s." % logname 163 165 print "Once solved the conflicts, issue:" … … 166 168 print changes 167 169 else: 168 added, removed = self. cvs_wc.compareDirectories()170 added, removed = self.source_wc.compareDirectories() 169 171 print 170 172 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) 173 175 174 176 for a in added: 175 self. svn_wc.add(a)177 self.target_wc.add(a) 176 178 177 179 for r in removed: 178 self. svn_wc.remove(r)180 self.target_wc.remove(r) 179 181 180 182 if options.commit: 181 183 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) 186 188 187 189 if not status: … … 201 203 print " svn ci --file %s" % logname 202 204 205 206 class 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 215 class 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 203 224 OPTIONS = [ 204 225 make_option("-d", "--dry-run", dest="dry_run", … … 220 241 default="", 221 242 help="Commit message, when using --no-changelog."), 243 make_option("--darcs", action="store_true", default=False, 244 help="Target is darcs instead of subversion."), 222 245 make_option("-u", "--no-svn-update", dest="svn_update", 223 246 action="store_false", default=True, … … 256 279 print "export CVS_RSH=ssh" 257 280 environ['CVS_RSH'] = 'ssh' 281 282 if options.darcs: 283 Syncronizer = SyncronizerForDarcs 284 else: 285 Syncronizer = SyncronizerForSubversion 258 286 259 287 base = getcwd() -
cvsync/darcs.py
r7 r10 15 15 16 16 from shwrap import SystemCommand 17 from target import SyncronizableTargetWorkingDir 17 18 18 19 AUTHOR = "tailor@localhost" 19 20 21 20 22 class DarcsInitialize(SystemCommand): 21 23 COMMAND = "darcs initialize" 24 22 25 23 26 class DarcsRecord(SystemCommand): … … 42 45 **kwargs) 43 46 47 44 48 class DarcsMv(SystemCommand): 45 49 COMMAND = "darcs mv %(old)s %(new)s" 50 46 51 47 52 class DarcsRemove(SystemCommand): 48 53 COMMAND = "darcs remove %(entry)s" 49 54 55 50 56 class DarcsAdd(SystemCommand): 51 57 COMMAND = "darcs add %(entry)s" 52 53 class DarcsWorkingDir(object): 58 59 60 class DarcsWorkingDir(SyncronizableTargetWorkingDir): 54 61 """Represent a Darcs working directory.""" 55 56 __slots__ = ('root',)57 58 def __init__(self, root):59 """Initialize a DarcsWorkingDir instance."""60 61 self.root = root62 """The directory in question."""63 62 64 63 def initialize(self): … … 68 67 di(output=True) 69 68 70 def record(self, patchname, logmessage=None):69 def commit(self, remark, changelog): 71 70 """Record current changes in a darcs patch.""" 72 71 73 72 drec = DarcsRecord(working_dir=self.root) 74 drec(output=True, patchname= patchname, logmessage=logmessage)73 drec(output=True, patchname=remark, logmessage=changelog) 75 74 76 75 def rename(self, old, new): 77 76 """Rename something named old to new.""" 78 79 # strip initial '/'80 old = old[1:]81 new = new[1:]82 77 83 78 dvm = DarcsMv(working_dir=self.root) … … 87 82 """Remove an entry from the darcs repos.""" 88 83 89 # strip initial '/'90 entry = entry[1:]91 92 84 drm = DarcsRemove(working_dir=self.root) 93 85 drm(entry=entry) … … 96 88 """Add a new entry to the darcs repos.""" 97 89 98 # strip initial '/'99 entry = entry[1:]100 101 90 dadd = DarcsAdd(working_dir=self.root) 102 91 dadd(entry=entry) 103 92 93 def update(self, revision): 94 """No op for darcs.""" 95 96 pass 97
Note: See TracChangeset
for help on using the changeset viewer.
