Changeset 304 in tailor


Ignore:
Timestamp:
05/18/05 17:17:43 (8 years ago)
Author:
rghetta <birrachiara@…>
Hash name:
20050518151743-2a8e2-9eb92aff73a452ba64d21bb7fb11ab0dc5f6fbc4
Message:

Use the new --message-file option of monotone
This patch make tailor use the new --message-file option of monotone,
avoiding the need to write directly into MT/log or quote the changelog
message.

In line with the other targets, the directory you give on tailor command
line needs to be a monotone working directory, i.e. it must have an MT
subdir.

Upstream changesets will be written into root/module (or root/subdir,
if you used the --subdir option). If you don't want this subdir, you
can use "--subdir=.". Unfortunately, not all source repos support
it. For example, CVS accepts --subdir=. on a local dir, but pserver
fails.

Important note: the current (0.19) release of monotone *doesn't*
support the --message-file option. Until 0.20 comes out you need to
compile monotone from sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/monotone.py

    r296 r304  
    1212__docformat__ = 'reStructuredText' 
    1313 
    14 from shwrap import SystemCommand, shrepr 
     14from shwrap import SystemCommand, shrepr, ReopenableNamedTemporaryFile 
    1515from source import UpdatableSourceWorkingDir, \ 
    1616     ChangesetApplicationFailure, GetUpstreamChangesetsFailure 
    1717from target import SyncronizableTargetWorkingDir, TargetInitializationFailure 
     18from sys import stderr 
    1819 
    1920class MonotoneCommit(SystemCommand): 
    20     COMMAND = "monotone commit --author=\"%(key)s\" --date=\"%(date)s\"" 
     21    COMMAND = "monotone commit --author=\"%(key)s\" --date=\"%(date)s\" --message-file=\"%(logfile)s\" 2>&1" 
    2122 
    2223    def __call__(self, output=None, dry_run=False, **kwargs): 
    2324 
    24         from os.path import exists, join 
    25  
    26         if not exists(join(self.working_dir, 'MT')): 
    27             # If MonotoneCommit is called outside the working copy 
    28             # (i.e. there is no MT directory) we test if we are given 
    29             # only the subdir as entry to commit. In that case, switch 
    30             # to root/subdir as working directory and issue a commit 
    31             # without any entries. 
    32              
    33             entries = kwargs['entries'] 
    34             entries = entries.replace(' ', '') 
    35             entries = entries.strip('\"') 
    36             if (exists(join(self.working_dir, entries))): 
    37                 self.working_dir = join(self.working_dir, entries) 
    38                 kwargs['entries'] = "" 
    39             else: 
    40                 raise TargetInitializationFailure("not a valid monotone working copy (MT directory is missing in %s)" % self.working_dir) 
    41  
    42         log = open(self.working_dir + "/MT/log", "w"); 
    43  
     25        # the log message is written on a temporary file 
     26        rontf = ReopenableNamedTemporaryFile('mtn', 'tailor') 
    4427        logmessage = kwargs.get('logmessage') 
    4528        if logmessage: 
    46             log.write(logmessage + "\n") 
    47  
    48         log.close(); 
     29            log = open(rontf.name, "w") 
     30            log.write(logmessage) 
     31            log.close()             
     32        kwargs['logfile'] = rontf.name 
    4933 
    5034        return SystemCommand.__call__(self, output=output, 
     
    8973            else: 
    9074                changelog = "**** empty log message ****" 
    91         changelog = changelog.replace('"', '\\"') 
    9275         
    93         # monotone date must be expressed as ISO8601  
     76        # monotone dates must be expressed as ISO8601  
    9477        outstr = c(output=True, key=author, logmessage=changelog, 
    9578                   date=date.isoformat(), entries=entries) 
     
    9982        if c.exit_status: 
    10083           if outstr.getvalue().find("monotone: misuse: no changes to commit") == -1: 
     84               stderr.write(outstr.getvalue()) 
    10185               outstr.close() 
    10286               raise TargetInitializationFailure( 
    10387                  "'monotone commit returned %s" % c.exit_status) 
     88           else: 
     89               stderr.write("No changes to commit - changeset ignored\n") 
     90              
    10491        outstr.close()       
    10592         
     
    131118 
    132119        from os.path import exists, join 
    133          
    134         if not exists(join(root, subdir, 'MT')): 
    135             raise TargetInitializationFailure("Please setup %s as a monotone working directory." % root) 
    136120 
    137         c = SystemCommand(working_dir=join(root, subdir), 
     121        if not exists(join(root, 'MT')): 
     122            raise TargetInitializationFailure("Please setup '%s' as a monotone working directory" % root) 
     123 
     124        c = SystemCommand(working_dir=root, 
    138125                          command="monotone add %(names)s") 
    139         c(names='.') 
     126        c(names=subdir) 
Note: See TracChangeset for help on using the changeset viewer.