@@ -42,6 +42,7 @@ class SymbolicReference(object):
42
42
#{ Configuration
43
43
# Object class to be used when instantiating objects
44
44
ObjectCls = Object
45
+ CommitCls = Commit
45
46
46
47
# all of the following are set by the package initializer
47
48
HEADCls = None
@@ -80,11 +81,11 @@ def name(self):
80
81
81
82
@property
82
83
def abspath (self ):
83
- return join_path_native (self .odb .root_path (), self .path )
84
+ return join_path_native (self .odb .git_dir (), self .path )
84
85
85
86
@classmethod
86
87
def _get_packed_refs_path (cls , odb ):
87
- return join (odb .root_path (), 'packed-refs' )
88
+ return join (odb .git_dir (), 'packed-refs' )
88
89
89
90
@classmethod
90
91
def _iter_packed_refs (cls , odb ):
@@ -137,7 +138,7 @@ def _get_ref_info(cls, odb, ref_path):
137
138
point to, or None"""
138
139
tokens = None
139
140
try :
140
- fp = open (join (odb .root_path (), ref_path ), 'r' )
141
+ fp = open (join (odb .git_dir (), ref_path ), 'r' )
141
142
value = fp .read ().rstrip ()
142
143
fp .close ()
143
144
tokens = value .split (" " )
@@ -216,7 +217,7 @@ def _get_commit(self):
216
217
obj = obj .object
217
218
#END dereference tag
218
219
219
- if obj .type != Commit .type :
220
+ if obj .type != self . CommitCls .type :
220
221
raise TypeError ("Symbolic Reference pointed to object %r, commit was required" % obj )
221
222
#END handle type
222
223
return obj
@@ -229,13 +230,13 @@ def set_commit(self, commit, logmsg = None):
229
230
:return: self"""
230
231
# check the type - assume the best if it is a base-string
231
232
is_invalid_type = False
232
- if isinstance (commit , Object ):
233
- is_invalid_type = commit .type != Commit .type
233
+ if isinstance (commit , self . ObjectCls ):
234
+ is_invalid_type = commit .type != self . CommitCls .type
234
235
elif isinstance (commit , SymbolicReference ):
235
- is_invalid_type = commit .object .type != Commit .type
236
+ is_invalid_type = commit .object .type != self . CommitCls .type
236
237
else :
237
238
try :
238
- is_invalid_type = self .odb .rev_parse (commit ).type != Commit .type
239
+ is_invalid_type = self .odb .rev_parse (commit ).type != self . CommitCls .type
239
240
except BadObject :
240
241
raise ValueError ("Invalid object: %s" % commit )
241
242
#END handle exception
@@ -286,7 +287,7 @@ def set_reference(self, ref, logmsg = None):
286
287
obj = None
287
288
if isinstance (ref , SymbolicReference ):
288
289
write_value = "ref: %s" % ref .path
289
- elif isinstance (ref , Object ):
290
+ elif isinstance (ref , self . ObjectCls ):
290
291
obj = ref
291
292
write_value = ref .hexsha
292
293
elif isinstance (ref , basestring ):
@@ -414,7 +415,7 @@ def delete(cls, odb, path):
414
415
or just "myreference", hence 'refs/' is implied.
415
416
Alternatively the symbolic reference to be deleted"""
416
417
full_ref_path = cls .to_full_path (path )
417
- abs_path = join (odb .root_path (), full_ref_path )
418
+ abs_path = join (odb .git_dir (), full_ref_path )
418
419
if exists (abs_path ):
419
420
os .remove (abs_path )
420
421
else :
@@ -467,7 +468,7 @@ def _create(cls, odb, path, resolve, reference, force, logmsg=None):
467
468
corresponding object and a detached symbolic reference will be created
468
469
instead"""
469
470
full_ref_path = cls .to_full_path (path )
470
- abs_ref_path = join (odb .root_path (), full_ref_path )
471
+ abs_ref_path = join (odb .git_dir (), full_ref_path )
471
472
472
473
# figure out target data
473
474
target = reference
@@ -539,8 +540,8 @@ def rename(self, new_path, force=False):
539
540
if self .path == new_path :
540
541
return self
541
542
542
- new_abs_path = join (self .odb .root_path (), new_path )
543
- cur_abs_path = join (self .odb .root_path (), self .path )
543
+ new_abs_path = join (self .odb .git_dir (), new_path )
544
+ cur_abs_path = join (self .odb .git_dir (), self .path )
544
545
if isfile (new_abs_path ):
545
546
if not force :
546
547
# if they point to the same file, its not an error
@@ -570,7 +571,7 @@ def _iter_items(cls, odb, common_path = None):
570
571
571
572
# walk loose refs
572
573
# Currently we do not follow links
573
- for root , dirs , files in os .walk (join_path_native (odb .root_path (), common_path )):
574
+ for root , dirs , files in os .walk (join_path_native (odb .git_dir (), common_path )):
574
575
if 'refs/' not in root : # skip non-refs subfolders
575
576
refs_id = [ i for i ,d in enumerate (dirs ) if d == 'refs' ]
576
577
if refs_id :
@@ -579,7 +580,7 @@ def _iter_items(cls, odb, common_path = None):
579
580
580
581
for f in files :
581
582
abs_path = to_native_path_linux (join_path (root , f ))
582
- rela_paths .add (abs_path .replace (to_native_path_linux (odb .root_path ()) + '/' , "" ))
583
+ rela_paths .add (abs_path .replace (to_native_path_linux (odb .git_dir ()) + '/' , "" ))
583
584
# END for each file in root directory
584
585
# END for each directory to walk
585
586
0 commit comments