Skip to contentSkip to conversation

parsecvs tool now creates git repositories

DISCUSSION Keith Packard 9 participants 22 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

I've hacked in cheesy system(3) calls to invoke various git tools to create a git repository from a parsed cvs repository. It's about the same speed as git-cvsimport now.

The UI is a total disaster, sufficient for testing. You must create an Authors file in the current directory which looks like the git-cvsimport authors file. You must also have a edit-change-log program in your path which edits the commit message in place. /bin/true will work if you don't need to edit the messages.

I should clearly steal the existing git-cvsimport command line arguments and use those.

This tool successfully, and usefully, imports the X.org xserver CVS repository, along with correctly importing several other repositories I've tried. It doesn't quite manage to compute correct branch points for the postgresql CVS repository, so there is clearly work remaining to be done.

CVS - your code's worst nightmare.

Signature · 1 line
[email protected]
#1 lore raw
Quoted 5 lines · Keith Packard

The UI is a total disaster, sufficient for testing. You must create an Authors file in the current directory which looks like the git-cvsimport authors file. You must also have a edit-change-log program in your path which edits the commit message in place. /bin/true will work if you don't need to edit the messages.

Well, at least this sounds quite promising. I'll give it a run once I've arrived back home on the Binutils repository.

MfG, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 für einen Freien Staat voll Freier Bürger"  | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#2 lore raw
Quoted 9 lines · Jan-Benedict Glaw
Quoted 5 lines · Keith Packard

The UI is a total disaster, sufficient for testing. You must create an Authors file in the current directory which looks like the git-cvsimport authors file. You must also have a edit-change-log program in your path which edits the commit message in place. /bin/true will work if you don't need to edit the messages.

Well, at least this sounds quite promising. I'll give it a run once I've arrived back home on the Binutils repository.

Doesn't build for me:

jbglaw@bixie:~/vax/gittish/parsecvs$ make clean
rm -f gram.o lex.o parsecvs.o cvsutil.o revlist.o atom.o revcvs.o git.o y.tab.h gram.c parsecvs
jbglaw@bixie:~/vax/gittish/parsecvs$ make
yacc -d gram.y 
mv -f y.tab.c gram.c
cc -O0 -g -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing   -c -o gram.o gram.c
cc -O0 -g -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing   -c -o lex.o lex.c
lex.l: In function ‘yylex’:
lex.l:69: warning: implicit declaration of function ‘yyget_lineno’
lex.l:69: warning: nested extern declaration of ‘yyget_lineno’
<stdout>: At top level:
<stdout>:1747: warning: no previous prototype for ‘yyget_lineno’
<stdout>:1756: warning: no previous prototype for ‘yyget_in’
<stdout>:1764: warning: no previous prototype for ‘yyget_out’
<stdout>:1772: warning: no previous prototype for ‘yyget_leng’
<stdout>:1781: warning: no previous prototype for ‘yyget_text’
<stdout>:1790: warning: no previous prototype for ‘yyset_lineno’
<stdout>:1802: warning: no previous prototype for ‘yyset_in’
<stdout>:1807: warning: no previous prototype for ‘yyset_out’
<stdout>:1812: warning: no previous prototype for ‘yyget_debug’
<stdout>:1817: warning: no previous prototype for ‘yyset_debug’
<stdout>:1823: warning: no previous prototype for ‘yylex_destroy’
lex.l: In function ‘parse_data’:
lex.l:90: error: ‘yytext_ptr’ undeclared (first use in this function)
lex.l:90: error: (Each undeclared identifier is reported only once
lex.l:90: error: for each function it appears in.)
make: *** [lex.o] Error 1

MfG, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 für einen Freien Staat voll Freier Bürger"  | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#3 lore raw
Quoted 5 lines · Jan-Benedict Glaw

lex.l: In function ‘parse_data’:
lex.l:90: error: ‘yytext_ptr’ undeclared (first use in this function) lex.l:90: error: (Each undeclared identifier is reported only once lex.l:90: error: for each function it appears in.)
make: *** [lex.o] Error 1

I think this is a bug in your version of flex; I'm using standard lex conventions here. I don't know how to make it work for you.

Signature · 1 line
[email protected]
#4 lore raw
Quoted 9 lines · Keith Packard
Quoted 5 lines · Jan-Benedict Glaw

