Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
hg-git
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mercurial
hg-git
Commits
2548735d
Commit
2548735d
authored
15 years ago
by
Scott Chacon
Browse files
Options
Downloads
Patches
Plain Diff
will now more or less correctly determine a changelist from a git commit
parent
89992b6d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dulwich/objects.py
+3
-12
3 additions, 12 deletions
dulwich/objects.py
dulwich/repo.py
+50
-0
50 additions, 0 deletions
dulwich/repo.py
git_handler.py
+7
-6
7 additions, 6 deletions
git_handler.py
with
60 additions
and
18 deletions
dulwich/objects.py
+
3
−
12
View file @
2548735d
...
@@ -362,6 +362,9 @@
...
@@ -362,6 +362,9 @@
"""
Return a list of tuples describing the tree entries
"""
"""
Return a list of tuples describing the tree entries
"""
return
[(
mode
,
name
,
hexsha
)
for
(
name
,
(
mode
,
hexsha
))
in
self
.
_entries
.
iteritems
()]
return
[(
mode
,
name
,
hexsha
)
for
(
name
,
(
mode
,
hexsha
))
in
self
.
_entries
.
iteritems
()]
def
entry
(
self
,
name
):
return
self
.
_entries
[
name
]
def
iteritems
(
self
):
def
iteritems
(
self
):
for
name
in
sorted
(
self
.
_entries
.
keys
()):
for
name
in
sorted
(
self
.
_entries
.
keys
()):
yield
name
,
self_entries
[
name
][
0
],
self
.
_entries
[
name
][
1
]
yield
name
,
self_entries
[
name
][
0
],
self
.
_entries
[
name
][
1
]
...
@@ -501,18 +504,6 @@
...
@@ -501,18 +504,6 @@
self
.
_text
+=
"
\n
"
# There must be a new line after the headers
self
.
_text
+=
"
\n
"
# There must be a new line after the headers
self
.
_text
+=
self
.
_message
self
.
_text
+=
self
.
_message
def
getfile
(
self
,
f
):
import
random
dt
=
"
file contents:
"
+
str
(
random
.
randrange
(
1
,
100
))
print
dt
return
dt
def
getmode
(
self
,
f
):
return
""
def
getfiles
(
self
):
return
[
'
test
'
]
@property
@property
def
tree
(
self
):
def
tree
(
self
):
"""
Returns the tree that is the state of this commit
"""
"""
Returns the tree that is the state of this commit
"""
...
...
This diff is collapsed.
Click to expand it.
dulwich/repo.py
+
50
−
0
View file @
2548735d
...
@@ -305,6 +305,56 @@
...
@@ -305,6 +305,56 @@
def
get_blob
(
self
,
sha
):
def
get_blob
(
self
,
sha
):
return
self
.
_get_object
(
sha
,
Blob
)
return
self
.
_get_object
(
sha
,
Blob
)
# takes a commit object and a file path
# returns the contents of that file at that commit
# TODO : make this recursive - any file in a subdir wont be found here
def
get_file
(
self
,
commit
,
f
):
otree
=
self
.
tree
(
commit
.
tree
)
parts
=
f
.
split
(
'
/
'
)
for
part
in
parts
:
(
mode
,
sha
)
=
otree
.
entry
(
part
)
obj
=
self
.
get_object
(
sha
)
if
isinstance
(
obj
,
Blob
):
return
(
mode
,
sha
,
obj
.
_text
)
elif
isinstance
(
obj
,
Tree
):
otree
=
obj
# takes a commit and returns an array of the files that were changed
# between that commit and it's parents
# TODO : optimize this, it's horrible
# TODO : if no parents, return all files
def
get_files_changed
(
self
,
commit
):
def
filenames
(
basetree
,
comptree
,
prefix
):
changes
=
list
()
csha
=
None
ctree
=
None
for
(
bmode
,
bname
,
bsha
)
in
basetree
.
entries
():
bobj
=
self
.
get_object
(
bsha
)
if
comptree
:
(
cmode
,
csha
)
=
comptree
.
entry
(
bname
)
if
csha
!=
bsha
:
if
isinstance
(
bobj
,
Blob
):
changes
.
append
(
prefix
+
bname
)
elif
isinstance
(
bobj
,
Tree
):
if
csha
:
ctree
=
self
.
get_object
(
csha
)
changes
.
extend
(
filenames
(
bobj
,
ctree
,
prefix
+
bname
+
'
/
'
))
# TODO: handle removals?
return
changes
all_changes
=
list
()
otree
=
self
.
tree
(
commit
.
tree
)
if
len
(
commit
.
parents
)
==
0
:
all_changes
=
filenames
(
otree
,
None
,
''
)
for
parent
in
commit
.
parents
:
pcommit
=
self
.
commit
(
parent
)
ptree
=
self
.
tree
(
pcommit
.
tree
)
all_changes
.
extend
(
filenames
(
otree
,
ptree
,
''
))
return
all_changes
def
revision_history
(
self
,
head
):
def
revision_history
(
self
,
head
):
"""
Returns a list of the commits reachable from head.
"""
Returns a list of the commits reachable from head.
...
...
This diff is collapsed.
Click to expand it.
git_handler.py
+
7
−
6
View file @
2548735d
...
@@ -81,10 +81,9 @@
...
@@ -81,10 +81,9 @@
# import each of the commits, oldest first
# import each of the commits, oldest first
for
commit
in
convert_list
:
for
commit
in
convert_list
:
print
"
commit: %s
"
%
sha
self
.
import_git_commit
(
commit
)
self
.
import_git_commit
(
commit
)
# TODO : update Hg bookmarks (possibly named heads?)
# TODO : update Hg bookmarks (possibly named heads?)
print
bookmarks
.
parse
(
self
.
repo
)
print
bookmarks
.
parse
(
self
.
repo
)
def
import_git_commit
(
self
,
commit
):
def
import_git_commit
(
self
,
commit
):
...
@@ -85,10 +84,10 @@
...
@@ -85,10 +84,10 @@
self
.
import_git_commit
(
commit
)
self
.
import_git_commit
(
commit
)
# TODO : update Hg bookmarks (possibly named heads?)
# TODO : update Hg bookmarks (possibly named heads?)
print
bookmarks
.
parse
(
self
.
repo
)
print
bookmarks
.
parse
(
self
.
repo
)
def
import_git_commit
(
self
,
commit
):
def
import_git_commit
(
self
,
commit
):
print
commit
.
parents
print
"
importing:
"
+
commit
.
id
# TODO : have to handle merge contexts at some point (two parent files, etc)
# TODO : have to handle merge contexts at some point (two parent files, etc)
def
getfilectx
(
repo
,
memctx
,
f
):
def
getfilectx
(
repo
,
memctx
,
f
):
...
@@ -93,7 +92,7 @@
...
@@ -93,7 +92,7 @@
# TODO : have to handle merge contexts at some point (two parent files, etc)
# TODO : have to handle merge contexts at some point (two parent files, etc)
def
getfilectx
(
repo
,
memctx
,
f
):
def
getfilectx
(
repo
,
memctx
,
f
):
data
=
comm
it
.
getfile
(
f
)
(
e
,
sha
,
data
)
=
self
.
g
it
.
get
_
file
(
commit
,
f
)
e
=
commit
.
get
mode
(
f
)
e
=
''
# TODO : make this a real
mode
return
context
.
memfilectx
(
f
,
data
,
'
l
'
in
e
,
'
x
'
in
e
,
None
)
return
context
.
memfilectx
(
f
,
data
,
'
l
'
in
e
,
'
x
'
in
e
,
None
)
p1
=
"
0
"
*
40
p1
=
"
0
"
*
40
...
@@ -109,7 +108,9 @@
...
@@ -109,7 +108,9 @@
# TODO : map extra parents to the extras file
# TODO : map extra parents to the extras file
pass
pass
files
=
commit
.
getfiles
()
files
=
self
.
git
.
get_files_changed
(
commit
)
print
files
# get a list of the changed, added, removed files
# get a list of the changed, added, removed files
extra
=
{}
extra
=
{}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment