Mercurial > hg-git
annotate dulwich/repo.py @ 87:babc85201dc4
merge of upstream work from dulwich project
author | Scott Chacon <schacon@gmail.com> |
---|---|
date | Fri, 08 May 2009 16:12:38 -0700 |
parents | 5deb5cbd86aa |
children | 52b4be85151d |
rev | line source |
---|---|
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
1 # repo.py -- For dealing wih git repositories. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
2 # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net> |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
3 # Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org> |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
4 # |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
5 # This program is free software; you can redistribute it and/or |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
6 # modify it under the terms of the GNU General Public License |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
7 # as published by the Free Software Foundation; version 2 |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
8 # of the License or (at your option) any later version of |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
9 # the License. |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
10 # |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
14 # GNU General Public License for more details. |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
15 # |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
19 # MA 02110-1301, USA. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
20 |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
21 """Repository access.""" |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
22 |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
23 import os |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
24 import stat |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
25 import zlib |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
26 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
27 from errors import ( |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
28 MissingCommitError, |
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
29 NotBlobError, |
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
30 NotCommitError, |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
31 NotGitRepository, |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
32 NotTreeError, |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
33 ) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
34 from object_store import ObjectStore |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
35 from objects import ( |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
36 Blob, |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
37 Commit, |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
38 ShaFile, |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
39 Tag, |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
40 Tree, |
23
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
41 hex_to_sha |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
42 ) |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
43 from misc import make_sha |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
44 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
45 OBJECTDIR = 'objects' |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
46 SYMREF = 'ref: ' |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
47 REFSDIR = 'refs' |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
48 INDEX_FILENAME = "index" |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
49 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
50 class Tags(object): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
51 """Tags container.""" |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
52 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
53 def __init__(self, tagdir, tags): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
54 self.tagdir = tagdir |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
55 self.tags = tags |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
56 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
57 def __getitem__(self, name): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
58 return self.tags[name] |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
59 |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
60 def __setitem__(self, name, ref): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
61 self.tags[name] = ref |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
62 f = open(os.path.join(self.tagdir, name), 'wb') |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
63 try: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
64 f.write("%s\n" % ref) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
65 finally: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
66 f.close() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
67 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
68 def __len__(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
69 return len(self.tags) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
70 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
71 def iteritems(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
72 for k in self.tags: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
73 yield k, self[k] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
74 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
75 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
76 def read_packed_refs(f): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
77 """Read a packed refs file. |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
78 |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
79 Yields tuples with ref names and SHA1s. |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
80 |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
81 :param f: file-like object to read from |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
82 """ |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
83 l = f.readline() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
84 for l in f.readlines(): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
85 if l[0] == "#": |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
86 # Comment |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
87 continue |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
88 if l[0] == "^": |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
89 # FIXME: Return somehow |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
90 continue |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
91 yield tuple(l.rstrip("\n").split(" ", 2)) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
92 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
93 |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
94 class Repo(object): |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
95 """A local git repository.""" |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
96 |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
97 ref_locs = ['', REFSDIR, 'refs/tags', 'refs/heads', 'refs/remotes'] |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
98 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
99 def __init__(self, root): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
100 if os.path.isdir(os.path.join(root, ".git", OBJECTDIR)): |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
101 self.bare = False |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
102 self._controldir = os.path.join(root, ".git") |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
103 elif os.path.isdir(os.path.join(root, OBJECTDIR)): |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
104 self.bare = True |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
105 self._controldir = root |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
106 else: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
107 raise NotGitRepository(root) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
108 self.path = root |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
109 self.tags = Tags(self.tagdir(), self.get_tags()) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
110 self._object_store = None |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
111 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
112 def controldir(self): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
113 """Return the path of the control directory.""" |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
114 return self._controldir |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
115 |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
116 def index_path(self): |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
117 """Return path to the index file.""" |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
118 return os.path.join(self.controldir(), INDEX_FILENAME) |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
119 |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
120 def open_index(self): |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
121 """Open the index for this repository.""" |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
122 from dulwich.index import Index |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
123 return Index(self.index_path()) |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
124 |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
125 def has_index(self): |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
126 """Check if an index is present.""" |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
127 return os.path.exists(self.index_path()) |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
128 |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
129 def find_missing_objects(self, determine_wants, graph_walker, progress): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
130 """Find the missing objects required for a set of revisions. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
131 |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
132 :param determine_wants: Function that takes a dictionary with heads |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
133 and returns the list of heads to fetch. |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
134 :param graph_walker: Object that can iterate over the list of revisions |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
135 to fetch and has an "ack" method that will be called to acknowledge |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
136 that a revision is present. |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
137 :param progress: Simple progress function that will be called with |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
138 updated progress strings. |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
139 :return: Iterator over (sha, path) pairs. |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
140 """ |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
141 wants = determine_wants(self.get_refs()) |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
142 return self.object_store.find_missing_objects(wants, |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
143 graph_walker, progress) |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
144 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
145 def fetch_objects(self, determine_wants, graph_walker, progress): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
146 """Fetch the missing objects required for a set of revisions. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
147 |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
148 :param determine_wants: Function that takes a dictionary with heads |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
149 and returns the list of heads to fetch. |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
150 :param graph_walker: Object that can iterate over the list of revisions |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
151 to fetch and has an "ack" method that will be called to acknowledge |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
152 that a revision is present. |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
153 :param progress: Simple progress function that will be called with |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
154 updated progress strings. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
155 :return: tuple with number of objects, iterator over objects |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
156 """ |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
157 return self.object_store.iter_shas( |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
158 self.find_missing_objects(determine_wants, graph_walker, progress)) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
159 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
160 def object_dir(self): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
161 """Return path of the object directory.""" |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
162 return os.path.join(self.controldir(), OBJECTDIR) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
163 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
164 @property |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
165 def object_store(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
166 if self._object_store is None: |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
167 self._object_store = DiskObjectStore(self.object_dir()) |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
168 return self._object_store |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
169 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
170 def pack_dir(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
171 return os.path.join(self.object_dir(), PACKDIR) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
172 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
173 def _get_ref(self, file): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
174 f = open(file, 'rb') |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
175 try: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
176 contents = f.read() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
177 if contents.startswith(SYMREF): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
178 ref = contents[len(SYMREF):] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
179 if ref[-1] == '\n': |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
180 ref = ref[:-1] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
181 return self.ref(ref) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
182 assert len(contents) == 41, 'Invalid ref in %s' % file |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
183 return contents[:-1] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
184 finally: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
185 f.close() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
186 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
187 def ref(self, name): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
188 """Return the SHA1 a ref is pointing to.""" |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
189 for dir in self.ref_locs: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
190 file = os.path.join(self.controldir(), dir, name) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
191 if os.path.exists(file): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
192 return self._get_ref(file) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
193 packed_refs = self.get_packed_refs() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
194 if name in packed_refs: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
195 return packed_refs[name] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
196 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
197 def get_refs(self): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
198 """Get dictionary with all refs.""" |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
199 ret = {} |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
200 if self.head(): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
201 ret['HEAD'] = self.head() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
202 for dir in ["refs/heads", "refs/tags"]: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
203 for name in os.listdir(os.path.join(self.controldir(), dir)): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
204 path = os.path.join(self.controldir(), dir, name) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
205 if os.path.isfile(path): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
206 ret["/".join([dir, name])] = self._get_ref(path) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
207 ret.update(self.get_packed_refs()) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
208 return ret |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
209 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
210 def get_packed_refs(self): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
211 """Get contents of the packed-refs file. |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
212 |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
213 :return: Dictionary mapping ref names to SHA1s |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
214 |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
215 :note: Will return an empty dictionary when no packed-refs file is |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
216 present. |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
217 """ |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
218 path = os.path.join(self.controldir(), 'packed-refs') |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
219 if not os.path.exists(path): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
220 return {} |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
221 ret = {} |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
222 f = open(path, 'r') |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
223 try: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
224 for entry in read_packed_refs(f): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
225 ret[entry[1]] = entry[0] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
226 return ret |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
227 finally: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
228 f.close() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
229 |
12
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
230 # takes refs passed from remote and renames them |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
231 def set_remote_refs(self, refs, remote_name): |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
232 keys = refs.keys() |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
233 if not keys: |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
234 return None |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
235 for k in keys[0:]: |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
236 ref_name = k |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
237 parts = k.split('/') |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
238 if parts[0] == 'refs': # strip off 'refs/heads' |
26
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
24
diff
changeset
|
239 if parts[1] == 'heads': |
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
24
diff
changeset
|
240 ref_name = "/".join([v for v in parts[2:]]) |
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
24
diff
changeset
|
241 self.set_ref('refs/remotes/' + remote_name + '/' + ref_name, refs[k]) |
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
24
diff
changeset
|
242 if parts[1] == 'tags': |
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
24
diff
changeset
|
243 ref_name = "/".join([v for v in parts[2:]]) |
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
24
diff
changeset
|
244 self.set_ref('refs/tags/' + ref_name, refs[k]) |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
245 |
4
9150a8f9d1f2
fetch will now set refs properly, including namespaced ones
Scott Chacon <schacon@gmail.com>
parents:
2
diff
changeset
|
246 def set_refs(self, refs): |
9150a8f9d1f2
fetch will now set refs properly, including namespaced ones
Scott Chacon <schacon@gmail.com>
parents:
2
diff
changeset
|
247 keys = refs.keys() |
12
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
248 if not keys: |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
249 return None |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
250 for k in keys[0:]: |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
251 self.set_ref(k, refs[k]) |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
252 |
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
253 |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
254 def set_ref(self, name, value): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
255 file = os.path.join(self.controldir(), name) |
4
9150a8f9d1f2
fetch will now set refs properly, including namespaced ones
Scott Chacon <schacon@gmail.com>
parents:
2
diff
changeset
|
256 dirpath = os.path.dirname(file) |
9150a8f9d1f2
fetch will now set refs properly, including namespaced ones
Scott Chacon <schacon@gmail.com>
parents:
2
diff
changeset
|
257 if not os.path.exists(dirpath): |
9150a8f9d1f2
fetch will now set refs properly, including namespaced ones
Scott Chacon <schacon@gmail.com>
parents:
2
diff
changeset
|
258 os.makedirs(dirpath) |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
259 f = open(file, 'w') |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
260 try: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
261 f.write(value+"\n") |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
262 finally: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
263 f.close() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
264 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
265 def remove_ref(self, name): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
266 """Remove a ref. |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
267 |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
268 :param name: Name of the ref |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
269 """ |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
270 file = os.path.join(self.controldir(), name) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
271 if os.path.exists(file): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
272 os.remove(file) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
273 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
274 def tagdir(self): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
275 """Tag directory.""" |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
276 return os.path.join(self.controldir(), REFSDIR, 'tags') |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
277 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
278 def get_tags(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
279 ret = {} |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
280 for root, dirs, files in os.walk(self.tagdir()): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
281 for name in files: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
282 ret[name] = self._get_ref(os.path.join(root, name)) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
283 return ret |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
284 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
285 def heads(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
286 ret = {} |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
287 for root, dirs, files in os.walk(os.path.join(self.controldir(), 'refs', 'heads')): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
288 for name in files: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
289 ret[name] = self._get_ref(os.path.join(root, name)) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
290 return ret |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
291 |
12
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
292 def remote_refs(self, remote_name): |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
293 ret = {} |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
294 for root, dirs, files in os.walk(os.path.join(self.controldir(), 'refs', 'remotes', remote_name)): |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
295 for name in files: |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
296 ret[name] = self._get_ref(os.path.join(root, name)) |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
297 return ret |
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
298 |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
299 def head(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
300 return self.ref('HEAD') |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
301 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
302 def _get_object(self, sha, cls): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
303 assert len(sha) in (20, 40) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
304 ret = self.get_object(sha) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
305 if ret._type != cls._type: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
306 if cls is Commit: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
307 raise NotCommitError(ret) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
308 elif cls is Blob: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
309 raise NotBlobError(ret) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
310 elif cls is Tree: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
311 raise NotTreeError(ret) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
312 else: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
313 raise Exception("Type invalid: %r != %r" % (ret._type, cls._type)) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
314 return ret |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
315 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
316 def get_object(self, sha): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
317 return self.object_store[sha] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
318 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
319 def get_parents(self, sha): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
320 return self.commit(sha).parents |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
321 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
322 def commit(self, sha): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
323 return self._get_object(sha, Commit) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
324 |
11
f2826f7b1ae5
sped up large imports significantly by caching parsed trees and sha_to_hexes
Scott Chacon <schacon@gmail.com>
parents:
10
diff
changeset
|
325 # we call this a lot on import, so we're caching it a bit |
f2826f7b1ae5
sped up large imports significantly by caching parsed trees and sha_to_hexes
Scott Chacon <schacon@gmail.com>
parents:
10
diff
changeset
|
326 already_parsed_trees = {} |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
327 def tree(self, sha): |
11
f2826f7b1ae5
sped up large imports significantly by caching parsed trees and sha_to_hexes
Scott Chacon <schacon@gmail.com>
parents:
10
diff
changeset
|
328 if sha in self.already_parsed_trees: |
f2826f7b1ae5
sped up large imports significantly by caching parsed trees and sha_to_hexes
Scott Chacon <schacon@gmail.com>
parents:
10
diff
changeset
|
329 return self.already_parsed_trees[sha] |
f2826f7b1ae5
sped up large imports significantly by caching parsed trees and sha_to_hexes
Scott Chacon <schacon@gmail.com>
parents:
10
diff
changeset
|
330 tree = self._get_object(sha, Tree) |
f2826f7b1ae5
sped up large imports significantly by caching parsed trees and sha_to_hexes
Scott Chacon <schacon@gmail.com>
parents:
10
diff
changeset
|
331 self.already_parsed_trees[sha] = tree |
f2826f7b1ae5
sped up large imports significantly by caching parsed trees and sha_to_hexes
Scott Chacon <schacon@gmail.com>
parents:
10
diff
changeset
|
332 return tree |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
333 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
334 def tag(self, sha): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
335 return self._get_object(sha, Tag) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
336 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
337 def get_blob(self, sha): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
338 return self._get_object(sha, Blob) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
339 |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
340 def write_blob(self, contents): |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
341 sha = self.write_object('blob', contents) |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
342 return sha |
23
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
343 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
344 # takes a hash of the commit data |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
345 # {'author': 'Scott Chacon <schacon@gmail.com> 1240868341 -0700' |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
346 # 'committer': 'Scott Chacon <schacon@gmail.com> 1240868341 -0700', |
47
3b62270c1fad
writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents:
38
diff
changeset
|
347 # 'message': 'test commit two\n\n--HG--\nbranch : default\n', |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
348 # 'tree': '36a63c12d097b487e4ed634c34d2f80870e64f68', |
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
349 # 'parents': ['ca82a6dff817ec66f44342007202690a93763949'], |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
350 # } |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
351 def write_commit_hash(self, commit): |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
352 if not 'committer' in commit: |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
353 commit['committer'] = commit['author'] |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
354 commit_data = '' |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
355 commit_data += 'tree ' + commit['tree'] + "\n" |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
356 for parent in commit['parents']: |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
357 commit_data += 'parent ' + parent + "\n" |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
358 commit_data += 'author ' + commit['author'] + "\n" |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
359 commit_data += 'committer ' + commit['committer'] + "\n" |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
360 commit_data += "\n" |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
361 commit_data += commit['message'] |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
362 sha = self.write_object('commit', commit_data) |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
363 return sha |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
364 |
23
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
365 # takes a multidim array |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
366 # [ ['blob', 'filename', SHA, exec_flag, link_flag], |
23
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
367 # ['tree', 'dirname/', SHA] |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
368 # ... |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
369 # ] |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
370 def write_tree_array(self, tree_array): |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
371 tree_array.sort(key=lambda x: x[1]) |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
372 tree_data = '' |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
373 for entry in tree_array: |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
374 rawsha = hex_to_sha(entry[2]) |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
375 if entry[0] == 'tree': |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
376 tree_name = entry[1][0:-1] |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
377 tree_data += "%s %s\0%s" % ('040000', tree_name, rawsha) |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
378 if entry[0] == 'blob': |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
379 # TODO : respect the modes |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
380 tree_data += "%s %s\0%s" % ('100644', entry[1], rawsha) |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
381 sha = self.write_object('tree', tree_data) |
ee217d3c6363
will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents:
21
diff
changeset
|
382 return sha |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
383 |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
384 def write_object(self, obj_type, obj_contents): |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
385 raw_data = "%s %d\0%s" % (obj_type, len(obj_contents), obj_contents) |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
386 git_sha = make_sha(raw_data) |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
387 git_hex_sha = git_sha.hexdigest() |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
388 if not git_hex_sha in self.object_store: |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
389 object_dir = os.path.join(self.path, OBJECTDIR, git_hex_sha[0:2]) |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
390 if not os.path.exists(object_dir): |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
391 os.mkdir(object_dir) |
37
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
33
diff
changeset
|
392 object_path = os.path.join(object_dir, git_hex_sha[2:]) |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
393 data = zlib.compress(raw_data) |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
394 open(object_path, 'w').write(data) # write the object |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
15
diff
changeset
|
395 return git_hex_sha |
8
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
396 |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
397 # takes a commit object and a file path |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
398 # returns the contents of that file at that commit |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
399 def get_file(self, commit, f): |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
400 otree = self.tree(commit.tree) |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
401 parts = f.split('/') |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
402 for part in parts: |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
403 (mode, sha) = otree.entry(part) |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
404 obj = self.get_object(sha) |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
405 if isinstance (obj, Blob): |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
406 return (mode, sha, obj._text) |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
407 elif isinstance(obj, Tree): |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
408 otree = obj |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
409 |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
410 # takes a commit and returns an array of the files that were changed |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
411 # between that commit and it's parents |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
412 def get_files_changed(self, commit): |
8
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
413 def filenames(basetree, comptree, prefix): |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
414 basefiles = set() |
8
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
415 changes = list() |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
416 csha = None |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
417 ctree = None |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
51
diff
changeset
|
418 cmode = None |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
419 if basetree: |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
420 for (bmode, bname, bsha) in basetree.entries(): |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
421 if bmode == 57344: # TODO : properly handle submodules |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
422 continue |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
423 basefiles.add(bname) |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
424 bobj = self.get_object(bsha) |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
425 if comptree: |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
426 (cmode, csha) = comptree.entry(bname) |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
51
diff
changeset
|
427 if not ((csha == bsha) and (cmode == bmode)): |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
428 if isinstance (bobj, Blob): |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
429 changes.append (prefix + bname) |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
430 elif isinstance(bobj, Tree): |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
431 if csha: |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
432 ctree = self.get_object(csha) |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
433 changes.extend(filenames(bobj, |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
434 ctree, |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
435 prefix + bname + '/')) |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
436 |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
437 # handle removals |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
438 if comptree: |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
439 for (bmode, bname, bsha, ) in comptree.entries(): |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
440 if bmode == 57344: # TODO: hande submodles |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
441 continue |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
442 if bname not in basefiles: |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
443 bobj = self.get_object(bsha) |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
444 if isinstance(bobj, Blob): |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
445 changes.append(prefix + bname) |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
446 elif isinstance(bobj, Tree): |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
447 changes.extend(filenames(None, bobj, |
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
38
diff
changeset
|
448 prefix + bname + '/')) |
8
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
449 return changes |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
450 |
8
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
451 all_changes = list() |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
452 otree = self.tree(commit.tree) |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
453 if len(commit.parents) == 0: |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
454 all_changes = filenames(otree, None, '') |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
455 for parent in commit.parents: |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
456 pcommit = self.commit(parent) |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
457 ptree = self.tree(pcommit.tree) |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
458 all_changes.extend(filenames(otree, ptree, '')) |
33
a3f976174d5f
Fix DeprecationWarnings in dulwich about sha.
Augie Fackler <durin42@gmail.com>
parents:
26
diff
changeset
|
459 |
8
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
460 return all_changes |
2548735d24ef
will now more or less correctly determine a changelist from a git commit
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
461 |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
462 def revision_history(self, head): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
463 """Returns a list of the commits reachable from head. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
464 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
465 Returns a list of commit objects. the first of which will be the commit |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
466 of head, then following theat will be the parents. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
467 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
468 Raises NotCommitError if any no commits are referenced, including if the |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
469 head parameter isn't the sha of a commit. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
470 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
471 XXX: work out how to handle merges. |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
472 """ |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
473 # We build the list backwards, as parents are more likely to be older |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
474 # than children |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
475 pending_commits = [head] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
476 history = [] |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
477 while pending_commits != []: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
478 head = pending_commits.pop(0) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
479 try: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
480 commit = self.commit(head) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
481 except KeyError: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
482 raise MissingCommitError(head) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
483 if commit in history: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
484 continue |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
485 i = 0 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
486 for known_commit in history: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
487 if known_commit.commit_time > commit.commit_time: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
488 break |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
489 i += 1 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
490 history.insert(i, commit) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
491 parents = commit.parents |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
492 pending_commits += parents |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
493 history.reverse() |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
494 return history |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
495 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
496 def __repr__(self): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
497 return "<Repo at %r>" % self.path |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
498 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
499 @classmethod |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
500 def init(cls, path, mkdir=True): |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
501 controldir = os.path.join(path, ".git") |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
502 os.mkdir(controldir) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
503 cls.init_bare(controldir) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
504 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
505 @classmethod |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
506 def init_bare(cls, path, mkdir=True): |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
507 for d in [[OBJECTDIR], |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
508 [OBJECTDIR, "info"], |
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
509 [OBJECTDIR, "pack"], |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
510 ["branches"], |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
511 [REFSDIR], |
2
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
512 ["refs", "tags"], |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
513 ["refs", "heads"], |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
514 ["hooks"], |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
515 ["info"]]: |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
516 os.mkdir(os.path.join(path, *d)) |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
517 open(os.path.join(path, 'HEAD'), 'w').write("ref: refs/heads/master\n") |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
518 open(os.path.join(path, 'description'), 'w').write("Unnamed repository") |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
519 open(os.path.join(path, 'info', 'excludes'), 'w').write("") |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
520 |
c43c02cc803a
added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
521 create = init_bare |
87
babc85201dc4
merge of upstream work from dulwich project
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
522 |