lex.l: In function ‘parse_data’:
lex.l:90: error: ‘yytext_ptr’ undeclared (first use in this function) lex.l:90: error: (Each undeclared identifier is reported only once lex.l:90: error: for each function it appears in.)
make: *** [lex.o] Error 1

I think this is a bug in your version of flex; I'm using standard lex conventions here. I don't know how to make it work for you.

It compiles for me with this patch (thanks to Linus for the hint):

Makefile +2 -1
index 639353a..b8f5014 100644
@@ -3,7 +3,8 @@ GCC_WARNINGS2=-Wmissing-prototypes -Wmis
 GCC_WARNINGS3=-Wnested-externs -fno-strict-aliasing
 GCC_WARNINGS=$(GCC_WARNINGS1) $(GCC_WARNINGS2) $(GCC_WARNINGS3)
 CFLAGS=-O0 -g $(GCC_WARNINGS)
-YFLAGS=-d
+YFLAGS=-d -l
+LFLAGS=-l
 
 SRCS=gram.y lex.l cvs.h parsecvs.c cvsutil.c revlist.c atom.c revcvs.c git.c
 

Would you please verify that it doesn't break things for you?

Thanks, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 für einen Freien Staat voll Freier Bürger"  | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#5 lore raw

Makefile GCC_WARNINGS2=-Wmissing-prototypes -Wmis · line 7

Quoted 3 lines · Jan-Benedict Glaw
Makefile +2 -1
-YFLAGS=-d
+YFLAGS=-d -l
+LFLAGS=-l

Works for me too; thanks for the fix.

Signature · 1 line
[email protected]
#6 lore raw
Quoted 7 lines · Keith Packard

Makefile GCC_WARNINGS2=-Wmissing-prototypes -Wmis · line 7

Quoted 3 lines · Jan-Benedict Glaw
Makefile +2 -1
-YFLAGS=-d
+YFLAGS=-d -l
+LFLAGS=-l

Works for me too; thanks for the fix.

Well, -l *kinda* works; it places a limit on the maximum token size. And, unlike 'lex', 'flex' places all input into the token buffer, even if handled outside the usual lexer loop. So, my external function that sucked up file contents was losing.

I switched it over to doing one-at-a-time reads from the input file, now the external data function can directly use stdio. This eliminates all calls to 'input' and 'unput' which should make it work for everyone now.

flex -- it's like lex, except less flexible.

Signature · 1 line
[email protected]
#7 lore raw
In reply to Jan-Benedict Glaw
Quoted 7 lines · Jan-Benedict Glaw
Quoted 2 lines · Keith Packard

I think this is a bug in your version of flex; I'm using standard lex conventions here. I don't know how to make it work for you.

It compiles for me with this patch (thanks to Linus for the hint):

Makefile +0 -0

[...]

Quoted 1 line

Would you please verify that it doesn't break things for you?

Almost there. I applied your patch and ran "make clean", but the Makefile forgets to remove lex.c. Here's an updated patch:

Makefile +3 -2
index 639353a..5651e70 100644
@@ -3,7 +3,8 @@ GCC_WARNINGS2=-Wmissing-prototypes -Wmis
 GCC_WARNINGS3=-Wnested-externs -fno-strict-aliasing
 GCC_WARNINGS=$(GCC_WARNINGS1) $(GCC_WARNINGS2) $(GCC_WARNINGS3)
 CFLAGS=-O0 -g $(GCC_WARNINGS)
-YFLAGS=-d
+YFLAGS=-d -l
+LFLAGS=-l
 
 SRCS=gram.y lex.l cvs.h parsecvs.c cvsutil.c revlist.c atom.c revcvs.c git.c
 
@@ -20,4 +21,4 @@ lex.o: lex.c
 y.tab.h: gram.c
 
 clean:
-	rm -f $(OBJS) y.tab.h gram.c parsecvs
+	rm -f $(OBJS) y.tab.h gram.c lex.c parsecvs

It compiles! Ship it! ;-)

Erik

Signature · 2 lines
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
#8 lore raw
In reply to Keith Packard
Quoted 10 lines · Keith Packard
Quoted 5 lines · Jan-Benedict Glaw

lex.l: In function ÿÿparse_dataÿÿ:
lex.l:90: error: ÿÿyytext_ptrÿÿ undeclared (first use in this function) lex.l:90: error: (Each undeclared identifier is reported only once lex.l:90: error: for each function it appears in.)
make: *** [lex.o] Error 1

