##// 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 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
59 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
60 filterfn, *pats, **opts):
60 filterfn, *pats, **opts):
61 import merge as mergemod
61 import merge as mergemod
62 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
63 ishunk = lambda x: isinstance(x, hunkclasses)
62
64
63 if not ui.interactive():
65 if not ui.interactive():
64 raise util.Abort(_('running non-interactively, use %s instead') %
66 raise util.Abort(_('running non-interactively, use %s instead') %
@@ -102,6 +104,14 b' def dorecord(ui, repo, commitfunc, cmdsu'
102 except patch.PatchError, err:
104 except patch.PatchError, err:
103 raise util.Abort(_('error parsing patch: %s') % err)
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 contenders = set()
115 contenders = set()
106 for h in chunks:
116 for h in chunks:
107 try:
117 try:
@@ -122,8 +132,8 b' def dorecord(ui, repo, commitfunc, cmdsu'
122 if backupall:
132 if backupall:
123 tobackup = changed
133 tobackup = changed
124 else:
134 else:
125 tobackup = [f for f in newfiles if f in modified]
135 tobackup = [f for f in newfiles if f in modified or f in \
126
136 newlyaddedandmodifiedfiles]
127 backups = {}
137 backups = {}
128 if tobackup:
138 if tobackup:
129 backupdir = repo.join('record-backups')
139 backupdir = repo.join('record-backups')
@@ -151,6 +161,7 b' def dorecord(ui, repo, commitfunc, cmdsu'
151 dopatch = fp.tell()
161 dopatch = fp.tell()
152 fp.seek(0)
162 fp.seek(0)
153
163
164 [os.unlink(c) for c in newlyaddedandmodifiedfiles]
154 # 3a. apply filtered patch to clean repo (clean)
165 # 3a. apply filtered patch to clean repo (clean)
155 if backups:
166 if backups:
156 # Equivalent to hg.revert
167 # Equivalent to hg.revert
@@ -820,9 +820,10 b' class header(object):'
820 """
820 """
821 diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
821 diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
822 diff_re = re.compile('diff -r .* (.*)$')
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 pretty_re = re.compile('(?:new file|deleted file) ')
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 def __init__(self, header):
828 def __init__(self, header):
828 self.header = header
829 self.header = header
@@ -870,8 +871,21 b' class header(object):'
870 def __repr__(self):
871 def __repr__(self):
871 return '<header %s>' % (' '.join(map(repr, self.files())))
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 def special(self):
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 class recordhunk(object):
890 class recordhunk(object):
877 """patch hunk
891 """patch hunk
@@ -229,11 +229,25 b' Add plain file'
229 $ hg add plain
229 $ hg add plain
230 $ hg commit -i -d '7 0' -m plain plain<<EOF
230 $ hg commit -i -d '7 0' -m plain plain<<EOF
231 > y
231 > y
232 > y
232 > EOF
233 > EOF
233 diff --git a/plain b/plain
234 diff --git a/plain b/plain
234 new file mode 100644
235 new file mode 100644
235 examine changes to 'plain'? [Ynesfdaq?] y
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 $ hg tip -p
251 $ hg tip -p
238 changeset: 7:11fb457c1be4
252 changeset: 7:11fb457c1be4
239 tag: tip
253 tag: tip
@@ -315,6 +329,7 b' Modify end of plain file, add EOL'
315 > y
329 > y
316 > y
330 > y
317 > y
331 > y
332 > y
318 > EOF
333 > EOF
319 diff --git a/plain b/plain
334 diff --git a/plain b/plain
320 1 hunks, 1 lines changed
335 1 hunks, 1 lines changed
@@ -333,6 +348,10 b' Modify end of plain file, add EOL'
333 new file mode 100644
348 new file mode 100644
334 examine changes to 'plain2'? [Ynesfdaq?] y
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 Modify beginning, trim end, record both, add another file to test
355 Modify beginning, trim end, record both, add another file to test
337 changes numbering
356 changes numbering
338
357
@@ -1406,4 +1425,41 b' Moving files'
1406 date: Thu Jan 01 00:00:23 1970 +0000
1425 date: Thu Jan 01 00:00:23 1970 +0000
1407 summary: moving_files
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 $ cd ..
1465 $ cd ..
@@ -479,6 +479,12 b' record added file alone'
479 new file mode 100644
479 new file mode 100644
480 examine changes to 'r'? [Ynesfdaq?] y
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 committing files:
488 committing files:
483 r
489 r
484 committing manifest
490 committing manifest
@@ -507,6 +513,12 b' record added keyword ignored file'
507 new file mode 100644
513 new file mode 100644
508 examine changes to 'i'? [Ynesfdaq?] y
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 committing files:
522 committing files:
511 i
523 i
512 committing manifest
524 committing manifest
@@ -295,6 +295,11 b' handle subrepos safely on qrecord'
295 new file mode 100644
295 new file mode 100644
296 examine changes to '.hgsub'? [Ynesfdaq?] y
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 abort: uncommitted changes in subrepository 'sub'
303 abort: uncommitted changes in subrepository 'sub'
299 [255]
304 [255]
300 % update substate when adding .hgsub w/clean updated subrepo
305 % update substate when adding .hgsub w/clean updated subrepo
@@ -304,6 +309,11 b' handle subrepos safely on qrecord'
304 new file mode 100644
309 new file mode 100644
305 examine changes to '.hgsub'? [Ynesfdaq?] y
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 path sub
317 path sub
308 source sub
318 source sub
309 revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31
319 revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31
General Comments 0
You need to be logged in to leave comments. Login now