Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
7eeec8f2
Commit
7eeec8f2
authored
May 24, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/network: consistently use tabs for indentation
parent
88bfe790
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
126 deletions
+126
-126
examples/network/fetch.c
+50
-50
examples/network/index-pack.c
+76
-76
No files found.
examples/network/fetch.c
View file @
7eeec8f2
...
...
@@ -60,54 +60,54 @@ int update_cb(const char *refname, const git_oid *a, const git_oid *b)
int
fetch
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
git_remote
*
remote
=
NULL
;
git_off_t
bytes
=
0
;
git_indexer_stats
stats
;
pthread_t
worker
;
struct
dl_data
data
;
// Figure out whether it's a named remote or a URL
printf
(
"Fetching %s
\n
"
,
argv
[
1
]);
if
(
git_remote_load
(
&
remote
,
repo
,
argv
[
1
])
<
0
)
{
if
(
git_remote_new
(
&
remote
,
repo
,
NULL
,
argv
[
1
],
NULL
)
<
0
)
return
-
1
;
}
// Set up the information for the background worker thread
data
.
remote
=
remote
;
data
.
bytes
=
&
bytes
;
data
.
stats
=
&
stats
;
data
.
ret
=
0
;
data
.
finished
=
0
;
memset
(
&
stats
,
0
,
sizeof
(
stats
));
pthread_create
(
&
worker
,
NULL
,
download
,
&
data
);
// Loop while the worker thread is still running. Here we show processed
// and total objects in the pack and the amount of received
// data. Most frontends will probably want to show a percentage and
// the download rate.
do
{
usleep
(
10000
);
printf
(
"
\r
Received %d/%d objects in %d bytes"
,
stats
.
processed
,
stats
.
total
,
bytes
);
}
while
(
!
data
.
finished
);
printf
(
"
\r
Received %d/%d objects in %d bytes
\n
"
,
stats
.
processed
,
stats
.
total
,
bytes
);
// Disconnect the underlying connection to prevent from idling.
git_remote_disconnect
(
remote
);
// Update the references in the remote's namespace to point to the
// right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been
// changed but all the neede objects are available locally.
if
(
git_remote_update_tips
(
remote
,
update_cb
)
<
0
)
return
-
1
;
git_remote_free
(
remote
);
return
0
;
on_error:
git_remote_free
(
remote
);
return
-
1
;
git_remote
*
remote
=
NULL
;
git_off_t
bytes
=
0
;
git_indexer_stats
stats
;
pthread_t
worker
;
struct
dl_data
data
;
// Figure out whether it's a named remote or a URL
printf
(
"Fetching %s
\n
"
,
argv
[
1
]);
if
(
git_remote_load
(
&
remote
,
repo
,
argv
[
1
])
<
0
)
{
if
(
git_remote_new
(
&
remote
,
repo
,
NULL
,
argv
[
1
],
NULL
)
<
0
)
return
-
1
;
}
// Set up the information for the background worker thread
data
.
remote
=
remote
;
data
.
bytes
=
&
bytes
;
data
.
stats
=
&
stats
;
data
.
ret
=
0
;
data
.
finished
=
0
;
memset
(
&
stats
,
0
,
sizeof
(
stats
));
pthread_create
(
&
worker
,
NULL
,
download
,
&
data
);
// Loop while the worker thread is still running. Here we show processed
// and total objects in the pack and the amount of received
// data. Most frontends will probably want to show a percentage and
// the download rate.
do
{
usleep
(
10000
);
printf
(
"
\r
Received %d/%d objects in %d bytes"
,
stats
.
processed
,
stats
.
total
,
bytes
);
}
while
(
!
data
.
finished
);
printf
(
"
\r
Received %d/%d objects in %d bytes
\n
"
,
stats
.
processed
,
stats
.
total
,
bytes
);
// Disconnect the underlying connection to prevent from idling.
git_remote_disconnect
(
remote
);
// Update the references in the remote's namespace to point to the
// right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been
// changed but all the neede objects are available locally.
if
(
git_remote_update_tips
(
remote
,
update_cb
)
<
0
)
return
-
1
;
git_remote_free
(
remote
);
return
0
;
on_error:
git_remote_free
(
remote
);
return
-
1
;
}
examples/network/index-pack.c
View file @
7eeec8f2
...
...
@@ -8,95 +8,95 @@
// the indexing to finish in a worker thread
int
index_cb
(
const
git_indexer_stats
*
stats
,
void
*
data
)
{
printf
(
"
\r
Processing %d of %d"
,
stats
->
processed
,
stats
->
total
);
printf
(
"
\r
Processing %d of %d"
,
stats
->
processed
,
stats
->
total
);
}
int
index_pack
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
git_indexer_stream
*
idx
;
git_indexer_stats
stats
=
{
0
,
0
};
int
error
,
fd
;
char
hash
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
ssize_t
read_bytes
;
char
buf
[
512
];
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"I need a packfile
\n
"
);
return
EXIT_FAILURE
;
}
if
(
git_indexer_stream_new
(
&
idx
,
".git"
)
<
0
)
{
puts
(
"bad idx"
);
return
-
1
;
}
if
((
fd
=
open
(
argv
[
1
],
0
))
<
0
)
{
perror
(
"open"
);
return
-
1
;
}
do
{
read_bytes
=
read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
read_bytes
<
0
)
break
;
if
((
error
=
git_indexer_stream_add
(
idx
,
buf
,
read_bytes
,
&
stats
))
<
0
)
goto
cleanup
;
printf
(
"
\r
Indexing %d of %d"
,
stats
.
processed
,
stats
.
total
);
}
while
(
read_bytes
>
0
);
if
(
read_bytes
<
0
)
{
error
=
-
1
;
perror
(
"failed reading"
);
goto
cleanup
;
}
if
((
error
=
git_indexer_stream_finalize
(
idx
,
&
stats
))
<
0
)
goto
cleanup
;
printf
(
"
\r
Indexing %d of %d
\n
"
,
stats
.
processed
,
stats
.
total
);
git_oid_fmt
(
hash
,
git_indexer_stream_hash
(
idx
));
puts
(
hash
);
cleanup:
close
(
fd
);
git_indexer_stream_free
(
idx
);
return
error
;
git_indexer_stream
*
idx
;
git_indexer_stats
stats
=
{
0
,
0
};
int
error
,
fd
;
char
hash
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
ssize_t
read_bytes
;
char
buf
[
512
];
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"I need a packfile
\n
"
);
return
EXIT_FAILURE
;
}
if
(
git_indexer_stream_new
(
&
idx
,
".git"
)
<
0
)
{
puts
(
"bad idx"
);
return
-
1
;
}
if
((
fd
=
open
(
argv
[
1
],
0
))
<
0
)
{
perror
(
"open"
);
return
-
1
;
}
do
{
read_bytes
=
read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
read_bytes
<
0
)
break
;
if
((
error
=
git_indexer_stream_add
(
idx
,
buf
,
read_bytes
,
&
stats
))
<
0
)
goto
cleanup
;
printf
(
"
\r
Indexing %d of %d"
,
stats
.
processed
,
stats
.
total
);
}
while
(
read_bytes
>
0
);
if
(
read_bytes
<
0
)
{
error
=
-
1
;
perror
(
"failed reading"
);
goto
cleanup
;
}
if
((
error
=
git_indexer_stream_finalize
(
idx
,
&
stats
))
<
0
)
goto
cleanup
;
printf
(
"
\r
Indexing %d of %d
\n
"
,
stats
.
processed
,
stats
.
total
);
git_oid_fmt
(
hash
,
git_indexer_stream_hash
(
idx
));
puts
(
hash
);
cleanup:
close
(
fd
);
git_indexer_stream_free
(
idx
);
return
error
;
}
int
index_pack_old
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
git_indexer
*
indexer
;
git_indexer_stats
stats
;
int
error
;
char
hash
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
git_indexer
*
indexer
;
git_indexer_stats
stats
;
int
error
;
char
hash
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"I need a packfile
\n
"
);
return
EXIT_FAILURE
;
}
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"I need a packfile
\n
"
);
return
EXIT_FAILURE
;
}
// Create a new indexer
error
=
git_indexer_new
(
&
indexer
,
argv
[
1
]);
if
(
error
<
0
)
return
error
;
// Create a new indexer
error
=
git_indexer_new
(
&
indexer
,
argv
[
1
]);
if
(
error
<
0
)
return
error
;
// Index the packfile. This function can take a very long time and
// should be run in a worker thread.
error
=
git_indexer_run
(
indexer
,
&
stats
);
if
(
error
<
0
)
return
error
;
// Index the packfile. This function can take a very long time and
// should be run in a worker thread.
error
=
git_indexer_run
(
indexer
,
&
stats
);
if
(
error
<
0
)
return
error
;
// Write the information out to an index file
error
=
git_indexer_write
(
indexer
);
// Write the information out to an index file
error
=
git_indexer_write
(
indexer
);
// Get the packfile's hash (which should become it's filename)
git_oid_fmt
(
hash
,
git_indexer_hash
(
indexer
));
puts
(
hash
);
// Get the packfile's hash (which should become it's filename)
git_oid_fmt
(
hash
,
git_indexer_hash
(
indexer
));
puts
(
hash
);
git_indexer_free
(
indexer
);
git_indexer_free
(
indexer
);
return
0
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment