cat: move most of the implementation into cmdutils.cat()

This will allow access to the reusable parts from subrepos, similar to add(),
forget(), etc.

--HG--
extra : rebase_source : 5db62462e866e59307a49b7b38f738c98847bc08
cat: support cat with explicit paths in subrepos

The cat command with an explicit path into a subrepo is now handled by invoking
cat on the file, from that subrepo.  The previous behavior was to complain that
the file didn't exist in the revision (of the top most repo).  Now when the file
is actually missing, the revision of the subrepo is named instead (though it is
probably desirable to continue naming the top level repo).

The documented output formatters %d and %p reflect the path from the top level
repo, since the purpose of this is to give the illusion of a unified repository.
Support for the undocumented (for cat) formatters %H, %R, %h, %m and %r was
added long ago (I tested back as far as 0.5), but unfortunately these will
reflect the subrepo node instead of the parent context.

The previous implementation was a bit loose with the return value, i.e. it would
return 0 if _any_ file requested was cat'd successfully.  This maintains that
behavior.

--HG--
extra : rebase_source : e4d4b66953e4894e7b00dc00a80ca299df8758cf
largefiles: centralize the logic to get outgoing largefiles

Before this patch, "overrides.getoutgoinglfiles()" (called by
"overrideoutgoing()" and "overridesummary()") and "lfilesrepo.push()"
implement similar logic to get outgoing largefiles separately.

This patch centralizes the logic to get outgoing largefiles in
"lfutil.getlfilestoupload()".

"lfutil.getlfilestoupload()" takes "addfunc" argument, because each
callers need different information (and it is useful for enhancement
in the future).

  - "overrides.getoutgoinglfiles()" needs only filenames
  - "lfilesrepo.push()" needs only hashes of largefiles

--HG--
extra : rebase_source : 03abf1e7a88d7a879db82a9e2272eb7973aad5cd
localrepo: introduce "prepushoutgoinghooks" to extend outgoing check easily

This patch introduces "prepushoutgoinghooks" to extend outgoing check
before pushing changesets to remote easily.

This chooses the function returning "util.hooks" instead of the one to
be overridden.

The latter may cause problems silently, if one of overriders forgets
(or fails) to execute a kind of "super(xxx, self).overridden(...)". In
the other hand, the former can ensure that all registered functions
are invoked, unless one of them raises an exception.

--HG--
extra : rebase_source : 8178230450878beae0a01347f084ad260881e78f
largefiles: reuse "findcommonoutgoing()" result at "hg push"

Before this patch, "hg push" invokes "findcommonoutgoing()" not only
in "exchange.push()" but also in "lfilesrepo.push()", when largefiles
is enabled. The latter is redundant.

This patch registers own "prepushoutgoinghook" function into
"prepushoutgoinghooks" of "localrepository" to reuse
"findcommonoutgoing()" result.

"prepushoutgoinghook" omits "changelog.nodesbetween()" invocation,
because "findcommonoutgoing()" invocation in "exchange.push()" takes
"onlyheads" argument and it considers "nodesbetween()".

--HG--
extra : rebase_source : 808bf7422ff89a6a386abf3535eddf170e840bfb
summary: separate checking incoming/outgoing and showing remote summary

This patch separates checking incoming/outgoing and showing remote
summary, as a preparation for refactoring in succeeding patches,
because:

  - checking incoming/outgoing may be needed, even if "--remote" is
    not specified for "hg summary"

  - checking incoming/outgoing may not be needed simultaneously

"hg summary --large" without "--remote" is typical case for these.

--HG--
extra : rebase_source : 192f640d66b181a9a0b325a2b91ea0c3195c6ccb
util: enable "hooks" to return list of the values returned from each hooks

--HG--
extra : rebase_source : 3e15c23c74a663a671ef7c74825de4a234f6aba4
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check

This patch introduces "summaryremotehooks" to avoid redundant
incoming/outgoing check for "hg summary" in other than
"commands.summary".

