Commit Graph

258 Commits

Author SHA1 Message Date
Siddharth Agarwal
fe5bb48ac2 git_handler: return early when no commits need to be exported
This will make our life easier in an upcoming patch.
2014-03-14 19:18:19 -07:00
Siddharth Agarwal
e5bd941852 hg2git: implement a method to initialize _dirs from a Git commit
Upcoming patches will start incrementally exporting from a particular commit
instead of from null. This function will be used for that..
2014-03-14 19:17:09 -07:00
Siddharth Agarwal
3e13ddc73e safebranchrevs: handle changelog having no commits
The usage of getattr was unsafe. Use hgutil.safehasattr instead.
util.safehasattr has been around since Mercurial 2.0.

This also fixes the formerly disabled test in test-pull.t.
2014-03-04 23:20:50 -08:00
Siddharth Agarwal
bf45b40ca3 git_handler.fetch: only import commits reachable from requested heads
Previously we'd attempt to import every single reachable commit in the Git
object store.

The test adds another branch to the Git repo and doesn't import it until much
later. Previously we'd import it when we ran `hg -R hgrepo pull -r beta`. Now
we won't.
2014-03-04 16:23:11 -08:00
Siddharth Agarwal
759062fbfd git_handler.fetch: actually return number of heads added or removed
The return value as implemented in git_handler.fetch was pretty bogus. It used
to return the number of values that changed in the 'refs/heads/' namespace,
regardless of whether multiple values in there point to the same Mercurial
commit, or whether particular heads were even imported. Fix all of that by
using the actual heads in the changelog, just like vanilla Mercurial.

The test output changes demonstrate examples where the code was buggy.
2014-03-04 16:05:19 -08:00
Siddharth Agarwal
0428a10ad5 import_git_objects: return number of commits imported
This will be used in an upcoming patch.
2014-03-04 16:51:43 -08:00
Siddharth Agarwal
e41aded84e git_handler: base 'no changes found' message on commits, not on heads
Since Mercurial is commit-oriented, the 'no changes found' message really
should rely on what new commits are in the repo, not on new heads. This also
makes an upcoming patch much simpler.

Since everything around this code is completely broken anyway, writing a test
for this that doesn't trigger other bugs is close to impossible. An upcoming
patch will include tests.

The test output change is for an empty clone -- the output is precisely how
vanilla Mercurial treats an empty clone.
2014-03-04 15:43:54 -08:00
Siddharth Agarwal
636c9670c6 update_hg_bookmarks: don't update bookmarks that don't have an hg commit
Still more bugs to fix.
2014-03-04 14:50:44 -08:00
Siddharth Agarwal
c090d035ea update_remote_branches: don't store refs that don't have an hg equivalent
Same reasoning as previous patch, and same reason why this patch doesn't
include a test.
2014-03-04 14:39:50 -08:00
Siddharth Agarwal
82ef213bf9 import_tags: don't import tags that don't have an hg commit equivalent
The theme of this and upcoming patches is that relying on self.git.object_store
to figure out which commits/tags/bookmarks to import is not great. This breaks
if the git repo is manually put in place (as might be done in a server-based
replication scenario), or if a partial fetch pulled too many commits in for
whatever reason. Indeed we were just about always pulling an entire pack in,
because listkeys for bookmarks currently calls fetch_pack without any
filtering. (This is probably a bug and should be fixed, but this series doesn't
do that.)

Instead, rely on whether we actually imported the commit into Mercurial to
determine whether to import the tag. This is clean, straightforward, and
clearly correct.

There is a whole series of bugs in this code that any test case for this would
hit -- an upcoming patch will include a test for all these bugs at once.
2014-03-04 14:26:30 -08:00
Siddharth Agarwal
6a6f93d8e3 determine_wants: factor ref filtering code out into a separate function
This will be used in another context in an upcoming patch.
2014-03-04 12:57:37 -08:00
Siddharth Agarwal
4877843f03 git_handler: don't write out objects if already in object store
object_store.add_object doesn't check to see if the object is already in a
pack, so it is still written out in that case. Do the check ourselves before
calling add_object.
2014-03-03 22:44:09 -08:00
Siddharth Agarwal
05dde62bce extsetup: use new-style extsetup with ui parameter
The "new-style" extsetup has been supported since at least 2009.
2014-02-27 17:20:31 -08:00
Augie Fackler
e1793c2341 verify: drop broken and unused import statement 2014-03-01 09:37:26 -05:00
Siddharth Agarwal
89c409af60 verify: add new command to verify the contents of a Mercurial rev
Since the Git to Mercurial conversion process is incremental, it's at risk of
missing files, or recording files the wrong way, or recording the wrong commit
metadata. Add a command called 'gverify' that can verify the contents of a
particular Mercurial rev against the corresponding Git commit.

Currently, this is limited to checking file names, flags and contents, but this
can be made as robust as desired. Further additions will probably require
refactoring git_handler.py a bit though.

This function is pretty fast: on a Linux machine with a warm cache, verifying a
repository with around 50,000 files takes just 20 seconds. There is scope for
further improvement through parallelization, but conducting tree walks in
parallel is non-trivial with the current worker infrastructure in Mercurial.
2014-02-26 14:19:24 -08:00
Siddharth Agarwal
56cbe49bb0 git_handler: remove init_if_missing
This function is a no-op and can be removed.
2014-02-25 20:01:42 -08:00
Siddharth Agarwal
6d1bd2e02e git_handler: make self.git a lazily evaluated property
This allows other functions to be able to use the `git` property without
needing to care about initializing it.

An upcoming patch will remove the `init_if_missing` function.
2014-02-25 19:51:02 -08:00
Siddharth Agarwal
bbfc3bf8b0 overlayrevlog: handle root commits correctly
Previously, we'd try to access commit.parents[0] and fail. Now, check for
commit.parents being empty and return what Mercurial thinks is a repository
root in that case.
2014-02-25 00:23:12 -08:00
Siddharth Agarwal
a5e956514d overlayrevlog: handle rev = 0 correctly
Previously we'd just test if gitrev was falsy, which it is if the rev returned
is 0, even though it shouldn't be. With this patch, test against None
explicitly.

This unmasks another bug: see next patch for a fix and a test.
2014-02-25 00:20:22 -08:00
Siddharth Agarwal
fea85d57c6 git_handler: fix call to self.ui.progress in flush
Since we now directly use progress on self.ui, we shouldn't pass in self.ui as
the first argument. Oops.
2014-02-24 15:29:31 -08:00
Siddharth Agarwal
2cc81f4c1f git_handler: don't compute tags for each tag imported
Previously we'd recompute the repo tags each time we'd consider importing a Git
tag. This is O(n^2) in the number of tags and produced noticeable slowdowns in
repos with large numbers of tags.

To fix this, compute the tags just once. This is correct because the only case
where we'd have issues is if multiple new Git tags with the same name were
introduced, which can't happen because Git tags cannot share names.

For a repository with over 200 tags, this causes a no-op hg pull to be sped up
by around 0.5 seconds.
2014-02-24 11:38:00 -08:00
Siddharth Agarwal
27784bf3bc util: drop support for Mercurial < 1.4 2014-02-19 18:49:42 -08:00
Siddharth Agarwal
01fb9068a0 git_handler: replace util.progress with ui.progress
util.progress was a shim for Mercurial < 1.4.
2014-02-19 18:49:28 -08:00
Siddharth Agarwal
01896282f6 overlay: drop support for Mercurial < 1.9 2014-02-19 18:46:56 -08:00
Siddharth Agarwal
a49ac12684 git_handler: remove old and bogus code for deleting entries from tags cache
This code never worked for Mercurial >= 2.0, since it neither had repo._tags
nor repo.tagscache.
2014-02-19 18:45:36 -08:00
Siddharth Agarwal
d7bad71d02 git_handler.save_tags: drop support for Mercurial < 1.9 2014-02-19 16:12:27 -08:00
Siddharth Agarwal
5ef555a629 git_handler.save_map: drop support for Mercurial < 1.9 2014-02-19 16:10:35 -08:00
Siddharth Agarwal
8f2d697a54 hgrepo.tags: drop support for Mercurial < 2.0
A new property called _tagscache was introduced in Mercurial 2.0, so the cache
wasn't actually working.

