Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 24845:8133494accf1 stable
record: edit patch of newly added files (issue4304)
I tried to fix this issue in the past and had to revert the fix. This is a
second attempt without the regression we found with the first one.
record defines special headers (of file) as headers whose hunk are not shown
to the user for editing, they are used to represent deleted, moved and new
files. Since we want to authorize editing the patch of newly added file we
make the newly added file with some content not special anymore. This entails
that we have to save their content before applying the backup to be able to
revert it if the patch does not apply properly.
We reintroduce the test showing that newly added files can be edited and that
their content is shown to the user.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Thu, 23 Apr 2015 14:27:26 -0700 |
parents | edf907bd8144 |
children | 0ca8410ea345 |
comparison
equal
deleted
inserted
replaced
24844:6c6aee6d395b | 24845:8133494accf1 |
---|---|
818 class header(object): | 818 class header(object): |
819 """patch header | 819 """patch header |
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 |
829 self.hunks = [] | 830 self.hunks = [] |
830 | 831 |
868 return self.files()[-1] | 869 return self.files()[-1] |
869 | 870 |
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 |
878 | 892 |
879 XXX shouldn't we merge this with the other hunk class? | 893 XXX shouldn't we merge this with the other hunk class? |