Only if "--remote" is not specified for "hg summary", hooks registered
in "summaryremotehooks" are invoked with "None" as "changes" argument
at first, and they should return tuple of two booleans meaning
"whether incomings are needed" and "whether outgoings are needed".

If no hooks return tuple containing "True", "hg summary" does nothing
any more, because incoming/outgoing check is not needed.

Otherwise, hooks are invoked again: at this time, "changes" argument
refers the result of incoming/outgoing check.

This patch also prevents RepoError from being raised if "--remote" is
not specified for "hg summary", because of backward compatibility for
"hg summary --large" without "--remote".

--HG--
extra : rebase_source : faed485356ee82c91158633f888a6c6ff5cc6ee0
largefiles: use "summaryremotehooks" to avoid redundant outgoing check

Before this patch, "hg summary --remote --large" invokes
"findcommonoutgoing()" not only in "commands.summary()" but also in
"overrides.overridesummary()" (via "getoutgoinglfiles()"). The latter
is redundant.

This patch uses "summaryremotehooks" to avoid redundant outgoing check.

Newly introduced function "overrides.summaryremotehook()" is
registered into "summaryremotehooks" to get the result of outgoing
check in "commands.summary()".

It invokes "lfutil.getlfilestoupload()" directly with the result of
outgoing check to avoid redundant outgoing check in
"getoutgoinglfiles()".

--HG--
extra : rebase_source : 003c5cd905919a6801e6c8eacce2e36970d3f317
hg: make "_outgoing()" return empty list instead of "None"

This patch makes "_outgoing()" return empty list instead of "None", if
there are no outgoing changesets, because:

  - returning "None" requires callers to examine whether returned
    value is "None" or not explicitly, if callers want to execute loop
    on returned value, but

  - there are no explicit needs to return "None"

--HG--
extra : rebase_source : 6419debbc611f95dbce387d51614631f1dffee56
hg: make "_outgoing()" return peer object for remote repository

This patch makes "_outgoing()" return peer object for remote
repository, to avoid re-execution "expandpath()", "parseurl()", and
"peer()" on caller side for specified URL.

--HG--
extra : rebase_source : 50c2c04e5d94968e6c685747900e524e66d7f1b0
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check

This patch introduces "outgoinghooks" to avoid redundant outgoing
check for "hg outgoing" in other than "commands.outgoing" (or utility
functions used by it).

--HG--
extra : rebase_source : 43a59f6905d348c2c4e578bef3247f0d3e5cf045
largefiles: use "outgoinghooks" to avoid redundant outgoing check

Before this patch, "hg outgoing" invokes "findcommonoutgoing()" not
only in "commands.outgoing()" but also in
"overrides.overrideoutgoing()" (via "getoutgoinglfiles()"), when
largefiles is enabled. The latter is redundant.

This patch uses "outgoinghooks" to avoid redundant outgoing check.

Newly introduced function "overrides.outgoinghook()" is registered
into "outgoinghooks" to get the result of outgoing check in
"commands.outgoing()".

It invokes "lfutil.getlfilestoupload()" directly with the result of
outgoing check to avoid redundant outgoing check in
"getoutgoinglfiles()": "sort()" is needed, because
"lfutil.getlfilestoupload()" doesn't sort the result of it.

This patch also omits "if toupload is None" ("No remote repo") case,
because failure of looking remote repository up should raise exception
in "commands.outgoing()" before invocation of "outgoinghooks".

Newly added "hg outgoing --large --graph" tests examine
"outgoinghooks" invocations in "hg outgoing --graph" code path.

--HG--
extra : rebase_source : 5c5479bbf349e27bbde827abb209c2f6f3368e63
largefiles: remove no more referred "getoutgoinglfiles()"

--HG--
extra : rebase_source : a02fe5801ccb4eba4d70d2d8ac135e0c784c5492