I think this is a bug in your version of flex; I'm using standard lex conventions here. I don't know how to make it work for you.

I need something like this to make it work with flex/lex..

The "-l" tells flex to be more traditional.

The "clean" rule is obvious.

And the "yylineno" is a lot more traditional than yyget_lineno(), which doesn't work for me at all. I think that's some issue with flex' support for re-entrant parsers.

Whether it works after this, I dunno. But at least it compiles.

Linus

---

Makefile +2 -1
index 639353a..c7e04a5 100644
@@ -4,6 +4,7 @@ GCC_WARNINGS3=-Wnested-externs -fno-stri
 GCC_WARNINGS=$(GCC_WARNINGS1) $(GCC_WARNINGS2) $(GCC_WARNINGS3)
 CFLAGS=-O0 -g $(GCC_WARNINGS)
 YFLAGS=-d
+LFLAGS=-l
 
 SRCS=gram.y lex.l cvs.h parsecvs.c cvsutil.c revlist.c atom.c revcvs.c git.c
 
@@ -20,4 +21,4 @@ lex.o: lex.c
 y.tab.h: gram.c
 
 clean:
-	rm -f $(OBJS) y.tab.h gram.c parsecvs
+	rm -f $(OBJS) y.tab.h gram.c parsecvs lex.c
lex.l +2 -4
index 39cafb0..c7833a4 100644
@@ -65,8 +65,7 @@ parse_data (int save);
 \t				;
 \n				;
 .				{ 
-				    fprintf (stderr, "%s: (%d) ignoring %c\n", 
-					     yyfilename, yyget_lineno (),
+				    fprintf (stderr, "%s: (%d) ignoring %c\n", yyfilename, yylineno,
 					     yytext[0]);
 				}
 %%
@@ -146,8 +145,7 @@ lex_date (cvs_number *n)
 	d = mktime (&tm);
 	if (d == 0) {
 	    int i;
-	    fprintf (stderr, "%s: (%d) unparsable date: ", yyfilename,
-		     yyget_lineno ());
+	    fprintf (stderr, "%s: (%d) unparsable date: ", yyfilename, yylineno);
 	    for (i = 0; i < n->c; i++) {
 		if (i) fprintf (stderr, ".");
 		fprintf (stderr, "%d", n->n[i]);
#9 lore raw
In reply to Keith Packard
Quoted 8 lines · Keith Packard

The UI is a total disaster, sufficient for testing. You must create an Authors file in the current directory which looks like the git-cvsimport authors file. You must also have a edit-change-log program in your path which edits the commit message in place. /bin/true will work if you don't need to edit the messages.

I should clearly steal the existing git-cvsimport command line arguments and use those.

What is the current way to use it? I get the impression it reads raw ,v files, but how do I get along with a remote CVS repository?

Erik

Signature · 2 lines
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
#10 lore raw
Quoted 7 lines · Erik Mouw
Quoted 6 lines · Keith Packard

The UI is a total disaster, sufficient for testing. You must create an Authors file in the current directory which looks like the git-cvsimport authors file. You must also have a edit-change-log program in your path which edits the commit message in place. /bin/true will work if you don't need to edit the messages.

Quoted 5 lines
Quoted 2 lines

I should clearly steal the existing git-cvsimport command line arguments and use those.

What is the current way to use it? I get the impression it reads raw ,v files, but how do I get along with a remote CVS repository?

You can't. You need to create a local copy of the repository. There is a tool which can do that using the cvs protocol, but I don't recall the name.

It turns out that parsing the ,v files directly is both faster and more accurate than attempting to interpret the output of cvs log.

Signature · 1 line
[email protected]
#11 lore raw
Quoted 3 lines · Keith Packard

You can't. You need to create a local copy of the repository. There is a tool which can do that using the cvs protocol, but I don't recall the name.

I believe you're thinking of CVSSuck:
http://cvs.m17n.org/~akr/cvssuck/

-Peff

#12 lore raw
In reply to Erik Mouw
Quoted 7 lines · Erik Mouw
Quoted 6 lines · Keith Packard

The UI is a total disaster, sufficient for testing. You must create an Authors file in the current directory which looks like the git-cvsimport authors file. You must also have a edit-change-log program in your path which edits the commit message in place. /bin/true will work if you don't need to edit the messages.

Quoted 7 lines
Quoted 2 lines

I should clearly steal the existing git-cvsimport command line arguments and use those.

What is the current way to use it? I get the impression it reads raw ,v files, but how do I get along with a remote CVS repository?

From the comments on #git, parsecvs reads raw ,v files for creating history

tree, then uses 'cvs co ...' for getting the contents.

If you have access to remote CVS repository, it was suggested to use either cvsclone or cvsup.

Signature · 2 lines
Jakub Narebski
Warsaw, Poland
#13 lore raw
Quoted 2 lines · Jakub Narebski

From the comments on #git, parsecvs reads raw ,v files for creating history tree, then uses 'cvs co ...' for getting the contents.

It's not using cvs co, it's using the rcs 'co' command. I will probably fix it to just generate the files directly as that will be a lot faster. If there was a git command to create blobs directly from file contents, it would be faster still as I could create all of the blobs for a particular file in one pass and then just build trees in the index out of those.

Signature · 1 line
[email protected]
#14 lore raw
In reply to Erik Mouw
Quoted 7 lines · Erik Mouw
Quoted 6 lines · Keith Packard

The UI is a total disaster, sufficient for testing. You must create an Authors file in the current directory which looks like the git-cvsimport authors file. You must also have a edit-change-log program in your path which edits the commit message in place. /bin/true will work if you don't need to edit the messages.

Quoted 5 lines
Quoted 2 lines

I should clearly steal the existing git-cvsimport command line arguments and use those.

What is the current way to use it? I get the impression it reads raw ,v files, but how do I get along with a remote CVS repository?

cvsclone, recently released, might be what you are after.

I've only used it on my own CVS repositories so I've no idea just how hard it hits the remote side.

<http://freshmeat.net/projects/cvsclone/>

Anand

#15 lore raw
In reply to Keith Packard

Keith,

Looks nifty. Though I thought you'd go for writing a smarter cvsps, so that git-cvsimport could take advantage of it.

Looks like I'll have to brush up on my C to get to play... :-(

m

#16 lore raw
Quoted 2 lines · Martin Langhoff

Looks nifty. Though I thought you'd go for writing a smarter cvsps, so that git-cvsimport could take advantage of it.

Once I had the change set information sitting in memory, it was far easier to just generate the appropriate git commands than attempt to recreate the cvsps output format...

Quoted 1 line

Looks like I'll have to brush up on my C to get to play... :-(

Trust me, it wasn't because I wanted to replace git-cvsimport; it's solely that cvsps was generating complete garbage for most of my repositories.

My new tool isn't perfect yet; it isn't getting exactly the expected answers for the postgresql repository, but it's working perfectly for my X server one.

Signature · 1 line
[email protected]
#17 lore raw
Quoted 3 lines · Keith Packard

Trust me, it wasn't because I wanted to replace git-cvsimport; it's solely that cvsps was generating complete garbage for most of my repositories.

Oh, I don't mind -- we may as well bury cvsimport but I can't do C like I can do Perl, and I surely want to help on this one.

Quoted 3 lines

My new tool isn't perfect yet; it isn't getting exactly the expected answers for the postgresql repository, but it's working perfectly for my X server one.

Meh, had you done it in Perl, I'd be helping you with the Pg repo, attic files and ensuring that files created on a branch and then put into HEAD are handled gracefully. (But you'll get Linus' and Junio's attention. Smarty cookie.)

Does it run incrementally? Can it discover non-binary files and pass -kk?

cheers,

martin

#18 lore raw
Quoted 4 lines · Martin Langhoff

Meh, had you done it in Perl, I'd be helping you with the Pg repo, attic files and ensuring that files created on a branch and then put into HEAD are handled gracefully. (But you'll get Linus' and Junio's attention. Smarty cookie.)

I think those parts are working correctly, I've had plenty of examples of that kind of adventure.

Quoted 1 line

Does it run incrementally? Can it discover non-binary files and pass -kk?

It doesn't run incrementally, and it unconditionally passes -kk. It's currently using rcs to check out versions of the files, so it should deal with binary content as well as rcs does. Is there something magic I need to do here? Like for DOS?

Signature · 1 line
[email protected]
#19 lore raw
Quoted 9 lines · Keith Packard
Quoted 4 lines · Martin Langhoff

Meh, had you done it in Perl, I'd be helping you with the Pg repo, attic files and ensuring that files created on a branch and then put into HEAD are handled gracefully. (But you'll get Linus' and Junio's attention. Smarty cookie.)

