From: <sv...@ww...> - 2004-06-06 10:34:26
|
Author: mkrose Date: 2004-06-06 03:34:20 -0700 (Sun, 06 Jun 2004) New Revision: 1001 Modified: trunk/CSP/tools/subset Log: Add a few more svn commands to subset. Most are pass-throughs; revert also removes files from changesets. Modified: trunk/CSP/tools/subset =================================================================== --- trunk/CSP/tools/subset 2004-06-06 08:52:15 UTC (rev 1000) +++ trunk/CSP/tools/subset 2004-06-06 10:34:20 UTC (rev 1001) @@ -253,15 +253,18 @@ index[file.abspath()] = file return index - def removeFile(self, file): + def removeFileByPath(self, abspath): index = self._fileIndex() - abspath = file.abspath() file = index.get(abspath, None) if not file: return Error('file not found in changeset %s' % self._name) self._files.remove(file) return Result(file) + def removeFile(self, file): + abspath = file.abspath() + return self.removeFileByPath(abspath) + def addFile(self, file): index = self._fileIndex() abspath = file.abspath() @@ -300,6 +303,7 @@ self._files = {} if not rootsvn: rootsvn = sublib.svn_rootsvn() self._load(rootsvn) + self.cleanup() def _load(self, rootsvn): ws = os.path.join(rootsvn, '.workspace') @@ -329,6 +333,20 @@ abspath = file.abspath() return not self._files.has_key(abspath) + def cleanup(self): + filemap = {} + for file in sublib.svn_st(): + filemap[file.abspath()] = file + items = self._files.items() + changed = 0 + for path, set in items: + if not filemap.has_key(path): + result = set.removeFileByPath(path) + assert result.ok + del self._files[path] + changed = 1 + if changed: self.save() + def assign(self, name, files): if name == 'default': dest = None @@ -340,10 +358,14 @@ if not files: return Error('no files found') for file in files: - set = self._files.get(file.abspath(), None) + abspath = file.abspath() + set = self._files.get(abspath, None) if set: set.removeFile(file) - if dest: dest.addFile(file) + del self._files[abspath] + if dest: + dest.addFile(file) + self._files[abspath] = dest self.save() return Result(0) @@ -664,13 +686,24 @@ class SVNCommand(Command): + def _svn(self, command, args): + paths = os.environ.get('PATH', '') + for path in paths.split(os.pathsep): + path = os.path.join(path, 'svn') + if os.path.exists(path): break + path = '' + if not path: return Error('svn not found') + code = os.spawnv(os.P_WAIT, path, ['svn', command] + args) + if code: return Error('svn failed') + return Result(0) + def _start(self, args): command = self._keys[0] - os.execvp('svn', ['svn', command] + args) + return self._svn(command, args) def help(self): command = self._keys[0] - os.execvp('svn', ['svn', 'help', command]) + return self._svn(command, 'help', (command,)) class Blame(SVNCommand): @@ -709,6 +742,49 @@ self._short = 'output the content of specified files or URLs' +class Add(SVNCommand): + def _define(self): + self._addKeys('add') + self._short = 'put files and directories under version control' + + +class Delete(SVNCommand): + def _define(self): + self._addKeys('delete', 'remove', 'rm') + self._short = 'remove files and directories from version control' + + +class Mkdir(SVNCommand): + def _define(self): + self._addKeys('mkdir') + self._short = 'create a new directory under version control' + + +class Copy(SVNCommand): + def _define(self): + self._addKeys('copy', 'cp') + self._short = 'duplicate something in working copy or repos, with history' + + +class Update(SVNCommand): + def _define(self): + self._addKeys('update', 'up', 'sync') + self._short = 'bring changes from the repository into the working copy' + + +class Revert(SVNCommand): + + def _define(self): + self._addKeys('revert') + self._short = 'restore pristine working copy file' + + def _start(self, args): + result = SVNCommand._start(self, args) + if result.ok: + return run('cleanup') + return result + + class Opened(Command): def _define(self): @@ -946,12 +1022,18 @@ Submit() # svn subcommands +Add() Blame() Cat() +Copy() +Delete() Info() List() Log() +Mkdir() +Revert() Status() +Update() def main(args): |