Commit Graph

202 Commits

Author SHA1 Message Date
Patrick Mezard
3680e66462 patch: generalize the use of patchmeta in applydiff()
- Add patchmeta.copy() and emit copies from iterhunks. Modifying patchmeta
  instances in applydiff() makes things simpler.
- Rename selectfile() into makepatchmeta(). It is responsible for creating
  patchmeta for regular patches.
- Pass patchmeta objects to patchfile() directly

patchmeta instances were associated with git patches, for regular patches we
had to pass additional variables to tell the patch intent to patchfile().
Instead, we generate patchmeta for regular patches and pass them. This will
also help with patch filtering by matcher objects.
2011-06-11 14:17:25 +02:00
Patrick Mezard
d4b7db6294 patch: use temporary files to handle intermediate copies
git patches may require copies to be handled out-of-order. For instance, take
the following sequence:

  * modify a
  * copy a into b

Here, we have to generate b from a before its modification. To do so,
applydiff() was scanning for copy metadata and performing the copies before
processing the other changes in-order. While smart and efficient, this approach
complicates things by handling file copies and file creations at different
places and times. While a new file must not exist before being patched a copied
file already exists before applying the first hunk.

Instead of copying the files at their final destination before patching, we
store them in a temporary file location and retrieve them when patching. The
filestore always stores file content in real files but nothing prevents adding
a cache layer. The filestore class was kept separate from fsbackend for at
least two reasons:

- This class is likely to be reused as a temporary result store for a future
  repository patching call (entries just have to be extended to contain copy
  sources).

- Delegating this role to backends might be more efficient in a repository
  backend case: the source files are already available in the repository itself
  and do not need to be copied again. It also means that third-parties backend
  would have to implement two other methods. If we ever decide to merge the
  filestore feature into backend, a minimalistic approach would be to compose
  with filestore directly. Keep in mind this copy overhead only applies for
  copy/rename sources, and may even be reduced to copy sources which have to
  handled ahead of time.
2011-05-27 21:50:10 +02:00
Patrick Mezard
e6f284be06 patch: refactor file creation/removal detection
The patcher has to know if a file is being created or removed to check if the
target already exists, or to actually unlink the file when a hunk emptying it
is applied. This was done by embedding the creation/removal information in the
first (and only) hunk attached to the file.

There are two problems with this approach:

- creation/removal is really a property of the file being patched and not its
  hunk.

- for regular patches, file creation cannot be deduced at parsing time: there
  are case where the *stripped* file paths must be compared. Modifying hunks
  after their creation is clumsy and prevent further refactorings related to
  copies handling.

Instead, we delegate this job to selectfile() which has all the relevant
information, and remove the hunk createfile() and rmfile() methods.
2011-05-27 21:50:09 +02:00
Patrick Mezard
514ff73602 patch: set desired mode when patching, not in updatedir()
This patch and the following aim at merging _updatedir() actions into
_applydiff().
2011-05-18 23:48:13 +02:00
Patrick Mezard
431a9d156a patch: extract fs access from patchfile into fsbackend
Most filesystem calls are already isolated in patchfile but this is not enough:
renames are performed before patchfile is available and some chmod calls are
even done outside of the applydiff call. Once all these calls are extracted
into a backend class, we can provide cleaner APIs to write to a working
directory context directly into the repository.
2011-05-17 23:46:15 +02:00
Matt Mackall
0832007f60 scmutil: drop aliases in cmdutil for match functions 2011-05-13 14:58:24 -05:00
Martin Geisler
249808f0a8 keyword: use cmdutil.command decorator 2011-05-12 14:31:07 +02:00
Dan Villiom Podlaski Christiansen
511c941422 prevent transient leaks of file handle by using new helper functions
These leaks may occur in environments that don't employ a reference
counting GC, i.e. PyPy.

This implies:
 - changing opener(...).read() calls to opener.read(...)
 - changing opener(...).write() calls to opener.write(...)
 - changing open(...).read(...) to util.readfile(...)
 - changing open(...).write(...) to util.writefile(...)
2011-05-02 10:11:18 +02:00
Adrian Buehlmann
f3e8eae526 move canonpath from util to scmutil 2011-04-20 21:41:41 +02:00
Martin Geisler
722384a5f7 keyword: convert a verbatim block to a field list 2011-04-05 11:07:25 +02:00
Christian Ebert
d7bf092ada keyword: offer additional datefilters when the extension is enabled
Before the additional datefilters (utcdate, svnisodate, svnutcdate)
were used when kwtemplater was initialized. Now they always be used
once the extension is enabled.
2011-03-14 12:26:50 +01:00
Christian Ebert
538e3f9097 keyword: docstrings for additional date filters 2011-03-14 12:19:59 +01:00
Patrick Mezard
3a56f6a3b1 templates: document missing keywords or filters
Keywords keywords are not documented yet but are turned into function
definitions to avoid lambda docstring weirdness.
2011-03-12 12:46:31 +01:00
Christian Ebert
95a7f264b7 keyword: move repo.__class__ assignment out of monkeypatch context
A cosmetic change to improve readability.
2011-01-23 03:15:44 +01:00
Christian Ebert
36f93ec22a keyword: inform user about current keywordset in kwdemo
The kwdemo --default output now looks roughly like this:

      configuration using default cvs keywordset
