Changeset 1501 in tailor


Ignore:
Timestamp:
05/18/08 19:55:31 (5 years ago)
Author:
lele@…
Hash name:
20080518175531-97f81-1ddbf126ce022be13c58d17c875cb0ef09e4e4e7
Message:

Fixup previous renames when reading darcs patches
For some reason a darcs patch may contain something like

    <move from="logo.png" to="logos-20041102120340/plain_logo.png"/>
    <move from="logos-20041102120340" to="logos"/>
    <move from="logos/large_logo.png-20041102120441" to="logos/large_logo.png"/>
    <move from="logos/logo.png-20041102120441" to="logos/logo.png"/>
    <add_directory>
    logos-20041102120340
    </add_directory>
    ...
Location:
vcpx
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • vcpx/tests/darcs.py

    r1499 r1501  
    186186        self.assertEqual(entry.name, 'darcs_cgi.lhs') 
    187187        self.assertEqual(entry.action_kind, entry.UPDATED) 
     188 
     189    def testRenameAndAddDir(self): 
     190        """Verify that the parser reduce rename A B+add B to rename A B""" 
     191 
     192        log = self.getDarcsOutput('darcs-rename_and_add_dir_test') 
     193        csets = changesets_from_darcschanges(log) 
     194 
     195        cset = csets.next() 
     196        self.assertEqual(len(cset.entries), 7) 
     197 
     198        entry = cset.entries[0] 
     199        self.assertEqual(entry.name, 'logos/plain_logo.png') 
     200        self.assertEqual(entry.action_kind, entry.RENAMED) 
     201        self.assertEqual(entry.old_name, 'logo.png') 
     202 
     203        entry = cset.entries[1] 
     204        self.assertEqual(entry.name, 'logos') 
     205        self.assertEqual(entry.action_kind, entry.ADDED) 
     206 
     207        entry = cset.entries[2] 
     208        self.assertEqual(entry.name, 'logos/large_logo.png') 
     209        self.assertEqual(entry.action_kind, entry.ADDED) 
    188210 
    189211    def testBadOrderedXML(self): 
  • vcpx/repository/darcs/source.py

    r1499 r1501  
    7171            # to an addition instead, and don't insert any other entry 
    7272 
    73             dirname = entry.name+'/' # darcs hopefully use forward slashes also under win 
     73            # darcs hopefully use forward slashes also under win 
     74            dirname = entry.name+'/' 
    7475 
    7576            for i,e in enumerate(self.entries): 
    76                 if e.action_kind == e.RENAMED and e.old_name == entry.name: 
    77                     # Unfortunately we have to check if the order if 
    78                     # messed up, in that case we should not do anything. 
    79                     # Example: mv a a2; mkdir a; mv a2 a/b 
    80                     skip = False 
    81                     for j in self.entries: 
    82                         if j.action_kind == j.RENAMED and j.name.startswith(dirname): 
    83                             skip = True 
    84                             break 
    85                     # Luckily enough (since removes are the first entries 
    86                     # in the list, that is) by anticipating the add we 
    87                     # cure also the case below, when addition follows 
    88                     # edit. 
    89                     if not skip: 
    90                         e.action_kind = e.ADDED 
    91                         e.old_name = None 
    92                         return e 
    93  
    94                 # The "rename A B; add B" into "add B" 
    95                 if e.action_kind == e.RENAMED and e.name == entry.name: 
    96                     del self.entries[i] 
     77                if e.action_kind == e.RENAMED: 
     78                    if e.old_name == entry.name: 
     79                        # Unfortunately we have to check if the order if 
     80                        # messed up, in that case we should not do anything. 
     81                        # Example: mv a a2; mkdir a; mv a2 a/b 
     82                        skip = False 
     83                        for j in self.entries: 
     84                            if j.action_kind == j.RENAMED and j.name.startswith(dirname): 
     85                                skip = True 
     86                                break 
     87                        # Luckily enough (since removes are the first entries 
     88                        # in the list, that is) by anticipating the add we 
     89                        # cure also the case below, when addition follows 
     90                        # edit. 
     91                        if not skip: 
     92                            e.action_kind = e.ADDED 
     93                            e.old_name = None 
     94                            return e 
     95 
     96                    # The "rename A B; add B" into "add B" 
     97                    if e.name == entry.name: 
     98                        del self.entries[i] 
    9799 
    98100                # Assert also that add_dir events must preceeds any 
     
    134136        # The "rename A B; rename B C" to "rename A C" part 
    135137        elif entry.action_kind == entry.RENAMED: 
     138            # Adjust previous renames 
     139            olddirname = entry.old_name+'/' 
     140            for e in self.entries: 
     141                if e.action_kind == e.RENAMED and e.name.startswith(olddirname): 
     142                    e.name = entry.name + '/' + e.name[len(olddirname):] 
     143 
    136144            for e in self.entries: 
    137145                if e.action_kind == e.RENAMED and e.name == entry.old_name: 
Note: See TracChangeset for help on using the changeset viewer.