I think those parts are working correctly, I've had plenty of examples of that kind of adventure.

Cool. What's the matter with the Pg repo? (Where can I get hold of that repo?)

Quoted 3 lines
Quoted 1 line

Does it run incrementally? Can it discover non-binary files and pass -kk?

It doesn't run incrementally, and it unconditionally passes -kk. It's

I thought that the .git-cvs directory it created was to be able to run incrementally (btw, I think it's fair game to create subdirs inside .git for this kind of status-tracking). And passing -kk uncoditionally is destructive in some cases (I know... git-cvsimport does it, and I want to fix that). If you can ask rcs about the mode if the file and not pass -kk for binary files...

Quoted 3 lines

currently using rcs to check out versions of the files, so it should deal with binary content as well as rcs does. Is there something magic I need to do here? Like for DOS?

We'll let DOS take care of itself ;)

m

#20 lore raw
Quoted 1 line · Martin Langhoff

Cool. What's the matter with the Pg repo? (Where can I get hold of that repo?)

As usual, the detection of branch locations is messed up.

The postgresql CVS tree is available at:

rsync anoncvs.postgresql.org::pgsql-cvs/* postgresql.cvs

It's a fairly hefty 300M.

Quoted 10 lines
Quoted 3 lines
Quoted 1 line

Does it run incrementally? Can it discover non-binary files and pass -kk?

It doesn't run incrementally, and it unconditionally passes -kk. It's

I thought that the .git-cvs directory it created was to be able to run incrementally (btw, I think it's fair game to create subdirs inside .git for this kind of status-tracking). And passing -kk uncoditionally is destructive in some cases (I know... git-cvsimport does it, and I want to fix that). If you can ask rcs about the mode if the file and not pass -kk for binary files...

nah, the .git-cvs directory is purely for debugging; I leave the various command outputs there so I can see what went wrong.

I don't really have a good idea of how we'd do this process incrementally; that's not something I am personally interested in either, I want to run screaming from CVS as fast as I can at this point.

Quoted 5 lines
Quoted 3 lines

currently using rcs to check out versions of the files, so it should deal with binary content as well as rcs does. Is there something magic I need to do here? Like for DOS?

We'll let DOS take care of itself ;)

I did discover that rcs has less sophisticated keyword substitution than cvs; not having any ability to customize stuff.

I guess we need to figure out when to pass -ko and when to pass -kk. The other alternative I'd like to get around to trying is to directly generate all of the revision contents from the ,v file.

I've just changed parsecvs to generate blobs for every revision in each ,v file right after they're read in; putting the necessary code right into parsecvs should be reasonably straightforward; we don't need the multi-patch logic as we do want to compute each intermediate version of the file.

With the blobs all generated, the rest of the operation is a simple matter of building suitable indices and creating commits out of them. That's a reasonably fast operation now as it doesn't manipulate any file contents. Plus, I can do all of the index operations using a single git-update-index command, so I eliminate a pile of forking.

Doing the file revision generation in-line would allow us to eliminate most of the remaining forks; we'd run one git-hash-object per file (or so), then a git-update-index, git-write-tree and git-commit-tree per resulting commit.

Signature · 1 line
[email protected]
#21 lore raw
Quoted 5 lines · Keith Packard

I've just changed parsecvs to generate blobs for every revision in each ,v file right after they're read in; putting the necessary code right into parsecvs should be reasonably straightforward; we don't need the multi-patch logic as we do want to compute each intermediate version of the file.

If you want to go really fast without extra fork, are writing it in C, and have the data for blob in core, you could link with libgit.a and call write_sha1_file() yourself:

	unsigned char sha1[20];
        void *buf;
        unsigned long len;

	write_sha1_file(buf, len, "blob", sha1);

instead of forking "hash-object -w". You feed your blob data in buf, with its length in len, and you will get the blob object name back in sha1[]. buf is owned by you and after write_sha1_file() returns it is safe for you to scribble over it or free() it. sha1[] stores binary object name (20 bytes, not 40-byte hexadecimal), and you can use the helper function sha1_to_hex() if you need a hex representation:

	char *sha1_to_hex(sha1)

which returns a pointer to a static buffer that is valid until next call to sha1_to_hex(), so you need to strdup it if you want to retain it.