author | Manuel Jacob <me@manueljacob.de> |
Mon, 01 Jun 2020 14:34:22 +0200 | |
changeset 44901 | 53b3baaadb64 |
parent 44624 | 7cab8dbd0497 |
child 44951 | 83e41b73d115 |
permissions | -rw-r--r-- |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 |
"""grant Mercurial the ability to operate on Git repositories. (EXPERIMENTAL) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 |
This is currently super experimental. It probably will consume your |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
firstborn a la Rumpelstiltskin, etc. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
""" |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
from __future__ import absolute_import |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
import os |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
from mercurial.i18n import _ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
from mercurial import ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
commands, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
error, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 |
extensions, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 |
localrepo, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 |
pycompat, |
44623
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
19 |
scmutil, |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
store, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 |
util, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
from . import ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 |
dirstate, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 |
gitlog, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
gitutil, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 |
index, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 |
# TODO: extract an interface for this in core |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 |
class gitstore(object): # store.basicstore): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
def __init__(self, path, vfstype): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
self.vfs = vfstype(path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 |
self.path = self.vfs.base |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 |
self.createmode = store._calcmode(self.vfs) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
# above lines should go away in favor of: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
# super(gitstore, self).__init__(path, vfstype) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
|
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
40 |
self.git = gitutil.get_pygit2().Repository( |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 |
os.path.normpath(os.path.join(path, b'..', b'.git')) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 |
self._progress_factory = lambda *args, **kwargs: None |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 |
@util.propertycache |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 |
def _db(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 |
# We lazy-create the database because we want to thread a |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 |
# progress callback down to the indexing process if it's |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 |
# required, and we don't have a ui handle in makestore(). |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 |
return index.get_index(self.git, self._progress_factory) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
def join(self, f): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
53 |
"""Fake store.join method for git repositories. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
55 |
For the most part, store.join is used for @storecache |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 |
decorators to invalidate caches when various files |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 |
change. We'll map the ones we care about, and ignore the rest. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
58 |
""" |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 |
if f in (b'00changelog.i', b'00manifest.i'): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 |
# This is close enough: in order for the changelog cache |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
61 |
# to be invalidated, HEAD will have to change. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
return os.path.join(self.path, b'HEAD') |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 |
elif f == b'lock': |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
64 |
# TODO: we probably want to map this to a git lock, I |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
65 |
# suspect index.lock. We should figure out what the |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
66 |
# most-alike file is in git-land. For now we're risking |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
67 |
# bad concurrency errors if another git client is used. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 |
return os.path.join(self.path, b'hgit-bogus-lock') |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
69 |
elif f in (b'obsstore', b'phaseroots', b'narrowspec', b'bookmarks'): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
70 |
return os.path.join(self.path, b'..', b'.hg', f) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 |
raise NotImplementedError(b'Need to pick file for %s.' % f) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 |
def changelog(self, trypending): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 |
# TODO we don't have a plan for trypending in hg's git support yet |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 |
return gitlog.changelog(self.git, self._db) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
76 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
77 |
def manifestlog(self, repo, storenarrowmatch): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 |
# TODO handle storenarrowmatch and figure out if we need the repo arg |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 |
return gitlog.manifestlog(self.git, self._db) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 |
def invalidatecaches(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
pass |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
83 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
84 |
def write(self, tr=None): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
85 |
# normally this handles things like fncache writes, which we don't have |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
86 |
pass |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
87 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 |
def _makestore(orig, requirements, storebasepath, vfstype): |
44493
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
90 |
if b'git' in requirements: |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
91 |
if not os.path.exists(os.path.join(storebasepath, b'..', b'.git')): |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
92 |
raise error.Abort( |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
93 |
_( |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
94 |
b'repository specified git format in ' |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
95 |
b'.hg/requires but has no .git directory' |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
96 |
) |
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
97 |
) |
44493
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
98 |
# Check for presence of pygit2 only here. The assumption is that we'll |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
99 |
# run this code iff we'll later need pygit2. |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
100 |
if gitutil.get_pygit2() is None: |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
101 |
raise error.Abort( |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
102 |
_( |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
103 |
b'the git extension requires the Python ' |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
104 |
b'pygit2 library to be installed' |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
105 |
) |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
106 |
) |
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
107 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
108 |
return gitstore(storebasepath, vfstype) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
109 |
return orig(requirements, storebasepath, vfstype) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
111 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 |
class gitfilestorage(object): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 |
def file(self, path): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 |
if path[0:1] == b'/': |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 |
path = path[1:] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 |
return gitlog.filelog(self.store.git, self.store._db, path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
117 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 |
def _makefilestorage(orig, requirements, features, **kwargs): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 |
store = kwargs['store'] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
121 |
if isinstance(store, gitstore): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 |
return gitfilestorage |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 |
return orig(requirements, features, **kwargs) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 |
def _setupdothg(ui, path): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 |
dothg = os.path.join(path, b'.hg') |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 |
if os.path.exists(dothg): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 |
ui.warn(_(b'git repo already initialized for hg\n')) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
else: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 |
os.mkdir(os.path.join(path, b'.hg')) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
# TODO is it ok to extend .git/info/exclude like this? |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 |
with open( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 |
os.path.join(path, b'.git', b'info', b'exclude'), 'ab' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 |
) as exclude: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
136 |
exclude.write(b'\n.hg\n') |
44493
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
137 |
with open(os.path.join(dothg, b'requires'), 'wb') as f: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 |
f.write(b'git\n') |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
139 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 |
_BMS_PREFIX = 'refs/heads/' |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
142 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
143 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
144 |
class gitbmstore(object): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
145 |
def __init__(self, gitrepo): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
self.gitrepo = gitrepo |
44624
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
147 |
self._aclean = True |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
148 |
self._active = gitrepo.references['HEAD'] # git head, not mark |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 |
def __contains__(self, name): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 |
return ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 |
_BMS_PREFIX + pycompat.fsdecode(name) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 |
) in self.gitrepo.references |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 |
def __iter__(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 |
for r in self.gitrepo.listall_references(): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
157 |
if r.startswith(_BMS_PREFIX): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 |
yield pycompat.fsencode(r[len(_BMS_PREFIX) :]) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 |
def __getitem__(self, k): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 |
return ( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 |
self.gitrepo.references[_BMS_PREFIX + pycompat.fsdecode(k)] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 |
.peel() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
164 |
.id.raw |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
165 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 |
def get(self, k, default=None): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
168 |
try: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
169 |
if k in self: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
170 |
return self[k] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 |
return default |
44484
ec54b3d2af0b
git: don't fail import when pygit2 is not install
Martin von Zweigbergk <martinvonz@google.com>
parents:
44477
diff
changeset
|
172 |
except gitutil.get_pygit2().InvalidSpecError: |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 |
return default |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
174 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
175 |
@property |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
176 |
def active(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
177 |
h = self.gitrepo.references['HEAD'] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 |
if not isinstance(h.target, str) or not h.target.startswith( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
179 |
_BMS_PREFIX |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
180 |
): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 |
return None |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
182 |
return pycompat.fsencode(h.target[len(_BMS_PREFIX) :]) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
184 |
@active.setter |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
185 |
def active(self, mark): |
44624
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
186 |
githead = mark is not None and (_BMS_PREFIX + mark) or None |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
187 |
if githead is not None and githead not in self.gitrepo.references: |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
188 |
raise AssertionError(b'bookmark %s does not exist!' % mark) |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
189 |
|
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
190 |
self._active = githead |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
191 |
self._aclean = False |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
192 |
|
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
193 |
def _writeactive(self): |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
194 |
if self._aclean: |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
195 |
return |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
196 |
self.gitrepo.references.create('HEAD', self._active, True) |
7cab8dbd0497
git: implement basic bookmark activation
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44623
diff
changeset
|
197 |
self._aclean = True |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
199 |
def names(self, node): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 |
r = [] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
201 |
for ref in self.gitrepo.listall_references(): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
202 |
if not ref.startswith(_BMS_PREFIX): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
203 |
continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
204 |
if self.gitrepo.references[ref].peel().id.raw != node: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
205 |
continue |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
206 |
r.append(pycompat.fsencode(ref[len(_BMS_PREFIX) :])) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
207 |
return r |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 |
# Cleanup opportunity: this is *identical* to core's bookmarks store. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 |
def expandname(self, bname): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
211 |
if bname == b'.': |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
212 |
if self.active: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
213 |
return self.active |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
214 |
raise error.RepoLookupError(_(b"no active bookmark")) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
215 |
return bname |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
216 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
217 |
def applychanges(self, repo, tr, changes): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
218 |
"""Apply a list of changes to bookmarks |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
219 |
""" |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
220 |
# TODO: this should respect transactions, but that's going to |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
221 |
# require enlarging the gitbmstore to know how to do in-memory |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 |
# temporary writes and read those back prior to transaction |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
223 |
# finalization. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
224 |
for name, node in changes: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
225 |
if node is None: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
226 |
self.gitrepo.references.delete( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
227 |
_BMS_PREFIX + pycompat.fsdecode(name) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
228 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
229 |
else: |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
230 |
self.gitrepo.references.create( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
231 |
_BMS_PREFIX + pycompat.fsdecode(name), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
232 |
gitutil.togitnode(node), |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
233 |
force=True, |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
234 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
235 |
|
44623
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
236 |
def checkconflict(self, mark, force=False, target=None): |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
237 |
githead = _BMS_PREFIX + mark |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
238 |
cur = self.gitrepo.references['HEAD'] |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
239 |
if githead in self.gitrepo.references and not force: |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
240 |
if target: |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
241 |
if self.gitrepo.references[githead] == target and target == cur: |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
242 |
# re-activating a bookmark |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
243 |
return [] |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
244 |
# moving a bookmark - forward? |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
245 |
raise NotImplementedError |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
246 |
raise error.Abort( |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
247 |
_(b"bookmark '%s' already exists (use -f to force)") % mark |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
248 |
) |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
249 |
if len(mark) > 3 and not force: |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
250 |
try: |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
251 |
shadowhash = scmutil.isrevsymbol(self._repo, mark) |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
252 |
except error.LookupError: # ambiguous identifier |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
253 |
shadowhash = False |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
254 |
if shadowhash: |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
255 |
self._repo.ui.warn( |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
256 |
_( |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
257 |
b"bookmark %s matches a changeset hash\n" |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
258 |
b"(did you leave a -r out of an 'hg bookmark' " |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
259 |
b"command?)\n" |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
260 |
) |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
261 |
% mark |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
262 |
) |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
263 |
return [] |
bb3e05ca21ca
git: implement a basic checkconflict bookmark store method
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
44542
diff
changeset
|
264 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
265 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
266 |
def init(orig, ui, dest=b'.', **opts): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
267 |
if opts.get('git', False): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
268 |
path = os.path.abspath(dest) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
269 |
# TODO: walk up looking for the git repo |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
270 |
_setupdothg(ui, path) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
271 |
return 0 |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
272 |
return orig(ui, dest=dest, **opts) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
273 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
274 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
275 |
def reposetup(ui, repo): |
44542
a2b49606a837
hgit: make sure repository is local before checking for store type
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44493
diff
changeset
|
276 |
if repo.local() and isinstance(repo.store, gitstore): |
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
277 |
orig = repo.__class__ |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
278 |
repo.store._progress_factory = repo.ui.makeprogress |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
279 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
280 |
class gitlocalrepo(orig): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
281 |
def _makedirstate(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
282 |
# TODO narrow support here |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
283 |
return dirstate.gitdirstate( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
284 |
self.ui, self.vfs.base, self.store.git |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
285 |
) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
286 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
287 |
def commit(self, *args, **kwargs): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
288 |
ret = orig.commit(self, *args, **kwargs) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
289 |
tid = self.store.git[gitutil.togitnode(ret)].tree.id |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
290 |
# DANGER! This will flush any writes staged to the |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
291 |
# index in Git, but we're sidestepping the index in a |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
292 |
# way that confuses git when we commit. Alas. |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
293 |
self.store.git.index.read_tree(tid) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
294 |
self.store.git.index.write() |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
295 |
return ret |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
296 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
297 |
@property |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
298 |
def _bookmarks(self): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
299 |
return gitbmstore(self.store.git) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
300 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
301 |
repo.__class__ = gitlocalrepo |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
302 |
return repo |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
303 |
|
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
304 |
|
44493
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
305 |
def _featuresetup(ui, supported): |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
306 |
# don't die on seeing a repo with the git requirement |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
307 |
supported |= {b'git'} |
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
308 |
|
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
309 |
|
44477
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
310 |
def extsetup(ui): |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
311 |
extensions.wrapfunction(localrepo, b'makestore', _makestore) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
312 |
extensions.wrapfunction(localrepo, b'makefilestorage', _makefilestorage) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
313 |
# Inject --git flag for `hg init` |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
314 |
entry = extensions.wrapcommand(commands.table, b'init', init) |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
315 |
entry[1].extend( |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
316 |
[(b'', b'git', None, b'setup up a git repository instead of hg')] |
ad718271a9eb
git: skeleton of a new extension to _directly_ operate on git repos
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
317 |
) |
44493
02c47b74366c
git: key off `git` in .hg/requires rather than separate file
Augie Fackler <raf@durin42.com>
parents:
44484
diff
changeset
|
318 |
localrepo.featuresetupfuncs.add(_featuresetup) |