[extensions]
keyword =
[keyword]
demo.txt =
[keywordset] * section added with this change
svn = False
[keywordmaps]
...
2011-01-23 03:15:39 +01:00
Christian Ebert
87f97c3b31 keyword: update documentation for kwshrink
* remove obsolete reference to potential problems with merge and import
* emphasize that running kwshrink before configuration changes which
  affect active/expanded keywords is mandatory
2011-01-16 15:45:26 +01:00
Christian Ebert
3482ce6068 keyword: make kwfiles show deleted files configured for expansion 2010-12-04 14:44:05 +01:00
Christian Ebert
04b255ebb4 keyword: colorize hg kwfiles output 2010-12-04 14:22:12 +01:00
Matt Mackall
15ad3a76d6 merge with stable 2010-12-01 18:47:40 -06:00
Christian Ebert
7130ab35da keyword: copy: when copied source is a symlink, follow it
1) hg cp symlink copy -> copy is a symlink.
2) cp symlink copy; hg cp -A symlink copy -> copy is a regular file.

In the second case we have to follow the symlink to its target
to find out whether we have to unexpand keywords in the copy.

Add test covering the case where the copied link's target is ignored
by keyword but has content which would match the regex for expanded
keywords to check whether we indeed leave the destination alone.
2010-12-01 10:51:49 +01:00
Martin Geisler
59192feb36 merge with stable 2010-11-22 17:39:46 +01:00
Christian Ebert
0a8e9b8d50 keyword: s/config/configuration/ in help 2010-11-22 16:05:31 +01:00
Christian Ebert
df0bc30259 keyword: turn regexes and escaped keywords into a propertycache 2010-11-04 22:56:38 +00:00
Christian Ebert
8d43aa49f8 keyword: function to look up changectx for expansion
Similarly rename variable in kwtemplater.overwrite().
2010-11-03 14:37:41 +01:00
Christian Ebert
baf94f43b9 keyword: fix regressions introduced in 1416551b9299
- dirstate of overwritten files must be forced to normal
  with kwexpand/kwshrink, not commit.
- recorded files must be weeded before overwriting.
- add test cases.
2010-10-24 15:11:41 +01:00
Christian Ebert
89ad77f3b8 keyword: only use expensive fctx.cmp when needed
Restrict expensive cmp to cases when:

- comparing against working directory
and
  - encode filters active
  or
  - path is configured for keyword expansion
2010-10-14 22:53:17 +02:00
Christian Ebert
94017a6ef9 keyword: code cleanup
- move preselection of expansion candidates for rollback
  and record into helper function
- same overwrite order in rollback and record:
  1. modified, 2. added
- self.wlock() inside kwrepo class instead of repo.wlock()
2010-10-12 12:49:23 +01:00
Nicolas Dumazet
04cf1f6b57 filectx: use ctx.size comparisons to speed up ctx.cmp
Comparing sizes is cheaper than comparing file contents, as it does not
involve reading the file on disk or from the filelog.

It is however not always possible: some extensions, or encode filters,
change data when extracting it to the working directory.
2010-07-27 23:07:30 +09:00
Christian Ebert
090eecd7fd keyword: enforce subn method via boolean switch
There are only 2 patterns to choose, and so far only 1 case
where kwtemplater.re_kw.subn is applied on data read from
the working directory: when recording added files.

With this change the code reflects more closely the boolean
character of the switch and underlines the special case.
2010-10-10 00:38:57 +01:00
Christian Ebert
f2c0019bd0 keyword: fix weeding of expansion candidates when recording
Rearrange tests to check this, i.e. that there are changes
in other files, not only the recorded one.
2010-10-10 00:30:09 +01:00
Christian Ebert
cdefb1362f keyword: switch kwtemplater.record in kw_dorecord()
Obsoletes the need for a global recordcommands variable.
2010-10-08 18:39:46 +01:00
Christian Ebert
924a741c44 keyword: specific regular expressions depending on read mode
More safeguarding against accidental (un)expansion:

Reading filelog: act only on \$(kw1|kw2|..)\$ as keywords are always
                 stored unexpanded.
Reading wdir:    act only on \$(kw1|kw2|..): [^$\n\r]*? \$ as we only
                 are interested in expanded keywords in this situation.
                 Note: we cannot use ..): [^$\n\r]+? \$ because e.g.
                 the {branch} template might be empty.

hg record is a special case as we read from the working directory and
need one regex each for modified and added files. Therefore test
recording an added file.

