forked from schacon/hg-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhgrepo.py
134 lines (112 loc) · 4.67 KB
/
hgrepo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from mercurial import localrepo, lock, node
from mercurial import changelog, dirstate, filelog, manifest, context, weakref
from mercurial.node import bin, hex, nullid, nullrev, short
class hgrepo(localrepo.localrepository):
def commit_import_ctx(self, wctx, ancestor, force_files = None):
tr = None
valid = 0 # don't save the dirstate if this isn't set
try:
force=False
force_editor=False
empty_ok=False
use_dirstate=False
update_dirstate=False
commit = sorted(wctx.modified() + wctx.added())
remove = wctx.removed()
extra = wctx.extra().copy()
branchname = extra['branch']
user = wctx.user()
text = wctx.description()
p1, p2 = [p.node() for p in wctx.parents()]
c1 = self.changelog.read(p1)
c2 = self.changelog.read(p2)
m1 = self.manifest.read(c1[0]).copy()
m2 = self.manifest.read(c2[0])
ma = None
if ancestor:
ma = ancestor.manifest()
xp1 = hex(p1)
if p2 == nullid: xp2 = ''
else: xp2 = hex(p2)
tr = self.transaction()
trp = weakref.proxy(tr)
# looking for files that have not actually changed content-wise,
# but have different nodeids because they were changed and then
# reverted, so they have changed in the revlog.
for f in m1:
if (f in m2) and (not f in commit) and (not m1[f] == m2[f]):
commit.append(f)
# check in files
new = {}
changed = []
linkrev = len(self)
for f in commit:
self.ui.note(f + "\n")
try:
fctx = wctx.filectx(f)
newflags = fctx.flags()
new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, changed)
if ((not changed or changed[-1] != f) and
m2.get(f) != new[f]):
# mention the file in the changelog if some
# flag changed, even if there was no content
# change.
if m1.flags(f) != newflags:
changed.append(f)
m1.set(f, newflags)
except (OSError, IOError):
remove.append(f)
updated, added = [], []
for f in sorted(changed):
if f in m1 or f in m2:
updated.append(f)
else:
added.append(f)
# update manifest
m1.update(new)
removed = [f for f in sorted(remove) if f in m1 or f in m2]
removed1 = []
for f in removed:
if f in m1:
del m1[f]
removed1.append(f)
else:
if ma and (f in ma):
del ma[f]
removed.remove(f)
mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
(new, removed1))
#lines = [line.rstrip() for line in text.rstrip().splitlines()]
#while lines and not lines[0]:
# del lines[0]
#text = '\n'.join(lines)
if text[-1] == "\n":
text = text[:-1]
file_list = []
if force_files == False:
file_list = []
else:
if force_files and len(force_files) > 0:
file_list = force_files
else:
file_list = changed + removed
self.changelog.delayupdate()
n = self.changelog.add(mn, file_list, text, trp, p1, p2,
user, wctx.date(), extra)
p = lambda: self.changelog.writepending() and self.root or ""
self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
parent2=xp2, pending=p)
self.changelog.finalize(trp)
tr.close()
if self.branchcache:
self.branchtags()
if update_dirstate:
self.dirstate.setparents(n)
valid = 1 # our dirstate updates are complete
self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
return n
finally:
if not valid: # don't save our updated dirstate
self.dirstate.invalidate()
del tr
instance = hgrepo