The contract for tags() also changed at some point -- it stopped returning
nodes that weren't in the repo. This will need to be accounted for if we
start using the tags cache again. However, it isn't very clear whether the
Mercurial tags cache is actually worth doing, since we already have a
separate in-memory cache for Git tags in the handler.
2014-02-19 16:09:23 -08:00
Siddharth Agarwal
41357ce554 hgrepo.push: drop support for Mercurial < 1.6 2014-02-19 15:55:45 -08:00
Siddharth Agarwal
732da34592 gitrepo: drop support for Mercurial < 1.7 2014-02-19 15:54:37 -08:00
Siddharth Agarwal
7e329463b5 getremotechanges: drop support for Mercurial < 1.7 2014-02-19 15:54:04 -08:00
Siddharth Agarwal
a1a2eb9b35 nodetags: drop support for Mercurial < 1.6 2014-02-19 15:53:14 -08:00
Siddharth Agarwal
c11b48a4e7 extsetup: drop support for Mercurial < 1.7 2014-02-19 15:52:14 -08:00
Siddharth Agarwal
6a0d42bac0 version: drop support for Mercurial 1.9.3
Upcoming patches will clean up some code that makes hg-git work with Mercurial
versions < 2.0.
2014-02-19 15:48:27 -08:00
Siddharth Agarwal
6b4e5f67db hg2git: fix subrepo handling to be deterministic
Previously, the correctness of _handle_subrepos was based on the order the
files were processed in. For example, consider the case where a subrepo at
location 'loc' is replaced with a file at 'loc', while another subrepo exists.
This would cause .hgsubstate and .hgsub to be modified and the file added.

If .hgsubstate was seen _before_ 'loc' in the modified/added loop, then
_handle_subrepos would run and remove 'loc' correctly, before 'loc' was added
back later. If, however, .hgsubstate was seen _after_ 'loc', then
_handle_subrepos would run after 'loc' was added and would remove 'loc'.

With this patch, _handle_subrepos merely computes the changes that need to be
applied. The changes are then applied, making sure removed files and subrepos
are processed before added ones.

This was detected by setting a random PYTHONHASHSEED (in this case, 3910358828)
and running the test suite against it. An upcoming patch will randomize the
PYTHONHASHSEED in run-tests.py, just like is done in Mercurial.
2014-02-19 20:52:59 -08:00
Siddharth Agarwal
689b38dc44 hg2git: move parse_subrepos to top level
durin42 expressed a desire for this function to be at the top level.
2014-02-19 20:18:43 -08:00
Siddharth Agarwal
08f028a3c9 gitnodekw: use githandler from repo
Since a fresh GitHandler is no longer created for every commit, this speeds up
the {gitnode} template massively.

For a repo with over 50,000 commits, the command

hg log -l 10 --template '{gitnode}\n'

speeds up from 2.4 seconds to 0.3.
2014-02-19 15:23:36 -08:00
Siddharth Agarwal
e7c06facc2 revset_gitnode: use githandler from repo 2014-02-19 15:22:54 -08:00
Siddharth Agarwal
1d58a0a197 revset_fromgit: use githandler from repo 2014-02-19 15:22:36 -08:00
Siddharth Agarwal
b1bbd30c48 getremotechanges: use githandler from repo 2014-02-19 15:15:01 -08:00
Siddharth Agarwal
886532ea23 findcommonoutgoing: use githandler from repo 2014-02-19 15:13:43 -08:00
Siddharth Agarwal
068acd034c gclear: use githandler from repo 2014-02-19 15:12:59 -08:00
Siddharth Agarwal
fcd7e472fc gexport: use githandler from repo 2014-02-19 15:12:42 -08:00
Siddharth Agarwal
298b98a518 gimport: use githandler from repo 2014-02-19 15:12:20 -08:00
Siddharth Agarwal
dd8bbcebed gitrepo: drop unused _initializehandler function and handler property
Also drop the GitHandler import. All this now lives on hgrepo.
2014-02-19 15:11:14 -08:00
Siddharth Agarwal
d239f557d1 gitrepo.listkeys: use githandler from localrepo
Previously we'd load the git and hg maps twice on separate git handler objects.
This avoids that.

For a repo with over 50,000 commits, this brings a no-op hg pull down from 2.45
seconds to 2.37.
2014-02-19 15:07:19 -08:00
Siddharth Agarwal
772133c48a hgrepo.tags: use githandler property
Currently we call hgrepo.tags() separately for each tag. (This should be fixed
at some point.) This avoids initializing a separate git handler for each tag.

For a repository with over 150 tags, this brings down a no-op hg pull by 0.05
seconds.
2014-02-19 14:16:40 -08:00
Siddharth Agarwal
232c6612ae hgrepo._findtags: use githandler property 2014-02-19 14:15:33 -08:00
Siddharth Agarwal
1c6dc044d5 hgrepo.findoutgoing: use githandler property 2014-02-19 14:14:54 -08:00
Siddharth Agarwal
f87f28dc3a hgrepo.push: use githandler property 2014-02-19 14:14:01 -08:00