Commit Graph

408 Commits

Author SHA1 Message Date
Gregory Szorc
b89d7e1505 subrepo: use absolute_import 2015-08-08 20:03:58 -07:00
Matt Mackall
af90fd51ba subrepo: mark internal-only option 2015-06-25 17:57:26 -05:00
FUJIWARA Katsunori
0fc6d6032b subrepo: use vfs.dirname instead of os.path.dirname
This patch uses "wvfs of the parent repository" ('pwvfs') instead of
'wvfs' of own repository, because 'self._path' is the path to this
subrepository as seen from the parent repository.
2015-07-10 00:59:51 +09:00
FUJIWARA Katsunori
48e4a30e20 subrepo: use vfs.basename instead of os.path.basename 2015-07-10 00:59:51 +09:00
FUJIWARA Katsunori
78eff9a5a8 subrepo: use repo.pathto instead of util.pathto to simplify invocation
This centralization into 'repo.pathto()' should reduce the cost of vfs
migration around 'getcwd()' and so on in the future.
2015-07-10 00:59:51 +09:00
FUJIWARA Katsunori
c84333ef17 subrepo: prefetch ctx.repo() for efficiency and centralization
'subrepo.state()' refers same 'ctx.repo()' in many places and times.
2015-07-10 00:59:51 +09:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Gregory Szorc
3aa1c73868 global: mass rewrite to use modern octal syntax
Python 2.6 introduced a new octal syntax: "0oXXX", replacing "0XXX". The
old syntax is not recognized in Python 3 and will result in a parse
error.

Mass rewrite all instances of the old octal syntax to the new syntax.

This patch was generated by `2to3 -f numliterals -w -n .` and the diff
was selectively recorded to exclude changes to "<N>l" syntax conversion,
which will be handled separately.
2015-06-23 22:30:33 -07:00
Matt Harbison
0dc20be5d4 archive: support 'wdir()'
This is a step toward replacing the extdiff internals with archive, in order to
support 'extdiff -S'.  Only Mercurial subrepos are supported for now.

If a file is missing from the filesystem, it is silently skipped.  Perhaps it
should warn, but it cannot abort when working with extdiff because deleting a
file is a legitimate diff.
2015-06-16 23:06:57 -04:00
Matt Harbison
ba46b0e533 subrepo: allow a representation of the working directory subrepo
Some code cannot handle a subrepo based on the working directory (e.g.
sub.dirty()), so the caller must opt in.  This will be useful for archive, and
perhaps some other commands.  The git and svn methods where this is used may
need to be fixed up on a case by case basis.
2015-06-16 23:03:36 -04:00
Matt Harbison
bf8d482cfd verify: check the subrepository references in .hgsubstate
While hopefully atypical, there are reasons that a subrepository revision can be
lost that aren't covered by corruption of the .hgsubstate revlog.  Such things
can happen when a subrepo is amended, stripped or simply isn't pulled from
upstream because the parent repo revision wasn't updated yet.  There's no way to
know if it is an error, but this will find potential problems sooner than when
some random revision is updated.

Until recently, convert made no attempt at rewriting the .hgsubstate file.  The
impetuous for this is to verify the conversion of some repositories, and this is
orders of magnitude faster than a bash script from 0..tip that does an
'hg update -C $rev'.  But it is equally useful to determine if everything has
been pulled down before taking a thumb drive on the go.

