##// END OF EJS Templates
patch: more precise NoHunk, raised for every file (issue2102)
Benoit Boissinot -
r10748:fb06e357 stable
parent child Browse files
Show More
@@ -1012,11 +1012,11 b' def iterhunks(ui, fp, sourcefile=None):'
1012 BFILE = 1
1012 BFILE = 1
1013 context = None
1013 context = None
1014 lr = linereader(fp)
1014 lr = linereader(fp)
1015 dopatch = True
1016 # gitworkdone is True if a git operation (copy, rename, ...) was
1015 # gitworkdone is True if a git operation (copy, rename, ...) was
1017 # performed already for the current file. Useful when the file
1016 # performed already for the current file. Useful when the file
1018 # section may have no hunk.
1017 # section may have no hunk.
1019 gitworkdone = False
1018 gitworkdone = False
1019 empty = None
1020
1020
1021 while True:
1021 while True:
1022 newfile = newgitfile = False
1022 newfile = newgitfile = False
@@ -1028,7 +1028,7 b' def iterhunks(ui, fp, sourcefile=None):'
1028 current_hunk.fix_newline()
1028 current_hunk.fix_newline()
1029 yield 'hunk', current_hunk
1029 yield 'hunk', current_hunk
1030 current_hunk = None
1030 current_hunk = None
1031 gitworkdone = False
1031 empty = False
1032 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or
1032 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or
1033 ((context is not False) and x.startswith('***************')))):
1033 ((context is not False) and x.startswith('***************')))):
1034 try:
1034 try:
@@ -1046,28 +1046,32 b' def iterhunks(ui, fp, sourcefile=None):'
1046 if emitfile:
1046 if emitfile:
1047 emitfile = False
1047 emitfile = False
1048 yield 'file', (afile, bfile, current_hunk)
1048 yield 'file', (afile, bfile, current_hunk)
1049 empty = False
1049 elif state == BFILE and x.startswith('GIT binary patch'):
1050 elif state == BFILE and x.startswith('GIT binary patch'):
1050 current_hunk = binhunk(changed[bfile])
1051 current_hunk = binhunk(changed[bfile])
1051 hunknum += 1
1052 hunknum += 1
1052 if emitfile:
1053 if emitfile:
1053 emitfile = False
1054 emitfile = False
1054 yield 'file', ('a/' + afile, 'b/' + bfile, current_hunk)
1055 yield 'file', ('a/' + afile, 'b/' + bfile, current_hunk)
1056 empty = False
1055 current_hunk.extract(lr)
1057 current_hunk.extract(lr)
1056 elif x.startswith('diff --git'):
1058 elif x.startswith('diff --git'):
1057 # check for git diff, scanning the whole patch file if needed
1059 # check for git diff, scanning the whole patch file if needed
1058 m = gitre.match(x)
1060 m = gitre.match(x)
1061 gitworkdone = False
1059 if m:
1062 if m:
1060 afile, bfile = m.group(1, 2)
1063 afile, bfile = m.group(1, 2)
1061 if not git:
1064 if not git:
1062 git = True
1065 git = True
1063 dopatch, gitpatches = scangitpatch(lr, x)
1066 gitpatches = scangitpatch(lr, x)[1]
1064 yield 'git', gitpatches
1067 yield 'git', gitpatches
1065 for gp in gitpatches:
1068 for gp in gitpatches:
1066 changed[gp.path] = gp
1069 changed[gp.path] = gp
1067 # else error?
1070 # else error?
1068 # copy/rename + modify should modify target, not source
1071 # copy/rename + modify should modify target, not source
1069 gp = changed.get(bfile)
1072 gp = changed.get(bfile)
1070 if gp and gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD'):
1073 if gp and (gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD')
1074 or gp.mode):
1071 afile = bfile
1075 afile = bfile
1072 gitworkdone = True
1076 gitworkdone = True
1073 newgitfile = True
1077 newgitfile = True
@@ -1097,6 +1101,12 b' def iterhunks(ui, fp, sourcefile=None):'
1097 afile = parsefilename(x)
1101 afile = parsefilename(x)
1098 bfile = parsefilename(l2)
1102 bfile = parsefilename(l2)
1099
1103
1104 if newfile:
1105 if empty:
1106 raise NoHunks
1107 empty = not gitworkdone
1108 gitworkdone = False
1109
1100 if newgitfile or newfile:
1110 if newgitfile or newfile:
1101 emitfile = True
1111 emitfile = True
1102 state = BFILE
1112 state = BFILE
@@ -1104,11 +1114,12 b' def iterhunks(ui, fp, sourcefile=None):'
1104 if current_hunk:
1114 if current_hunk:
1105 if current_hunk.complete():
1115 if current_hunk.complete():
1106 yield 'hunk', current_hunk
1116 yield 'hunk', current_hunk
1117 empty = False
1107 else:
1118 else:
1108 raise PatchError(_("malformed patch %s %s") % (afile,
1119 raise PatchError(_("malformed patch %s %s") % (afile,
1109 current_hunk.desc))
1120 current_hunk.desc))
1110
1121
1111 if hunknum == 0 and dopatch and not gitworkdone:
1122 if (empty is None and not gitworkdone) or empty:
1112 raise NoHunks
1123 raise NoHunks
1113
1124
1114 def applydiff(ui, fp, changed, strip=1, sourcefile=None, eolmode='strict'):
1125 def applydiff(ui, fp, changed, strip=1, sourcefile=None, eolmode='strict'):
@@ -433,3 +433,44 b' cd trickyheaders'
433 hg import -d '0 0' ../trickyheaders.patch
433 hg import -d '0 0' ../trickyheaders.patch
434 hg export --git tip
434 hg export --git tip
435 cd ..
435 cd ..
436
437 echo '% issue2102'
438 hg init issue2102
439 cd issue2102
440 mkdir -p src/cmd/gc
441 touch src/cmd/gc/mksys.bash
442 hg ci -Am init
443 hg import - <<EOF
444 # HG changeset patch
445 # User Rob Pike
446 # Date 1216685449 25200
447 # Node ID 03aa2b206f499ad6eb50e6e207b9e710d6409c98
448 # Parent 93d10138ad8df586827ca90b4ddb5033e21a3a84
449 help management of empty pkg and lib directories in perforce
450
451 R=gri
452 DELTA=4 (4 added, 0 deleted, 0 changed)
453 OCL=13328
454 CL=13328
455
456 diff --git a/lib/place-holder b/lib/place-holder
457 new file mode 100644
458 --- /dev/null
459 +++ b/lib/place-holder
460 @@ -0,0 +1,2 @@
461 +perforce does not maintain empty directories.
462 +this file helps.
463 diff --git a/pkg/place-holder b/pkg/place-holder
464 new file mode 100644
465 --- /dev/null
466 +++ b/pkg/place-holder
467 @@ -0,0 +1,2 @@
468 +perforce does not maintain empty directories.
469 +this file helps.
470 diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
471 old mode 100644
472 new mode 100755
473 EOF
474 hg sum
475 hg diff --git -c tip
476 cd ..
@@ -348,3 +348,28 b' new file mode 100644'
348 +++ b/foo
348 +++ b/foo
349 @@ -0,0 +1,1 @@
349 @@ -0,0 +1,1 @@
350 +foo
350 +foo
351 % issue2102
352 adding src/cmd/gc/mksys.bash
353 applying patch from stdin
354 parent: 1:d59915696727 tip
355 help management of empty pkg and lib directories in perforce
356 branch: default
357 commit: (clean)
358 update: (current)
359 diff --git a/lib/place-holder b/lib/place-holder
360 new file mode 100644
361 --- /dev/null
362 +++ b/lib/place-holder
363 @@ -0,0 +1,2 @@
364 +perforce does not maintain empty directories.
365 +this file helps.
366 diff --git a/pkg/place-holder b/pkg/place-holder
367 new file mode 100644
368 --- /dev/null
369 +++ b/pkg/place-holder
370 @@ -0,0 +1,2 @@
371 +perforce does not maintain empty directories.
372 +this file helps.
373 diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
374 old mode 100644
375 new mode 100755
General Comments 0
You need to be logged in to leave comments. Login now