This way we finally also forbid sequences like $Id:  $ being treated
as keywords.
2010-10-08 18:39:46 +01:00
Christian Ebert
c7f6297b25 keyword: disable expansion in kwfilelog.read() if file renamed in node
Simplifies kwfilelog.cmp() and avoids fiddling with/importing revlog.

Reorder imports alphabetically.
2010-10-08 18:39:46 +01:00
Christian Ebert
05408dc4ec keyword: make iskwfile() a weeding method in lieu of a boolean
Update iskwfile docstring.
2010-10-08 18:39:46 +01:00
Christian Ebert
f6775a8777 keyword: support copy and rename
copy/rename destinations being unversioned and possibly ignored by
the extension should not contain expanded keywords.

Files copied/renamed from an ignored source are not touched.

Add tests covering both of the above cases, plus the corner case of
cp symlink foo; hg cp -A symlink foo (where foo becomes a regular file).
2010-10-08 18:39:46 +01:00
Christian Ebert
6ced1f0e94 keyword: refactor kwtemplater.overwrite()
Make kwexpand, kwshrink restricted commands - i.e. read from
filelog without expansion for substition in kwtemplater.overwrite,
and set/unset restricted mode for overwrite() in in kwcommitctx
and the dorecord wrapper.

Preselect candidates when working on changed files (rollback, record)
outside kwtemplater class, and remove 6th argument from overwrite().

Avoid duplicate substitution/search in overwrite():
Only go into restricted read mode when reading from filelog.
rollback and record read from the working directory, where
restricted mode would already shrink keywords before overwrite()
either expands or shrinks them again.

This ensures that the usual automatic operations on keywords
are turned off during overwrite() and only overwrite() itself
acts on them.

Reduce manifest calculation to the cases where it is needed.

Move helper function for expansion removal outside kwtemplater class.
2010-10-08 18:39:46 +01:00
Christian Ebert
7faf4b3245 keyword: use workingctx to detect modified and added files after rollback 2010-10-01 02:13:31 +02:00
Christian Ebert
8c9ae08c43 keyword: rename variable "cfiles" to "changed" for clarity 2010-10-01 02:13:31 +02:00
Christian Ebert
405806c3f9 keyword: support rollback by restoring expansion to previous values
Prevent spurious differences in the working directory
after a rollback.

Add tests for several rollback situations.
2010-09-26 19:18:41 +02:00
Christian Ebert
9915bf5605 keyword: do not expand at all during diff
Always shrink and never expand keywords during a diff operation.
Avoid user distraction e.g. because of spurious differences
appearing in the commit editor.
2010-09-26 19:18:41 +02:00
Christian Ebert
24b171fdd3 keyword: restore restricted read mode value after overwriting
Even though just enforcing expansion after overwriting files in
the working directory caused no problems that we know of, this avoids
a potential source of problems (e.g. in collaboration other extensions)
at no costs.
2010-09-26 19:18:41 +02:00
Christian Ebert
3fb88c8dbb Use more note admonitions in help texts 2010-09-23 16:31:38 +02:00
Martin Geisler
6335a7f166 merge with stable 2010-09-10 20:19:16 +02:00
Christian Ebert
55548a8056 keyword: explain file-wise expansion in help 2010-09-10 16:58:13 +02:00
Martin Geisler
e9c2a20771 diff: recurse into subrepositories with --subrepos/-S flag 2010-09-03 12:58:51 +02:00
Matt Mackall
42d9b2046b Merge with stable 2010-07-25 21:20:05 -05:00
Christian Ebert
e697dd5558 keyword: move collecting of [keyword] patterns to reposetup (issue2303)
When cloning, prevent [keyword] filename patterns configured locally
in the source directory to persist during the update in the destination.

a) move [keyword] retrieval (back) to reposetup
b) remove the corresponding global kwtools attributes

Add test cases.
2010-07-25 20:01:33 -05:00
Christian Ebert
15f0c93000 keyword: add extra datefilters in a single update call 2010-07-15 10:24:31 +02:00
Christian Ebert
e5d231e804 keyword: postpone manifest calculation in kwtemplater.overwrite
We can check for file existence in the working directory (needed
in case of recording) by simply using the given context and
calculate the manifest only when there are in fact candidates
for expansion/shrinking.
2010-06-15 17:15:31 +02:00
FUJIWARA Katsunori
ce06b102df help: show value requirement and multiple occurrence of options
this helps users to know what kind of option is:

  - no value is required(flag option)
  - value is required
  - value is required, and multiple occurrences are allowed

each kinds are shown as below:

 -f --force              force push
 -e --ssh CMD            specify ssh command to use
 -b --branch BRANCH [+]  a specific branch you would like to push

if one or more 3rd type options are shown, explanation for '[+]' mark
is also shown as footnote.
2010-06-06 17:25:00 +09:00