It feels somewhat wrong to leave this out of verifymod (mostly because the file
is already read in there, and the final summary is printed before the subrepos
are checked).  But verifymod looks very low level, so importing subrepo stuff
there seems more wrong.
2015-06-16 16:15:15 -04:00
Matt Harbison
61135ed1ee subrepo: introduce hgsubrepo._getctx()
This code is already used in a couple of places, and will need to be used in
others where wdir() support is needed.  Trying to get the wdir() revision stored
in self._substate[1] when creating the object in subrepo.subrepo() resulted in
breaking various status and diff tests.  This is a far less invasive change.
2015-06-14 21:51:57 -04:00
Matt Harbison
ddab23309c subrepo: introduce the nullsubrepo() method
This will be used in an upcoming patch.  It's a one-off use, but seems better to
be contained in the subrepo module, than for the next patch to overwrite the
_ctx and _state fields in another module.  '' is used as the default revision in
subrepo.state() if it can't be found, so it seems like a safe choice.
2015-06-03 13:45:42 -04:00
Matt Harbison
f25dcb1c8d files: recurse into subrepos automatically with an explicit path 2015-05-17 22:42:47 -04:00
Pierre-Yves David
d3f3b7ac09 subrepo: further replacement of try/except with 'next'
Burn StopIteration, Burn!
2015-05-18 12:31:41 -05:00
Matt Harbison
972919198f subrepo: introduce getfileset()
This will be used in the next patch to help matchers resolve filesets in
subrepos.  The default implementation returns an empty set (for git and svn).
2015-05-15 23:13:05 -04:00
Mathias De Maré
633c0af10d subrepo: correctly handle git subdirectory status change
'git diff-index' by default does not recurse into subdirectories
when changes are found. As a result, the directory is shown as changed,
rather than the files in this directory.
Adding '-r' results in recursing until the blobs themselves are checked.
2015-05-06 17:15:38 +02:00
Matt Harbison
7ae29b6407 archive: always use portable path component separators with subrepos
The previous behavior when archiving a subrepo 's' on Windows was to internally
name the file under it 's\file', due to the use of vfs.reljoin().  When printing
the file list from the archive on Windows or Linux, the file was named
's\\file'.  The archive extracted OK on Windows, but if the archive was brought
to a Linux system, it created a file named 's\file' instead of a directory 's'
containing 'file'.

*.zip format achives seemed not to have the problem, but this was definitely an
issue with *.tgz archives.

Largefiles actually got this right, but a test is added to keep this from
regressing.  The subrepo-deep-nested-change.t test was repurposed to archive to
a file, since there are several subsequent tests that archive to a directory.
The output change is losing the filesystem prefix '../archive_lf' and not
listing the directories 'sub1' and 'sub1/sub2'.
2015-05-04 22:33:29 -04:00
Matt Harbison
1df2171ff6 subrepo: propagate the --hidden option to hg subrepositories
With many commands accepting a '-S' or an explicit path to trigger recursing
into subrepos, it seems that --hidden needs to be propagated too.
Unfortunately, many of the subrepo layer methods discard the options map, so
passing the option along explicitly isn't currently an option.  It also isn't
clear if other filtered views need to be propagated, so changing all of those
commands may be insufficient anyway.

