##// END OF EJS Templates
record: edit patch of newly added files (issue4304)...
Laurent Charignon -
r24845:8133494a stable
parent child Browse files
Show More
@@ -59,6 +59,8 b' def recordfilter(ui, originalhunks):'
59 59 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
60 60 filterfn, *pats, **opts):
61 61 import merge as mergemod
62 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
63 ishunk = lambda x: isinstance(x, hunkclasses)
62 64
63 65 if not ui.interactive():
64 66 raise util.Abort(_('running non-interactively, use %s instead') %
@@ -102,6 +104,14 b' def dorecord(ui, repo, commitfunc, cmdsu'
102 104 except patch.PatchError, err:
103 105 raise util.Abort(_('error parsing patch: %s') % err)
104 106
107 # We need to keep a backup of files that have been newly added and
108 # modified during the recording process because there is a previous
109 # version without the edit in the workdir
110 newlyaddedandmodifiedfiles = set()
111 for chunk in chunks:
112 if ishunk(chunk) and chunk.header.isnewfile() and chunk not in \
113 originalchunks:
114 newlyaddedandmodifiedfiles.add(chunk.header.filename())
105 115 contenders = set()
106 116 for h in chunks:
107 117 try:
@@ -122,8 +132,8 b' def dorecord(ui, repo, commitfunc, cmdsu'
122 132 if backupall:
123 133 tobackup = changed
124 134 else:
125 tobackup = [f for f in newfiles if f in modified]
126
135 tobackup = [f for f in newfiles if f in modified or f in \
136 newlyaddedandmodifiedfiles]
127 137 backups = {}
128 138 if tobackup:
129 139 backupdir = repo.join('record-backups')
@@ -151,6 +161,7 b' def dorecord(ui, repo, commitfunc, cmdsu'
151 161 dopatch = fp.tell()
152 162 fp.seek(0)
153 163
164 [os.unlink(c) for c in newlyaddedandmodifiedfiles]
154 165 # 3a. apply filtered patch to clean repo (clean)
155 166 if backups:
156 167 # Equivalent to hg.revert
@@ -820,9 +820,10 b' class header(object):'
820 820 """
821 821 diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
822 822 diff_re = re.compile('diff -r .* (.*)$')
823 allhunks_re = re.compile('(?:index|new file|deleted file) ')
823 allhunks_re = re.compile('(?:index|deleted file) ')
824 824 pretty_re = re.compile('(?:new file|deleted file) ')
825 special_re = re.compile('(?:index|new|deleted|copy|rename) ')
825 special_re = re.compile('(?:index|deleted|copy|rename) ')
826 newfile_re = re.compile('(?:new file)')
826 827
827 828 def __init__(self, header):
828 829 self.header = header
@@ -870,8 +871,21 b' class header(object):'
870 871 def __repr__(self):
871 872 return '<header %s>' % (' '.join(map(repr, self.files())))
872 873
874 def isnewfile(self):
875 return util.any(self.newfile_re.match(h) for h in self.header)
876
873 877 def special(self):
874 return util.any(self.special_re.match(h) for h in self.header)
878 # Special files are shown only at the header level and not at the hunk
879 # level for example a file that has been deleted is a special file.
880 # The user cannot change the content of the operation, in the case of
881 # the deleted file he has to take the deletion or not take it, he
882 # cannot take some of it.
883 # Newly added files are special if they are empty, they are not special
884 # if they have some content as we want to be able to change it
885 nocontent = len(self.header) == 2
886 emptynewfile = self.isnewfile() and nocontent
887 return emptynewfile or \
888 util.any(self.special_re.match(h) for h in self.header)
875 889
876 890 class recordhunk(object):
877 891 """patch hunk
@@ -229,11 +229,25 b' Add plain file'
229 229 $ hg add plain
230 230 $ hg commit -i -d '7 0' -m plain plain<<EOF
231 231 > y
232 > y
232 233 > EOF
233 234 diff --git a/plain b/plain
234 235 new file mode 100644
235 236 examine changes to 'plain'? [Ynesfdaq?] y
236 237
238 @@ -0,0 +1,10 @@
239 +1
240 +2
241 +3
242 +4
243 +5
244 +6
245 +7
246 +8
247 +9
248 +10
249 record this change to 'plain'? [Ynesfdaq?] y
250
237 251 $ hg tip -p
238 252 changeset: 7:11fb457c1be4
239 253 tag: tip
@@ -315,6 +329,7 b' Modify end of plain file, add EOL'
315 329 > y
316 330 > y
317 331 > y
332 > y
318 333 > EOF
319 334 diff --git a/plain b/plain
320 335 1 hunks, 1 lines changed
@@ -333,6 +348,10 b' Modify end of plain file, add EOL'
333 348 new file mode 100644
334 349 examine changes to 'plain2'? [Ynesfdaq?] y
335 350
351 @@ -0,0 +1,1 @@
352 +1
353 record change 2/2 to 'plain2'? [Ynesfdaq?] y
354
336 355 Modify beginning, trim end, record both, add another file to test
337 356 changes numbering
338 357
@@ -1406,4 +1425,41 b' Moving files'
1406 1425 date: Thu Jan 01 00:00:23 1970 +0000
1407 1426 summary: moving_files
1408 1427
1428 Editing patch of newly added file
1429
1430 $ hg update -C .
1431 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1432 $ cat > editor.sh << '__EOF__'
1433 > cat "$1" | sed "s/first/very/g" > tt
1434 > mv tt "$1"
1435 > __EOF__
1436 $ cat > newfile << '__EOF__'
1437 > This is the first line
1438 > This is the second line
1439 > This is the third line
1440 > __EOF__
1441 $ hg add newfile
1442 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -d '23 0' -medit-patch-new <<EOF
1443 > y
1444 > e
1445 > EOF
1446 diff --git a/newfile b/newfile
1447 new file mode 100644
1448 examine changes to 'newfile'? [Ynesfdaq?] y
1449
1450 @@ -0,0 +1,3 @@
1451 +This is the first line
1452 +This is the second line
1453 +This is the third line
1454 record this change to 'newfile'? [Ynesfdaq?] e
1455
1456 $ hg cat -r tip newfile
1457 This is the very line
1458 This is the second line
1459 This is the third line
1460
1461 $ cat newfile
1462 This is the first line
1463 This is the second line
1464 This is the third line
1409 1465 $ cd ..
@@ -479,6 +479,12 b' record added file alone'
479 479 new file mode 100644
480 480 examine changes to 'r'? [Ynesfdaq?] y
481 481
482 @@ -0,0 +1,1 @@
483 +$Id$
484 record this change to 'r'? [Ynesfdaq?] y
485
486 resolving manifests
487 patching file r
482 488 committing files:
483 489 r
484 490 committing manifest
@@ -507,6 +513,12 b' record added keyword ignored file'
507 513 new file mode 100644
508 514 examine changes to 'i'? [Ynesfdaq?] y
509 515
516 @@ -0,0 +1,1 @@
517 +$Id$
518 record this change to 'i'? [Ynesfdaq?] y
519
520 resolving manifests
521 patching file i
510 522 committing files:
511 523 i
512 524 committing manifest
@@ -295,6 +295,11 b' handle subrepos safely on qrecord'
295 295 new file mode 100644
296 296 examine changes to '.hgsub'? [Ynesfdaq?] y
297 297
298 @@ -0,0 +1,1 @@
299 +sub = sub
300 record this change to '.hgsub'? [Ynesfdaq?] y
301
302 warning: subrepo spec file '.hgsub' not found
298 303 abort: uncommitted changes in subrepository 'sub'
299 304 [255]
300 305 % update substate when adding .hgsub w/clean updated subrepo
@@ -304,6 +309,11 b' handle subrepos safely on qrecord'
304 309 new file mode 100644
305 310 examine changes to '.hgsub'? [Ynesfdaq?] y
306 311
312 @@ -0,0 +1,1 @@
313 +sub = sub
314 record this change to '.hgsub'? [Ynesfdaq?] y
315
316 warning: subrepo spec file '.hgsub' not found
307 317 path sub
308 318 source sub
309 319 revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31
General Comments 0
You need to be logged in to leave comments. Login now