hgext/convert/cvs.py
changeset 10282 08a0f04b56bd
parent 10263 25e572394f5c
child 10800 49c109d037dd
equal deleted inserted replaced
10281:e7d3b509af8b 10282:08a0f04b56bd
    44             # TODO: handle tags
    44             # TODO: handle tags
    45             try:
    45             try:
    46                 # patchset number?
    46                 # patchset number?
    47                 maxrev = int(self.rev)
    47                 maxrev = int(self.rev)
    48             except ValueError:
    48             except ValueError:
    49                 raise util.Abort(_('revision %s is not a patchset number') % self.rev)
    49                 raise util.Abort(_('revision %s is not a patchset number')
       
    50                                  % self.rev)
    50 
    51 
    51         d = os.getcwd()
    52         d = os.getcwd()
    52         try:
    53         try:
    53             os.chdir(self.path)
    54             os.chdir(self.path)
    54             id = None
    55             id = None
    63                 fuzz=int(self.ui.config('convert', 'cvsps.fuzz', 60)),
    64                 fuzz=int(self.ui.config('convert', 'cvsps.fuzz', 60)),
    64                 mergeto=self.ui.config('convert', 'cvsps.mergeto', None),
    65                 mergeto=self.ui.config('convert', 'cvsps.mergeto', None),
    65                 mergefrom=self.ui.config('convert', 'cvsps.mergefrom', None))
    66                 mergefrom=self.ui.config('convert', 'cvsps.mergefrom', None))
    66 
    67 
    67             for cs in db:
    68             for cs in db:
    68                 if maxrev and cs.id>maxrev:
    69                 if maxrev and cs.id > maxrev:
    69                     break
    70                     break
    70                 id = str(cs.id)
    71                 id = str(cs.id)
    71                 cs.author = self.recode(cs.author)
    72                 cs.author = self.recode(cs.author)
    72                 self.lastbranch[cs.branch] = id
    73                 self.lastbranch[cs.branch] = id
    73                 cs.comment = self.recode(cs.comment)
    74                 cs.comment = self.recode(cs.comment)
    74                 date = util.datestr(cs.date)
    75                 date = util.datestr(cs.date)
    75                 self.tags.update(dict.fromkeys(cs.tags, id))
    76                 self.tags.update(dict.fromkeys(cs.tags, id))
    76 
    77 
    77                 files = {}
    78                 files = {}
    78                 for f in cs.entries:
    79                 for f in cs.entries:
    79                     files[f.file] = "%s%s" % ('.'.join([str(x) for x in f.revision]),
    80                     files[f.file] = "%s%s" % ('.'.join([str(x)
       
    81                                                         for x in f.revision]),
    80                                               ['', '(DEAD)'][f.dead])
    82                                               ['', '(DEAD)'][f.dead])
    81 
    83 
    82                 # add current commit to set
    84                 # add current commit to set
    83                 c = commit(author=cs.author, date=date,
    85                 c = commit(author=cs.author, date=date,
    84                            parents=[str(p.id) for p in cs.parents],
    86                            parents=[str(p.id) for p in cs.parents],
   184                           " Merged Removed\n")
   186                           " Merged Removed\n")
   185         self.writep.write("valid-requests\n")
   187         self.writep.write("valid-requests\n")
   186         self.writep.flush()
   188         self.writep.flush()
   187         r = self.readp.readline()
   189         r = self.readp.readline()
   188         if not r.startswith("Valid-requests"):
   190         if not r.startswith("Valid-requests"):
   189             raise util.Abort(_("unexpected response from CVS server "
   191             raise util.Abort(_('unexpected response from CVS server '
   190                                "(expected \"Valid-requests\", but got %r)")
   192                                '(expected "Valid-requests", but got %r)')
   191                              % r)
   193                              % r)
   192         if "UseUnchanged" in r:
   194         if "UseUnchanged" in r:
   193             self.writep.write("UseUnchanged\n")
   195             self.writep.write("UseUnchanged\n")
   194             self.writep.flush()
   196             self.writep.flush()
   195             r = self.readp.readline()
   197             r = self.readp.readline()
   206             chunksize = 65536
   208             chunksize = 65536
   207             output = StringIO()
   209             output = StringIO()
   208             while count > 0:
   210             while count > 0:
   209                 data = fp.read(min(count, chunksize))
   211                 data = fp.read(min(count, chunksize))
   210                 if not data:
   212                 if not data:
   211                     raise util.Abort(_("%d bytes missing from remote file") % count)
   213                     raise util.Abort(_("%d bytes missing from remote file")
       
   214                                      % count)
   212                 count -= len(data)
   215                 count -= len(data)
   213                 output.write(data)
   216                 output.write(data)
   214             return output.getvalue()
   217             return output.getvalue()
   215 
   218 
   216         if rev.endswith("(DEAD)"):
   219         if rev.endswith("(DEAD)"):