The specific jam I got into was amending an ancestor of qbase in a subrepo, and
then evolving.  The patch ended up being hidden, and outgoing said it would only
push one unrelated commit.  But push aborted with an 'unknown revision' that I
traced back to the patch.  (Odd it didn't say 'filtered revision'.)  A push with
--hidden worked from the subrepo, but that wasn't possible from the parent repo
before this.

Since the underlying problem doesn't actually require a subrepo, there's
probably more to investigate here in the discovery area.  Yes, evolve + mq is
not exactly sane, but I don't know what is seeing the hidden revision.

In lieu of creating a test for the above situation (evolving mq should probably
be blocked), the test here is a marginally useful case where --hidden is needed
in a subrepo: cat'ing a file in a hidden revision.  Without this change, cat
aborts with:

  $ hg --hidden cat subrepo/a
  skipping missing subrepository: subrepo
  [1]
2015-02-03 15:01:43 -05:00
Matt Harbison
d85501c01b subrepo: don't pass the outer repo's --rev or --branch to subrepo incoming()
When passing a --rev, 'hg incoming -S' previously suffered from the same output
truncation or abort that was fixed for 'hg outgoing -S' in the previous patch,
for the same reasons.

Unlike push, subrepos are currently only pulled when the outer repo is updated,
not when the outer repo is pulled.  That makes matching 'hg pull' behavior
impossible.  Listing all incoming csets in the subrepo seems like the most
useful behavior, and is consistent with 'hg outgoing -S'.
2015-04-27 21:34:23 -04:00
Matt Harbison
87ea927ca1 subrepo: don't pass the outer repo's --rev or --branch to subrepo outgoing()
The previous behavior didn't reflect what would actually be pushed- push will
ignore --rev and --branch in the subrepo and push everything.  Therefore,
'push -r {rev}' would not list everything, unless {rev} was also the revision of
the subrepo's tip.  Worse, if a hash was passed in, the command would abort
because that hash would either not be in the outer repo or not in the subrepo.
2015-04-27 21:15:25 -04:00
Matt Harbison
8ed0a9ea81 subrepo: don't write .hgsubstate lines with empty subrepo state (issue4622)
The '' that is used to represent the state of a not-yet-committed
subrepo cannot be written to the file, because the code that parses
the file splits on ' ' and expects two parts.

Given that the .hgsubstate file is automatically rewritten on commit, it seems
a little strange that the file is written out during a merge.
2015-04-24 23:23:55 -04:00
Matt Harbison
cc76d4f63c subrepo: calculate _relpath for hgsubrepo based on self instead of parent
Prior to ef4d6b79dd3a, the subrelpath() (now _relpath) for hgsubrepo was
calculated by removing the root path of the outermost repo from the root path of
the subrepo.  Since the root paths use platform specific separators, and the
relative path is printed by various commands, the output of these commands
require a glob (and check-code.py enforces this).

In an effort to be generic to all subrepos, ef4d6b79dd3a started calculating
this path based on the parent repo, and then joining the subrepo path in .hgsub.
One of the tests in test-subrepo.t creates a subrepo inside a directory, so the
path being joined contained '/' instead of '\'.  This made the test fail with a
'~' status, because the glob is unnecessary[1].  Removing them made the test
work, but then check-code complains.  We can't just drop the check-code rule,
because sub-subrepos are still joined with '\'.  Presumably the other subrepo
types have this issue as well, but there likely isn't a test with git or svn
repos inside a subdirectory.

This simply restores the exact _relpath value (and output) for hgsubrepos prior
to ef4d6b79dd3a.


[1] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068720.html
2015-04-15 11:49:44 -04:00
Matt Harbison
92a80db936 subrepo: backout 2ee77509c828 to restore reporelpath()
The path for hgsubrepo needs to be calculated slightly differently from other
subrepo types, but can reuse this.  See the next patch for details.
2015-04-15 11:23:26 -04:00
Mathias De Maré
3f5d166a19 subrepo: add include/exclude support for diffing git subrepos
Previously, git subrepos were ignored if any type of path selection
was done.
This can be solved by using subrepo status and filtering matching files.
2015-04-14 20:09:56 +02:00
FUJIWARA Katsunori
bb58089c88 subrepo: use vfs.walk instead of os.walk
"dirpath" in the tuple yielded by "vfs.walk()" is relative one from
the root of specified vfs, and absolute path in the warning message is
composed by "vfs.join()".

On the other hand, target file "f" exists in "dirpath", and
"reljoin()" is needed to unlink "f" by "vfs.unlink()".
2015-04-11 23:00:04 +09:00
FUJIWARA Katsunori
e6ce58b269 subrepo: pass wvfs to _sanitize instead of absolute path to a subrepository
As a preparation for vfs migration of "_sanitize()", this patch passes
"wvfs" to "_sanitize()" and use "wvfs.base" instead of absolute path
to a subrepository.
2015-04-11 23:00:04 +09:00
Matt Harbison
de8806d8c6 subrepo: convert the os.path references in git to vfs
There are a handful of os.path references in the free functions at the top of
the module that will be trickier to remove.
2015-02-07 12:57:40 -05:00
FUJIWARA Katsunori
1de7607de0 subrepo: use vfs.removedirs instead of os.removedirs
This patch also removes useless composing absolute path by "repo.wjoin()".
2015-04-11 00:47:09 +09:00
FUJIWARA Katsunori
85f9891920 subrepo: use vfs.unlink instead of os.remove
This patch also removes useless composing absolute path by
"os.path.join()".
2015-04-11 00:47:09 +09:00
FUJIWARA Katsunori
3a9e7a3504 subrepo: use vfs.rmtree instead of shutil.rmtree
This patch also removes useless "shutil" import.
2015-04-11 00:47:09 +09:00
FUJIWARA Katsunori
406aa94dc6 subrepo: use vfs.readdir instead of os.listdir to avoid expensive stat calls
"kind" information given from "vfs.readdir()" makes expensive stat
calls "os.path.isdir()" and "os.path.islink()" useless.
2015-04-11 00:47:09 +09:00
FUJIWARA Katsunori
39cf1ce825 subrepo: use vfs.reljoin instead of os.path.join 2015-04-10 00:36:42 +09:00
FUJIWARA Katsunori
95d1624750 subrepo: inline reporelpath into abstractsubrepo._relpath to centralize logic
"reporelpath()" is referred only from "abstractsubrepo._relpath()".
2015-04-10 00:36:42 +09:00
FUJIWARA Katsunori
11f7c1e0a8 subrepo: add _relpath field to centralize subrelpath logic
This patch adds propertycache-ed "_relpath" field to
"abstractsubrepo", to centralize "subrelpath" logic into it.

Now, "subrelpath()" can always return "_relpath" field of the
specified subrepo object, because it is ensured that subrepo object
has it. To reduce changes in this patch, "subrelpath()" itself is
still kept, even though it seems to be redundant.

This is also a part of eliminating "os.path.*" API invocations for
"Windows UTF-8 Plan".
2015-04-10 00:36:42 +09:00
FUJIWARA Katsunori
0372433bb6 subrepo: add wvfs field to access the working directory via vfs
This patch doesn't create vfs object in "abstractsubrepo.__init__()"
but adds propertycache-ed "wvfs" field, because the latter can:

  - delay vfs instantiation until it is actually needed

  - allow to use "hgsubrepo._repo.wvfs" as "wvfs"

    "hgsubrepo._repo" is initialized after
    "abstractsubrepo.__init__()" invocation, and passing
    "hgsubrepo._repo.wvfs" to "abstractsubrepo.__init__()" is
    difficult.
2015-04-10 00:36:42 +09:00
FUJIWARA Katsunori
f594576ac1 subrepo: change arguments of abstractsubrepo.__init__ (API)
This patch passes "ctx" and "path" instead of "ui" to
"abstractsubrepo.__init__()" and stores them as "_ctx" and "_path" to
use them in subsequent patches.

This also removes redundant field initializations in the constructor
of classes derived from "abstractsubrepo".
2015-04-10 00:36:42 +09:00
Matt Harbison
a941ba77e5 subrepo: precisely identify the missing subrepo spec file
It isn't obvious which file is the problem with deep subrepos, so provide the
path.  Since the parsing is done with a ctx and not a subrepo object, it isn't
possible to display a path from the root subrepo.  Therefore, the path shown is
relative to cwd.

There's no test coverage for the first abort, and I couldn't figure out how to
trigger it, but it is changed for consistency.
2015-04-05 15:08:55 -04:00
FUJIWARA Katsunori
e269967115 subrepo: add bailifchanged to centralize raising Abort if subrepo is dirty
This patch also centralizes composing dirty reason message like
"uncommitted changes in subrepository 'xxxx'".
2015-03-25 13:55:35 +09:00
FUJIWARA Katsunori
d9071e6959 subrepo: add dirtyreason to centralize composing dirty reason message
This patch newly adds "dirtyreason()" to centralize composing dirty
reason message like "uncommitted changes in subrepository 'xxxx'".

There are 3 similar messages below, and this patch is a part of
preparations for unifying them into (1), too.

  1. uncommitted changes in subrepository 'XXXX'
  2. uncommitted changes in subrepository XXXX
  3. uncommitted changes in subrepo XXXX

This patch chooses adding new method "dirtyreason()" instead of making
"dirty()" return "reason string", because:

  - some of existing "dirty()" implementation is too complicated to do
    so simply, and

  - ill-mannered 3rd party subrepo classes, of which "dirty()" doesn't
    return "reason string", cause meaningless message (even though it
    is rare case)
2015-03-25 13:55:32 +09:00
Matt Harbison
3ea5067ed3 subrepo: add basic support to hgsubrepo for the files command
Paths into the subrepo are not yet supported.

The need to use the workingctx in the subrepo will likely be used more in the
future, with the proposed working directory revset symbol.  It is also needed
with archive, if that code is to be reused to support 'extdiff -S'.
Unfortunately, it doesn't seem possible to put the smarts in subrepo.subrepo(),
as it breaks various status and diff tests.

I opted not to pass the desired revision into the subrepo method explicitly,
because the only ones that do pass an explicit revision are methods like status
and diff, which actually operate on two contexts- the subrepo state and the
explicitly passed revision.
2015-03-18 23:03:41 -04:00
Matt Harbison
7c8254811a subrepo: add the parent context to hgsubrepo
This brings parity with gitsubrepo and svnsubrepo (which already reference their
parent), and will be used in an upcoming patch.

I'm a bit concerned that the parent context could get stale (consider what
happens when the parent repo is reverted for example).  I tried adding the
parent context to the substate tuple so that the parent is available everywhere
a state change is possible, but that made submerge() unhappy.  Even with
removing the parent context inside submerge(), I wasn't able to get all of the
test diffs fixed.

But since the other subrepos reference their parent too, if there is a problem,
it is a preexisting one (that nobody seems to be running into).  It can be fixed
if/when it pops up.
2015-03-18 22:56:41 -04:00
Matt Harbison
d699cf2334 subrepo: replace 'ctx._repo' with 'ctx.repo()' 2015-03-12 22:59:52 -04:00
Mathias De Maré
5f319261ae subrepo: add status support for ignored and clean files in git subrepos 2015-03-09 22:14:09 +01:00
Matt Harbison
35abf3dc30 subrepo: only fetch unknown files from git when explicitly requested 2015-03-03 21:31:16 -05:00
Matt Harbison
52e1f15fa0 subrepo: always return scmutil.status() from gitsubrepo.status()
This was accidentally left out of bae0ebbd0e75.
2015-03-03 21:24:16 -05:00
Matt Harbison
385a112cb0 subrepo: explicitly request clean and unknown files in status for git's add
No behavior changes here since gitsubrepo.status() doesn't currently populate
clean, and ignores whether unknown files were actually requested.  But this is
in line with other calls to status, and should avoid future surprises.
2015-03-03 21:17:29 -05:00
Matt Harbison
53cb50db7b subrepo: warn when adding already tracked files in gitsubrepo
This follows normal Mercurial rules, and the message is lifted from
workingctx.add().  The file is printed with abs() to be consistent with how it
is printed in workingctx, even though that is inconsistent with how added files
are printed in verbose mode.  Further, the 'already tracked' notifications come
after all of the files that are added are printed, like in Mercurial.

As a side effect, we now have the reject list to return to the caller, so that
'hg add' exits with the proper code.  It looks like an abort occurs if git fails
to add the file.  Prior to touching 'snake.python' in the test, this was the
result of attempting to add the file after a 'git rm':

    fatal: pathspec 'snake.python' did not match any files
    abort: git add error 128 in s (in subrepo s)

I'm not sure what happens when git is a deep subrepo, but the 'in s' and
'in subrepo s' from @annotatesubrepoerror are redundant here.  Maybe we should
stat the files before invoking git to catch this case and print out the prettier
hg message?  The other thing missing from workingctx.add() is the call to
scmutil.checkportable(), but that would need to borrow the parent's ui object.
2015-02-27 23:30:42 -05:00
Matt Harbison
62fe6a5d98 subrepo: don't exclude files in .hgignore when adding to git
The previous test gave a false success because only an hg-ignored pattern was
specified.  Therefore match.files() was empty, and it fell back to the files
unknown to git.  The simplest fix is to always consider what is unknown to git,
as well as anything specified explicitly.  Files that are ignored by git can
only be introduced by an explicit mention in match.files().
2015-02-26 15:53:54 -05:00
Mathias De Maré
50bc3c4ab5 subrepos: support adding files in git subrepos
This support includes correct matching, so includes,
excludes and patterns are all supported.
2015-02-24 08:49:22 +01:00